Examples#

Example 01 - Custom Dialog#

Custom Dialog#
 1from hwx import gui
 2from hwx.xmlui import gui as gui2
 3
 4import os
 5
 6def MyCustomGui():
 7
 8    # Set of functions used as commands linked to various widgets
 9    def onClose(event):
10        dialog.Hide()
11
12    def onRun(event):
13        dialog.Hide()
14        gui.tellUser("Done!")
15
16    def onModified():
17        # Function to update the output label with the slider value when
18        # the slider is interactively used
19        output.value = str(f"Output Quality: {slider.value}")
20
21    def comboboxFunc(event):
22        # output.text = event.value
23        pass
24
25    # Creating objects for various UI widgets
26    label1 = gui.Label(text="Model File")
27    modelFile = gui2.OpenFileEntry(placeholdertext="Model File")
28    label2 = gui.Label(text="Result File")
29    resultFile = gui2.OpenFileEntry(placeholdertext="Result File")
30    label3 = gui.Label(text="Screenshot Folder")
31    folderSel = gui2.ChooseDirEntry(tooltip="Select output directory")
32    slider = gui.Slider(maxvalue=100, tracking=False, value=10, command=onModified)
33    output = gui.Label(f"Output Quality: {slider.value}")
34    formats = (("jpeg", "JPEG"), ("png", "PNG"))
35    buttons = gui.HRadioButtons(formats)
36    levels = (("lvl1", "Level 1"), ("lvl2", "Level 2"), ("lvl3", "Level 3"))
37    combobox = gui.ComboBox(levels, command=comboboxFunc)
38
39    # Defining the pair of custom buttons at the bottom of the dialog
40    close = gui.Button("Close", command=onClose)
41    create = gui.Button("Run", command=onRun)
42
43    # Creating a vertical frame to organize all the widgets.
44    # We are using integer values or <-> spacer to control the spacing between widgets.
45    mainFrame = gui.VFrame(
46        (label1, 10, modelFile),
47        (label2, 10, resultFile),
48        (label3, 10, folderSel),
49        (output, 10, slider),
50        (buttons, "<->"),
51        (combobox, "<->"),
52        (create, close),
53    )
54
55    # Creating a dialog instance that hosts and displays all the widgets constructed above
56    dialog = gui.Dialog(caption="Example Dialog", width=400, height=200)
57    dialog.addChildren(mainFrame)
58
59    # Displaying the dialog with prescribed dimensions
60    dialog.show()
61
62MyCustomGui()
../_images/example01.png

Figure 1. Custom dialog containing various widgets