示例#1
0
 def on_click(self, event):
     if not event.inaxes: return
     if event.button == 3:
         my_menu = Menu(MPLAction(name="Recenter", action="object.recenter",
                                  event=event),
                        MPLAction(name="Yo!", action="object.do_something",
                                  event=event))
         wxmenu = my_menu.create_menu(self.mpl_control, self)
         self.mpl_control.PopupMenuXY(wxmenu)
示例#2
0
 def _quick_drag_menu ( self, object ):           
     """ Displays the quick drag menu for a specified drag object.
     """
     
     # Get all the features it could be dropped on:
     feature_lists = []
     if isinstance( object, IFeatureTool ):
         msg = 'Apply to'
         for dc in self.dock_control.dock_controls:
             if (dc.visible and
                 (object.feature_can_drop_on( dc.object ) or 
                  object.feature_can_drop_on_dock_control( dc ))): 
                 from feature_tool import FeatureTool
                 
                 feature_lists.append( [ FeatureTool( dock_control = dc ) ] )
     else:
         msg = 'Send to'
         for dc in self.dock_control.dock_controls:
             if dc.visible:
                 allowed = [ f for f in dc.features 
                             if (f.feature_name != '') and
                                 f.can_drop( object ) ]
                 if len( allowed ) > 0:
                     feature_lists.append( allowed )
                 
     # If there are any compatible features:
     if len( feature_lists ) > 0:
         # Create the pop-up menu:
         features = []
         actions  = []
         for list in feature_lists:
             if len( list ) > 1:
                 sub_actions = []
                 for feature in list:
                     sub_actions.append( Action(
                         name   = '%s Feature' % feature.feature_name,
                         action = "self._drop_on(%d)" % len( features ) )
                     )
                     features.append( feature )
                 actions.append( Menu( 
                     name = '%s the %s' % ( msg, feature.dock_control.name ), 
                     *sub_actions )
                 )
             else:
                 actions.append( Action( 
                     name   = '%s %s' % ( msg, list[0].dock_control.name ),
                     action = "self._drop_on(%d)" % len( features ) )
                 ) 
                 features.append( list[0] )
         
         # Display the pop-up menu:
         self._object   = object
         self._features = features
         self.popup_menu( Menu( name = 'popup', *actions ) )
         self._object = self._features = None
def initOdorsDisp(fname, fig, bulb):
    odorlbl, glomval = OdorsInput(fname)
    try:
        from enthought.traits.ui.menu import Action, MenuBar, Menu, Separator  # create odor list
    except:
        from traitsui.menu import Action, MenuBar, Menu, Separator  # create odor list

    menu = Menu(name='Odors')
    for i, name in enumerate(odorlbl):
        menu.append(Action(name=name, action='_show%g' % i))
    #menu.append(Separator())
    menu1 = Menu(name='View')
    menu1.append(Action(name='Set View as Vinci\'s', action='_setview'))
    menu1.append(Action(name='Clean gloms', action='_clean'))
    return MenuBar(menu, menu1), OdorHandler(fig, bulb, glomval)
    def _menu_default(self):
        """ Standard menus for network nodes """

        menu_actions = [Separator(), \
                        self._OpenFile]

        return Menu(*menu_actions)
 def _menu_default(self):
     """ Standard menus for network nodes """
     
     menu_actions = []
     
     
     return Menu( *menu_actions)
示例#6
0
class Flip(SingletonHasTraits):

    flippen = Button(desc="flip the mirror", label="flip mirror")

    def __init__(self, TriggerChannels):
        self._trigger_task = DOTask(TriggerChannels)
        SingletonHasTraits.__init__(self)

    def _flippen_changed(self):
        self._change_mirror()

    def _change_mirror(self):
        self._trigger_task.Write(numpy.array((1, ), dtype=numpy.uint8))
        time.sleep(0.001)
        self._trigger_task.Write(numpy.array((0, ), dtype=numpy.uint8))

    view = View(Item('flippen', show_label=False),
                menubar=MenuBar(
                    Menu(Action(action='_on_close', name='Quit'),
                         name='File')),
                title='Flip mirror',
                width=100,
                height=100,
                buttons=[],
                resizable=True,
                handler=CloseHandler)
示例#7
0
def init_gui_menu():
    odmenu = Menu(name='Odors')
    for odname in bv.odors.odors.keys():
        odmenu.append(Action(name=odname, action='_show_%s' % odname))

    viewmenu = Menu(name='View')
    viewmenu.append(Action(name='Set as Vincis view', action='_setview'))

    return MenuBar(odmenu, viewmenu), MenuHandler()
示例#8
0
 def _add_viewer_actions_menu_default(self):
   actions = []
   for viewer_plugin in find_viewer_plugins():
     actions += [Action(
       name = viewer_plugin.__name__,
       action = 'handler.add_viewer(editor,object,"%s")' % viewer_plugin.__name__
     )]
   return Menu(name = 'Add', *actions)
示例#9
0
文件: base.py 项目: sjl421/code-2
 def __menu_default(self):
     extras = []
     if self.menu_helper is not None:
         extras = self.menu_helper.actions + self._extra_menu_items()
     menu_actions = [Separator()] + extras + \
                    [Separator(), self._HideShowAction, Separator()] + \
                    deepcopy(standard_menu_actions)
     return Menu( *menu_actions)
    def _menu_default(self):
        """ Standard menus for network nodes """

        menu_actions = [Separator(), \
                        self._TracksRender, \
                        self._TrackVisLaunchAction]

        return Menu(*menu_actions)
示例#11
0
def _create_menubar_actions():
    desc = (('&File', ( {"name": "open_trace_file","tooltip":'open new file into pytimechart'},
                        {"name": "exit","tooltip":'exit pytimechart'})),
            ('&Help', ( {"name": "about","tooltip":'about'},{"name": "doc","tooltip":'doc'})))
    ret = []
    for menu in desc:
        actions = []
        for action in menu[1]:
            actions.append(_buildAction(action))
        ret.append(Menu(*tuple(actions), name = menu[0]))
    return tuple(ret)
示例#12
0
 def traits_view(self):
     file_menu = Menu( 
         ActionGroup(
             Action(id="open", name=u"打开", action="open_file"),
             Action(id="save", name=u"保存", action="save_file"),
         ),
         ActionGroup(
             Action(id="exit_app", name=u"退出", action="exit_app"),
         ),
         name = u"文件"
     )
     
     about_menu = Menu(
         Action(id="about", name=u"关于", action="about_dialog"),
         name = u"帮助"
     )
     
     tool_bar = ToolBar( 
         Action(
             image = ImageResource("folder_page.png", search_path = ["img"]),
             tooltip = u"打开文档",
             action = "open_file"
         ), 
         Action(
             image = ImageResource("disk.png", search_path = ["img"]),
             tooltip = u"保存文档",
             action = "save_file"
         ),                 
     )
     
     return View(
         Item("text", style="custom", show_label=False, 
             editor=CodeEditor(line="current_line")),
         menubar = MenuBar(file_menu, about_menu), 
         toolbar = tool_bar,
         statusbar = ["status_info"], 
         resizable = True,
         width = 500, height = 300,
         title = u"程序编辑器",
         handler = MenuDemoHandler()
     )
示例#13
0
def initOdorsDisp(fname, fig, bulb):
    odorlbl, glomval = OdorsInput(fname)
    try:
        from enthought.traits.ui.menu import Action, MenuBar, Menu, Separator # create odor list
    except:
        from traitsui.menu import Action, MenuBar, Menu, Separator # create odor list


    menu = Menu(name='Odors') 
    for i, name in enumerate(odorlbl): menu.append(Action(name=name, action='_show%g' % i))
    #menu.append(Separator())
    menu1 = Menu(name='View') 
    menu1.append(Action(name='Set View as Vinci\'s', action='_setview'))
    menu1.append(Action(name='Clean gloms', action='_clean'))
    return MenuBar(menu, menu1), OdorHandler(fig, bulb, glomval)
示例#14
0
    def __init__(self, renwin=None, **traits):
        """Initializes the object.

        Parameters
        ----------

        - renwin: `Scene` instance.  Defaults to None.

          This may be passed in addition to the renwins attribute
          which can be a list of scenes.

        """
        super(PipelineBrowser, self).__init__(**traits)
        self.ui = None
        self.view = None
        if renwin:
            self.renwins.append(renwin)

        self._root_object_changed(self.root_object)
        menu = Menu(Action(name='Refresh', action='editor.update_editor'),
                    Action(name='Expand all', action='editor.expand_all'))
        self.menu = menu

        nodes = self.tree_generator.get_nodes(menu)

        self.tree_editor = TreeEditor(nodes=nodes,
                                      editable=False,
                                      orientation='vertical',
                                      hide_root=True,
                                      on_dclick=self._on_dclick)
        self.view = View(Group(Item(name='_root',
                                    editor=self.tree_editor,
                                    resizable=True),
                               show_labels=False,
                               show_border=False,
                               orientation='vertical'),
                         title='Pipeline browser',
                         help=False,
                         resizable=True,
                         undo=False,
                         revert=False,
                         width=.3,
                         height=.3)
示例#15
0
    def __init__(self, avl=None, **traits):
        """Initializes the object.
        """
        super(AVLTreeBrowser, self).__init__(**traits)
        self.ui = None
        self.view = None
        if avl:
            self.avl = avl

        menu = Menu(Action(name='Refresh', action='editor.update_editor'),
                    Action(name='Expand all', action='editor.expand_all'))
        self.menu = menu

        self._root_object_changed(self.root_object)

        nodes = self.tree_generator.get_nodes(menu)

        self.tree_editor = TreeEditor(nodes=nodes,
                                      orientation='vertical',
                                      hide_root=True,
                                      on_dclick=self._on_dclick,
                                      selected='selected')
        self.view = View(Group(Item(name='_root',
                                    editor=self.tree_editor,
                                    resizable=True),
                               show_labels=False,
                               show_border=False,
                               orientation='vertical'),
                         title='pyAVL',
                         help=False,
                         resizable=True,
                         undo=False,
                         revert=False,
                         width=.3,
                         height=.3,
                         handler=self.avlhandler,
                         toolbar=ToolBar(*self.avlhandler.toolbar_actions))
class AffectsAverageColumn(ObjectColumn):

    # The context menu for the column:
    menu = Menu(Action(name='Add', action='column.add( object )'),
                Action(name='Sub', action='column.sub( object )'))

    # Right-align numeric values (override):
    horizontal_alignment = 'center'

    # Column width (override):
    width = 0.09

    # Don't allow the data to be edited directly:
    editable = False

    def add(self, object):
        """ Increment the affected player statistic.
        """
        setattr(object, self.name, getattr(object, self.name) + 1)

    def sub(self, object):
        """ Decrement the affected player statistic.
        """
        setattr(object, self.name, getattr(object, self.name) - 1)
示例#17
0
           add       = [ Department ] ),
 TreeNode( node_for  = [ Company ],
           auto_open = True,
           children  = 'employees',
           label     = '=Employees',
           view      = no_view,
           add       = [ Employee ] ),
 TreeNode( node_for  = [ Department ],
           auto_open = True,
           children  = 'employees',
           label     = 'name',
           menu      = Menu( NewAction,
                             Separator(),
                             DeleteAction,
                             Separator(),
                             RenameAction,
                             Separator(),
                             CopyAction, 
                             CutAction, 
                             PasteAction ),
           view      = View( [ 'name', '|<' ] ),
           add       = [ Employee ] ),
 TreeNode( node_for  = [ Employee ],
           auto_open = True,
           label     = 'name',
           menu      = Menu( NewAction,
                             Separator(),
                             Action( name   = 'Default title',
                                     action = 'object.default_title' ),
                             Action( name   = 'Department',
                                     action = 'handler.employee_department(editor,object)' ),
示例#18
0
class ImagePlot(HasTraits):
    plot = Instance(Plot)
    meanrate = CFloat(0.0)

    updater = Instance(UpdateEvents)

    #Plot properties
    tDuration = Range(0., 20)
    channel = Enum(range(getDefaultMonChannelAddress().nChannels))

    def _tDuration_default(self):
        return 5.

    def _meanrate_default(self):
        return 0.

    traits_view = View(Item('plot', editor=ComponentEditor(),
                            show_label=False),
                       Item('meanrate', label='MeanRate(Hz)'),
                       menubar=MenuBar(
                           Menu(Action(name="Edit Plot", action="edit_plot"),
                                CloseAction,
                                name="File")),
                       handler=Controller,
                       width=800,
                       height=500,
                       resizable=True,
                       title="Aer1DViewer",
                       buttons=['OK'])

    plot_edit_view = View(
        Group(
            Item('tDuration'),
            #Item('colormap'),
            Item('channel')),
        buttons=['OK', 'Cancel'])

    def __init__(self, dims=(128, 10)):
        super(ImagePlot, self).__init__()
        #z = numpy.zeros(dims)
        self.plotdata = ArrayPlotData(neurons=[0], times=[0])
        plot = Plot(self.plotdata)
        plot.plot(
            ("times", "neurons"),
            type="scatter",
            marker="dot",
            marker_size=1,
            color='black',
        )
        self.plot = plot

    def _channel_changed(self):
        print('Switching to channel: %d' % self.channel)
        self.updater.channel = self.channel
        self.updater.tot_neurons = []
        self.updater.tot_times = []
        try:
            self.updater.eventsQueue.stop()
        except:
            pass
        pyNCS.pyST.STas.addrBuildHashTable(self.updater.stcs[self.channel])
        self.updater.eventsQueue = pyAex.aexclient.AEXMonClient(
            MonChannelAddress=self.updater.stcs,
            channels=[self.channel],
            host=self.updater.host,
            port=self.updater.port,
            autostart=True,
            fps=self.updater.fps)
示例#19
0
class ImagePlot(HasTraits):
    plot = Instance(Plot)
    meanrate = CFloat(0.0)

    updater = Instance(UpdateEvents)

    #Plot properties
    decay_factor = Range(0., 1)
    colormap = Enum(color_map_name_dict.keys())

    channel = Enum(range(getDefaultMonChannelAddress().nChannels))

    #Private properties
    _cmap = Trait(Greys, Callable)

    def _colormap_default(self):
        return 'Greys'

    def _decay_factor_default(self):
        return 0.5

    def _meanrate_default(self):
        return 0.

    traits_view = View(Item('plot', editor=ComponentEditor(),
                            show_label=False),
                       Item('meanrate', label='MeanRate(Hz)'),
                       menubar=MenuBar(
                           Menu(Action(name="Edit Plot", action="edit_plot"),
                                CloseAction,
                                name="File")),
                       handler=Controller,
                       width=500,
                       height=500,
                       resizable=True,
                       title="Aer2DViewer",
                       buttons=['OK'])

    plot_edit_view = View(Group(Item('decay_factor'), Item('colormap'),
                                Item('channel')),
                          buttons=['OK', 'Cancel'])

    def __init__(self, dims=(128, 10)):
        super(ImagePlot, self).__init__()
        z = numpy.zeros(dims)
        self.plotdata = ArrayPlotData(imagedata=z)
        plot = Plot(self.plotdata)
        plot.img_plot("imagedata",
                      xbounds=(0, dims[1]),
                      ybounds=(0, dims[0]),
                      colormap=self._cmap)
        self.plot = plot
        self.flag = True

    def _colormap_changed(self):
        self._cmap = color_map_name_dict[self.colormap]
        if hasattr(self, 'plot'):
            value_range = self.plot.color_mapper.range
            self.plot.color_mapper = self._cmap(value_range)
        self.plot.request_redraw()

    def _channel_changed(self):
        print('Switching to channel: %d' % self.channel)
        self.updater.channel = self.channel
        self.updater.z = self.updater.z * 0
        try:
            self.updater.eventsQueue.stop()
        except:
            pass
        pyNCS.pyST.STas.addrBuildHashTable(self.updater.stcs[self.channel])

        self.updater.eventsQueue = pyAex.aexclient.AEXMonClient(
            MonChannelAddress=self.updater.stcs,
            channels=[self.channel],
            host=self.updater.host,
            port=self.updater.port,
            autostart=True,
            fps=self.updater.fps)
示例#20
0
about_action = Action(name="About Godot",
                      action="about_godot",
                      image=ImageResource("about"),
                      tooltip="About Godot")

#------------------------------------------------------------------------------
#  Menus:
#------------------------------------------------------------------------------

file_menu = Menu(
    "|",  # Hack suggested by Brennan Williams to achieve correct ordering
    new_action,
    open_action,
    "_",
    save_action,
    save_as_action,
    revert_action,
    "_",
    close_action,
    name="&File")

edit_menu = Menu("|",
                 undo_action,
                 redo_action,
                 "_",
                 options_action,
                 name="&Edit")

view_menu = Menu("|",
                 tree_view_action,
示例#21
0
class MainWindow(HasTraits):
    parameter_file_collections = Instance(ParameterFileCollectionList)
    parameter_files = Instance(ParameterFileCollection)
    plot_frame_tabs = List(Instance(DataObject))
    open_parameterfile = Button
    shell = PythonValue

    def _shell_default(self):
        return globals()

    notebook_editor = ListEditor(editor=InstanceEditor(editable=True),
                                 use_notebook=True)

    traits_view = View(
        VSplit(
            HSplit(
                VGroup(
                    Item(
                        'parameter_file_collections',
                        width=120.0,
                        height=500.0,
                        show_label=False,
                        editor=TreeEditor(
                            editable=False,
                            nodes=[
                                TreeNode(
                                    node_for=[ParameterFileCollectionList],
                                    children='parameter_file_collections',
                                    label="=Data Collections"),
                                TreeNode(node_for=[ParameterFileCollection],
                                         children='parameter_files',
                                         label="name",
                                         view=View()),
                                TreeNode(node_for=[ParameterFile],
                                         children='data_objects',
                                         label="name",
                                         menu=Menu(
                                             Action(name='Slice',
                                                    action='object.do_slice'),
                                             Action(name='Project',
                                                    action='object.do_proj'),
                                             Action(name='VTK',
                                                    action='object.do_vtk')),
                                         view=View()),
                                TreeNode(node_for=[DataObject],
                                         children='',
                                         label="name"),
                            ],
                            show_icons=False),
                    ), Item('open_parameterfile', show_label=False)),
                Item('plot_frame_tabs',
                     style='custom',
                     editor=notebook_editor,
                     show_label=False,
                     height=500.0,
                     width=500.0),
            ),
            HGroup(
                #Item('shell', editor=ShellEditor(share=True),
                #show_label=False, height=120.0),
            ),
        ),
        resizable=True,
        width=800.0,
        height=660.0,
        title="reason v2 [prototype]")

    def _open_parameterfile_fired(self):
        print "OPENING"

    def _parameter_file_collections_default(self):
        return ParameterFileCollectionList()
示例#22
0
class MainWindow(HasTraits):
    """Main window for the viewer built using Traits."""

    # mpl figure
    figure = Instance(Figure)

    # Range slider for selecing slice to view
    slice_index_low = Int(0)  # These have to be trait ints or they don't work
    slice_index_high = Int(
        91)  # with the dynamic updating of the Range slider.
    slice_index = Range(low='slice_index_low', high='slice_index_high')

    # Radio box for selecting orthogonal slice
    slice_plane = Enum(_slice_planes)

    # Affine TextCtrl
    affine = Array(Float, (4, 4))

    def __init__(self):
        super(MainWindow, self).__init__()
        # Initialize our nipy image object
        self.img = ImageData()
        # Initialize our matplotlib figure
        self.img_plot = SingleImage(self.figure, self.img.data)

    #
    # Initializers for Traited attrs
    #
    def _figure_default(self):
        """Initialize matplotlib figure."""
        figure = Figure()
        return figure

    def _slice_index_default(self):
        """Initialize slice_index attr without triggering the
        on_trait_change method.
        """
        return 0

    #
    # Event handlers
    #
    @on_trait_change('slice_index, slice_plane')
    def update_slice_index(self):
        self.img.set_slice_index(self.slice_index)
        self.update_image_slicing()
        self.image_show()

    #
    # Data Model methods
    #
    def update_affine(self):
        self.affine = self.img.get_affine()

    def update_image_slicing(self):

        # XXX: BUG: self.slice_index is set by the slider of the
        # current slice.  When we switch the slice plane, this index
        # may be outside the range of the new slice.  Need to handle
        # this.

        if self.slice_plane == 'Axial':
            self.img.set_slice_plane(_slice_planes[0])
        elif self.slice_plane == 'Sagittal':
            self.img.set_slice_plane(_slice_planes[1])
        elif self.slice_plane == 'Coronal':
            self.img.set_slice_plane(_slice_planes[2])
        else:
            raise AttributeError('Unknown slice plane')

        # update image array
        self.img.update_data()

        # update figure data
        self.img_plot.set_data(self.img.data)

        # get range information for slider
        low, high = self.img.get_range()
        # update range slider
        self.slice_index_low = low
        self.slice_index_high = high

    def image_show(self):
        self.img_plot.draw()

    #
    # View code
    #

    # Menus
    def open_menu(self):
        dlg = FileDialog()
        dlg.open()
        if dlg.return_code == OK:
            self.img.load_image(dlg.path)
            self.update_affine()
            self.update_slice_index()

    menu_open_action = Action(name='Open Nifti', action='open_menu')

    file_menubar = MenuBar(Menu(menu_open_action, name='File'))

    # Items
    fig_item = Item('figure', editor=MPLFigureEditor())
    # radio button to pick slice
    _slice_opts = {
        'Axial': '1:Axial',
        'Sagittal': '2:Sagittal',
        'Coronal': '3:Coronal'
    }
    slice_opt_item = Item(name='slice_plane',
                          editor=EnumEditor(values=_slice_opts),
                          style='custom')

    affine_item = Item('affine', label='Affine', style='readonly')
    # BUG: The rendering with the 'readonly' style creates an ugly wx
    # "multi-line" control.

    traits_view = View(HSplit(
        Group(fig_item), Group(affine_item, slice_opt_item,
                               Item('slice_index'))),
                       menubar=file_menubar,
                       width=0.80,
                       height=0.80,
                       resizable=True)
示例#23
0
class PlotOMaticHandler(Controller):
    # ------------ Menu related --------------------
    exit_action = Action(name='&Exit', action='exit')
    save_session_action = Action(name='&Open Session',
                                 action='open_session',
                                 accelerator='Ctrl+O')
    open_session_action = Action(name='&Save Session',
                                 action='save_session',
                                 accelerator='Ctrl+S')

    file_menu = Menu(exit_action,
                     Separator(),
                     save_session_action,
                     open_session_action,
                     name='&File')

    def exit(self, uii):
        print 'Exit called, really should implement this'

    def save_session(self, uii):
        filename = save_file(
            wildcard=
            'Plot-o-matic session (*.plot_session)|*.plot_session|All files (*)|*',
            file_name='my_session.plot_session',
            message='Save session')
        if filename != '':
            print "Saving session as '%s'" % filename
            session = uii.object.get_config()
            fp = open(filename, 'w')
            yaml.safe_dump(session, fp, default_flow_style=False)
            fp.close()

    def open_session(self, uii):
        filename = open_file(
            wildcard=
            'Plot-o-matic session (*.plot_session)|*.plot_session|All files (*)|*',
            file_name='my_session.plot_session',
            message='Open session')
        if filename != '':
            print "Opening session '%s'" % filename
            fp = open(filename, 'r')
            session = yaml.load(fp)
            fp.close()
            uii.object.set_config(session)

    clear_data_action = Action(name='&Clear Data',
                               action='clear_data',
                               accelerator='Ctrl+W')
    save_data_action = Action(name='&Save Data Set',
                              action='save_data',
                              accelerator='Ctrl+Shift+S')
    open_data_action = Action(name='&Open Data Set',
                              action='open_data',
                              accelerator='Ctrl+Shift+O')

    data_menu = Menu(clear_data_action,
                     Separator(),
                     save_data_action,
                     open_data_action,
                     name='&Data')

    def clear_data(self, uii):
        uii.object.variables.clear()

    def save_data(self, uii):
        filename = save_file(
            wildcard=
            'Plot-o-matic data set (*.plot_data)|*.plot_data|All files (*)|*',
            file_name='my_data.plot_data',
            message='Save data set')
        if filename != '':
            uii.object.variables.save_data_set(filename)
            print "Saved data set '%s'" % filename

    def open_data(self, uii):
        filename = open_file(
            wildcard=
            'Plot-o-matic data set (*.plot_data)|*.plot_data|All files (*)|*',
            file_name='my_data.plot_data',
            message='Open data set')
        if filename != '':
            uii.object.variables.open_data_set(filename)
            print "Opened data set '%s'" % filename

    # ------------ Tree related --------------------

    remove_io_driver_action = Action(
        name='Remove', action='handler.remove_io_driver(editor,object)')
    add_io_driver_actions_menu = Instance(Menu)

    remove_decoder_action = Action(
        name='Remove', action='handler.remove_decoder(editor,object)')
    add_decoder_actions_menu = Instance(Menu)

    remove_viewer_action = Action(
        name='Remove', action='handler.remove_viewer(editor,object)')
    add_viewer_actions_menu = Instance(Menu)

    refresh_tree_action = Action(name='Refresh',
                                 action='handler.refresh_tree(editor)')

    def refresh_tree(self, editor):
        editor.update_editor()

    def _add_io_driver_actions_menu_default(self):
        actions = []
        for io_driver_plugin in find_io_driver_plugins():
            actions += [
                Action(name=io_driver_plugin.__name__,
                       action='handler.add_io_driver(editor,object,"%s")' %
                       io_driver_plugin.__name__)
            ]
        return Menu(name='Add', *actions)

    def remove_io_driver(self, editor, io_driver_object):
        io_driver_list = editor._menu_parent_object
        io_driver_list._remove_io_driver(io_driver_object)
        editor.update_editor()

    def add_io_driver(self, editor, io_driver_list, new_io_driver_name):
        new_io_driver = get_io_driver_plugin_by_name(new_io_driver_name)()
        io_driver_list._add_io_driver(new_io_driver)
        editor.update_editor()

    def _add_decoder_actions_menu_default(self):
        actions = []
        for decoder_plugin in find_decoder_plugins():
            actions += [
                Action(name=decoder_plugin.__name__,
                       action='handler.add_decoder(editor,object,"%s")' %
                       decoder_plugin.__name__)
            ]
        return Menu(name='Add', *actions)

    def remove_decoder(self, editor, decoder_object):
        parent_io_driver = editor._menu_parent_object
        parent_io_driver._remove_decoder(decoder_object)
        editor.update_editor()

    def add_decoder(self, editor, io_driver, decoder_name):
        io_driver_list = editor._menu_parent_object
        new_decoder = get_decoder_plugin_by_name(decoder_name)()
        io_driver._add_decoder(new_decoder)
        editor.update_editor()

    def _add_viewer_actions_menu_default(self):
        actions = []
        for viewer_plugin in find_viewer_plugins():
            actions += [
                Action(name=viewer_plugin.__name__,
                       action='handler.add_viewer(editor,object,"%s")' %
                       viewer_plugin.__name__)
            ]
        return Menu(name='Add', *actions)

    def remove_viewer(self, editor, viewer_object):
        viewers = editor._menu_parent_object.viewers_instance
        viewers._remove_viewer(viewer_object)
        editor.update_editor()

    def add_viewer(self, editor, object, viewer_name):
        new_viewer = get_viewer_plugin_by_name(viewer_name)()
        object.viewers_instance._add_viewer(new_viewer)
        editor.update_editor()
示例#24
0
class PlotOMatic(HasTraits):
    io_driver_list = Instance(IODriverList)
    variables = Instance(Variables)
    viewers = Instance(Viewers)
    selected_viewer = Instance(Viewer)

    handler = PlotOMaticHandler()

    viewer_node = TreeNode(node_for=[Viewer],
                           auto_open=True,
                           label='name',
                           menu=Menu(handler.remove_viewer_action),
                           icon_path='icons/',
                           icon_item='plot.png')

    tree_editor = TreeEditor(nodes=[
        TreeNode(
            node_for=[IODriverList],
            auto_open=True,
            children='io_drivers',
            label='=Input Drivers',
            menu=Menu(handler.refresh_tree_action,
                      handler.add_io_driver_actions_menu),
            view=View(),
        ),
        TreeNode(node_for=[IODriver],
                 auto_open=True,
                 children='_decoders',
                 label='name',
                 add=[DataDecoder],
                 menu=Menu(handler.remove_io_driver_action,
                           handler.refresh_tree_action,
                           handler.add_decoder_actions_menu),
                 icon_path='icons/',
                 icon_open='input.png',
                 icon_group='input.png'),
        TreeNode(node_for=[DataDecoder],
                 auto_open=True,
                 children='',
                 label='name',
                 menu=Menu(handler.refresh_tree_action,
                           handler.remove_decoder_action),
                 icon_path='icons/',
                 icon_item='decoder.png'),
        TreeNode(node_for=[IODriverList],
                 auto_open=True,
                 children='viewers',
                 label='=Viewers',
                 menu=Menu(handler.refresh_tree_action,
                           handler.add_viewer_actions_menu),
                 view=View()), viewer_node
    ],
                             hide_root=True,
                             orientation='vertical')

    view = View(HSplit(
        Item(name='io_driver_list',
             editor=tree_editor,
             resizable=True,
             show_label=False,
             width=.32),
        VSplit(
            Item(name='selected_viewer',
                 style='custom',
                 resizable=True,
                 show_label=False,
                 editor=InstanceEditor(view='view')),
            Item(name='variables', show_label=False, style='custom',
                 height=.3))),
                menubar=MenuBar(handler.file_menu, handler.data_menu),
                title='Plot-o-matic',
                resizable=True,
                width=1000,
                height=600,
                handler=PlotOMaticHandler())

    def __init__(self, **kwargs):
        HasTraits.__init__(self, **kwargs)
        self.viewer_node.on_select = self.click_viewer

    def click_viewer(self, viewer):
        self.selected_viewer = viewer
        self.viewers.select_viewer(viewer)

    def start(self):
        self.io_driver_list.start_all()
        self.viewers.start()

    def stop(self):
        self.viewers.stop()
        self.io_driver_list.stop_all()

    def get_config(self):
        config = {}
        config['io_drivers'] = self.io_driver_list.get_config()
        config['viewers'] = self.viewers.get_config()
        return config

    def set_config(self, config):
        if 'io_drivers' in config:
            self.io_driver_list.set_config(config['io_drivers'])
        if 'viewers' in config:
            self.viewers.set_config(config['viewers'])
        self.variables.clear()
示例#25
0
    def __init__(self, *args, **kargs):
        super(StonerPlot, self).__init__(*args, **kargs)
        self.data = numpy.zeros((2, 2))
        acols = [(self.column_headers[i], i)
                 for i in range(len(self.column_headers))]
        acols[:0] = [("index", "index")]
        self.adapter = ArrayAdapter()
        self.adapter.columns = acols
        self.plotgroup = Group(HGroup(
            VGroup(
                Item('xc',
                     label='X Column',
                     editor=CheckListEditor(name='column_headers')),
                Item('xm', label="X Scale")),
            VGroup(
                Item('yc',
                     label='Y Column',
                     editor=CheckListEditor(name='column_headers')),
                Item('ym', label="Y scale")), Item('p_type',
                                                   label='Plot Type')),
                               HGroup(
                                   Item('color',
                                        label="Colour",
                                        style="simple",
                                        width=75,
                                        visible_when='"scatter" in p_type'),
                                   Item('line_color',
                                        label="Line Colour",
                                        style="simple",
                                        visible_when='outline_width>0',
                                        width=75),
                                   Item('marker',
                                        label="Marker",
                                        visible_when='"scatter" in p_type'),
                                   Item('line_style',
                                        label='Line Style',
                                        visible_when="'line' in p_type"),
                                   Item('marker_size',
                                        label="Marker Size",
                                        visible_when='"scatter" in p_type'),
                                   Item('outline_width', label="Line Width")),
                               Item('plot',
                                    editor=ComponentEditor(),
                                    show_label=False),
                               label="Plot",
                               orientation="vertical")
        self.datagroup = HGroup(Item(
            'data',
            show_label=False,
            style='readonly',
            editor=TabularEditor(adapter=self.adapter)),
                                Item('metadata',
                                     editor=ValueEditor(),
                                     show_label=False,
                                     width=0.25),
                                label="Data")
        self.tabs = Tabbed(self.plotgroup,
                           self.datagroup,
                           orientation="horizontal")

        self.menubar = MenuBar(
            Menu(
                Action(name='E&xit',
                       accelerator="Ctrl+Q",
                       tooltip="E&xit",
                       action='_on_close'),
                Separator(),
                Action(name="&Open",
                       accelerator="Ctrl+O",
                       tooltip="&Open Data File",
                       action="load"),  # these callbacks
                Action(name="&Close",
                       accelerator="Ctrl+W",
                       tooltip="&Close Plot",
                       action="close_plot"),  # these callbacks
                name="File"))

        self._paint()
示例#26
0
 def _actions_default(self):
     actions = self._build_source_actions()
     return [Menu(name='Add Source', *actions)]
示例#27
0
 def _actions_default(self):
     filter_actions = self._build_filter_actions()
     module_actions = self._build_module_actions()
     return [Menu(name='Add Filter', *filter_actions),
             Menu(name='Add Module', *module_actions)]
示例#28
0
 def _actions_default(self):
     module_actions = self._build_module_actions()
     return [Menu(name='Add Module', *module_actions)]
示例#29
0
             auto_open=True,
             children='departments',
             label='=Departments',
             view=no_view,
             add=[Department]),
    TreeNode(node_for=[Company],
             auto_open=True,
             children='employees',
             label='=Employees',
             view=no_view,
             add=[Employee]),
    TreeNode(node_for=[Department],
             auto_open=True,
             children='employees',
             label='name',
             menu=Menu(NewAction, Separator(), DeleteAction, Separator(
             ), RenameAction, Separator(), CopyAction, CutAction, PasteAction),
             view=View(Group('name', orientation='vertical', show_left=True)),
             add=[Employee]),
    TreeNode(node_for=[Employee],
             auto_open=True,
             label='name',
             menu=Menu(NewAction, Separator(), def_title_action, dept_action,
                       Separator(), CopyAction, CutAction, PasteAction,
                       Separator(), DeleteAction, Separator(), RenameAction),
             view=employee_view)
])
# The main view
view = View(
           Group(
               Item(
                    name = 'company',
示例#30
0
class PlotOMaticHandler(Controller):
  # ------------ Menu related --------------------
  exit_action = Action(name='&Exit', action='exit')
  save_session_action = Action(name='&Open Session', action='open_session')
  open_session_action = Action(name='&Save Session', action='save_session')

  file_menu = Menu(
      exit_action,
      Separator(),
      save_session_action,
      open_session_action,
      name = '&File'
  )

  def exit(self, uii):
    print 'Exit called, really should implement this'

  def save_session(self, uii):
    print 'save'
    print pickle.dumps(uii.object.viewers)

  def open_session(self, uii):
    print 'open'
  
  clear_data_action = Action(name = '&Clear Data', action='clear_data')
  save_data_action = Action(name = '&Save Data Set', action='save_data')
  open_data_action = Action(name = '&Open Data Set', action='open_data')

  data_menu = Menu(
      clear_data_action,
      Separator(),
      save_data_action,
      open_data_action,
      name = '&Data'
  )

  def clear_data(self, uii):
    uii.object.variables.clear()

  def save_data(self, uii):
    filename = save_file()
    if filename != '':
      uii.object.variables.save_data_set(filename)
      print "Saved data set as", filename

  def open_data(self, uii):
    filename = open_file()
    if filename != '':
      uii.object.variables.open_data_set(filename)
      print "Opened data set ", filename


  # ------------ Tree related --------------------

  remove_io_driver_action = Action(name='Remove', action='handler.remove_io_driver(editor,object)')
  add_io_driver_actions_menu = Instance(Menu)

  remove_decoder_action = Action(name='Remove', action='handler.remove_decoder(editor,object)')
  add_decoder_actions_menu = Instance(Menu)

  remove_viewer_action = Action(name='Remove', action='handler.remove_viewer(editor,object)')
  add_viewer_actions_menu = Instance(Menu)

  def _add_io_driver_actions_menu_default(self):
    actions = []
    for io_driver_plugin in find_io_driver_plugins():
      actions += [Action(
        name = io_driver_plugin.__name__,
        action = 'handler.add_io_driver(editor,object,"%s")' % io_driver_plugin.__name__
      )]
    return Menu(name = 'Add', *actions)

  def remove_io_driver(self, editor, io_driver_object):
    io_driver_list = editor._menu_parent_object
    io_driver_list._remove_io_driver(io_driver_object)
    editor.update_editor()

  def add_io_driver(self, editor, io_driver_list, new_io_driver_name):
    new_io_driver = get_io_driver_plugin_by_name(new_io_driver_name)()
    io_driver_list._add_io_driver(new_io_driver)
    editor.update_editor()

  def _add_decoder_actions_menu_default(self):
    actions = []
    for decoder_plugin in find_decoder_plugins():
      actions += [Action(
        name = decoder_plugin.__name__,
        action = 'handler.add_decoder(editor,object,"%s")' % decoder_plugin.__name__
      )]
    return Menu(name = 'Add', *actions)

  def remove_decoder(self, editor, decoder_object):
    parent_io_driver = editor._menu_parent_object
    parent_io_driver._remove_decoder(decoder_object)
    editor.update_editor()

  def add_decoder(self, editor, io_driver, decoder_name):
    io_driver_list = editor._menu_parent_object
    new_decoder = get_decoder_plugin_by_name(decoder_name)(variables = io_driver_list.variables)
    io_driver._add_decoder(new_decoder)
    editor.update_editor()
    
  def _add_viewer_actions_menu_default(self):
    actions = []
    for viewer_plugin in find_viewer_plugins():
      actions += [Action(
        name = viewer_plugin.__name__,
        action = 'handler.add_viewer(editor,object,"%s")' % viewer_plugin.__name__
      )]
    return Menu(name = 'Add', *actions)

  def remove_viewer(self, editor, viewer_object):
    viewers = editor._menu_parent_object.viewers_instance
    viewers._remove_viewer(viewer_object)
    editor.update_editor()

  def add_viewer(self, editor, object, viewer_name):
    new_viewer = get_viewer_plugin_by_name(viewer_name)()
    object.viewers_instance._add_viewer(new_viewer)
    editor.update_editor()