def buildWidgets(self, value=None, interactive=0): debug.mainthreadTest() # Construct a Chooser widget for each WhoClass in the target # WhoClass's hierarchy. interactive is 1 if this call is in # response to a user action. ## oldvalue = self.get_value() oldpath = self.currentPath[:] classlist = self.whoclass.hierarchy() depth = len(classlist) # Make sure value is a list. value = labeltree.makePath(value) # Make a list of the allowed proxies for the lowermost tier of # the class hierarchy for this widget. Allowed proxies are # those which satisfy both the passed-in condition *and* are # proxies. self.proxy_names = [ x[0] for x in classlist[-1].keys(condition=lambda x: self.condition(x) and not whoville.excludeProxies(x), sort=self.sort) ] # Make sure that value contains a setting for each chooser widget if value and len(value) < depth: value += [None] * (depth - len(value)) for d in range(depth): try: # Exclude proxies from this part of the process... paths = classlist[d].keys(base=self.currentPath[:d], condition=lambda x: self.condition(x) and whoville.excludeProxies(x), sort=self.sort) except KeyError, exc: names = [] else: names = [p[0] for p in paths] if d == 0: # In the top-most level of the widget, include the # proxy names for the lowermost level. names += self.proxy_names if self.widgets[d] is None: if self.widgettype == 'Chooser' or d < depth - 1: self.widgets[d] = chooser.ChooserWidget( names, callback=self.selectCB, callbackargs=(d, ), name=classlist[d].name()) else: self.widgets[d] = chooser.ChooserComboWidget( names, callback=self.comboCB, name=classlist[d].name()) self.gtk[d] = self.widgets[d].gtk self.destroysignals[d] = self.gtk[d].connect( 'destroy', self.destroyCB, d) else: # Update the list of choices in an existing ChooserWidget. self.widgets[d].update(names) if value and value[d] in names: # Set widget to the given value self.widgets[d].set_state(value[d]) self.currentPath[d] = value[d] elif self.currentPath[d] in names: # ... or retain previous value self.widgets[d].set_state(self.currentPath[d]) elif len(names) > 0: # ... or pick the first value in the list self.currentPath[d] = names[0] self.widgets[d].set_state(0) else: # ... or don't pick anything self.currentPath[d] = '' if self.widgettype == 'Chooser': self.gtk[d].set_sensitive(names != [])
def __init__(self, param, scope=None, name=None, ident=None, verbose=False): debug.mainthreadTest() self.param = param self.ident = ident or param.ident self.lastFile = {} # last file selected in each directory self.fileNames = [] # files in the current directory self.dirHier = [] # directories in the current hierarchy self.dirHistory = ringbuffer.RingBuffer(50) parameterwidgets.ParameterWidget.__init__(self, gtk.Frame(), scope, name, expandable=True, verbose=verbose) vbox = gtk.VBox() self.gtk.add(vbox) # Directory selector hbox = gtk.HBox() vbox.pack_start(hbox, expand=False, fill=False) hbox.pack_start(gtk.Label("Directory:"), expand=False, fill=False) self.dirWidget = chooser.ChooserComboWidget([], callback=self.dirChangedCB, name="Directory") hbox.pack_start(self.dirWidget.gtk, expand=True, fill=True) # Directory selection buttons hbox = gtk.HBox(homogeneous=False) vbox.pack_start(hbox, expand=False, fill=False) self.backbutton = gtkutils.StockButton(gtk.STOCK_GO_BACK, "Back", align=0.0) gtklogger.setWidgetName(self.backbutton, "Back") gtklogger.connect(self.backbutton, 'clicked', self.backCB) hbox.pack_start(self.backbutton, expand=True, fill=True) self.addDirButtons(hbox) homebutton = gtkutils.StockButton(gtk.STOCK_HOME) gtklogger.setWidgetName(homebutton, "Home") gtklogger.connect(homebutton, 'clicked', self.homeCB) hbox.pack_start(homebutton, expand=False, fill=True) self.nextbutton = gtkutils.StockButton(gtk.STOCK_GO_FORWARD, "Next", reverse=True, align=1.0) gtklogger.setWidgetName(self.nextbutton, "Next") gtklogger.connect(self.nextbutton, 'clicked', self.nextCB) hbox.pack_start(self.nextbutton, expand=True, fill=True) # File list self.fileList = self.chooserClass(name="FileList", callback=self.fileListCB, dbcallback=self.fileListDoubleCB, markup=True) self.fileList.gtk.set_size_request(-1, 100) vbox.pack_start(self.fileList.gtk, expand=True, fill=True) # Set the comparison function used when typing in the file # list. _filename_cmp matches the beginnings of file names, # ignoring the markup added to directories ane escaped # characters. if use_markup: self.fileList.treeview.set_search_equal_func(_filename_cmp, None) align = gtk.Alignment(xalign=1.0) vbox.pack_start(align, expand=False, fill=False) hbox = gtk.HBox() align.add(hbox) hbox.pack_start(gtk.Label("show hidden files"), expand=False, fill=False) self.hiddenButton = gtk.CheckButton() hbox.pack_start(self.hiddenButton, expand=False, fill=False) gtklogger.setWidgetName(self.hiddenButton, "ShowHidden") gtklogger.connect(self.hiddenButton, 'clicked', self.showHiddenCB) # Include additional widgets required by subclasses. self.addMoreWidgets(vbox)
def __init__(self, param, scope=None, name=None, ident=None): debug.mainthreadTest() self.ident = ident or param.ident self.lastFile = {} # last file selected in each directory self.fileNames = [] # files in the current directory self.dirHier = [] # directories in the current hierarchy self.dirHistory = ringbuffer.RingBuffer(50) parameterwidgets.ParameterWidget.__init__(self, gtk.Frame(), scope, name, expandable=True) vbox = gtk.VBox() self.gtk.add(vbox) # Directory selector hbox = gtk.HBox() vbox.pack_start(hbox, expand=False, fill=False) hbox.pack_start(gtk.Label("Directory:"), expand=False, fill=False) self.dirWidget = chooser.ChooserComboWidget([], callback=self.dirChangedCB, name="Directory") hbox.pack_start(self.dirWidget.gtk, expand=True, fill=True) # Directory selection buttons hbox = gtk.HBox(homogeneous=False) vbox.pack_start(hbox, expand=False, fill=False) self.backbutton = gtkutils.StockButton(gtk.STOCK_GO_BACK, "Back", align=0.0) gtklogger.setWidgetName(self.backbutton, "Back") gtklogger.connect(self.backbutton, 'clicked', self.backCB) hbox.pack_start(self.backbutton, expand=True, fill=True) self.addDirButtons(hbox) homebutton = gtkutils.StockButton(gtk.STOCK_HOME) gtklogger.setWidgetName(homebutton, "Home") gtklogger.connect(homebutton, 'clicked', self.homeCB) hbox.pack_start(homebutton, expand=False, fill=True) self.nextbutton = gtkutils.StockButton(gtk.STOCK_GO_FORWARD, "Next", reverse=True, align=1.0) gtklogger.setWidgetName(self.nextbutton, "Next") gtklogger.connect(self.nextbutton, 'clicked', self.nextCB) hbox.pack_start(self.nextbutton, expand=True, fill=True) # File list self.fileList = chooser.ScrolledChooserListWidget( name="FileList", callback=self.fileListCB, dbcallback=self.fileListDoubleCB, markup=True) self.fileList.gtk.set_size_request(-1, 100) vbox.pack_start(self.fileList.gtk, expand=True, fill=True) # Set the comparison function used when typing in the file # list. _filename_cmp matches the beginnings of file names, # ignoring the markup added to directories and escaped # characters. if use_markup: self.fileList.treeview.set_search_equal_func(_filename_cmp, None) align = gtk.Alignment(xalign=1.0) vbox.pack_start(align, expand=False, fill=False) hbox = gtk.HBox() align.add(hbox) hbox.pack_start(gtk.Label("show hidden files"), expand=False, fill=False) self.hiddenButton = gtk.CheckButton() hbox.pack_start(self.hiddenButton, expand=False, fill=False) gtklogger.setWidgetName(self.hiddenButton, "ShowHidden") gtklogger.connect(self.hiddenButton, 'clicked', self.showHiddenCB) # Include additional widgets required by subclasses. self.addMoreWidgets(vbox) # Set initial state. if param.value is not None: directory, phile = os.path.split(param.value) # param.value might not have a directory component, # especially if the last value was set by a script or # command line argument. if not directory or not os.path.isdir(directory): directory = _last_dir.get(self.ident, os.path.abspath(os.getcwd())) else: directory = _last_dir.get(self.ident, os.path.abspath(os.getcwd())) phile = _last_file.get(self.ident, None) self.hiddenButton.set_active(_last_hid.get(self.ident, False)) directory = endSlash(directory) self.lastFile[directory] = phile self.dirHistory.push(directory) self.dirWidget.suppress_signals() self.dirHier = getDirectoryHierarchy(directory) self.dirWidget.update(self.dirHier) self.dirWidget.set_state(directory) self.dirWidget.allow_signals() self.fileList.suppress_signals() self.updateFiles(directory) if phile: self.fileList.set_selection(phile) self.fileList.allow_signals() self.initializeExtras(directory, phile) self.sensitize() self.widgetChanged(self.checkValidity(), interactive=False)