def __init__(self, param, scope=None, name=None, verbose=False): self.state = None self.widget = chooser.ChooserWidget([], self.chooserCB, name=name) parameterwidgets.ParameterWidget.__init__(self, self.widget.gtk, scope=scope, verbose=verbose) if not (guilogger.recording() or guilogger.replaying()): self.fileSelector = self.scope.findWidget( lambda x: (isinstance(x, WriteFileSelectorWidget))) else: self.fileSelector = self.scope.findWidget( lambda x: (isinstance(x, FakeFileSelectorWidget))) if self.fileSelector is None: raise ooferror.ErrPyProgrammingError("Can't find file selector") self.set_options() self.widgetChanged(True, True) self.sbcallback = switchboard.requestCallbackMain(self.fileSelector, self.fileSelectorCB)
def __init__(self, param, scope, name=None, verbose=False): self.chooser = chooser.ChooserWidget([], callback=self.chooserCB, name=name) parameterwidgets.ParameterWidget.__init__(self, self.chooser.gtk, scope, verbose=verbose) self.meshwidget = scope.findWidget(lambda w: isinstance( w, whowidget.WhoWidget) and w.whoclass is mesh.meshes) assert self.meshwidget is not None self.sbcallbacks = [ switchboard.requestCallbackMain(self.meshwidget, self.update), switchboard.requestCallbackMain("scheduled outputs changed", self.update) ] self.update(interactive=False)
def __init__(self, enumclass, param, scope=None, name=None, verbose=False): self.enumclass = enumclass nameset = list(self.enumclass.names) self.widget = chooser.ChooserWidget(nameset, self.selection, helpdict=self.enumclass.helpdict, name=name) if param.value is not None: self.set_value(param.value) else: self.set_value(enumclass(enumclass.names[0])) self.sbcallback = switchboard.requestCallbackMain( enumclass, self.update) ParameterWidget.__init__(self, self.widget.gtk, scope=scope, verbose=verbose) self.widgetChanged(len(nameset) > 0, interactive=0)
def __init__(self, param, scope=None, name=None, verbose=False): self.widget = chooser.ChooserWidget([], callback=self.widgetCB, name=name) parameterwidgets.ParameterWidget.__init__(self, self.widget.gtk, scope=scope, name=name, verbose=verbose) self.mswidget = self.scope.findWidget( lambda w: isinstance(w, whowidget.WhoWidget) and w.whoclass is ooflib.common.microstructure.microStructures) self.sbcallbacks = [ switchboard.requestCallbackMain(self.mswidget, self.update) ] self.update(interactive=0) if param.value is not None and self.widget.nChoices() > 0: self.set_value(param.value)
def __init__(self, param, scope, name=None, verbose=False): debug.mainthreadTest() self.chooser = chooser.ChooserWidget([], callback=self.chooserCB, name=name) box = gtk.VBox() box.pack_start(self.chooser.gtk, expand=0, fill=0) parameterwidgets.ParameterWidget.__init__(self, box, scope, verbose) self.fieldwidget = scope.findWidget( lambda w: isinstance(w, IndexableWidget)) self.sbcallback = switchboard.requestCallbackMain(self.fieldwidget, self.fieldCB) self.notapplicable = gtk.Label('(Not Applicable)') self.notapplicable.set_alignment(0.0, 0.5) box.pack_start(self.notapplicable, expand=0, fill=0) self.nIndices = 0 self.update() if param.value in self.chooser.choices(): self.chooser.set_state(param.value) self.widgetChanged(1, interactive=0)
def __init__(self, param, scope=None, name=None): self.groupchooser = chooser.ChooserWidget([], name=name) parameterwidgets.ParameterWidget.__init__(self, self.groupchooser.gtk, scope=scope) self.mswidget = self.scope.findWidget( lambda w: isinstance(w, whowidget.WhoWidget) and w.whoclass is ooflib.common.microstructure.microStructures) self.update() if param.value is not None: self.set_value(param.value) self.sbcallbacks = [ switchboard.requestCallbackMain(self.mswidget, self.update), switchboard.requestCallbackMain("new pixel group", self.update), switchboard.requestCallbackMain("renamed pixel group", self.update), switchboard.requestCallbackMain("destroy pixel group", self.update), switchboard.requestCallbackMain(self.groupchooser, self.chooserCB) ]
def set_value(self, object): debug.mainthreadTest() path = labeltree.makePath(self.tree.objpath(object)) depth = len(path) for widget in self.widgets: widget.destroy() self.widgets = [] tree = self.tree depth = 0 for name in path: names = [node.name for node in tree.nodes] widget = chooser.ChooserWidget(names, callback=self.chooserCB, callbackargs=(depth,), name="%s_%d"%(self.name,depth)) depth += 1 widget.set_state(name) self.widgets.append(widget) self.gtk.pack_start(widget.gtk, expand=0, fill=0) tree = tree[name] self.gtk.show_all()
def __init__(self, param=None, scope=None, name=None, framed=True): vbox = gtk.VBox(spacing=2) if framed: parameterwidgets.ParameterWidget.__init__(self, gtk.Frame(), scope=scope, name=name) self.gtk.add(vbox) else: parameterwidgets.ParameterWidget.__init__(self, vbox, scope=scope, name=name) self.chooser = chooser.ChooserWidget(DestinationParamWidget.namelist, callback=self.chooserCB, name='Chooser') vbox.pack_start(self.chooser.gtk, expand=0, fill=0) bbox = gtk.HBox(spacing=2, homogeneous=True) vbox.pack_start(bbox, expand=0, fill=0) newbutton = gtkutils.StockButton(gtk.STOCK_NEW, "New...") gtklogger.setWidgetName(newbutton, "New") bbox.pack_start(newbutton, expand=1, fill=1) gtklogger.connect(newbutton, 'clicked', self.newCB) self.clearbutton = gtkutils.StockButton(gtk.STOCK_CLEAR, "Clear") gtklogger.setWidgetName(self.clearbutton, "Clear") bbox.pack_start(self.clearbutton, expand=1, fill=1) gtklogger.connect(self.clearbutton, 'clicked', self.clearCB) self.sbcallbacks = [ switchboard.requestCallbackMain('destinations changed', self.rebuild) ] self.rebuild() if param and param.value is not None: self.set_value(param.value) self.widgetChanged(1, interactive=0) _allDestinationWidgets.add(self)
def __init__(self, param, scope=None, name=None): self.widget = chooser.ChooserWidget([], callback=self.widgetCB, name=name) parameterwidgets.ParameterWidget.__init__(self, self.widget.gtk, scope=scope, name=name) self.mswidget = self.scope.findWidget( lambda w: isinstance(w, whowidget.WhoWidget) and w.whoclass is skeletoncontext.skeletonContexts) #Needs an MS:Skeleton self.sbcallbacks = [ switchboard.requestCallbackMain(self.mswidget, self.update), switchboard.requestCallbackMain("new interface created", self.update), switchboard.requestCallbackMain("interface removed", self.update), switchboard.requestCallbackMain("interface renamed", self.update), ] self.update(interactive=0) if param.value is not None and self.widget.nChoices() > 0: self.set_value(param.value)
def __init__(self, param, scope=None, name=None, verbose=False): self.groupchooser = chooser.ChooserWidget([], name=name) parameterwidgets.ParameterWidget.__init__(self, self.groupchooser.gtk, scope=scope, verbose=verbose) self.mswidget = self.scope.findWidget(lambda w: isinstance( w, whowidget.WhoWidget) and (w.whoclass is whoville.getClass( "Microstructure") or w.whoclass is whoville.getClass("Image"))) self.update() if param.value is not None: self.set_value(param.value) self.sbcallbacks = [ switchboard.requestCallbackMain(self.mswidget, self.update), switchboard.requestCallbackMain("new pixel group", self.update), switchboard.requestCallbackMain("renamed pixel group", self.update), switchboard.requestCallbackMain("destroy pixel group", self.update), switchboard.requestCallbackMain(self.groupchooser, self.chooserCB) ]
def __init__(self, param, boundaries=[], scope=None, name=None): self.widget = chooser.ChooserWidget(boundaries, self.selectCB, name=name) parameterwidgets.ParameterWidget.__init__(self, self.widget.gtk, scope) self.skelwidget = scope.findWidget( lambda w: isinstance(w, whowidget.WhoWidget) and (w.whoclass is skeletoncontext.skeletonContexts)) self.update() self.sbcallbacks = [ switchboard.requestCallbackMain(self.skelwidget, self.skelwidgetCB), switchboard.requestCallbackMain("new boundary configuration", self.update), switchboard.requestCallbackMain("new boundary created", self.update), switchboard.requestCallbackMain("boundary removed", self.update), switchboard.requestCallbackMain("boundary renamed", self.update) ] if param.value is not None: self.widget.set_state(param.value) self.widgetChanged(self.widget.nChoices() > 0, interactive=0)
def build(self, interactive): debug.mainthreadTest() elclasses = masterelement.getMasterElementEnumClasses() elgeometries = masterelement.getMasterElementGeometries() nclasses = len(elclasses) # Build the widgets if self.table is None or nclasses != self.nclasses: self.nclasses = nclasses if self.table: self.table.destroy() self.tablelabels = [] self.table = gtk.Table(rows=2 + nclasses, columns=2) self.gtk.add(self.table) # Choosers for mapping and interpolation order self.mapchooser = chooser.ChooserWidget([], callback=self.orderCB, name="Map") self.funchooser = chooser.ChooserWidget([], callback=self.orderCB, name="Func") label = gtk.Label('mapping order') tooltips.set_tooltip_text( label, 'Polynomial order of the functions used to map master elements to physical space.' ) label.set_alignment(1.0, 0.5) self.tablelabels.append(label) self.table.attach(label, 0, 1, 0, 1, xpadding=5, xoptions=gtk.FILL) self.table.attach(self.mapchooser.gtk, 1, 2, 0, 1, xpadding=5, xoptions=gtk.EXPAND | gtk.FILL) label = gtk.Label('interpolation order:') tooltips.set_tooltip_text( label, 'Polynomial order of the functions used to interpolate within elements.' ) label.set_alignment(1.0, 0.5) self.tablelabels.append(label) self.table.attach(label, 0, 1, 1, 2, xpadding=5, xoptions=gtk.FILL) self.table.attach(self.funchooser.gtk, 1, 2, 1, 2, xpadding=5, xoptions=gtk.EXPAND | gtk.FILL) # Choosers for each element geometry row = 2 self.classwidgets = [] for geometry, elclass in zip(elgeometries, elclasses): label = gtk.Label( ` geometry ` + '-cornered element:') tooltips.set_tooltip_text( label, 'Type of finite element to use for %d cornered Skeleton elements' % geometry) label.set_alignment(1.0, 0.5) self.tablelabels.append(label) self.table.attach(label, 0, 1, row, row + 1, xoptions=gtk.FILL) ewidget = chooser.ChooserWidget([], name="%d-cornered" % geometry) self.classwidgets.append((elclass, ewidget)) self.table.attach(ewidget.gtk, 1, 2, row, row + 1, xpadding=5, xoptions=gtk.EXPAND | gtk.FILL) row += 1 # Set the allowed values for each chooser. # Find out which mapping and interpolation orders have to be listed. maporderdict = {} funorderdict = {} for elclass in elclasses: for elname in elclass.names: el = masterelement.getMasterElementFromEnum(elclass(elname)) maporderdict[el.map_order()] = 1 funorderdict[el.fun_order()] = 1 maporders = maporderdict.keys() maporders.sort() funorders = funorderdict.keys() funorders.sort() # List the orders in the widgets self.mapchooser.update([ ` order ` for order in maporders]) self.funchooser.update([ ` order ` for order in funorders]) try: current_map = int(self.mapchooser.get_value()) current_fun = int(self.funchooser.get_value()) except: # If the choosers don't have values, it's because there # aren't any elements defined. self.widgetChanged(validity=0, interactive=interactive) else: # Find and list the element types for the current orders ok = True for elclass, ewidget in self.classwidgets: elements = masterelement.getMasterElementsFromEnumClass( elclass) okels = [ el for el in elements if el.map_order() == current_map and el.fun_order() == current_fun ] ok = ok and len(okels) > 0 ewidget.update([el.name() for el in okels], elclass.helpdict) self.widgetChanged(validity=ok, interactive=interactive)
def __init__(self, toolbox): toolboxGUI.GfxToolbox.__init__(self, utils.underscore2space(toolbox.name()), toolbox) mainbox = gtk.VBox() self.gtk.add(mainbox) sourceframe = gtk.Frame("Source") sourceframe.set_shadow_type(gtk.SHADOW_IN) mainbox.pack_start(sourceframe, fill=0, expand=0) sourcescroll = gtk.ScrolledWindow() gtklogger.logScrollBars(sourcescroll, "Source") sourceframe.add(sourcescroll) sourcescroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_NEVER) datatable = gtk.Table(rows=2, columns=2) sourcescroll.add_with_viewport(datatable) meshlabel = gtk.Label("mesh = ") meshlabel.set_alignment(1.0, 0.5) self.meshname = gtk.Label() gtklogger.setWidgetName(self.meshname, "meshname") self.meshname.set_alignment(0.0, 0.5) datatable.attach(meshlabel, 0, 1, 0, 1) datatable.attach(self.meshname, 1, 2, 0, 1) layerlabel = gtk.Label("output = ") layerlabel.set_alignment(1.0, 0.5) self.layername = gtk.Label() gtklogger.setWidgetName(self.layername, "layername") self.layername.set_alignment(0.0, 0.5) datatable.attach(layerlabel, 0, 1, 1, 2) datatable.attach(self.layername, 1, 2, 1, 2) csframe = gtk.Frame("Cross Section") csframe.set_shadow_type(gtk.SHADOW_IN) mainbox.pack_start(csframe, expand=0, fill=0) csbox = gtk.VBox() csframe.add(csbox) # Table contains the "current" and "points" widgets table = gtk.Table(rows=2, columns=2) csbox.pack_start(table, expand=0, fill=0) # Widget which shows the name of the current cross-section. label = gtk.Label("current: ") label.set_alignment(1.0, 0.5) table.attach(label, 0, 1, 0, 1, xoptions=0) self.csChooser = chooser.ChooserWidget([], callback=self.csChooserCB, name='csList') table.attach(self.csChooser.gtk, 1, 2, 0, 1, xoptions=gtk.EXPAND | gtk.FILL, yoptions=0) # Widget for how to sample the cross-section. label = gtk.Label("points: ") label.set_alignment(1.0, 0.5) table.attach(label, 0, 1, 1, 2, xoptions=0) self.cs_sample_widget = sampleregclassfactory.SampleRCF( name="Sampling", domainClass=analysisdomain.CrossSectionDomain, operationClass=analyze.DirectOutput) table.attach(self.cs_sample_widget.gtk, 1, 2, 1, 2, xoptions=gtk.EXPAND | gtk.FILL, yoptions=0) self.cs_sample_widget.update(analysissample.SampleSet.registry) self.int_valid_swcb = switchboard.requestCallbackMain( ('validity', self.cs_sample_widget), self.validCB) hbox = gtk.HBox() csbox.pack_start(hbox, expand=0, fill=0, padding=1) # Rename button. self.renamebutton = gtk.Button("Rename") gtklogger.setWidgetName(self.renamebutton, 'Rename') gtklogger.connect(self.renamebutton, 'clicked', self.csrenameCB) tooltips.set_tooltip_text(self.renamebutton, "Rename the current cross-section.") hbox.pack_start(self.renamebutton, fill=1, expand=1, padding=1) # Edit button self.editbutton = gtkutils.StockButton(gtk.STOCK_EDIT, "Edit...") gtklogger.setWidgetName(self.editbutton, 'Edit') gtklogger.connect(self.editbutton, 'clicked', self.cseditCB) tooltips.set_tooltip_text(self.editbutton, "Edit the current cross-section.") hbox.pack_start(self.editbutton, fill=1, expand=1, padding=1) # Copy button self.copybutton = gtkutils.StockButton(gtk.STOCK_COPY, "Copy...") gtklogger.setWidgetName(self.copybutton, 'Copy') gtklogger.connect(self.copybutton, 'clicked', self.cscopyCB) tooltips.set_tooltip_text(self.copybutton, "Copy the current cross-section.") hbox.pack_start(self.copybutton, fill=1, expand=1, padding=1) # Delete button. self.csdeletebutton = gtkutils.StockButton(gtk.STOCK_DELETE, "Remove") gtklogger.setWidgetName(self.csdeletebutton, 'Remove') gtklogger.connect(self.csdeletebutton, "clicked", self.csdeleteCB) tooltips.set_tooltip_text(self.csdeletebutton, "Remove the current cross-section.") hbox.pack_start(self.csdeletebutton, fill=1, expand=1, padding=1) goframe = gtk.Frame("Output") goframe.set_shadow_type(gtk.SHADOW_IN) mainbox.pack_start(goframe, expand=0, fill=0) self.gobox = gtk.VBox() goframe.add(self.gobox) hbox = gtk.HBox() self.gobox.pack_start(hbox, expand=0, fill=0) label = gtk.Label("Destination: ") label.set_alignment(1.0, 0.5) hbox.pack_start(label, expand=0, fill=0) self.destwidget = outputdestinationwidget.TextDestinationWidget( name="Destination") self.dw_valid_swcb = switchboard.requestCallbackMain( ('validity', self.destwidget), self.validCB) hbox.pack_start(self.destwidget.gtk, expand=1, fill=1, padding=2) self.gobutton = gtkutils.StockButton(gtk.STOCK_EXECUTE, "Go!") gtklogger.setWidgetName(self.gobutton, 'Go') hbox.pack_start(self.gobutton, expand=1, fill=1, padding=2) tooltips.set_tooltip_text(self.gobutton, "Send the output to the destination.") gtklogger.connect(self.gobutton, "clicked", self.goCB) self.startpoint = None self.endpoint = None # Data needed by the "go" button. Set in "show_data", when # the state of all the widgets is examined. self.meshobj = None self.current_cs_name = None # Shut off non-GUI toolbox's switchboard callbacks. We will # take them over at activate-time. self.toolbox.stop_callbacks()
def __init__(self): debug.mainthreadTest() widgetscope.WidgetScope.__init__(self, None) self.gtk = gtk.Window(gtk.WINDOW_TOPLEVEL) self.gtk.set_title(oofname) initial_width, initial_height = map(int, runtimeflags.geometry.split('x')) self.gtk.set_default_size(initial_width, initial_height) gtklogger.newTopLevelWidget(self.gtk, oofname) gtklogger.connect(self.gtk, "delete-event", self.deleteEventCB) gtklogger.connect_passive(self.gtk, "configure-event") self.gtk.connect("destroy", self.destroyCB) guitop.setTop(self) self.mainbox = gtk.VBox() self.gtk.add(self.mainbox) self.menubar = gtk.MenuBar() self.mainbox.pack_start(self.menubar, expand=0, fill=0) accelgrp = gtk.AccelGroup() self.gtk.add_accel_group(accelgrp) self.mainmenu = mainmenu.OOF self.oofmenu = gfxmenu.gtkOOFMenuBar(self.mainmenu, bar=self.menubar, accelgroup=accelgrp) gtklogger.setWidgetName(self.oofmenu, "MenuBar") self.pageChooserFrame = gtk.Frame() self.pageChooserFrame.set_shadow_type(gtk.SHADOW_IN) self.mainbox.pack_start(self.pageChooserFrame, expand=0, fill=0, padding=2) align = gtk.Alignment(xalign=0.5) self.pageChooserFrame.add(align) chooserBox = gtk.HBox() chooserBox.set_border_width(2) gtklogger.setWidgetName(chooserBox, 'Navigation') align.add(chooserBox) self.historian = historian.Historian(self.historianCB, self.sensitizeHistory) label = gtk.Label('Task: ') label.set_alignment(1.0, 0.5) chooserBox.pack_start(label, expand=0, fill=0) self.prevHistoryButton = gtkutils.StockButton(gtk.STOCK_GOTO_FIRST) chooserBox.pack_start(self.prevHistoryButton, expand=0, fill=0, padding=3) gtklogger.setWidgetName(self.prevHistoryButton, 'PrevHist') gtklogger.connect(self.prevHistoryButton, 'clicked', self.historian.prevCB) tooltips.set_tooltip_text( self.prevHistoryButton, "Go to the chronologically previously page.") self.prevPageButton = gtkutils.StockButton(gtk.STOCK_GO_BACK) chooserBox.pack_start(self.prevPageButton, expand=0, fill=0, padding=3) gtklogger.setWidgetName(self.prevPageButton, 'Prev') gtklogger.connect(self.prevPageButton, 'clicked', self.prevPageCB) self.pageChooser = chooser.ChooserWidget([], callback=self.pageChooserCB, name="PageMenu") chooserBox.pack_start(self.pageChooser.gtk, expand=0, fill=0) self.currentPageName = None self.nextPageButton = gtkutils.StockButton(gtk.STOCK_GO_FORWARD) chooserBox.pack_start(self.nextPageButton, expand=0, fill=0, padding=3) gtklogger.setWidgetName(self.nextPageButton, 'Next') gtklogger.connect(self.nextPageButton, 'clicked', self.nextPageCB) self.nextHistoryButton = gtkutils.StockButton(gtk.STOCK_GOTO_LAST) chooserBox.pack_start(self.nextHistoryButton, expand=0, fill=0, padding=3) gtklogger.setWidgetName(self.nextHistoryButton, 'NextHist') gtklogger.connect(self.nextHistoryButton, 'clicked', self.historian.nextCB) tooltips.set_tooltip_text(self.nextHistoryButton, "Go to the chronologically next page.") # Find the font size, so widgets can be sized appropriately. # digitsize and charsize are in pixels. self.digitsize, self.charsize = gtkutils.widgetFontSizes(self.gtk) # Add a GUI callback to the "OOF2" or "OOF3D" windows item. oof_item = getattr(self.mainmenu.Windows, oofname) oof_item.add_gui_callback(self.menu_raise) # Frame around main pages. GUI pages are added and removed # from it by installPage(). self.pageframe = gtk.Frame() self.pageframe.set_shadow_type(gtk.SHADOW_IN) self.mainbox.pack_start(self.pageframe, expand=1, fill=1) # Add pages that may have been created before the main GUI was built. for pagename, i in zip(pagenames, range(len(allPages))): self.addPage(allPages[pagename], i)
def __init__thread(self, gfxwindow, time, position, output): debug.mainthreadTest() allMeshDataWindows.append(self) widgetscope.WidgetScope.__init__(self, None) current_count = MeshDataGUI.count MeshDataGUI.count += 1 self._name = "Mesh_Data_%d" % current_count self.output = output self.time = time self.position = position self.sbcallbacks = [] self.gsbcallbacks = [] # callbacks from a specific gfx window self.updateLock = lock.Lock() self.outputparam = \ ooflib.engine.IO.output.AggregateOutputParameter('output') # Although it's not displayed, we need a mesh widget in the # widgetscope, or the OutputParameterWidget won't work. # TODO LATER: Is this ugly, or what? self.meshWidget = whowidget.WhoWidget(mesh.meshes, scope=self, name="Godot") self.gtk = gtk.Window(gtk.WINDOW_TOPLEVEL) title = utils.underscore2space(self._name) self.gtk.set_title(title) gtklogger.newTopLevelWidget(self.gtk, title) gtklogger.connect_passive(self.gtk, 'delete-event') gtklogger.connect_passive(self.gtk, 'configure-event') self.mainbox = gtk.VBox() self.gtk.add(self.mainbox) # Put this window into the Windows menu. The menu item can't # be logged, since the creation and operation of the window # aren't logged, so scripts shouldn't refer to it at all. mainmenu.OOF.Windows.Mesh_Data.addItem( oofmenu.OOFMenuItem(self._name, no_log=1, help="Raise Mesh Data window %d." % current_count, threadable=oofmenu.UNTHREADABLE, callback=self.raiseWindow)) expander = gtk.Expander("Source") gtklogger.setWidgetName(expander, 'ViewSource') gtklogger.connect_passive_after(expander, 'activate') self.mainbox.pack_start(expander) expander.set_expanded(1) self.table = gtk.Table(rows=config.dimension() + 4, columns=2) expander.add(self.table) label = gtk.Label("Source Window:") label.set_alignment(1.0, 0.5) self.table.attach(label, 0, 1, 0, 1, xpadding=3, xoptions=gtk.FILL) tooltips.set_tooltip_text( label, "Display data for mouse clicks in this Graphics window.") self.gfxWindowChooser = chooser.ChooserWidget([], callback=self.chooserCB, name='GfxWindow') self.table.attach(self.gfxWindowChooser.gtk, 1, 2, 0, 1, xpadding=3, xoptions=gtk.EXPAND | gtk.FILL, yoptions=0) label = gtk.Label("Mesh:") label.set_alignment(1.0, 0.5) self.table.attach(label, 0, 1, 1, 2, xpadding=3, xoptions=gtk.FILL, yoptions=0) tooltips.set_tooltip_text( label, "Data is displayed for values on this mesh.") self.meshText = gtk.Entry() gtklogger.setWidgetName(self.meshText, "meshname") self.meshText.set_editable(False) self.meshText.set_size_request(12 * guitop.top().charsize, -1) self.table.attach(self.meshText, 1, 2, 1, 2, xpadding=3, xoptions=gtk.EXPAND | gtk.FILL, yoptions=0) # Position controls label = gtk.Label("position x:") label.set_alignment(1.0, 0.5) self.table.attach(label, 0, 1, 2, 3, xpadding=3, xoptions=gtk.FILL, yoptions=0) self.xText = gtk.Entry() gtklogger.setWidgetName(self.xText, 'x') self.xText.set_size_request(12 * guitop.top().digitsize, -1) self.table.attach(self.xText, 1, 2, 2, 3, xpadding=3, xoptions=gtk.EXPAND | gtk.FILL, yoptions=0) self.xsignal = gtklogger.connect(self.xText, 'changed', self.posChangedCB) label = gtk.Label("position y:") label.set_alignment(1.0, 0.5) self.table.attach(label, 0, 1, 3, 4, xpadding=3, xoptions=gtk.FILL, yoptions=0) self.yText = gtk.Entry() gtklogger.setWidgetName(self.yText, 'y') self.yText.set_size_request(12 * guitop.top().digitsize, -1) self.table.attach(self.yText, 1, 2, 3, 4, xpadding=3, xoptions=gtk.EXPAND | gtk.FILL, yoptions=0) self.ysignal = gtklogger.connect(self.yText, 'changed', self.posChangedCB) if config.dimension() == 3: label = gtk.Label("position z:") label.set_alignment(1.0, 0.5) self.table.attach(label, 0, 1, 4, 5, xpadding=3, xoptions=gtk.FILL, yoptions=0) self.zText = gtk.Entry() gtklogger.setWidgetName(self.zText, 'z') self.zText.set_size_request(12 * guitop.top().digitsize, -1) self.table.attach(self.zText, 1, 2, 4, 5, xpadding=3, xoptions=gtk.EXPAND | gtk.FILL, yoptions=0) self.zsignal = gtklogger.connect(self.zText, 'changed', self.posChangedCB) timerow = 5 else: timerow = 6 # Time controls. Typing in the time widget does not # immediately update the displayed data, because interpolating # to a new time is an expensive computation, and shouldn't be # done while the user is in the middle of typing. Instead, # the time widget is normally desensitized and uneditable. # When the user clicks the "Edit" button, the widget becomes # editable, the rest of the window is desensitized, and the # "Edit" button changes do a "Done" button. When the user # clicks "Done" the data is updated and the time widget # becomes uneditable again. label = gtk.Label("time:") label.set_alignment(1.0, 0.5) self.table.attach(label, 0, 1, timerow, timerow + 1, xpadding=3, xoptions=gtk.FILL, yoptions=0) tBox = gtk.HBox(spacing=3) self.table.attach(tBox, 1, 2, timerow, timerow + 1, xpadding=3, xoptions=gtk.EXPAND | gtk.FILL, yoptions=0) self.tText = gtk.Entry() self.tText.set_editable(False) self.tText.set_sensitive(False) tBox.pack_start(self.tText, expand=1, fill=1) gtklogger.setWidgetName(self.tText, 't') self.tText.set_size_request(12 * guitop.top().digitsize, -1) self.tEditButton = gtk.Button("Edit") tBox.pack_start(self.tEditButton, expand=0, fill=0) gtklogger.setWidgetName(self.tEditButton, "tEdit") gtklogger.connect(self.tEditButton, 'clicked', self.tEditCB) self.tEditMode = False # Output selection label = gtk.Label("Output:") label.set_alignment(1.0, 0.5) self.table.attach(label, 0, 1, timerow + 2, timerow + 3, xpadding=3, xoptions=gtk.FILL, yoptions=0) tooltips.set_tooltip_text(label, "Choose which data is displayed.") self.outputwidget = self.outputparam.makeWidget(scope=self) self.table.attach(self.outputwidget.gtk, 1, 2, timerow + 2, timerow + 3, xpadding=3, xoptions=gtk.EXPAND | gtk.FILL, yoptions=0) switchboard.requestCallback(self.outputwidget, self.outputwidgetCB) # Data display panel hbox = gtk.HBox() self.mainbox.pack_start(hbox, expand=1, fill=1, padding=5) frame = gtk.Frame("Data") gtklogger.setWidgetName(frame, 'Data') frame.set_shadow_type(gtk.SHADOW_IN) hbox.pack_start(frame, expand=1, fill=1, padding=5) vbox = gtk.VBox() frame.add(vbox) self.databox = gtk.HBox() vbox.pack_start(self.databox, expand=1, fill=1, padding=3) self.datawidget = None # set by updateData # Buttons at the bottom of the window buttonbox = gtk.HBox() self.mainbox.pack_start(buttonbox, expand=0, fill=0, padding=3) # Freeze buttons freezeframe = gtk.Frame("Freeze") gtklogger.setWidgetName(freezeframe, "Freeze") buttonbox.pack_start(freezeframe, expand=1, fill=1, padding=3) hbox = gtk.HBox() freezeframe.add(hbox) # Freeze Space button self.freezeSpaceFlag = False self.freezeSpaceButton = gtk.CheckButton('Space') gtklogger.setWidgetName(self.freezeSpaceButton, 'Space') hbox.pack_start(self.freezeSpaceButton, expand=1, fill=0, padding=0) self.freezeSpaceButton.set_active(self.freezeSpaceFlag) gtklogger.connect(self.freezeSpaceButton, 'clicked', self.freezeSpaceButtonCB) tooltips.set_tooltip_text( self.freezeSpaceButton, "Prevent the data in this window from being updated when the sample position changes." ) # Freeze Time button self.freezeTimeFlag = False self.freezeTimeButton = gtk.CheckButton('Time') gtklogger.setWidgetName(self.freezeTimeButton, "Time") hbox.pack_start(self.freezeTimeButton, expand=1, fill=0, padding=0) self.freezeTimeButton.set_active(self.freezeTimeFlag) gtklogger.connect(self.freezeTimeButton, 'clicked', self.freezeTimeButtonCB) tooltips.set_tooltip_text( self.freezeTimeButton, "Prevent the data in this window from being updated when the Mesh's time changes." ) # Clone button self.cloneButton = gtkutils.StockButton(gtk.STOCK_COPY, 'Clone') gtklogger.setWidgetName(self.cloneButton, 'Clone') gtklogger.connect(self.cloneButton, 'clicked', self.cloneButtonCB) buttonbox.pack_start(self.cloneButton, expand=0, fill=0, padding=3) tooltips.set_tooltip_text( self.cloneButton, "Make a copy of this window with its current settings.") # Close button self.closeButton = gtk.Button(stock=gtk.STOCK_CLOSE) gtklogger.setWidgetName(self.closeButton, 'Close') gtklogger.connect(self.closeButton, 'clicked', self.closeButtonCB) buttonbox.pack_end(self.closeButton, expand=0, fill=0, padding=3) self.gtk.connect('destroy', self.destroyCB) self.updateGfxWindowChooser() if gfxwindow: self.gfxWindowChooser.set_state(gfxwindow.name) if position is not None: self.updatePosition(position) self.currentMesh = None self.updateMesh() self.setupSwitchboard() # gfx window dependent callbacks self.sbcallbacks += [ switchboard.requestCallbackMain('open graphics window', self.gfxwindowChanged), switchboard.requestCallbackMain('close graphics window', self.gfxwindowChanged), switchboard.requestCallbackMain('mesh data changed', self.meshDataChanged), switchboard.requestCallbackMain((gfxwindow, "time changed"), self.timeChanged) ] self.gtk.show_all()
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 preinitialize(self, name, gfxmanager, clone): # preinitialize is called by GfxWindowBase.__init__ on the # main thread *before* GhostGfxWindow.__init__ is called. debug.mainthreadTest() self.gtk = None self.closed = None # State data used at window-close time. self.name = name self.oofcanvas = None self.realized = 0 self.zoomed = 0 self.settings = ghostgfxwindow.GfxSettings() self.mouseHandler = mousehandler.nullHandler # doesn't do anything # Build all the GTK objects for the interior of the box. These # actually get added to the window itself after the SubWindow # __init__ call. They need to be created first so the # GhostGfxWindow can operate on them, and then create the menus # which are handed off to the SubWindow. self.mainpane = gtk.VPaned() gtklogger.setWidgetName(self.mainpane, 'Pane0') # Pane dividing upper pane horizontally into 2 parts. self.paned1 = gtk.HPaned() gtklogger.setWidgetName(self.paned1, "Pane2") # "resize=True" here means that when the window is resized # vertically, the canvas and toolboxes will resize, but the # layer list won't. It also makes the layer list compact when # the window is first opened. This is what we want. However, # on some systems (those using Unity WM, maybe) the layer list # is completely collapsed in the initial window, which is # unfriendly but not fatal. Ubuntu 17.10 doesn't have the # problem so it's not going to be fixed. self.mainpane.pack1(self.paned1, resize=True) gtklogger.connect_passive(self.paned1, 'size-allocate') # The toolbox is in the left half of paned1 (ie the left frame of 3) toolboxframe = gtk.Frame() toolboxframe.set_shadow_type(gtk.SHADOW_IN) self.paned1.pack1(toolboxframe, resize=True) ## TODO OPT: Does the frame size really need to be logged? It ## should just follow from the pane size. gtklogger.setWidgetName(toolboxframe, "ToolboxFrame") gtklogger.connect_passive(toolboxframe, 'size-allocate') # Box containing the toolbox label and the scroll window for # the toolbox itself. toolboxbox1 = gtk.VBox() toolboxframe.add(toolboxbox1) hbox = gtk.HBox() toolboxbox1.pack_start(hbox, expand=0, fill=0, padding=2) hbox.pack_start(gtk.Label("Toolbox:"), expand=0, fill=0, padding=3) self.toolboxchooser = chooser.ChooserWidget( [], callback=self.switchToolbox, name="TBChooser") hbox.pack_start(self.toolboxchooser.gtk, expand=1, fill=1, padding=3) # Scroll window for the toolbox itself. toolboxbox2 = gtk.ScrolledWindow() gtklogger.logScrollBars(toolboxbox2, 'TBScroll') toolboxbox2.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) toolboxbox1.pack_start(toolboxbox2, expand=1, fill=1) # Actually, the tool box goes inside yet another box, so that # we have a gtk.VBox that we can refer to later. self.toolboxbody = gtk.VBox() toolboxbox2.add_with_viewport(self.toolboxbody) self.toolboxGUIs = [] # GUI wrappers for toolboxes. self.current_toolbox = None # The canvas is in the right half of paned1. The toolbar goes # on top of the canvas. self.canvasBox = gtk.VBox() toolbarFrame = gtk.Frame() toolbarFrame.set_shadow_type(gtk.SHADOW_IN) self.canvasBox.pack_start(toolbarFrame, expand=0, fill=0, padding=0) self.toolbarBox = gtk.VBox() toolbarFrame.add(self.toolbarBox) self.canvasFrame = gtk.Frame() self.canvasFrame.set_shadow_type(gtk.SHADOW_IN) gtklogger.setWidgetName(self.canvasFrame, "Canvas") self.canvasBox.pack_start(self.canvasFrame, expand=1, fill=1, padding=0) self.paned1.pack2(self.canvasBox, resize=True) # Bottom part of main pane is a list of layers. The actual # DisplayLayer objects are stored in self.display. layerFrame = gtk.Frame(label='Layers') self.mainpane.pack2(layerFrame, resize=False) self.layerScroll = gtk.ScrolledWindow() gtklogger.logScrollBars(self.layerScroll, "LayerScroll") self.layerScroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) layerFrame.add(self.layerScroll) self.layerList = gtk.ListStore(gobject.TYPE_PYOBJECT) self.layerListView = gtk.TreeView(self.layerList) gtklogger.setWidgetName(self.layerListView, "LayerList") self.layerListView.set_row_separator_func(self.layerRowSepFunc) self.layerListView.set_reorderable(True) self.layerListView.set_fixed_height_mode(False) self.layerScroll.add(self.layerListView) gtklogger.adoptGObject(self.layerList, self.layerListView, access_method=self.layerListView.get_model) # Handle right-clicks on the layer list. They pop up the # Layer menu. gtklogger.connect(self.layerListView, 'button-press-event', self.layerListButtonCB) # The row-deleted and row-inserted signals are used to detect # when the user has reordered rows manually. When the program # does anything that might cause these signals to be emitted, # it must first call suppressRowOpSignals. self.rowOpSignals = [ gtklogger.connect(self.layerList, "row-deleted", self.listRowDeletedCB), gtklogger.connect(self.layerList, "row-inserted", self.listRowInsertedCB) ] self.destination_path = None showcell = gtk.CellRendererToggle() showcol = gtk.TreeViewColumn("Show") showcol.pack_start(showcell, expand=False) showcol.set_cell_data_func(showcell, self.renderShowCell) self.layerListView.append_column(showcol) gtklogger.adoptGObject(showcell, self.layerListView, access_function=gtklogger.findCellRenderer, access_kwargs={ 'col': 0, 'rend': 0 }) gtklogger.connect(showcell, 'toggled', self.showcellCB) ## cmapcell = gtk.CellRendererToggle() ## cmapcell.set_radio(True) ## cmapcol = gtk.TreeViewColumn("Map") ## cmapcol.pack_start(cmapcell, expand=False) ## cmapcol.set_cell_data_func(cmapcell, self.renderCMapCell) ## self.layerListView.append_column(cmapcol) ## gtklogger.adoptGObject(cmapcell, self.layerListView, ## access_function='findCellRenderer', ## access_kwargs={'col':1, 'rend':0}) ## gtklogger.connect(cmapcell, 'toggled', self.cmapcellCB) layercell = gtk.CellRendererText() layercol = gtk.TreeViewColumn("What") layercol.set_resizable(True) layercol.pack_start(layercell, expand=True) layercol.set_cell_data_func(layercell, self.renderLayerCell) self.layerListView.append_column(layercol) methodcell = gtk.CellRendererText() methodcol = gtk.TreeViewColumn("How") methodcol.set_resizable(True) methodcol.pack_start(methodcell, expand=True) methodcol.set_cell_data_func(methodcell, self.renderMethodCell) self.layerListView.append_column(methodcol) gtklogger.adoptGObject(self.layerListView.get_selection(), self.layerListView, access_method=self.layerListView.get_selection) self.selsignal = gtklogger.connect(self.layerListView.get_selection(), 'changed', self.selectionChangedCB) gtklogger.connect(self.layerListView, 'row-activated', self.layerDoubleClickCB)
def __init__(self, vwrtoolbox): debug.mainthreadTest() toolboxGUI.GfxToolbox.__init__(self, "Viewer", vwrtoolbox) mainbox = gtk.VBox(spacing=3) self.gtk.add(mainbox) self.historian = historian.Historian( setCB=self.restoreHistoricalView, sensitizeCB=self.sensitize, compareCB=lambda v1, v2: v1.equiv(v2)) # camera position infoExpander = gtk.Expander("Camera Info") gtklogger.setWidgetName(infoExpander, "CameraInfo") infoFrame = gtk.Frame() infoFrame.set_shadow_type(gtk.SHADOW_IN) mainbox.pack_start(infoExpander, fill=0, expand=0) infoExpander.add(infoFrame) infoBox = gtk.VBox(spacing=3) infoFrame.add(infoBox) positionlabel = gtk.Label("Camera Position:") infoBox.pack_start(positionlabel, fill=0, expand=0) positiontable = gtk.Table(columns=3, rows=1) infoBox.pack_start(positiontable, fill=0, expand=0) self.camera_x = gtk.Entry() gtklogger.setWidgetName(self.camera_x, "CameraX") self.camera_x.set_size_request(ndigits * guitop.top().digitsize, -1) self.camera_x.set_editable(0) positiontable.attach(self.camera_x, 0, 1, 0, 1) self.camera_y = gtk.Entry() gtklogger.setWidgetName(self.camera_y, "CameraY") self.camera_y.set_size_request(ndigits * guitop.top().digitsize, -1) self.camera_y.set_editable(0) positiontable.attach(self.camera_y, 1, 2, 0, 1) self.camera_z = gtk.Entry() gtklogger.setWidgetName(self.camera_z, "CameraZ") self.camera_z.set_size_request(ndigits * guitop.top().digitsize, -1) self.camera_z.set_editable(0) positiontable.attach(self.camera_z, 2, 3, 0, 1) focalpointlabel = gtk.Label("Focal Point:") infoBox.pack_start(focalpointlabel, fill=0, expand=0) focalpointtable = gtk.Table(columns=3, rows=1) infoBox.pack_start(focalpointtable, fill=0, expand=0) self.fp_x = gtk.Entry() gtklogger.setWidgetName(self.fp_x, "FocalX") self.fp_x.set_size_request(ndigits * guitop.top().digitsize, -1) self.fp_x.set_editable(0) focalpointtable.attach(self.fp_x, 0, 1, 0, 1) self.fp_y = gtk.Entry() gtklogger.setWidgetName(self.fp_y, "FocalY") self.fp_y.set_size_request(ndigits * guitop.top().digitsize, -1) self.fp_y.set_editable(0) focalpointtable.attach(self.fp_y, 1, 2, 0, 1) self.fp_z = gtk.Entry() gtklogger.setWidgetName(self.fp_z, "FocalZ") self.fp_z.set_size_request(ndigits * guitop.top().digitsize, -1) self.fp_z.set_editable(0) focalpointtable.attach(self.fp_z, 2, 3, 0, 1) viewuplabel = gtk.Label("View Up Vector:") infoBox.pack_start(viewuplabel, fill=0, expand=0) viewuptable = gtk.Table(columns=3, rows=1) infoBox.pack_start(viewuptable, fill=0, expand=0) self.viewup_x = gtk.Entry() gtklogger.setWidgetName(self.viewup_x, "ViewUpX") self.viewup_x.set_size_request(ndigits * guitop.top().digitsize, -1) self.viewup_x.set_editable(0) viewuptable.attach(self.viewup_x, 0, 1, 0, 1) self.viewup_y = gtk.Entry() gtklogger.setWidgetName(self.viewup_y, "ViewUpY") self.viewup_y.set_size_request(ndigits * guitop.top().digitsize, -1) self.viewup_y.set_editable(0) viewuptable.attach(self.viewup_y, 1, 2, 0, 1) self.viewup_z = gtk.Entry() gtklogger.setWidgetName(self.viewup_z, "ViewUpZ") self.viewup_z.set_size_request(ndigits * guitop.top().digitsize, -1) self.viewup_z.set_editable(0) viewuptable.attach(self.viewup_z, 2, 3, 0, 1) distancetable = gtk.Table(columns=2, rows=1) infoBox.pack_start(distancetable, fill=0, expand=0) distancelabel = gtk.Label("Distance:") distancetable.attach(distancelabel, 0, 1, 0, 1) self.distance = gtk.Entry() gtklogger.setWidgetName(self.distance, "Distance") self.distance.set_size_request(ndigits * guitop.top().digitsize, -1) self.distance.set_editable(0) distancetable.attach(self.distance, 1, 2, 0, 1) angletable = gtk.Table(columns=2, rows=1) infoBox.pack_start(angletable, fill=0, expand=0) anglelabel = gtk.Label("View Angle:") angletable.attach(anglelabel, 0, 1, 0, 1) self.viewangle = gtk.Entry() gtklogger.setWidgetName(self.viewangle, "ViewAngle") self.viewangle.set_size_request(ndigits * guitop.top().digitsize, -1) self.viewangle.set_editable(0) angletable.attach(self.viewangle, 1, 2, 0, 1) # Translation transExpander = gtk.Expander("Translate") gtklogger.setWidgetName(transExpander, "Translation") mainbox.pack_start(transExpander, fill=0, expand=0) transFrame = gtk.Frame() transFrame.set_shadow_type(gtk.SHADOW_IN) transExpander.add(transFrame) transBox = gtk.VBox() transFrame.add(transBox) # dolly dollyrow = gtk.HBox(homogeneous=1, spacing=2) transBox.pack_start(dollyrow, expand=0, fill=1, padding=2) inbutton = gtk.Button('Dolly In') gtklogger.setWidgetName(inbutton, 'DollyIn') tooltips.set_tooltip_text( inbutton, "Translate camera towards focal point by given factor.") dollyrow.pack_start(inbutton, expand=0, fill=1) gtklogger.connect(inbutton, 'clicked', self.dollyin) outbutton = gtk.Button('Dolly Out') gtklogger.setWidgetName(outbutton, 'DollyOut') tooltips.set_tooltip_text( outbutton, "Translate camera away from focal point by given factor.") dollyrow.pack_start(outbutton, expand=0, fill=1) gtklogger.connect(outbutton, 'clicked', self.dollyout) fillbutton = gtk.Button('Fill') gtklogger.setWidgetName(fillbutton, 'Fill') tooltips.set_tooltip_text( fillbutton, "Set the camera position so that the image" " approximately fills the window.") dollyrow.pack_start(fillbutton, expand=0, fill=1) gtklogger.connect(fillbutton, 'clicked', self.dollyfill) factorrow = gtk.HBox() transBox.pack_start(factorrow, expand=0, fill=0, padding=2) factorrow.pack_start(gtk.Label("Factor: "), expand=0, fill=0) self.dollyfactor = gtk.Entry() self.dollyfactor.set_editable(1) self.dollyfactor.set_size_request(ndigits * guitop.top().digitsize, -1) gtklogger.setWidgetName(self.dollyfactor, "DollyFactor") self.dollyfactor.set_text("1.5") tooltips.set_tooltip_text( self.dollyfactor, "Factor by which to multiply distance from camera to focal point.") factorrow.pack_start(self.dollyfactor, expand=1, fill=1) # track trackrow = gtk.HBox(homogeneous=1, spacing=2) transBox.pack_start(trackrow, expand=0, fill=1, padding=2) horizbutton = gtk.Button('Horizontal') tooltips.set_tooltip_text(horizbutton, "Shift camera and focal point horizontally") trackrow.pack_start(horizbutton, expand=0, fill=1) gtklogger.connect(horizbutton, 'clicked', self.trackh) vertbutton = gtk.Button('Vertical') tooltips.set_tooltip_text(vertbutton, "Shift camera and focal point vertically") trackrow.pack_start(vertbutton, expand=0, fill=1) gtklogger.connect(vertbutton, 'clicked', self.trackv) recenterbutton = gtk.Button('Recenter') tooltips.set_tooltip_text( recenterbutton, "Recenter the microstructure in the viewport.") trackrow.pack_start(recenterbutton, expand=0, fill=1) gtklogger.connect(recenterbutton, 'clicked', self.recenter) distrow = gtk.HBox() transBox.pack_start(distrow, expand=0, fill=0, padding=2) distrow.pack_start(gtk.Label("Distance: "), expand=0, fill=0) self.trackdist = gtk.Entry() self.trackdist.set_editable(1) self.trackdist.set_size_request(ndigits * guitop.top().digitsize, -1) self.trackdist.set_text("10.0") tooltips.set_tooltip_text( self.trackdist, "Distance by which to track camera, in pixel units.") distrow.pack_start(self.trackdist, expand=1, fill=1) #rotate rotateExpander = gtk.Expander("Rotate") rotateFrame = gtk.Frame() rotateFrame.set_shadow_type(gtk.SHADOW_IN) mainbox.pack_start(rotateExpander, fill=0, expand=0) rotateBox = gtk.VBox() rotateExpander.add(rotateFrame) rotateFrame.add(rotateBox) rotrow1 = gtk.HBox(homogeneous=1, spacing=2) rotateBox.pack_start(rotrow1, expand=0, fill=1, padding=2) rollbutton = gtk.Button('Roll') tooltips.set_tooltip_text(rollbutton, "Rotate about direction of projection.") rotrow1.pack_start(rollbutton, expand=0, fill=1) gtklogger.connect(rollbutton, 'clicked', self.roll) pitchbutton = gtk.Button('Pitch') tooltips.set_tooltip_text( pitchbutton, "Rotate about cross product of direction of projection and" " view up vector centered at camera position.") rotrow1.pack_start(pitchbutton, expand=0, fill=1) gtklogger.connect(pitchbutton, 'clicked', self.pitch) yawbutton = gtk.Button('Yaw') tooltips.set_tooltip_text( yawbutton, "Rotate about view up vector centered at camera position.") rotrow1.pack_start(yawbutton, expand=0, fill=1) gtklogger.connect(yawbutton, 'clicked', self.yaw) rotrow2 = gtk.HBox(homogeneous=1, spacing=2) rotateBox.pack_start(rotrow2, expand=0, fill=1, padding=2) azbutton = gtk.Button('Azimuth') tooltips.set_tooltip_text( azbutton, "Rotate about view up vector centered at focal point.") rotrow2.pack_start(azbutton, expand=0, fill=1) gtklogger.connect(azbutton, 'clicked', self.azimuth) elbutton = gtk.Button('Elevation') tooltips.set_tooltip_text( elbutton, "Rotate about cross product of direction of projection and" " view up vector centered at focal point") rotrow2.pack_start(elbutton, expand=0, fill=1) gtklogger.connect(elbutton, 'clicked', self.elevation) anglerow = gtk.HBox() rotateBox.pack_start(anglerow, expand=0, fill=0, padding=2) anglerow.pack_start(gtk.Label("Angle: "), expand=0, fill=0) self.angle = gtk.Entry() self.angle.set_editable(1) self.angle.set_size_request(ndigits * guitop.top().digitsize, -1) self.angle.set_text("10.0") tooltips.set_tooltip_text(self.angle, "Angle by which to rotate, in degrees.") anglerow.pack_start(self.angle, expand=1, fill=1) # Zoom zoomExpander = gtk.Expander('Zoom') gtklogger.setWidgetName(zoomExpander, 'Zoom') mainbox.pack_start(zoomExpander, fill=0, expand=0) zoomFrame = gtk.Frame() zoomFrame.set_shadow_type(gtk.SHADOW_IN) zoomExpander.add(zoomFrame) zoomBox = gtk.VBox() zoomFrame.add(zoomBox) buttonbox = gtk.HBox(homogeneous=1, spacing=2) zoomBox.pack_start(buttonbox, expand=0, fill=0) zoominbutton = gtk.Button('In') gtklogger.setWidgetName(zoominbutton, 'In') gtklogger.connect(zoominbutton, 'clicked', self.zoomInCB) buttonbox.pack_start(zoominbutton, expand=1, fill=1) tooltips.set_tooltip_text( zoominbutton, "Zoom in (decrease the viewing angle) by the given factor.") zoomoutbutton = gtk.Button('Out') gtklogger.setWidgetName(zoomoutbutton, 'Out') gtklogger.connect(zoomoutbutton, 'clicked', self.zoomOutCB) buttonbox.pack_start(zoomoutbutton, expand=1, fill=1) tooltips.set_tooltip_text( zoomoutbutton, "Zoom out (increase the viewing angle) by the given factor.") zoomfillbutton = gtk.Button('Fill') gtklogger.setWidgetName(zoomfillbutton, 'Fill') gtklogger.connect(zoomfillbutton, 'clicked', self.zoomFillCB) buttonbox.pack_start(zoomfillbutton, expand=1, fill=1) tooltips.set_tooltip_text( zoomfillbutton, "Set the viewing angle so that the image fills the window.") zoomrow = gtk.HBox() zoomBox.pack_start(zoomrow, expand=0, fill=0) zoomrow.pack_start(gtk.Label("Factor: "), expand=0, fill=0) self.zoomfactor = gtk.Entry() self.zoomfactor.set_text("1.1") self.zoomfactor.set_editable(1) gtklogger.setWidgetName(self.zoomfactor, "Factor") gtklogger.connect_passive(self.zoomfactor, "changed") tooltips.set_tooltip_text( self.zoomfactor, "Factor by which to multiply the camera angle.") zoomrow.pack_start(self.zoomfactor, expand=1, fill=1) # Clipping planes clippingExpander = gtk.Expander("Clip") clippingFrame = gtk.Frame() gtklogger.setWidgetName(clippingExpander, "Clipping") clippingFrame.set_shadow_type(gtk.SHADOW_IN) mainbox.pack_start(clippingExpander, fill=1, expand=1) clippingExpander.add(clippingFrame) clippingBox = gtk.VBox() clippingFrame.add(clippingBox) clippingScroll = gtk.ScrolledWindow() gtklogger.logScrollBars(clippingScroll, "Scroll") clippingScroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) clippingBox.pack_start(clippingScroll, expand=1, fill=1) self.clippingList = gtk.ListStore(gobject.TYPE_PYOBJECT, gobject.TYPE_INT) self.clippingListView = gtk.TreeView(self.clippingList) gtklogger.setWidgetName(self.clippingListView, "ClippingList") clippingScroll.add(self.clippingListView) gtklogger.adoptGObject(self.clippingList, self.clippingListView, access_method=self.clippingListView.get_model) gtklogger.adoptGObject( self.clippingListView.get_selection(), self.clippingListView, access_method=self.clippingListView.get_selection) self.clipSelectSignal = gtklogger.connect( self.clippingListView.get_selection(), 'changed', self.clipSelectionChangedCB) gtklogger.connect(self.clippingListView, 'row-activated', self.editClipCB) # A check button that enables or disables a clipping plane enablecell = gtk.CellRendererToggle() enablecol = gtk.TreeViewColumn("On") enablecol.pack_start(enablecell, expand=False) enablecol.set_cell_data_func(enablecell, self.renderEnableCell) self.clippingListView.append_column(enablecol) gtklogger.adoptGObject(enablecell, self.clippingListView, access_function=gtklogger.findCellRenderer, access_kwargs={ 'col': 0, 'rend': 0 }) gtklogger.connect(enablecell, 'toggled', self.enableCellCB) # A check button for inverting the plane flipcell = gtk.CellRendererToggle() flipcol = gtk.TreeViewColumn("Flip") flipcol.pack_start(flipcell, expand=False) flipcol.set_cell_data_func(flipcell, self.renderFlipCell) self.clippingListView.append_column(flipcol) gtklogger.adoptGObject(flipcell, self.clippingListView, access_function=gtklogger.findCellRenderer, access_kwargs={ 'col': 1, 'rend': 0 }) gtklogger.connect(flipcell, 'toggled', self.flipCellCB) # The normal to the clipping plane normalcell = gtk.CellRendererText() normalcol = gtk.TreeViewColumn("Normal") normalcol.set_resizable(True) normalcol.pack_start(normalcell, expand=True) normalcol.set_cell_data_func(normalcell, self.renderNormalCol) self.clippingListView.append_column(normalcol) # The offset offsetcell = gtk.CellRendererText() offsetcol = gtk.TreeViewColumn("Offset") offsetcol.set_resizable(True) offsetcol.pack_start(offsetcell, expand=True) offsetcol.set_cell_data_func(offsetcell, self.renderOffsetCol) self.clippingListView.append_column(offsetcol) # Buttons for operating on clipping planes bbox = gtk.HBox() bbox.set_homogeneous(True) clippingBox.pack_start(bbox, expand=0, fill=0) newclipbutton = gtk.Button("New") gtklogger.setWidgetName(newclipbutton, "New") gtklogger.connect(newclipbutton, 'clicked', self.newClipCB) tooltips.set_tooltip_text(newclipbutton, "Add a clipping plane.") bbox.pack_start(newclipbutton) self.editclipbutton = gtk.Button("Edit") gtklogger.setWidgetName(self.editclipbutton, "Edit") gtklogger.connect(self.editclipbutton, 'clicked', self.editClipCB) tooltips.set_tooltip_text(self.editclipbutton, "Edit a clipping plane.") bbox.pack_start(self.editclipbutton) self.delclipbutton = gtk.Button("Delete") gtklogger.setWidgetName(self.delclipbutton, "Delete") gtklogger.connect(self.delclipbutton, 'clicked', self.delClipCB) tooltips.set_tooltip_text(self.delclipbutton, "Delete a clipping plane.") bbox.pack_start(self.delclipbutton) # Second row of buttons for clipping plane operations bbox = gtk.HBox() bbox.set_homogeneous(True) clippingBox.pack_start(bbox, expand=0, fill=0) self.invclipButton = gtk.CheckButton("Invert All") gtklogger.setWidgetName(self.invclipButton, "Invert") gtklogger.connect(self.invclipButton, 'clicked', self.invClipCB) tooltips.set_tooltip_text(self.invclipButton, "Invert clipping sense globally") bbox.pack_start(self.invclipButton) self.suppressButton = gtk.CheckButton("Suppress All") gtklogger.setWidgetName(self.suppressButton, "Suppress") gtklogger.connect(self.suppressButton, 'clicked', self.suppressCB) tooltips.set_tooltip_text(self.suppressButton, "Suppress all clipping planes.") bbox.pack_start(self.suppressButton) ## TODO 3.1: Clipping plane operations ## Delete all ## Save/Load? ## Copy to/from other window ## Click & drag editing # save and restore historyFrame = gtk.Frame("Save and Restore Views") historyFrame.set_shadow_type(gtk.SHADOW_IN) mainbox.pack_start(historyFrame, fill=0, expand=0) viewTable = gtk.Table(columns=2, rows=3) historyFrame.add(viewTable) align = gtk.Alignment(xalign=0.9, yalign=0.5) align.add(gtk.Label("Restore:")) viewTable.attach(align, 0, 1, 0, 1) self.viewChooser = chooser.ChooserWidget(viewertoolbox.viewNames(), callback=self.setViewCB, name="viewChooser") viewTable.attach(self.viewChooser.gtk, 1, 2, 0, 1) saveViewButton = gtk.Button("Save...") tooltips.set_tooltip_text(saveViewButton, "Save the current view settings.") gtklogger.setWidgetName(saveViewButton, "Save") gtklogger.connect(saveViewButton, 'clicked', self.saveViewCB) viewTable.attach(saveViewButton, 0, 1, 1, 2) deleteViewButton = gtk.Button("Delete...") tooltips.set_tooltip_text(deleteViewButton, "Delete a saved view.") gtklogger.setWidgetName(deleteViewButton, "Delete") gtklogger.connect(deleteViewButton, 'clicked', self.deleteViewCB) viewTable.attach(deleteViewButton, 1, 2, 1, 2) self.prevViewButton = gtkutils.prevButton() gtklogger.setWidgetName(self.prevViewButton, "Prev") gtklogger.connect(self.prevViewButton, 'clicked', self.historian.prevCB) tooltips.set_tooltip_text(self.prevViewButton, "Reinstate the previous view.") viewTable.attach(self.prevViewButton, 0, 1, 2, 3) self.nextViewButton = gtkutils.nextButton() gtklogger.setWidgetName(self.nextViewButton, "Next") gtklogger.connect(self.nextViewButton, 'clicked', self.historian.nextCB) tooltips.set_tooltip_text(self.nextViewButton, "Reinstate the next view.") viewTable.attach(self.nextViewButton, 1, 2, 2, 3) # # position information # voxelinfoFrame = gtk.Frame("Voxel Info") # voxelinfoFrame.set_shadow_type(gtk.SHADOW_IN) # mainbox.pack_start(voxelinfoFrame) # voxelinfoBox = gtk.VBox() # voxelinfoFrame.add(voxelinfoBox) # voxelinfotable = gtk.Table(rows=3,columns=2) # voxelinfoBox.pack_start(voxelinfotable, expand=False, fill=False) # label = gtk.Label('x=') # label.set_alignment(1.0, 0.5) # voxelinfotable.attach(label, 0,1, 0,1, xpadding=5, xoptions=gtk.FILL) # self.xtext = gtk.Entry() # self.xtext.set_size_request(ndigits*guitop.top().digitsize, -1) # voxelinfotable.attach(self.xtext, 1,2, 0,1, # xpadding=5, xoptions=gtk.EXPAND|gtk.FILL) # label = gtk.Label('y=') # label.set_alignment(1.0, 0.5) # voxelinfotable.attach(label, 0,1, 1,2, xpadding=5, xoptions=gtk.FILL) # self.ytext = gtk.Entry() # self.ytext.set_size_request(ndigits*guitop.top().digitsize, -1) # voxelinfotable.attach(self.ytext, 1,2, 1,2, # xpadding=5, xoptions=gtk.EXPAND|gtk.FILL) # label = gtk.Label('z=') # label.set_alignment(1.0, 0.5) # voxelinfotable.attach(label, 0,1, 2,3, xpadding=5, xoptions=gtk.FILL) # self.ztext = gtk.Entry() # self.ztext.set_size_request(ndigits*guitop.top().digitsize, -1) # voxelinfotable.attach(self.ztext, 1,2, 2,3, # xpadding=5, xoptions=gtk.EXPAND|gtk.FILL) self.sbcallbacks = [ switchboard.requestCallbackMain("view changed", self.viewChangedCB), switchboard.requestCallbackMain("view restored", self.viewRestoredCB), switchboard.requestCallbackMain("new view", self.newViewCB), switchboard.requestCallbackMain("view deleted", self.viewDeletedCB), switchboard.requestCallbackMain("clip planes changed", self.updateClipList) ] self.sensitize()
def __init__(self, registry, obj=None, title=None, callback=None, fill=0, expand=0, scope=None, name=None, widgetdict={}, verbose=False, *args, **kwargs): debug.mainthreadTest() # if verbose: # debug.fmsg("RCF ctor: title=", title) self.registry = registry # The optionally supplied callbacks are called when a new # subclass is selected. The args to each callback are the subclass's # registration, plus the extra args and kwargs given to # __init__. if callback is not None: self.callbacks = [callback] self.callbackargs = [args] self.callbackkwargs = [kwargs] else: self.callbacks = [] self.callbackargs = [] self.callbackkwargs = [] # fill & expand options are passed to the gtk pack command in # setByRegistration(). self.fill = fill self.expand = expand self.readonly = False RCFBase.__init__(self, gtk.Frame(), scope, widgetdict, name, verbose=verbose) self.box = gtk.VBox() self.gtk.add(self.box) self.options = chooser.ChooserWidget([], callback=self.optionCB, update_callback=self.updateCB, name='Chooser') if not title: self.box.pack_start(self.options.gtk, expand=0, fill=0) self.titlebox = None else: self.titlebox = gtk.HBox() self.box.pack_start(self.titlebox, expand=0, fill=0) self.titlebox.pack_start(gtk.Label(title), expand=0, fill=0) self.titlebox.pack_start(self.options.gtk, expand=1, fill=1) self.widgetcallback = None self.menu = None self.paramWidget = None self.currentOption = None # useDefault indicates whether or not the chooser should be set # to the first legal registration in the registry. It should # be false only if the widget has been explicitly set, either # programmatically or by the user. self.useDefault = obj is None self.suppress_updateCB = False self.update(registry, obj, interactive=0)
def buildBottomRow(self, mainbox): # Build the bottom row of widgets, containing the named # analysis buttons, the Destination chooser, and the Go # button. # Box along the bottom of the page, containing Named Analyses, # Destination, and Go. hbox = gtk.HBox() hbox.set_homogeneous(True) mainbox.pack_start(hbox, expand=0, fill=0, padding=3) # Named Analyses nameframe = gtk.Frame("Named Analyses") gtklogger.setWidgetName(nameframe, 'Name') nameframe.set_shadow_type(gtk.SHADOW_IN) hbox.pack_start(nameframe, expand=1, fill=1, padding=3) namebox = gtk.VBox(spacing=2) namebox.set_border_width(1) nameframe.add(namebox) # The namedOps_button isn't used as a button, really. It's # just a place to click to bring up the menu of named analysis # operations. There isn't room in the frame to make separate # buttons for all the operations and still display the name of # the current analysis, if any. self.namedOps_button = gtk.Button("Create/Delete/etc...") gtklogger.setWidgetName(self.namedOps_button, "Operations") namebox.pack_start(self.namedOps_button, expand=1, fill=1) gtklogger.connect(self.namedOps_button, 'button-press-event', self.namedOpsCB) # Construct the menu of operations. self.namedOpsPopUp = gtk.Menu() gtklogger.newTopLevelWidget(self.namedOpsPopUp, self.menuWidgetName) self.namedOpsPopUp.set_screen(self.namedOps_button.get_screen()) gtklogger.connect_passive(self.namedOpsPopUp, 'deactivate') self.namedOpsMenuItems = {} for position, (name, callback, tip) in enumerate([ ('Create', self.createCB, "Create a new named analysis."), ('Save', self.savenamedCB, "Save named analysis definitions."), ('Delete', self.deleteCB, "Delete a named analysis.") ]): menuitem = gtk.MenuItem() self.namedOpsMenuItems[name] = menuitem gtklogger.setWidgetName(menuitem, name) label = gtk.Label(name + "...") tooltips.set_tooltip_text(label, tip) menuitem.add(label) self.namedOpsPopUp.insert(menuitem, position) gtklogger.connect(menuitem, 'activate', callback) self.namedOpsPopUp.show_all() # Display the name of the current analysis, if it has one. hbox4 = gtk.HBox() namebox.pack_start(hbox4, expand=0, fill=0) hbox4.pack_start(gtk.Label("Current:"), expand=0, fill=0) self.namedAnalysisChooser = chooser.ChooserWidget( [], callback=self.retrieveCB, name="Retrieve") hbox4.pack_start(self.namedAnalysisChooser.gtk, expand=1, fill=1) # reduce no. of calls to setNamedAnalysisChooser self.suppressRetrievalLoop = False # Destination destinationframe = gtk.Frame("Destination") destinationframe.set_shadow_type(gtk.SHADOW_IN) hbox.pack_start(destinationframe, expand=1, fill=1, padding=3) destbox = gtk.HBox() destbox.set_border_width(1) destinationframe.add(destbox) self.destwidget = outputdestinationwidget.TextDestinationWidget( name="Destination", framed=False) destbox.pack_start(self.destwidget.gtk, expand=1, fill=1, padding=2) # Go button self.go_button = gtkutils.StockButton(gtk.STOCK_EXECUTE, "Go") self.go_button.set_border_width(2) gtklogger.setWidgetName(self.go_button, 'Go') gtklogger.connect(self.go_button, "clicked", self.go_buttonCB) tooltips.set_tooltip_text(self.go_button, "Send the output to the destination.") hbox.pack_start(self.go_button, fill=1, expand=1, padding=2)
def __init__(self, gfxwindow): self.gfxwindow = gfxwindow ## TODO 3.1: buttonrow should really have a gtklogger name ## assigned to it. That would require all of the gui scripts ## to be updated. buttonrow = gtk.HBox() self.selectbutton = gtk.RadioButton(label='Select') buttonrow.pack_start(self.selectbutton, expand=0, fill=0) gtklogger.setWidgetName(self.selectbutton, 'select') gtklogger.connect(self.selectbutton, 'clicked', self.selectCB) tooltips.set_tooltip_text( self.selectbutton, "Click on the graphics window to select objects" " according to the current selection mode.") tumblebutton = gtk.RadioButton(label='Tumble', group=self.selectbutton) buttonrow.pack_start(tumblebutton, expand=0, fill=0) gtklogger.setWidgetName(tumblebutton, 'tumble') gtklogger.connect(tumblebutton, 'clicked', self.tumbleCB) tooltips.set_tooltip_text( tumblebutton, "Click and drag on the graphics window to rotate the view." " Hold 'shift' to rotate about the center of the visible region." " Hold 'control' to rotate about the focal point." " Using no keys rotates about the previous axis.") dollybutton = gtk.RadioButton(label='Dolly', group=self.selectbutton) buttonrow.pack_start(dollybutton, expand=0, fill=0) gtklogger.setWidgetName(dollybutton, 'dolly') gtklogger.connect(dollybutton, 'clicked', self.dollyCB) tooltips.set_tooltip_text( dollybutton, "Click and drag on the graphics window to move the viewpoint" " closer to or further from the displayed objects.") trackbutton = gtk.RadioButton(label='Track', group=self.selectbutton) buttonrow.pack_start(trackbutton, expand=0, fill=0) gtklogger.setWidgetName(trackbutton, 'track') gtklogger.connect(trackbutton, 'clicked', self.trackCB) tooltips.set_tooltip_text( trackbutton, "Click and drag on the graphics window to move the" " displayed objects.") self.fillbutton = gtk.Button("Fill") gtklogger.setWidgetName(self.fillbutton, "fill") buttonrow.pack_start(self.fillbutton, expand=0, fill=0) tooltips.set_tooltip_text( self.fillbutton, "Dolly in or out such that visible objects approximately" " fill the viewport") gtklogger.connect(self.fillbutton, "clicked", self.fillCB) viewbox = gtk.HBox() buttonrow.pack_end(viewbox, expand=0, fill=0) self.prevButton = gtkutils.StockButton(gtk.STOCK_GO_BACK) viewbox.pack_start(self.prevButton, expand=0, fill=0) gtklogger.setWidgetName(self.prevButton, "PrevView") gtklogger.connect(self.prevButton, 'clicked', self.prevViewCB) tooltips.set_tooltip_text(self.prevButton, "Reinstate the previous view.") self.viewChooser = chooser.ChooserWidget(viewertoolbox.viewNames(), callback=self.setView, name="viewChooser") viewbox.pack_start(self.viewChooser.gtk, expand=0, fill=0) self.gfxwindow.addSwitchboardCallback( switchboard.requestCallbackMain("completed view change", self.viewChangedCB), switchboard.requestCallbackMain("view restored", self.viewChangedCB)) self.nextButton = gtkutils.StockButton(gtk.STOCK_GO_FORWARD) viewbox.pack_start(self.nextButton, expand=0, fill=0) gtklogger.setWidgetName(self.nextButton, "NextView") gtklogger.connect(self.nextButton, 'clicked', self.nextViewCB) tooltips.set_tooltip_text(self.nextButton, "Reinstate the next view.") # TODO 3.1: more useful things in the toolbar? self.gtk = buttonrow self.tumbleHandler = TumbleMouseHandler(gfxwindow) self.dollyHandler = DollyMouseHandler(gfxwindow) self.trackHandler = TrackMouseHandler(gfxwindow)
def __init__(self, parent): debug.mainthreadTest() self.parent = parent self.gtk = gtk.Frame('Material') gtklogger.setWidgetName(self.gtk, 'Material') self.gtk.set_shadow_type(gtk.SHADOW_IN) vbox = gtk.VBox() self.gtk.add(vbox) buttonbox = gtk.HBox() vbox.pack_start(buttonbox, expand=0, fill=0) self.newmaterial = gtkutils.StockButton(gtk.STOCK_NEW, 'New...') gtklogger.setWidgetName(self.newmaterial, 'New') buttonbox.pack_start(self.newmaterial, expand=1, fill=0) tooltips.set_tooltip_text(self.newmaterial, 'Create a new Material.') gtklogger.connect(self.newmaterial, "clicked", self.on_newmaterial) self.renamematerial = gtkutils.StockButton(gtk.STOCK_EDIT, 'Rename...') gtklogger.setWidgetName(self.renamematerial, 'Rename') buttonbox.pack_start(self.renamematerial, expand=1, fill=0) tooltips.set_tooltip_text(self.renamematerial, 'Rename this material.') gtklogger.connect(self.renamematerial, "clicked", self.on_rename) self.copymaterial = gtkutils.StockButton(gtk.STOCK_COPY, 'Copy...') gtklogger.setWidgetName(self.copymaterial, 'Copy') buttonbox.pack_start(self.copymaterial, expand=1, fill=0) tooltips.set_tooltip_text(self.copymaterial, 'Create a copy of this material.') gtklogger.connect(self.copymaterial, "clicked", self.on_copy) self.deletebutton = gtkutils.StockButton(gtk.STOCK_DELETE, 'Delete') gtklogger.setWidgetName(self.deletebutton, 'Delete') buttonbox.pack_start(self.deletebutton, expand=1, fill=0) tooltips.set_tooltip_text(self.deletebutton, 'Delete this material.') gtklogger.connect(self.deletebutton, "clicked", self.on_delete) self.savebutton = gtkutils.StockButton(gtk.STOCK_SAVE, 'Save...') gtklogger.setWidgetName(self.savebutton, 'Save') buttonbox.pack_start(self.savebutton, expand=1, fill=0) tooltips.set_tooltip_text(self.savebutton, 'Save this material in a file.') gtklogger.connect(self.savebutton, 'clicked', self.on_save) self.materialName = chooser.ChooserWidget( materialmanager.getMaterialNames(), callback=self.newMatSelection, update_callback=self.newMatSelection, name="MaterialList") self.materialName.gtk.set_border_width(3) vbox.pack_start(self.materialName.gtk, expand=0, fill=0) tooltips.set_tooltip_text(self.materialName.gtk, 'Choose a Material to edit.') # The list of Properties belonging to a Material self.matproplist = chooser.ScrolledChooserListWidget( callback=self.matproplistCB, autoselect=False, name="PropertyList") self.matproplist.gtk.set_border_width(3) vbox.pack_start(self.matproplist.gtk, expand=1, fill=1) self.removebutton = gtk.Button('Remove Property from Material') gtklogger.setWidgetName(self.removebutton, "RemoveProperty") self.removebutton.set_border_width(3) vbox.pack_start(self.removebutton, expand=0, fill=0, padding=3) tooltips.set_tooltip_text( self.removebutton, 'Remove the currently selected property from this material.') gtklogger.connect(self.removebutton, "clicked", self.on_remove) # Assignment of materials to pixels and removal of materials # from pixels may belong in a separate GUI page. For now, # it's done via the dialog boxes raised by the buttons defined # here. assignframe = gtk.Frame() assignframe.set_shadow_type(gtk.SHADOW_IN) assignframe.set_border_width(3) vbox.pack_start(assignframe, expand=0, fill=0) # NB surface-mode flag is operative here. if runtimeflags.surface_mode: inner2vbox_pair = gtk.VBox() align = gtk.Alignment(xalign=0.5) inner2hbox_both = gtk.HBox() inner2vbox = gtk.VBox() if runtimeflags.surface_mode: assignframe.add(inner2hbox_both) else: assignframe.add(align) align.add(inner2hbox_both) inner2hbox_both.pack_start(inner2vbox) if runtimeflags.surface_mode: inner2hbox_both.pack_start(inner2vbox_pair) # Assign materials to pixels self.assignbutton = gtk.Button('Assign Material to %ss...' % Pixstring) gtklogger.setWidgetName(self.assignbutton, "Assign") self.assignbutton.set_border_width(3) inner2vbox.pack_start(self.assignbutton, expand=0, fill=0) tooltips.set_tooltip_text( self.assignbutton, 'Assign the currently selected Material to %ss in a Microstructure.' % pixstring) gtklogger.connect(self.assignbutton, 'clicked', self.on_assignment) # Remove materials from pixels self.removematbutton = gtk.Button('Remove Materials from %ss...' % Pixstring) gtklogger.setWidgetName(self.removematbutton, "RemoveMaterial") self.removematbutton.set_border_width(3) inner2vbox.pack_start(self.removematbutton, expand=0, fill=0) tooltips.set_tooltip_text( self.removematbutton, 'Remove all Materials from %ss in a Microstructure.' % pixstring) gtklogger.connect(self.removematbutton, 'clicked', self.on_MS_remove_material) if runtimeflags.surface_mode: self.assigninterfacebutton = gtk.Button('Assign to interface...') gtklogger.setWidgetName(self.assigninterfacebutton, "AssignInterface") self.assigninterfacebutton.set_border_width(3) inner2vbox_pair.pack_start(self.assigninterfacebutton, expand=0, fill=0) tooltips.set_tooltip_text( self.assigninterfacebutton, 'Assign the currently selected Material to an interface in a Microstructure.' ) gtklogger.connect(self.assigninterfacebutton, 'clicked', self.on_interface_assign) # Remove material from interface self.removeinterfacebutton = gtk.Button('Remove from interface...') gtklogger.setWidgetName(self.removeinterfacebutton, "RemoveInterface") self.removeinterfacebutton.set_border_width(3) inner2vbox_pair.pack_start(self.removeinterfacebutton, expand=0, fill=0) tooltips.set_tooltip_text( self.removeinterfacebutton, 'Remove Material from an interface in a Microstructure.') gtklogger.connect(self.removeinterfacebutton, 'clicked', self.on_interface_remove) # End of surface-mode block. self.updatePropList() self.gtk.show_all() # Switchboard callbacks. switchboard.requestCallbackMain("new_material", self.new_mat) switchboard.requestCallbackMain("remove_material", self.del_mat) switchboard.requestCallbackMain("prop_added_to_material", self.prop_added) switchboard.requestCallbackMain("prop_removed_from_material", self.prop_removed) switchboard.requestCallbackMain(('new who', 'Microstructure'), self.sensitize) switchboard.requestCallbackMain(('remove who', 'Microstructure'), self.sensitize)
def preinitialize(self, name, gfxmanager, clone): debug.mainthreadTest() self.gtk = None self.closed = None # State data used at window-close time. self.name = name self.oofcanvas = None self.realized = 0 self.zoomed = 0 self.settings = ghostgfxwindow.GfxSettings() self.mouseHandler = mousehandler.nullHandler # doesn't do anything self.rubberband = rubberband.NoRubberBand() #self.contourmapdata = None # Build all the GTK objects for the interior of the box. These # actually get added to the window itself after the SubWindow # __init__ call. They need to be created first so the # GhostGfxWindow can operate on them, and then create the menus # which are handed off to the SubWindow. self.mainpane = gtk.VPaned() gtklogger.setWidgetName(self.mainpane, 'Pane0') # Panes dividing upper pane horizontally into 3 parts. # paned1's left half contains paned2. self.paned1 = gtk.HPaned() gtklogger.setWidgetName(self.paned1, "Pane1") self.mainpane.pack1(self.paned1, resize=True) gtklogger.connect_passive(self.paned1, 'size-allocate') # paned2 is in left half of paned1 self.paned2 = gtk.HPaned() gtklogger.setWidgetName(self.paned2, "Pane2") self.paned1.pack1(self.paned2, resize=True) gtklogger.connect_passive(self.paned2, 'size-allocate') # The toolbox is in the left half of paned2 (ie the left frame of 3) toolboxframe = gtk.Frame() toolboxframe.set_shadow_type(gtk.SHADOW_IN) self.paned2.pack1(toolboxframe, resize=True) gtklogger.connect_passive(toolboxframe, 'size-allocate') # Box containing the toolbox label and the scroll window for # the toolbox itself. toolboxbox1 = gtk.VBox() toolboxframe.add(toolboxbox1) hbox = gtk.HBox() toolboxbox1.pack_start(hbox, expand=0, fill=0, padding=2) hbox.pack_start(gtk.Label("Toolbox:"), expand=0, fill=0, padding=3) self.toolboxchooser = chooser.ChooserWidget( [], callback=self.switchToolbox, name="TBChooser") hbox.pack_start(self.toolboxchooser.gtk, expand=1, fill=1, padding=3) # Scroll window for the toolbox itself. toolboxbox2 = gtk.ScrolledWindow() gtklogger.logScrollBars(toolboxbox2, 'TBScroll') toolboxbox2.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) toolboxbox1.pack_start(toolboxbox2, expand=1, fill=1) # Actually, the tool box goes inside yet another box, so that # we have a gtk.VBox that we can refer to later. self.toolboxbody = gtk.VBox() toolboxbox2.add_with_viewport(self.toolboxbody) self.toolboxGUIs = [] # GUI wrappers for toolboxes. self.current_toolbox = None # The canvas is in the right half of paned2 (ie the middle # pane of 3). # TODO: make this a table with compact, view control buttons, # for now, just a frame with the gtkglext window. self.canvasBox = gtk.VBox() self.toolbarFrame = gtk.Frame() self.toolbarFrame.set_shadow_type(gtk.SHADOW_IN) self.canvasBox.pack_start(self.toolbarFrame, expand=0, fill=0, padding=0) self.toolbar = toolbarGUI.ToolBar(self) self.toolbarFrame.add(self.toolbar.gtk) self.toolbar.gtk.show() self.canvasFrame = gtk.Frame() self.canvasFrame.set_shadow_type(gtk.SHADOW_IN) gtklogger.setWidgetName(self.canvasFrame, "Canvas") self.canvasBox.pack_start(self.canvasFrame, expand=1, fill=1, padding=0) self.paned2.pack2(self.canvasBox, resize=True) # HACK. Set the position of the toolbox/canvas divider. This # prevents the toolbox pane from coming up minimized. self.paned2.set_position(300) # Bottom part of main pane is a list of layers. The actual # DisplayLayer objects are stored in self.display. layerFrame = gtk.Frame(label='Layers') self.mainpane.pack2(layerFrame, resize=False) self.layerScroll = gtk.ScrolledWindow() gtklogger.logScrollBars(self.layerScroll, "LayerScroll") self.layerScroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) layerFrame.add(self.layerScroll) self.layerList = gtk.ListStore(gobject.TYPE_PYOBJECT) self.layerListView = gtk.TreeView(self.layerList) gtklogger.setWidgetName(self.layerListView, "LayerList") self.layerListView.set_row_separator_func(self.layerRowSepFunc) self.layerListView.set_reorderable(True) self.layerListView.set_fixed_height_mode(False) self.layerScroll.add(self.layerListView) gtklogger.adoptGObject(self.layerList, self.layerListView, access_method=self.layerListView.get_model) # The row-deleted and row-inserted signals are used to detect # when the user has reordered rows manually. When the program # does anything that might cause these signals to be emitted, # it must first call suppressRowOpSignals. self.rowOpSignals = [ gtklogger.connect(self.layerList, "row-deleted", self.listRowDeletedCB), gtklogger.connect(self.layerList, "row-inserted", self.listRowInsertedCB) ] self.destination_path = None showcell = gtk.CellRendererToggle() showcol = gtk.TreeViewColumn("Show") showcol.pack_start(showcell, expand=False) showcol.set_cell_data_func(showcell, self.renderShowCell) self.layerListView.append_column(showcol) gtklogger.adoptGObject(showcell, self.layerListView, access_function=gtklogger.findCellRenderer, access_kwargs={ 'col': 0, 'rend': 0 }) gtklogger.connect(showcell, 'toggled', self.showcellCB) ## cmapcell = gtk.CellRendererToggle() ## cmapcell.set_radio(True) ## cmapcol = gtk.TreeViewColumn("Map") ## cmapcol.pack_start(cmapcell, expand=False) ## cmapcol.set_cell_data_func(cmapcell, self.renderCMapCell) ## self.layerListView.append_column(cmapcol) ## gtklogger.adoptGObject(cmapcell, self.layerListView, ## access_function='findCellRenderer', ## access_kwargs={'col':1, 'rend':0}) ## gtklogger.connect(cmapcell, 'toggled', self.cmapcellCB) layercell = gtk.CellRendererText() layercol = gtk.TreeViewColumn("What") layercol.set_resizable(True) layercol.pack_start(layercell, expand=True) layercol.set_cell_data_func(layercell, self.renderLayerCell) self.layerListView.append_column(layercol) methodcell = gtk.CellRendererText() methodcol = gtk.TreeViewColumn("How") methodcol.set_resizable(True) methodcol.pack_start(methodcell, expand=True) methodcol.set_cell_data_func(methodcell, self.renderMethodCell) self.layerListView.append_column(methodcol) gtklogger.adoptGObject(self.layerListView.get_selection(), self.layerListView, access_method=self.layerListView.get_selection) self.selsignal = gtklogger.connect(self.layerListView.get_selection(), 'changed', self.selectionChangedCB) gtklogger.connect(self.layerListView, 'row-activated', self.layerDoubleClickCB)
def __init__(self, param, scope, name=None, verbose=False): debug.mainthreadTest() # Find the enclosing mesh widget. self.meshwidget = scope.findWidget(lambda x: isinstance( x, whowidget.WhoWidget) and x.whoclass is mesh.meshes) meshname = self.meshwidget.get_value() if meshname: self.meshobj = mesh.meshes[meshname] if issubclass(self.meshobj.__class__, whoville.WhoProxy): gfxwindow = scope.findData("gfxwindow") self.meshobj = mesh.resolve(gfxwindow) else: self.meshobj = None frame = gtk.Frame() vbox = gtk.VBox() frame.add(vbox) self.chooser = chooser.ChooserWidget([], callback=self.chooserCB, name="List") vbox.pack_start(self.chooser.gtk, expand=0, fill=0) bbox = gtk.HBox() bbox.set_spacing(1) vbox.pack_start(bbox, expand=0, fill=0, padding=1) self.newbutton = gtk.Button('New') gtklogger.setWidgetName(self.newbutton, "New") gtklogger.connect(self.newbutton, 'clicked', self.newCB) bbox.pack_start(self.newbutton, expand=1, fill=1) self.copybutton = gtk.Button('Copy') gtklogger.setWidgetName(self.copybutton, "Copy") gtklogger.connect(self.copybutton, 'clicked', self.copyCB) bbox.pack_start(self.copybutton, expand=1, fill=1) self.editbutton = gtk.Button('Edit') gtklogger.setWidgetName(self.editbutton, "Edit") gtklogger.connect(self.editbutton, 'clicked', self.editCB) bbox.pack_start(self.editbutton, expand=1, fill=1) self.renamebutton = gtk.Button('Rename') gtklogger.setWidgetName(self.renamebutton, "Rename") gtklogger.connect(self.renamebutton, 'clicked', self.renameCB) bbox.pack_start(self.renamebutton, expand=1, fill=1) self.deletebutton = gtk.Button('Remove') gtklogger.setWidgetName(self.deletebutton, "Remove") gtklogger.connect(self.deletebutton, 'clicked', self.deleteCB) bbox.pack_start(self.deletebutton, expand=1, fill=1) parameterwidgets.ParameterWidget.__init__(self, frame, scope, name=name, verbose=verbose) self.sbcbs = [ switchboard.requestCallbackMain(self.meshwidget, self.mesh_update), switchboard.requestCallbackMain("cross sections changed", self.cs_update), switchboard.requestCallbackMain( ("cross section renamed", self.meshobj), self.renamedCS) ] self.update(interactive=0) # The parameter could have a non-None value which is not in # the list of allowed choices when this widget is created. In # that case, do nothing. If the parameter has a non-null # value that *is* in the list, set the widget to that value. if param.value in self.chooser.choices(): self.set_value(param.value) self.gtk.show_all()
def __init__(self): debug.mainthreadTest() self.built = False layereditor.LayerEditor.__init__(self) gtklogger.checkpoint("layereditor layerset changed") self.suppressCallbacks = 0 widgetscope.WidgetScope.__init__(self, None) self.setData("gfxwindow", None) # widgetscope data, that is self.sbcallbacks = [ switchboard.requestCallbackMain('open graphics window', self.gfxwindowChanged), switchboard.requestCallbackMain('close graphics window', self.gfxwindowChanged) ] self.menu.File.Quit.gui_callback = quit.queryQuit subWindow.SubWindow.__init__(self, title="%s Graphics Layer Editor" % subWindow.oofname(), menu=self.menu) ## self.gtk.set_policy(1, 1, 0) self.gtk.set_default_size(600, 250) self.gtk.connect('destroy', self.destroyCB) mainpane = gtk.HPaned() mainpane.set_border_width(3) mainpane.set_position(300) self.mainbox.pack_start(mainpane, expand=1, fill=1) # The left side of the layer editor is for choosing the object # being drawn. whoframe = gtk.Frame('Displayed Object') mainpane.pack1(whoframe, resize=1, shrink=0) wscroll = gtk.ScrolledWindow() gtklogger.logScrollBars(wscroll, "ObjectScroll") wscroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) whoframe.add(wscroll) vbox = gtk.VBox() wscroll.add_with_viewport(vbox) cmd = self.menu.LayerSet.DisplayedObject # This creates a table containing a WhoClassWidget and a WhoWidget: ptable = parameterwidgets.ParameterTable( [cmd.get_arg('category'), cmd.get_arg('object')], scope=self) vbox.pack_start(ptable.gtk, expand=0, fill=0) # The right side of the layer editor lists the display methods # for the object on the left side. methframe = gtk.Frame('Display Methods') gtklogger.setWidgetName(methframe, "DisplayMethods") mainpane.pack2(methframe, resize=1, shrink=0) mvbox = gtk.VBox() methframe.add(mvbox) mhbox = gtk.HBox() mvbox.pack_start(mhbox, expand=1, fill=1) self.methodList = chooser.ScrolledChooserListWidget( callback=self.singleClickMethodCB, dbcallback=self.doubleClickMethodCB, comparator=lambda x, y: (not x.inequivalent(y)), name="List") mhbox.pack_start(self.methodList.gtk, expand=1, fill=1, padding=3) # The who widget is replaced each time the who class widget is # activated, so its switchboard callback must be reset often, # and is done in findWidget(). self.whowidgetsignal = None self.findWhoWidget() buttonbox = gtk.HBox() mvbox.pack_start(buttonbox, expand=0, fill=0, padding=3) self.newMethodButton = gtkutils.StockButton(gtk.STOCK_NEW, 'New...') buttonbox.pack_start(self.newMethodButton, expand=0, fill=0) gtklogger.setWidgetName(self.newMethodButton, "New") gtklogger.connect(self.newMethodButton, 'clicked', self.newMethodButtonCB) self.editMethodButton = gtkutils.StockButton(gtk.STOCK_EDIT, 'Edit...') buttonbox.pack_start(self.editMethodButton, expand=0, fill=0) gtklogger.setWidgetName(self.editMethodButton, "Edit") gtklogger.connect(self.editMethodButton, 'clicked', self.editMethodButtonCB) self.copyMethodButton = gtkutils.StockButton(gtk.STOCK_COPY, 'Copy') buttonbox.pack_start(self.copyMethodButton, expand=0, fill=0) gtklogger.setWidgetName(self.copyMethodButton, "Copy") gtklogger.connect(self.copyMethodButton, 'clicked', self.copyMethodButtonCB) self.deleteMethodButton = gtkutils.StockButton(gtk.STOCK_DELETE, 'Delete') buttonbox.pack_start(self.deleteMethodButton, expand=0, fill=0) gtklogger.setWidgetName(self.deleteMethodButton, "Delete") gtklogger.connect(self.deleteMethodButton, 'clicked', self.deleteMethodButtonCB) self.mainbox.pack_start(gtk.HSeparator(), expand=0, fill=0) # Buttons at the bottom governing LayerSet operations: # New LayerSet, Send to Gfx Window, etc. mainbuttonbox = gtk.HBox() self.mainbox.pack_start(mainbuttonbox, expand=0, fill=0, padding=3) newLayerButton = gtkutils.StockButton(gtk.STOCK_NEW, 'New Layer') mainbuttonbox.pack_start(newLayerButton, expand=0, fill=0, padding=3) gtklogger.setWidgetName(newLayerButton, "NewLayer") gtklogger.connect(newLayerButton, 'clicked', self.newLayerButtonCB) self.sendButton = gtkutils.StockButton(gtk.STOCK_GO_FORWARD, 'Send', reverse=1) ## self.sendButton.set_usize(80, -1) mainbuttonbox.pack_end(self.sendButton, expand=0, fill=0, padding=3) gtklogger.setWidgetName(self.sendButton, "Send") gtklogger.connect(self.sendButton, 'clicked', self.sendCB) self.destinationMenu = chooser.ChooserWidget([], name="Destination") mainbuttonbox.pack_end(self.destinationMenu.gtk, expand=0, fill=0) self.updateDestinationMenu() label = gtk.Label('Destination=') tooltips.set_tooltip_text( label, 'The graphics window(s) that will display the layer(s).') label.set_alignment(1.0, 0.5) mainbuttonbox.pack_end(label, expand=0, fill=0) self.mainbox.pack_start(gtk.HSeparator(), expand=0, fill=0, padding=3) # When the lhs widgets change state the rhs might have to # change too. The widgets referred to here are inside the # ParameterTable constructed above. self.whoclasswidget = self.findWidget( lambda w: isinstance(w, whowidget.WhoClassParameterWidget)) self.whoclasswidgetsignal = switchboard.requestCallbackMain( self.whoclasswidget, self.whoClassChangedCB) self.sbcallbacks.append(self.whoclasswidgetsignal) self.built = True self.sensitize() self.gtk.show_all()