|
Author
|
Message
|
|
The-any-Key
|
The-any-Key
Posted 7 Years Ago
|
|
Group: Forum Members
Last Active: 2 Years Ago
Posts: 356,
Visits: 1.9K
|
You can alos use the built in dialogs in PySide2. All you need is some scripts: # Basic import import RLPy import PySide2 from PySide2 import * from PySide2.shiboken2 import wrapInstance # Load UI files import os def get_save_filename_dialog(title, filter, default_filename): return PySide2.QtWidgets.QFileDialog.getSaveFileName(None,str(title),str(default_filename),str(filter)) def get_load_filename_dialog(title, filter, default_filename): return PySide2.QtWidgets.QFileDialog.getOpenFileName(None,str(title),str(default_filename),str(filter)) def save_file(filename, text): file = open(filename,'w') file.write(text) file.close() def load_file(filename): file = open(filename,'r') text=file.read() file.close() return text Here is how to create a load dialog and load the data: # Select file load_file=get_load_filename_dialog("Load dialog title","My file ending (*.mfe)","Default load name.mfe") if load_file[0]: # Get only filename load_filename=load_file[0] # Load file data_string=load_file(load_filename) Here is how to create a save data with a save dialog: # Open save file dialog save_filename=get_save_filename_dialog("Save dialog title","My file ending (*.mfe)","Default save name.mfe") # Check if provided filename if save_filename: save_file(save_filename[0],data_string)
iClone 7, 3DXchange 7 Pipeline, CC3 Pipeline, CT8 Pipeline, Iray, Live Face, iPhone Xr, Win 10, i9 9900K ~5GHz, Nvidia RTX 2080 8GB, 16GB Ram, M.2 SSD
|
|
|
|
|
Kelleytoons
|
Kelleytoons
Posted 7 Years Ago
|
|
Group: Forum Members
Last Active: 2 Years Ago
Posts: 9.2K,
Visits: 22.1K
|
Any, I'm not trying to either save or load files -- just get the file names. But I'm sure that info will help someone if they come across this thread.
Alienware Aurora R16, Win 11, i9-149000KF, 3.20GHz CPU, 64GB RAM, RTX 4090 (24GB), Samsung 870 Pro 8TB, Gen3 MVNe M-2 SSD, 4TBx2, 39" Alienware Widescreen Monitor Mike "ex-genius" Kelley
|
|
|
|
|
Kelleytoons
|
Kelleytoons
Posted 7 Years Ago
|
|
Group: Forum Members
Last Active: 2 Years Ago
Posts: 9.2K,
Visits: 22.1K
|
videodv (6/13/2019) Hi Mike
From the link above I had a tinkle with the code
import PySide2, RLPy, os from PySide2 import * from PySide2.QtWidgets import * from PySide2.shiboken2 import wrapInstance
class filedialogdemo(QWidget): def __init__(self, parent = None): super(filedialogdemo, self).__init__(parent) layout = QVBoxLayout() self.btn = QPushButton("QFileDialog static method demo") self.btn.clicked.connect(self.getfile) layout.addWidget(self.btn) self.le = QLabel("Hello") self.contents = QTextEdit() layout.addWidget(self.contents) self.setLayout(layout) self.setWindowTitle("File Dialog demo") def getfile(self): fname = QFileDialog.getOpenFileName(self, 'Open file Mike Kelly', 'c:\\',"Image files (*.jpg *.gif)") #self.le.setPixmap(QPixmap(fname))
global invisable_dialog
set_screen_widget = filedialogdemo()
invisable_dialog = RLPy.RUi.CreateRDialog() invisable_dialog.SetWindowTitle("Make Invisable")
#-- Create Pyside layout for RDialog --# pyside_dialog = wrapInstance(int(invisable_dialog.GetWindow()), QtWidgets.QDialog) sample_layout = pyside_dialog.layout()
#-- Assign the setscreenwidget class to PySide Dialog --# sample_layout.addWidget(set_screen_widget)
invisable_dialog.Show()
This produces a file dialog from within Icone and as you can see you can set the title ect.
Chris.
Okay, maybe it's the drugs I'm still taking for my knee, but I don't for the life of me see how to get the name of the file picked from that dialog. Do you have an example of that, Chris? That's all I really want to do, something like: file_name = getfiledialog("Set Title"). I can't imagine this is THAT difficult when it clearly isn't if I could use the supposedly built in tkinter (which I can't for some reason).
Alienware Aurora R16, Win 11, i9-149000KF, 3.20GHz CPU, 64GB RAM, RTX 4090 (24GB), Samsung 870 Pro 8TB, Gen3 MVNe M-2 SSD, 4TBx2, 39" Alienware Widescreen Monitor Mike "ex-genius" Kelley
|
|
|
|
|
The-any-Key
|
The-any-Key
Posted 7 Years Ago
|
|
Group: Forum Members
Last Active: 2 Years Ago
Posts: 356,
Visits: 1.9K
|
Kelleytoons (6/15/2019) Any,
I'm not trying to either save or load files -- just get the file names. But I'm sure that info will help someone if they come across this thread.You dont need to save or load the file. The get_save_filename_dialog and get_load_filename_dialog will just open a dialog where the user can select a file. Then the script will return the path in load_file[0] or save_filename[0] that you can use for whatever you need a filepath with. Maybe I am missing the idea. I thought you wanted a dialog where the user can select a file? Or do you just want to display a treeview with files and folders?
iClone 7, 3DXchange 7 Pipeline, CC3 Pipeline, CT8 Pipeline, Iray, Live Face, iPhone Xr, Win 10, i9 9900K ~5GHz, Nvidia RTX 2080 8GB, 16GB Ram, M.2 SSD
|
|
|
|
|
Kelleytoons
|
Kelleytoons
Posted 7 Years Ago
|
|
Group: Forum Members
Last Active: 2 Years Ago
Posts: 9.2K,
Visits: 22.1K
|
Sorry, Any -- after my surgery the drugs I'm taking are clouding my mind. For some reason all I could see was the file reading and writing you were doing. Let me play a bit -- I only have a limited amount of time I can sit upright but it would be nice to get this working.
Alienware Aurora R16, Win 11, i9-149000KF, 3.20GHz CPU, 64GB RAM, RTX 4090 (24GB), Samsung 870 Pro 8TB, Gen3 MVNe M-2 SSD, 4TBx2, 39" Alienware Widescreen Monitor Mike "ex-genius" Kelley
|
|
|
|
|
Kelleytoons
|
Kelleytoons
Posted 7 Years Ago
|
|
Group: Forum Members
Last Active: 2 Years Ago
Posts: 9.2K,
Visits: 22.1K
|
I may have to wait until the drugs wear off. I can get it to work... after a fashion. I cannot discern how it's choosing the directory to start in, which is Bad. I thought maybe I could do this by specifying a file pattern in the default file but this doesn't appear to do anything useful (using another drive letter just got me to my Dropbox and not even on that drive, which is really, really weird -- prior to that it just appeared to pick the Python directory I was running in iClone). I'll have to most likely learn Pyside, I see, but this drug-addled brain ain't gonna do that right now.
Alienware Aurora R16, Win 11, i9-149000KF, 3.20GHz CPU, 64GB RAM, RTX 4090 (24GB), Samsung 870 Pro 8TB, Gen3 MVNe M-2 SSD, 4TBx2, 39" Alienware Widescreen Monitor Mike "ex-genius" Kelley
|
|
|
|
|
videodv
|
videodv
Posted 7 Years Ago
|
|
Group: Forum Members
Last Active: 3 Years Ago
Posts: 342,
Visits: 12.0K
|
Hi Mike
The filename returned if you look at the example is fname
Chris
|
|
|
|
|
Kelleytoons
|
Kelleytoons
Posted 7 Years Ago
|
|
Group: Forum Members
Last Active: 2 Years Ago
Posts: 9.2K,
Visits: 22.1K
|
Okay, so thanks for all the help, Chris and Any. I think I have it working for what I want (I added the Dir to the example Any posted). I suspect I will have to learn Pyside if nothing more than to do some UI for things (there was a reason I ALWAYS left the UI and the print functions to my staff, as I hate that part of programming). But I at least have something workable for now.
Alienware Aurora R16, Win 11, i9-149000KF, 3.20GHz CPU, 64GB RAM, RTX 4090 (24GB), Samsung 870 Pro 8TB, Gen3 MVNe M-2 SSD, 4TBx2, 39" Alienware Widescreen Monitor Mike "ex-genius" Kelley
|
|
|
|
|
The-any-Key
|
The-any-Key
Posted 7 Years Ago
|
|
Group: Forum Members
Last Active: 2 Years Ago
Posts: 356,
Visits: 1.9K
|
Tested to set a default folder and I can't seem to get it to work. You use setDirectory but it seems I only get an error when trying to set the folder.
EDIT: But it seems you only need to add the path in the default filename: ex "C:\\Windows\\test.txt"
iClone 7, 3DXchange 7 Pipeline, CC3 Pipeline, CT8 Pipeline, Iray, Live Face, iPhone Xr, Win 10, i9 9900K ~5GHz, Nvidia RTX 2080 8GB, 16GB Ram, M.2 SSD
|
|
|
|
|
Kelleytoons
|
Kelleytoons
Posted 7 Years Ago
|
|
Group: Forum Members
Last Active: 2 Years Ago
Posts: 9.2K,
Visits: 22.1K
|
This is what I did: def get_load_filename_dialog(title, filter, default_filename,dir): return PySide2.QtWidgets.QFileDialog.getOpenFileName(None,str(title),str(dir),str(default_filename),str(filter))
And then this call: loadDir = "V:\\exports" load_file=get_load_filename_dialog("Legs Diffuse","","*.jpg",loadDir)
sets the directory. Now, in my drug-addled state, I'm not sure why this works (indeed it appears as if it should NOT work) but it works for me just fine. Again, I'm going to need to learn Pyside I can see, just not right now.
Alienware Aurora R16, Win 11, i9-149000KF, 3.20GHz CPU, 64GB RAM, RTX 4090 (24GB), Samsung 870 Pro 8TB, Gen3 MVNe M-2 SSD, 4TBx2, 39" Alienware Widescreen Monitor Mike "ex-genius" Kelley
|
|
|
|