class ConfiguratorGUI(Tkinter.Frame): def __init__(self, parent, configurator_service): Tkinter.Frame.__init__(self, parent) self.configurator_service = configurator_service choices = [cfg['config_filepath'] for cfg in self.configurator_service.configs] # Add some contents to the dialog self.menu = Pmw.OptionMenu(self, items = choices, labelpos='nw', label_text='Configuration Files', command = self._option_menu_command, #called when choice is switched #selectioncommand=self.selectionCommand, #dblclickcommand = self.setup_control_mode, #usehullsize = 1, #hull_width = 200, #hull_height = 200, ) self.text_display = TextDisplayBox(self,text_height=TEXT_DISPLAY_TEXT_HEIGHT, text_width=TEXT_DISPLAY_TEXT_WIDTH, buffer_size = TEXT_BUFFER_SIZE) self.select_button = Tkinter.Button(text='Select',command = self._select_button_command) self.menu.pack(side='top', anchor='nw') self.text_display.pack(expand = True, fill = 'both', padx = 4, pady = 4) self.select_button.pack(side='bottom') self.selection = None self.menu.invoke(index=0) def _select_button_command(self): print "Selection made: %s" % self.menu.getvalue() root = self._root() root.destroy() def _option_menu_command(self, option): choice_index = self.menu.index(Pmw.SELECT) self.selection = self.configurator_service.configs[choice_index] print "Current choice index %d, option: %s" % (choice_index,option) self.text_display.clear_text() try: #read in the raw file and display it in the text box config_filename = self.selection.filename text = open(config_filename, 'r').read() self.text_display.print_text(text) self.text_display.set_text_yview(0) #forces scroll back to top except: self.text_display.print_text("*** Could not read file: %s" % config_filename)