Beispiel #1
0
 def __call__(self, params, scope=None, name=None, verbose=False):
     # This function may be redefined for derived classes.  It
     # should return a ParameterWidget of some sort.  It must be
     # called __call__ because it's called by
     # RegisteredClassFactory.makeWidget, which thinks it's
     # instantiating an object of a class.  The default version
     # here does what RegisteredClassFactory does if it doesn't a
     # specialized widget isn't defined.
     return parameterwidgets.ParameterTable(params,
                                            scope=scope,
                                            name=name,
                                            showLabels=True,
                                            verbose=verbose)
Beispiel #2
0
    def makeWidget(self, registration):
        debug.mainthreadTest()
        try:
            # Use the special widget from the widgetdict, if there is one
            widget = self.widgetdict[registration.subclass](registration.params,
                                                            scope=self,
                                                            name=registration.name())
        except KeyError:
            # Otherwise, just use a parameter table.
            widget = parameterwidgets.ParameterTable(
                registration.params, scope=self, name=registration.name())
        self.widgetcallback = switchboard.requestCallbackMain(widget,
                                                              self.widgetCB)
##        self.widgetChanged(widget.isValid(), interactive)
        return widget
Beispiel #3
0
    def makeWidget(self, registration):
        debug.mainthreadTest()
        try:
            widget = self.widgetdict[registration.subclass](
                registration.params,
                self.base_value,
                scope=self,
                name=registration.name())
        except KeyError:
            widget = parameterwidgets.ParameterTable(registration.params,
                                                     scope=self,
                                                     name=registration.name())
        self.widgetcallback = switchboard.requestCallbackMain(widget,
                                                              self.widgetCB)
##        self.widgetChanged(widget.isValid(), interactive)
        return widget
    def __init__(self, selectionmethodGUI, params, scope=None, name=None,
                 showLabels=True, data={}, verbose=False):
        debug.mainthreadTest()
        self.selectionmethodGUI = selectionmethodGUI
        self.params = params

        # A VBox, which will be the self.gtk attribute of this
        # ParameterWidget.
        base = gtk.VBox()
        parameterwidgets.ParameterWidget.__init__(
            self, base, scope=scope, name=name, verbose=verbose)

        # A ParameterTable for the params passed into the constructor.
        self.parameterTable = parameterwidgets.ParameterTable(
            params, scope=scope, name=name,
            showLabels=showLabels, data=data, verbose=verbose)
        base.pack_start(self.parameterTable.gtk, expand=0, fill=0)

        # This is a VBox holding extra GUI content that we want a
        # PixelSelectionMethodFactory to build for certain
        # PixelSelectionMethodRegistrations.
        self.extraGUIbox = gtk.VBox()
        base.pack_start(self.extraGUIbox, expand=0, fill=0)

        # Instructions for using the associated pixel SelectionMethod.
        # TODO: Make these look nicer. Tailor them to different region
        # shapes (e.g. we probably want different instructions if
        # we're trying to select an ellipsoid-shaped region).
        howTo = gtk.Label("""\
Click the Start button below.
Adjust the box widget in the canvas by
clicking and dragging its faces.
Click Done to select all the voxels in the box."""
)
        howTo.set_justify(gtk.JUSTIFY_LEFT)
        self.extraGUIbox.pack_start(howTo, fill=0, expand=0, padding=2)

        # Table containing the Start/Done/Reset/Cancel buttons.
        btable = gtk.Table(rows=2, columns=2, homogeneous=True)
        self.extraGUIbox.pack_start(btable, expand=0, fill=0)
        
        # Clicking the "Start" button brings up the voxel selection
        # widget.
        self.startbutton = gtk.Button('Start')
        gtklogger.setWidgetName(self.startbutton, "Start")
        gtklogger.connect(self.startbutton, 'clicked', self.startCB)
        tooltips.set_tooltip_text(
            self.startbutton, "Display a box for choosing voxels graphically.")
        btable.attach(self.startbutton, 0,1, 0,1, xpadding=1, ypadding=1)
       
        # A button that the user presses once they are done adjusting
        # the region containing the voxels which they wish to select,
        # and are ready to perform the actual selection.
        self.donebutton = gtk.Button('Done')
        gtklogger.setWidgetName(self.donebutton, "Done")
        gtklogger.connect(self.donebutton, 'clicked', self.doneCB)
        tooltips.set_tooltip_text(
            self.donebutton, "Select all voxels within the box.")
        btable.attach(self.donebutton, 1,2, 0,1, xpadding=1, ypadding=1)
        
        self.resetbutton = gtk.Button("Reset")
        gtklogger.setWidgetName(self.resetbutton, 'Reset')
        gtklogger.connect(self.resetbutton, 'clicked', self.resetCB)
        tooltips.set_tooltip_text(
            self.resetbutton,
            "Align the selection box to the full extent of the Microstructure.")
        btable.attach(self.resetbutton, 0,1, 1,2, xpadding=1, ypadding=1)

        self.cancelbutton = gtk.Button("Cancel")
        gtklogger.setWidgetName(self.cancelbutton, 'Cancel')
        gtklogger.connect(self.cancelbutton, 'clicked', self.cancelCB)
        tooltips.set_tooltip_text(
            self.cancelbutton,
            "Stop choosing voxels without selecting anything.")
        btable.attach(self.cancelbutton, 1,2, 1,2, xpadding=1, ypadding=1)
        
        self.sensitize()
Beispiel #5
0
    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()
Beispiel #6
0
    def __init__(self,
                 mode,
                 title=None,
                 filename=None,
                 params=None,
                 pattern=False):
        debug.mainthreadTest()
        widgetscope.WidgetScope.__init__(self, None)
        self.dialog = gtklogger.Dialog()
        self.set_title(title)
        gtklogger.newTopLevelWidget(self.dialog, self.dialog.get_title())
        self.filechooser = gtk.FileChooserWidget(action=_modes[mode])
        self.dialog.set_default_size(500, 300)
        self.filechooser.show()
        self.dialog.vbox.pack_start(self.filechooser, expand=1, fill=1)
        gtklogger.setWidgetName(self.filechooser, "FileChooser")
        gtklogger.connect(self.filechooser, 'selection-changed',
                          self.selectionchangedCB)
        self.dialog.add_button(gtk.STOCK_OK, self.OK)
        self.dialog.add_button(gtk.STOCK_CANCEL, self.CANCEL)
        self.dialog.set_default_response(self.OK)

        self.pattern = (pattern and (mode == 'r'))
        if self.pattern:
            # TODO: Fix aesthetics of the widgets.
            self.filechooser.set_select_multiple(True)
            self.patternrow = gtk.HBox()
            self.patternrow.pack_start(gtk.Label("Pattern: "),
                                       expand=0,
                                       fill=0,
                                       padding=5)
            self.pattern_entry = gtk.Entry()
            self.pattern_entry.set_editable(1)
            self.pattern_entry.set_text("*")
            gtklogger.connect(self.pattern_entry, 'changed',
                              self.patternchangedCB)
            self.patternrow.pack_start(self.pattern_entry,
                                       expand=1,
                                       fill=1,
                                       padding=5)
            self.patternrow.show_all()

        if params is None:
            self.table = None
            if self.pattern:
                self.filechooser.set_extra_widget(self.patternrow)
        else:
            self.table = parameterwidgets.ParameterTable(params,
                                                         scope=self,
                                                         name="Parameters")
            self.sbcallback = switchboard.requestCallbackMain(
                ('validity', self.table), self.validityCB)
            if not self.pattern:
                self.filechooser.set_extra_widget(self.table.gtk)
            else:
                vbox = gtk.VBox()
                vbox.pack_start(self.patternrow)
                vbox.pack_start(self.table.gtk)
                vbox.show()
                self.filechooser.set_extra_widget(vbox)

        if filename is not None:
            self.filechooser.set_current_name(filename)