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)
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()
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 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() )
configure_dot_code_action, name="&View") graph_menu = Menu("|", node_action, edge_action, subgraph_action, cluster_action, name="&Graph") help_menu = Menu( "|", #help_action, "_", about_action, name="&Help") menubar = MenuBar(file_menu, edit_menu, view_menu, graph_menu, help_menu) #------------------------------------------------------------------------------ # Godot "ToolBar" instance: #------------------------------------------------------------------------------ toolbar = ToolBar( "|", #close_action, "_", new_action, open_action, save_action, save_as_action, "_", undo_action, redo_action, "_",
class tcWindow(HasTraits): project = tcProject plot = tcPlot def __init__(self, project): self.project = project self.plot = create_timechart_container(project) self.plot_range_tools = self.plot.range_tools self.plot_range_tools.on_trait_change(self._selection_time_changed, "time") self.trait_view().title = self.get_title() def get_title(self): if self.project.filename == "dummy": return "PyTimechart: Please Open a File" return "PyTimechart:" + self.project.filename # Create an action that exits the application. status = Str("Welcome to PyTimechart") traits_view = View( HSplit( VSplit( Item('project', show_label=False, editor=InstanceEditor(view='process_view'), style='custom', width=150), # Item('plot_range_tools', show_label = False, editor=InstanceEditor(view = 'selection_view'), style='custom',width=150,height=100) ), Item('plot', show_label=False, editor=ComponentEditor()), ), toolbar=ToolBar(*_create_toolbar_actions(), image_size=(24, 24), show_tool_names=False), menubar=MenuBar(*_create_menubar_actions()), statusbar=[ StatusItem(name='status'), ], resizable=True, width=1280, height=1024, handler=tcActionHandler()) def _on_open_trace_file(self): if open_file(None) and self.project.filename == "dummy": self._ui.dispose() def _on_view_properties(self): self.plot.options.edit_traits() def _on_exit(self, n=None): self.close() sys.exit(0) def close(self, n=None): pass def _on_about(self): aboutBox().edit_traits() def _on_doc(self): browse_doc() def _selection_time_changed(self): self.status = "selection time:%s" % (self.plot_range_tools.time)
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()
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()
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)
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)
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)