Profile Picture

File Dialog?

Posted By Kelleytoons 6 Years Ago
You don't have permission to rate!
1
2
3

Author
Message
Kelleytoons
Kelleytoons
Posted 6 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)

Group: Forum Members
Last Active: Last Year
Posts: 9.2K, Visits: 22.1K
So I'm just now getting back to programming (sigh -- and my brain is fried) and for the life of me I can't get a simple file dialog box to work as it works in Blender.  Anyone had any luck?

It shouldn't be rocket science:
import tkinter as tk
from tkinter import filedialog
file_path = tkinter.filedialog.askopenfilename()
file_path = filedialog.askopenfilename()

(neither works although they both work in Blender).




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 6 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)

Group: Forum Members
Last Active: 2 Years Ago
Posts: 342, Visits: 12.0K
Kelleytoons (6/13/2019)
So I'm just now getting back to programming (sigh -- and my brain is fried) and for the life of me I can't get a simple file dialog box to work as it works in Blender.  Anyone had any luck?

It shouldn't be rocket science:
import tkinter as tk
from tkinter import filedialog
file_path = tkinter.filedialog.askopenfilename()
file_path = filedialog.askopenfilename()

(neither works although they both work in Blender).



Hi Mike

I think you just need to add

import tkFileDialog

Chris.
Kelleytoons
Kelleytoons
Posted 6 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)

Group: Forum Members
Last Active: Last Year
Posts: 9.2K, Visits: 22.1K
No, that doesn't work (tried that as well earlier -- sorry, but I didn't outline all the things I tried which didn't work).  For one thing, you have to import that dialog function from *somewhere* (you'll get an error if you just

import tkFileDialog

So you could try:

from tkinter import *
or
from tkinter import tkFileDialog

but the second is redundant (and doesn't work anyway).

Someone MUST have done this already, right?



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 6 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)

Group: Forum Members
Last Active: Last Year
Posts: 9.2K, Visits: 22.1K
I give up -- I'll just use the file dialog box built-in to RL's Python (not exactly what I had in mind but it will do 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
videodv
videodv
Posted 6 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)

Group: Forum Members
Last Active: 2 Years Ago
Posts: 342, Visits: 12.0K
Hi Mike
I got this piece of code snippets that run from python not from Iclone.

# import tkinter
# import tkFileDialog

# from tkinter import filedialog
# from tkinter import *

# def main():

    # #tkinter.tk().withdraw() # Close the root window
    # in_path = tkFileDialog.askopenfilename()
    # print(in_path)

# if __name__ == "__main__":
    # main()

# from tkinter import filedialog
# from tkinter import *
# from tkinter import colorchooser
# import tkinter as tk
# import os

# application_window = tk.Tk()

# #Build a list of tuples for each file type the file dialog should display
# my_filetypes = [('all files', '.*'), ('text files', '.txt')]

# # Ask the user to select a folder.
# answer = filedialog.askdirectory(parent=application_window, initialdir=os.getcwd(), title="Please select a folder:")

# # Ask the user to select a single file name.
# answer = filedialog.askopenfilename(parent=application_window, initialdir=os.getcwd(), title="Please select a file:", filetypes=my_filetypes)

# # Ask the user to select a one or more file names.
# answer = filedialog.askopenfilenames(parent=application_window, initialdir=os.getcwd(), title="Please select one or more files:", filetypes=my_filetypes)

# # Ask the user to select a single file name for saving.
# answer = filedialog.asksaveasfilename(parent=application_window, initialdir=os.getcwd(), title="Please select a file name for saving:", filetypes=my_filetypes)

# rgb_color, web_color = colorchooser.askcolor(parent=application_window, initialcolor=(255, 0, 0))

# root = Tk()
# root.filename =  filedialog.askopenfilename(initialdir = "/",title = "Select file",filetypes = (("jpeg files","*.jpg"),("all files","*.*")))
# print (root.filename)

#Here is an example of storing the directory path as a global variable and using that to populate a Label.

from tkinter import filedialog
from tkinter import *

def browse_button():
    # Allow user to select a directory and store it in global var
    # called folder_path
    global folder_path
    filename = filedialog.askdirectory()
    folder_path.set(filename)
    print(filename)


root = Tk()
folder_path = StringVar()
lbl1 = Label(master=root,textvariable=folder_path)
lbl1.grid(row=0, column=1)
button2 = Button(text="Browse", command=browse_button)
button2.grid(row=0, column=3)

mainloop()

Not sure if this helps but as you know I am new to python and tkinter.

Chris.
Kelleytoons
Kelleytoons
Posted 6 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)

Group: Forum Members
Last Active: Last Year
Posts: 9.2K, Visits: 22.1K
So, unfortunately, the RL file open dialog doesn't have what I really need, which is the ability to tell the user what I want them to do (the box heading).  Anyone have an idea how I would emulate the tk approach (giving the fileopen box a title)?



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 6 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)

Group: Forum Members
Last Active: Last Year
Posts: 9.2K, Visits: 22.1K
videodv (6/13/2019)
Hi Mike
I got this piece of code snippets that run from python not from Iclone.

# import tkinter
# import tkFileDialog

# from tkinter import filedialog
# from tkinter import *

# def main():

    # #tkinter.tk().withdraw() # Close the root window
    # in_path = tkFileDialog.askopenfilename()
    # print(in_path)

# if __name__ == "__main__":
    # main()

# from tkinter import filedialog
# from tkinter import *
# from tkinter import colorchooser
# import tkinter as tk
# import os

# application_window = tk.Tk()

# #Build a list of tuples for each file type the file dialog should display
# my_filetypes = [('all files', '.*'), ('text files', '.txt')]

# # Ask the user to select a folder.
# answer = filedialog.askdirectory(parent=application_window, initialdir=os.getcwd(), title="Please select a folder:")

# # Ask the user to select a single file name.
# answer = filedialog.askopenfilename(parent=application_window, initialdir=os.getcwd(), title="Please select a file:", filetypes=my_filetypes)

# # Ask the user to select a one or more file names.
# answer = filedialog.askopenfilenames(parent=application_window, initialdir=os.getcwd(), title="Please select one or more files:", filetypes=my_filetypes)

# # Ask the user to select a single file name for saving.
# answer = filedialog.asksaveasfilename(parent=application_window, initialdir=os.getcwd(), title="Please select a file name for saving:", filetypes=my_filetypes)

# rgb_color, web_color = colorchooser.askcolor(parent=application_window, initialcolor=(255, 0, 0))

# root = Tk()
# root.filename =  filedialog.askopenfilename(initialdir = "/",title = "Select file",filetypes = (("jpeg files","*.jpg"),("all files","*.*")))
# print (root.filename)

#Here is an example of storing the directory path as a global variable and using that to populate a Label.

from tkinter import filedialog
from tkinter import *

def browse_button():
    # Allow user to select a directory and store it in global var
    # called folder_path
    global folder_path
    filename = filedialog.askdirectory()
    folder_path.set(filename)
    print(filename)


root = Tk()
folder_path = StringVar()
lbl1 = Label(master=root,textvariable=folder_path)
lbl1.grid(row=0, column=1)
button2 = Button(text="Browse", command=browse_button)
button2.grid(row=0, column=3)

mainloop()

Not sure if this helps but as you know I am new to python and tkinter.

Chris.


Chris,
None of that works in iClone, unfortunately (it all works in Blender, which is what I am familiar with).  And, unfortunately, RL's implementation of file open doesn't do me much good (it won't tell the user what the heck file you are looking for so you had better damn well know what the point of the file open is as the script runs).

I still can't believe this is what we have to deal with, so clearly I'm doing something wrong.  But I have no idea how to make it work in iClone.





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 6 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)

Group: Forum Members
Last Active: 2 Years Ago
Posts: 342, Visits: 12.0K
Hi Mike

Maybe this Link may point you in the right direction.

Think I will take some time myself and see if I can work this out.

Chris.
videodv
videodv
Posted 6 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)Distinguished Member (2.9K reputation)

Group: Forum Members
Last Active: 2 Years Ago
Posts: 342, Visits: 12.0K
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.
Kelleytoons
Kelleytoons
Posted 6 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)Distinguished Member (37.8K reputation)

Group: Forum Members
Last Active: Last Year
Posts: 9.2K, Visits: 22.1K
Thanks, Chris, for all your effort in this -- it's too late here for me to try this out (too much sitting for my knee recovery) but I'll look at it tomorrow.

It's a TON of work to go through for a simple dialog, though.  I still hope there's an easier way.



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

1
2
3



Reading This Topic