class Gui(object): """ A simple gui class """ def __init__(self): """ create the GUI """ categories = ['Trees', 'Birds', 'Flowers'] self.gui = Window() self.gui.setTitle('Dynamic Widget Demo') self.gui.addRadio('category', 'Item Types', categories) self.gui.addCombo('items', 'Items', None, postcommand=self.update) self.gui.addButton('command') self.gui.set('category', 'Trees') self.gui.set('items', '...') self.gui.plot('category', row=0) self.gui.plot('items', row=1, pady=20) self.gui.plot('command', row=2) def update(self): # callback function """ set the combobox values by what is in the radio button box """ lookup = { 'Trees': ['Oak', 'Maple', 'Beech'], 'Birds': ['Cardinal', 'Robin', 'Sparrow'], 'Flowers': ['Rose', 'Petunia', 'Daylily'] } select = self.gui.get('category') self.gui.set('items', lookup[select], allValues=True)
class Gui(object): """ The Tornado Path Plotting GUI """ def __init__(self): """ create the GUI """ counties = ['Clark','Crawford','Dubois','Floyd','Harrison','Jefferson', 'Orange','Perry','Scott','Washigton'] damage = ['EF0','EF1','EF2','EF3','EF4','EF5'] dateParms = [[2,1,12],[2,1,12],[4,1900,2100]] initDate = [1,1,1980] cols = [['Date', 100],['County', 100],['Damage', 100]] self.gui = Window() self.gui.setTitle('Tornado Path Generator') self.gui.addSpin('tdate', dateParms, '/', 'Date of Tornado') self.gui.set('tdate', initDate) self.gui.addCombo('county', 'Affected County', counties) self.gui.addRadio('level', 'Maximum EF Damage', damage) self.gui.addCollector('paths', 10, cols, ['tdate','county','level'], 'Included Tornadoes') self.gui.addButton('command') self.gui.plot('tdate', row=0, pady=5) self.gui.plot('county', row=1, pady=5) self.gui.plot('level', row=2, pady=5) self.gui.plot('paths', row=3, pady=5) self.gui.plot('command', row=4, pady=10)
def update(gui): # callback function """ set the alist attribute by what is in the radio button box """ lookup = { 'Trees': ['Oak', 'Maple', 'Beech'], 'Birds': ['Cardinal', 'Robin', 'Sparrow'], 'Flowers': ['Rose', 'Petunia', 'Daylily'] } select = gui.get('category') gui.set('items', lookup[select], allValues=True) categories = ['Trees', 'Birds', 'Flowers'] gui = Window() gui.setTitle('Dynamic Widget Demo') gui.addRadio('category', 'Item Types', categories) gui.addCombo('items', 'Items', None, postcommand=(lambda: update(gui))) gui.addButton('command') gui.set('category', 'Trees') gui.set('items', '...') gui.plot('category', row=0) gui.plot('items', row=1, pady=20) gui.plot('command', row=2) gui.waitforUser() if gui.content: selected_cat = gui.get('category') item = gui.get('items') # more code would go here... gui.cancel()