GUI Toolkit Examples#

Example 01 - Custom Dialog#

Custom Dialog#
 1from hw import *
 2from hw.hv import *
 3from hwx.xmlui import gui
 4from hwx import gui as gui2
 5import os
 6
 7
 8def MyCustomGui():
 9
10    def onClose(event):
11        dialog.Hide()
12
13    def onRun(event):
14        dialog.Hide()
15        gui2.tellUser("Done!")
16
17    def onModified():
18        output.value = str(f"Output Quality: {slider.value}")
19
20    def comboboxFunc(event):
21        # output.text = event.value
22        pass
23
24    label1 = gui.Label(text="Model File")
25    modelFile = gui.OpenFileEntry(placeholdertext="Model File")
26    label2 = gui.Label(text="Result File")
27    resultFile = gui.OpenFileEntry(placeholdertext="Result File")
28    label3 = gui.Label(text="Screenshot Folder")
29    folderSel = gui.ChooseDirEntry(tooltip="Select output directory")
30    slider = gui2.Slider(maxvalue=100, tracking=False, value=10, command=onModified)
31    output = gui2.Label(f"Output Quality: {slider.value}")
32    formats = (("jpeg", "JPEG"), ("png", "PNG"))
33    buttons = gui2.HRadioButtons(formats)
34    levels = (("lvl1", "Level 1"), ("lvl2", "Level 2"), ("lvl3", "Level 3"))
35    combobox = gui2.ComboBox(levels, command=comboboxFunc)
36
37    close = gui.Button("Close", command=onClose)
38    create = gui.Button("Run", command=onRun)
39
40    mainFrame = gui.VFrame(
41        (label1, 10, modelFile),
42        (label2, 10, resultFile),
43        (label3, 10, folderSel),
44        (output, 10, slider),
45        (buttons, "<->"),
46        (combobox, "<->"),
47        (create, close),
48    )
49
50    dialog = gui.Dialog(caption="Example Dialog")
51    dialog.recess().add(mainFrame)
52    dialog.setButtonVisibile("ok", False)
53    dialog.setButtonVisibile("cancel", False)
54    dialog.show(width=400, height=100)
../_images/example01.png

Figure 1. Custom dialog containing various widgets