Vizard 8 » Reference » Graphical user interfaces (GUIs) » Organizing GUIs » vizdlg advanced
8.0

vizdlg advanced

By extending the vizdlg.Dialog class, you can add GUIs and other components to a Panel and use the buttons provided to create a custom form.

In order to follow this section some knowledge of object oriented programming is required.

All dialog components discussed in the last section extend vizdlg.Dialog. A vizdlg.Dialog object creates the following: A panel that content can be added to using the <Dialog>.content attribute,  accept/cancel buttons, a show method that displays the panel and waits for a button press, and a remove method that removes the object.

 

The following example script shows how to extend vizdlg.Dialog and add content. One of the buttons is renamed and the other is hidden. The viztask function yields until the show method is complete and the form data is retrieved and printed.

import viz
viz.go()

import vizdlg

class MyForm(vizdlg.Dialog):

    def __init__(self,**kw):

        #Initialize base class
        vizdlg.Dialog.__init__(self,**kw)

        #Add row of checkboxes
        row = vizdlg.Panel(layout=vizdlg.LAYOUT_HORZ_BOTTOM,border=False,background=False,margin=0)
        row.addItem(viz.addText('Checkboxes'))
        self.check1 = row.addItem(viz.addCheckbox())
        self.check2 = row.addItem(viz.addCheckbox())
        self.check3 = row.addItem(viz.addCheckbox())

        #Add row to dialog content section
        self.content.addItem(row)

        #Add a subgroup containing slider/textbox
        group = vizdlg.Panel()

        #Add row for slider to subgroup
        row = vizdlg.Panel(layout=vizdlg.LAYOUT_HORZ_BOTTOM,border=False,background=False,margin=0)
        row.addItem(viz.addText('Slider'))
        self.slider = row.addItem(viz.addSlider())
        group.addItem(row)

        #Add row for textbox to subgroup
        row = vizdlg.Panel(layout=vizdlg.LAYOUT_HORZ_BOTTOM,border=False,background=False,margin=0)
        row.addItem(viz.addText('Textbox'))
        self.textbox = row.addItem(viz.addTextbox())
        group.addItem(row)

        #Add group to dialog content section
        self.content.addItem(group)

        #Hide cancel button
        self.cancel.visible(0)

        #Rename accept button to 'submit'
        self.accept.message('Submit')

import viztask
import vizinfo

def FormTask():

    info = vizinfo.InfoPanel("Press the 's' key to show the form")

    #Create input form
    form = MyForm(title='Form title')

    #Link form to center of screen
    viz.link(viz.MainWindow.CenterCenter,form)

    while True:

        #Wait for 's' key to be pressed
        yield viztask.waitKeyDown('s')

        #TODO: Pause simulation

        #Display form
        yield form.show()

        if form.accepted:
            #User pressed 'Submit', process data
            print('Checkboxes:',form.check1.get(),form.check2.get(),form.check3.get())
            print('Slider:',form.slider.get())
            print('Textbox:',form.textbox.get())

        #TODO: Resume simulation

    #Remove form when completely finished with it
    form.remove()

viztask.schedule( FormTask() )

vizdlg introduction

vizdlg panels

vizdlg dialog components

vizdlg advanced