Isotropix Forums

File and Context Browser in Customized GUIs

Clarisse Scripting related topics

File and Context Browser in Customized GUIs

Unread postby gerdhofer » Fri Dec 06, 2019 11:53 am

Hello,

I've successfully managed to create a custom GUI with checkboxes and number fields, but now I got stuck with file and context browsers, Is it possible to integrate a context browser inside an already open GUI or do I have to call such a browser from a separate process? This also applies to other elements like colour pickers and many others from the the GuiWidget class.

I'm a bit lost here, since I don't fully understand how to use elements like "GuiFileBowserWidget" or "GuiContextField". They're all members of the GuiWidget class, but obviously they work completely different from functions like "GuiCheckbox", for example. But maybe I'm messing things up here :?

As always, any input is most appreciated. Thanks!

Best,
Gerd
gerdhofer
 
Posts: 55
Joined: Thu Aug 30, 2018 11:05 am

Re: File and Context Browser in Customized GUIs

Unread postby anemoff » Mon Dec 09, 2019 3:24 pm

Hi,

GuiFileBrowserWidget and GuiContextField are not available in the Python bindings. In fact, the Gui library is not completely ready for Python so it is only partially exposed.
In general, if there is a documentation page for a class you are interested in, it means it is available in the C++ SDK but not necessarily in the Python bindings. For now, there is no user-friendly way of knowing which ones aren't available in Python.
A workaround is to use Clarisse Script Editor auto-completion: start typing the class you want to use and press CTRL + SPACE, a list of suggestions will appear. If the name you're looking for appears then it is available. Otherwise, it isn't, and if you run your script you'll get an error like "'module' object has no attribute 'GuiFileBrowserWidget'".

If you want to invoke a file browser to select an input or output file, you can use the following code in the action of a button:

py code

# open a dialog to select a single output file: returns selected file path
file = ix.api.GuiWidget.open_file(ix.application)

# dialog to select multiple files: returns a list of file paths
files = ix.api.GuiWidget.open_files(ix.application)

# dialog to select a folder: returns selected folder path
folder = ix.api.GuiWidget.open_folder(ix.application)

# dialog to select an output file: returns file path
file = ix.api.GuiWidget.save_file(ix.application)


Full example:

py code

filenames = ix.api.GuiWidget.open_files(ix.application)
if filenames.get_count() > 0:
ix.enable_command_history()
# do something with the files
ix.disable_command_history()


What do you want to achieve? Maybe there are alternatives.

Regards,
Anthony Nemoff
Isotropix
R&D Engineer
User avatar
anemoff
 
Posts: 300
Joined: Wed Jan 13, 2016 10:10 am

Re: File and Context Browser in Customized GUIs

Unread postby gerdhofer » Mon Dec 09, 2019 4:40 pm

Many thanks Anthony! Demian told me about the auto-completion trick already, but I didn't consider it in this case. I was just looking in the SDK reference so far and indeed got the "'module object has no attribute GuiFileBrowserWidget" error. This is why I was asking here. But the button-invoked call of a file/context browser should cut it and I'll give a go.

"What do you want to achieve? Maybe there are alternatives."

I'm creating a script to randomly apply textures to a large number of objects, e.g. adding 10 different textures of burnt clay to 100 bricks together with displacement. I have the main functionality already running, but a nice little GUI would really complete this tool.
gerdhofer
 
Posts: 55
Joined: Thu Aug 30, 2018 11:05 am

Re: File and Context Browser in Customized GUIs

Unread postby anemoff » Mon Dec 09, 2019 5:09 pm

Glad to help.

The GuiContextField is the following widget in the toolbar.
gui_context_field.png
gui_context_field.png (4.96 KiB) Viewed 1522 times


Is that what you wanted to use?
Anthony Nemoff
Isotropix
R&D Engineer
User avatar
anemoff
 
Posts: 300
Joined: Wed Jan 13, 2016 10:10 am

Re: File and Context Browser in Customized GUIs

Unread postby gerdhofer » Mon Dec 09, 2019 5:45 pm

Oh :D

I really thought it's possible to select a context from a browser with the commands from your snippet. It's the first time I'm experimenting with custom GUIs, so I'm not really proficient with these things, and where the functions will finally lead me to. But never mind! My previous workaround was to use text fields to the GUI where I can fill in/complete the context names and I think I'll stick with this moment for now. Even with this simplified GUI it's already much more comfortable than hardcoding everything inside the script. So thanks anyway.
gerdhofer
 
Posts: 55
Joined: Thu Aug 30, 2018 11:05 am

Re: File and Context Browser in Customized GUIs

Unread postby anemoff » Mon Dec 09, 2019 6:41 pm

If you want a dialog to prompt the user to pick a context:

py code

ctx = ix.api.IOHelpers.pick_context(ix.application, "Dialog Title")
if ctx:
print('You selected context "{}"'.format(ctx))
else:
print('No context selected.')


Check the other pick_* helpers in IOHelpers: https://www.clarissewiki.com/4.0/sdk/cl ... lpers.html

By the way, don't hesitate to join the unofficial Clarisse Discord server if you haven't already: https://discord.gg/he8QTvD
You'll probably get faster answers, and Isotropix Staff is also there.
But the forum is good too, for keeping posts history for future users.
Anthony Nemoff
Isotropix
R&D Engineer
User avatar
anemoff
 
Posts: 300
Joined: Wed Jan 13, 2016 10:10 am

Re: File and Context Browser in Customized GUIs

Unread postby gerdhofer » Mon Dec 09, 2019 7:42 pm

Amazing! Thanks so much. And, no, I'm not on discord yet, but I'll definitely register there when new questions arise.
gerdhofer
 
Posts: 55
Joined: Thu Aug 30, 2018 11:05 am


Return to Scripting