def _menu_bar_default(self): return SMenuBar(SMenu(TaskAction(name='New', method='new', accelerator='Ctrl+N'), id='File', name='&File'), SMenu(DockPaneToggleGroup(), TaskToggleGroup(), id='View', name='&View'))
class SecondTask(ExampleTask): """ A simple task for opening a blank editor. """ #### Task interface ####################################################### id = 'example.second_task' name = 'Second Multi-Tab Editor' menu_bar = SMenuBar( SMenu(TaskAction(name='New', method='new', accelerator='Ctrl+N'), id='File', name='&File'), SMenu(DockPaneToggleGroup(), TaskToggleGroup(), id='View', name='&View')) tool_bars = [ SToolBar(TaskAction(method='new', tooltip='New file', image=ImageResource('document_new')), image_size=(32, 32)), ] ########################################################################### # 'Task' interface. ########################################################################### def _default_layout_default(self): return TaskLayout(left=Tabbed(PaneItem('steps.first_pane'), PaneItem('steps.second_pane'), PaneItem('steps.third_pane')))
class ExampleTask(Task): """ A simple task for opening a blank editor. """ #### Task interface ####################################################### id = 'example.example_task' name = 'Multi-Tab Editor' active_editor = Property(Instance(IEditor), depends_on='editor_area.active_editor') editor_area = Instance(IEditorAreaPane) menu_bar = SMenuBar( SMenu(TaskAction(name='New', method='new', accelerator='Ctrl+N'), id='File', name='&File'), SMenu(DockPaneToggleGroup(), id='View', name='&View')) tool_bars = [ SToolBar(TaskAction(method='new', tooltip='New file', image=ImageResource('document_new')), image_size=(32, 32)), ] ########################################################################### # 'Task' interface. ########################################################################### def create_central_pane(self): """ Create the central pane: the script editor. """ self.editor_area = EditorAreaPane() return self.editor_area ########################################################################### # 'ExampleTask' interface. ########################################################################### def new(self): """ Opens a new empty window """ editor = Editor() self.editor_area.add_editor(editor) self.editor_area.activate_editor(editor) self.activated() #### Trait property getter/setters ######################################## def _get_active_editor(self): if self.editor_area is not None: return self.editor_area.active_editor return None
def _menu_bar_default(self): return SMenuBar( SMenu( TaskAction(name="New", method="new", accelerator="Ctrl+N"), id="File", name="&File", ), SMenu( DockPaneToggleGroup(), TaskToggleGroup(), id="View", name="&View", ), )
class SecondTask(ExampleTask): """ A simple task for opening a blank editor. """ # Task interface ------------------------------------------------------- id = "example.second_task" name = "Second Multi-Tab Editor" menu_bar = SMenuBar( SMenu( TaskAction(name="New", method="new", accelerator="Ctrl+N"), id="File", name="&File", ), SMenu( DockPaneToggleGroup(), TaskToggleGroup(), id="View", name="&View" ), ) tool_bars = [ SToolBar( TaskAction( method="new", tooltip="New file", image=ImageResource("document_new"), ), image_size=(32, 32), ) ] # ------------------------------------------------------------------------ # 'Task' interface. # ------------------------------------------------------------------------ def _default_layout_default(self): return TaskLayout( left=VSplitter( HSplitter( PaneItem("steps.pane1"), PaneItem("steps.pane2"), PaneItem("steps.pane3"), ), HSplitter( PaneItem("steps.pane4"), PaneItem("steps.pane5"), PaneItem("steps.pane6"), ), ) )
def get_actions_Menu_View_TaskGroup(self): return [ DocumentationOnlyAction( name="Pane Visibility:", description= "Toggles whether or not the named extra pane is shown or hidden in the current window." ), DockPaneToggleGroup(separator=False), DocumentationOnlyAction( name="Current Task:", description= "Changes the view in the entire window to a new editing task. The files in the current task are not lost, it's just a way to edit different types of files while using the same top level window on the desktop." ), TaskToggleGroup(separator=False), ]
class ExampleTask(Task): """ A simple task for opening a blank editor. """ #### Task interface ####################################################### id = 'example.example_task' name = 'Multi-Tab Editor' active_editor = Property(Instance(IEditor), depends_on='editor_area.active_editor') editor_area = Instance(IEditorAreaPane) menu_bar = SMenuBar( SMenu(TaskAction(name='New', method='new', accelerator='Ctrl+N'), id='File', name='&File'), SMenu(DockPaneToggleGroup(), TaskToggleGroup(), id='View', name='&View')) tool_bars = [ SToolBar(TaskAction(method='new', tooltip='New file', image=ImageResource('document_new')), image_size=(32, 32)), ] ########################################################################### # 'Task' interface. ########################################################################### def _default_layout_default(self): return TaskLayout(top=Tabbed(PaneItem('steps.first_pane'), PaneItem('steps.second_pane'), PaneItem('steps.third_pane'))) def create_central_pane(self): """ Create the central pane: the script editor. """ self.editor_area = EditorAreaPane() return self.editor_area def create_dock_panes(self): """ Create the file browser and connect to its double click event. """ return [FirstPane(), SecondPane(), ThirdPane()] ########################################################################### # 'ExampleTask' interface. ########################################################################### def new(self): """ Opens a new empty window """ editor = Editor() self.editor_area.add_editor(editor) self.editor_area.activate_editor(editor) self.activated() #### Trait property getter/setters ######################################## def _get_active_editor(self): if self.editor_area is not None: return self.editor_area.active_editor return None
class ImageViewerTask(Task): """ A simple task for viewing images. """ #### Task interface ####################################################### id = 'example.image_viewer_task' name = 'Image Viewer' #default_layout = TaskLayout( # left=PaneItem('example.python_script_browser_pane')) menu_bar = SMenuBar( SMenu(TaskAction(name='Open...', method='open', accelerator='Ctrl+O'), id='File', name='&File'), SMenu(DockPaneToggleGroup(), id='View', name='&View')) tool_bars = [ SToolBar( TaskAction(method='open', tooltip='Open a file', image=ImageResource('document_open'))) ] ########################################################################### # 'Task' interface. ########################################################################### def _default_layout_default(self): return TaskLayout(left=PaneItem('image_viewer.file_browser_pane')) def activated(self): """ Overriden to set the window's title. """ filename = self.window.central_pane.model.path self.window.title = filename if filename else 'Untitled' def create_central_pane(self): """ Create the central pane: the image viewer. """ return ImageViewerPane() def create_dock_panes(self): """ Create the file browser and connect to its double click event. """ browser = FileBrowserPane(filters=["*.jpg"]) handler = lambda: self._open_file(browser.selected_file) browser.on_trait_change(handler, 'activated') return [browser] ########################################################################### # 'ExampleTask' interface. ########################################################################### def open(self): """ Shows a dialog to open a file. """ dialog = FileDialog(parent=self.window.control, wildcard='*.jpg') if dialog.open() == OK: self._open_file(dialog.path) ########################################################################### # Protected interface. ########################################################################### def _open_file(self, filename): """ Opens the file at the specified path in the editor. """ self.window.central_pane.model.path = filename self.activated()
class ExampleTask(Task): """ A simple task for opening a blank editor. """ # Task interface ------------------------------------------------------- id = "example.example_task" name = "Multi-Tab Editor" active_editor = Property(Instance(IEditor), observe="editor_area.active_editor") editor_area = Instance(IEditorAreaPane) menu_bar = SMenuBar( SMenu( TaskAction(name="New", method="new", accelerator="Ctrl+N"), id="File", name="&File", ), SMenu(DockPaneToggleGroup(), id="View", name="&View"), ) tool_bars = [ SToolBar( TaskAction( method="new", tooltip="New file", image=ImageResource("document_new"), ), image_size=(32, 32), ) ] # ------------------------------------------------------------------------ # 'Task' interface. # ------------------------------------------------------------------------ def _default_layout_default(self): return TaskLayout(top=PaneItem("steps.example_pane")) def create_central_pane(self): """ Create the central pane: the script editor. """ self.editor_area = EditorAreaPane() return self.editor_area def create_dock_panes(self): """ Create the file browser and connect to its double click event. """ pane = ExamplePane() return [pane] # ------------------------------------------------------------------------ # 'ExampleTask' interface. # ------------------------------------------------------------------------ def new(self): """ Opens a new empty window """ editor = Editor() self.editor_area.add_editor(editor) self.editor_area.activate_editor(editor) self.activated() # Trait property getter/setters ---------------------------------------- def _get_active_editor(self): if self.editor_area is not None: return self.editor_area.active_editor return None
class ExampleTask(Task): """ A simple task for editing Python code. """ #### Task interface ####################################################### id = 'example.example_task' name = 'Multi-Tab Editor' active_editor = Property(Instance(IEditor), depends_on='editor_area.active_editor') editor_area = Instance(IEditorAreaPane) menu_bar = SMenuBar( SMenu(TaskAction(name='New', method='new', accelerator='Ctrl+N'), TaskAction(name='Open...', method='open', accelerator='Ctrl+O'), TaskAction(name='Save', method='save', accelerator='Ctrl+S'), id='File', name='&File'), SMenu(DockPaneToggleGroup(), id='View', name='&View')) tool_bars = [ SToolBar(TaskAction(method='new', tooltip='New file', image=ImageResource('document_new')), TaskAction(method='open', tooltip='Open a file', image=ImageResource('document_open')), TaskAction(method='save', tooltip='Save the current file', image=ImageResource('document_save')), image_size=(32, 32), show_tool_names=False), ] ########################################################################### # 'Task' interface. ########################################################################### def _default_layout_default(self): return TaskLayout(left=PaneItem('example.python_script_browser_pane')) def activated(self): """ Overriden to set the window's title. """ return filename = self.active_editor.path if self.active_editor else '' self.window.title = filename if filename else 'Untitled' def create_central_pane(self): """ Create the central pane: the script editor. """ self.editor_area = EditorAreaPane() return self.editor_area def create_dock_panes(self): """ Create the file browser and connect to its double click event. """ browser = PythonScriptBrowserPane() handler = lambda: self._open_file(browser.selected_file) browser.on_trait_change(handler, 'activated') return [browser] ########################################################################### # 'ExampleTask' interface. ########################################################################### def new(self): """ Opens a new empty window """ editor = PythonEditor() self.editor_area.add_editor(editor) self.editor_area.activate_editor(editor) self.activated() def open(self): """ Shows a dialog to open a file. """ dialog = FileDialog(parent=self.window.control, wildcard='*.py') if dialog.open() == OK: self._open_file(dialog.path) def save(self): """ Attempts to save the current file, prompting for a path if necessary. Returns whether the file was saved. """ editor = self.active_editor try: editor.save() except IOError: # If you are trying to save to a file that doesn't exist, open up a # FileDialog with a 'save as' action. dialog = FileDialog(parent=self.window.control, action='save as', wildcard='*.py') if dialog.open() == OK: editor.save(dialog.path) else: return False return True ########################################################################### # Protected interface. ########################################################################### def _open_file(self, filename): """ Opens the file at the specified path in the editor. """ editor = PythonEditor(path=filename) self.editor_area.add_editor(editor) self.editor_area.activate_editor(editor) self.activated() def _prompt_for_save(self): """ Prompts the user to save if necessary. Returns whether the dialog was cancelled. """ dirty_editors = dict([(editor.name, editor) for editor in self.editor_area.editors if editor.dirty]) if not list(dirty_editors.keys()): return True message = 'You have unsaved files. Would you like to save them?' dialog = ConfirmationDialog(parent=self.window.control, message=message, cancel=True, default=CANCEL, title='Save Changes?') result = dialog.open() if result == CANCEL: return False elif result == YES: for name, editor in list(dirty_editors.items()): editor.save(editor.path) return True #### Trait change handlers ################################################ @on_trait_change('window:closing') def _prompt_on_close(self, event): """ Prompt the user to save when exiting. """ close = self._prompt_for_save() event.veto = not close #### Trait property getter/setters ######################################## def _get_active_editor(self): if self.editor_area is not None: return self.editor_area.active_editor return None
class ExampleTask(Task): """ A simple task for editing Python code. """ #### Task interface ####################################################### id = 'example.example_task' name = 'Python Script Editor' #default_layout = TaskLayout( # left=PaneItem('example.python_script_browser_pane')) menu_bar = SMenuBar( SMenu( TaskAction( name='Open...', method='open', accelerator='Ctrl+O'), TaskAction( name='Save', method='save', accelerator='Ctrl+S'), id='File', name='&File'), SMenu( DockPaneToggleGroup(), id='View', name='&View')) tool_bars = [ SToolBar( TaskAction( method='open', tooltip='Open a file', image=ImageResource('document_open')), TaskAction( method='save', tooltip='Save the current file', image=ImageResource('document_save'))) ] ########################################################################### # 'Task' interface. ########################################################################### def _default_layout_default(self): return TaskLayout(left=PaneItem('example.python_script_browser_pane')) def activated(self): """ Overriden to set the window's title. """ filename = self.window.central_pane.editor.path self.window.title = filename if filename else 'Untitled' def create_central_pane(self): """ Create the central pane: the script editor. """ return PythonEditorPane() def create_dock_panes(self): """ Create the file browser and connect to its double click event. """ browser = PythonScriptBrowserPane() handler = lambda: self._open_file(browser.selected_file) browser.on_trait_change(handler, 'activated') return [browser] ########################################################################### # 'ExampleTask' interface. ########################################################################### def open(self): """ Shows a dialog to open a file. """ dialog = FileDialog(parent=self.window.control, wildcard='*.py') if dialog.open() == OK: self._open_file(dialog.path) def save(self): """ Attempts to save the current file, prompting for a path if necessary. Returns whether the file was saved. """ editor = self.window.central_pane.editor try: editor.save() except IOError: # If you are trying to save to a file that doesn't exist, open up a # FileDialog with a 'save as' action. dialog = FileDialog( parent=self.window.control, action='save as', wildcard='*.py') if dialog.open() == OK: editor.save(dialog.path) else: return False return True ########################################################################### # Protected interface. ########################################################################### def _open_file(self, filename): """ Opens the file at the specified path in the editor. """ if self._prompt_for_save(): self.window.central_pane.editor.path = filename self.activated() def _prompt_for_save(self): """ Prompts the user to save if necessary. Returns whether the dialog was cancelled. """ if self.window.central_pane.editor.dirty: message = 'The current file has unsaved changes. ' \ 'Do you want to save your changes?' dialog = ConfirmationDialog( parent=self.window.control, message=message, cancel=True, default=CANCEL, title='Save Changes?') result = dialog.open() if result == CANCEL: return False elif result == YES: if not self.save(): return self._prompt_for_save() return True @on_trait_change('window:closing') def _prompt_on_close(self, event): """ Prompt the user to save when exiting. """ if not self._prompt_for_save(): event.veto = True
class ExampleTask(Task): """ A simple task for editing Python code. """ # Task interface ------------------------------------------------------- id = "example.example_task" name = "Python Script Editor" # default_layout = TaskLayout( # left=PaneItem('example.python_script_browser_pane')) menu_bar = SMenuBar( SMenu( TaskAction(name="Open...", method="open", accelerator="Ctrl+O"), TaskAction(name="Save", method="save", accelerator="Ctrl+S"), id="File", name="&File", ), SMenu(DockPaneToggleGroup(), id="View", name="&View"), ) tool_bars = [ SToolBar( TaskAction( method="open", tooltip="Open a file", image=ImageResource("document_open"), ), TaskAction( method="save", tooltip="Save the current file", image=ImageResource("document_save"), ), ) ] # ------------------------------------------------------------------------ # 'Task' interface. # ------------------------------------------------------------------------ def _default_layout_default(self): return TaskLayout(left=PaneItem("example.python_script_browser_pane")) def activated(self): """ Overriden to set the window's title. """ filename = self.window.central_pane.editor.path self.window.title = filename if filename else "Untitled" def create_central_pane(self): """ Create the central pane: the script editor. """ return PythonEditorPane() def create_dock_panes(self): """ Create the file browser and connect to its double click event. """ browser = PythonScriptBrowserPane() handler = lambda _: self._open_file(browser.selected_file) browser.observe(handler, "activated") return [browser] # ------------------------------------------------------------------------ # 'ExampleTask' interface. # ------------------------------------------------------------------------ def open(self): """ Shows a dialog to open a file. """ dialog = FileDialog(parent=self.window.control, wildcard="*.py") if dialog.open() == OK: self._open_file(dialog.path) def save(self): """ Attempts to save the current file, prompting for a path if necessary. Returns whether the file was saved. """ editor = self.window.central_pane.editor try: editor.save() except IOError: # If you are trying to save to a file that doesn't exist, open up a # FileDialog with a 'save as' action. dialog = FileDialog(parent=self.window.control, action="save as", wildcard="*.py") if dialog.open() == OK: editor.save(dialog.path) else: return False return True # ------------------------------------------------------------------------ # Protected interface. # ------------------------------------------------------------------------ def _open_file(self, filename): """ Opens the file at the specified path in the editor. """ if self._prompt_for_save(): self.window.central_pane.editor.path = filename self.activated() def _prompt_for_save(self): """ Prompts the user to save if necessary. Returns whether the dialog was cancelled. """ if self.window.central_pane.editor.dirty: message = ("The current file has unsaved changes. " "Do you want to save your changes?") dialog = ConfirmationDialog( parent=self.window.control, message=message, cancel=True, default=CANCEL, title="Save Changes?", ) result = dialog.open() if result == CANCEL: return False elif result == YES: if not self.save(): return self._prompt_for_save() return True @observe("window:closing") def _prompt_on_close(self, event): """ Prompt the user to save when exiting. """ window = event.new if not self._prompt_for_save(): window.veto = True
class ExampleTask(Task): """ A simple task for editing Python code. """ # Task interface ------------------------------------------------------- id = "example.example_task" name = "Multi-Tab Editor" active_editor = Property(Instance(IEditor), observe="editor_area.active_editor") editor_area = Instance(IEditorAreaPane) menu_bar = SMenuBar( SMenu( TaskAction(name="New", method="new", accelerator="Ctrl+N"), TaskAction(name="Open...", method="open", accelerator="Ctrl+O"), TaskAction(name="Save", method="save", accelerator="Ctrl+S"), id="File", name="&File", ), SMenu(DockPaneToggleGroup(), id="View", name="&View"), ) tool_bars = [ SToolBar( TaskAction( method="new", tooltip="New file", image=ImageResource("document_new"), ), TaskAction( method="open", tooltip="Open a file", image=ImageResource("document_open"), ), TaskAction( method="save", tooltip="Save the current file", image=ImageResource("document_save"), ), image_size=(32, 32), show_tool_names=False, ) ] # ------------------------------------------------------------------------ # 'Task' interface. # ------------------------------------------------------------------------ def _default_layout_default(self): return TaskLayout(left=PaneItem("example.python_script_browser_pane")) def activated(self): """ Overriden to set the window's title. """ return filename = self.active_editor.path if self.active_editor else "" self.window.title = filename if filename else "Untitled" def create_central_pane(self): """ Create the central pane: the script editor. """ self.editor_area = EditorAreaPane() return self.editor_area def create_dock_panes(self): """ Create the file browser and connect to its double click event. """ browser = PythonScriptBrowserPane() handler = lambda _: self._open_file(browser.selected_file) browser.observe(handler, "activated") return [browser] # ------------------------------------------------------------------------ # 'ExampleTask' interface. # ------------------------------------------------------------------------ def new(self): """ Opens a new empty window """ editor = PythonEditor() self.editor_area.add_editor(editor) self.editor_area.activate_editor(editor) self.activated() def open(self): """ Shows a dialog to open a file. """ dialog = FileDialog(parent=self.window.control, wildcard="*.py") if dialog.open() == OK: self._open_file(dialog.path) def save(self): """ Attempts to save the current file, prompting for a path if necessary. Returns whether the file was saved. """ editor = self.active_editor try: editor.save() except IOError: # If you are trying to save to a file that doesn't exist, open up a # FileDialog with a 'save as' action. dialog = FileDialog(parent=self.window.control, action="save as", wildcard="*.py") if dialog.open() == OK: editor.save(dialog.path) else: return False return True # ------------------------------------------------------------------------ # Protected interface. # ------------------------------------------------------------------------ def _open_file(self, filename): """ Opens the file at the specified path in the editor. """ editor = PythonEditor(path=filename) self.editor_area.add_editor(editor) self.editor_area.activate_editor(editor) self.activated() def _prompt_for_save(self): """ Prompts the user to save if necessary. Returns whether the dialog was cancelled. """ dirty_editors = dict([(editor.name, editor) for editor in self.editor_area.editors if editor.dirty]) if not dirty_editors.keys(): return True message = "You have unsaved files. Would you like to save them?" dialog = ConfirmationDialog( parent=self.window.control, message=message, cancel=True, default=CANCEL, title="Save Changes?", ) result = dialog.open() if result == CANCEL: return False elif result == YES: for name, editor in dirty_editors.items(): editor.save(editor.path) return True # Trait change handlers ------------------------------------------------ @observe("window:closing") def _prompt_on_close(self, event): """ Prompt the user to save when exiting. """ close = self._prompt_for_save() window = event.new window.veto = not close # Trait property getter/setters ---------------------------------------- def _get_active_editor(self): if self.editor_area is not None: return self.editor_area.active_editor return None
class ExampleTask(Task): """ A simple task for opening a blank editor. """ # Task interface ------------------------------------------------------- id = "example.example_task" name = "Multi-Tab Editor" active_editor = Property( Instance(IEditor), depends_on="editor_area.active_editor" ) editor_area = Instance(IEditorAreaPane) menu_bar = SMenuBar( SMenu( TaskAction(name="New", method="new", accelerator="Ctrl+N"), id="File", name="&File", ), SMenu(DockPaneToggleGroup(), id="View", name="&View"), ) tool_bars = [ SToolBar( TaskAction( method="new", tooltip="New file", image=ImageResource("document_new"), ), image_size=(32, 32), ) ] # ------------------------------------------------------------------------ # 'Task' interface. # ------------------------------------------------------------------------ def create_central_pane(self): """ Create the central pane: the script editor. """ self.editor_area = EditorAreaPane() return self.editor_area # ------------------------------------------------------------------------ # 'ExampleTask' interface. # ------------------------------------------------------------------------ def new(self): """ Opens a new empty window """ editor = Editor() self.editor_area.add_editor(editor) self.editor_area.activate_editor(editor) self.activated() # Trait property getter/setters ---------------------------------------- def _get_active_editor(self): if self.editor_area is not None: return self.editor_area.active_editor return None
def _menu_bar_default(self): from apptools.undo.action.api import UndoAction, RedoAction menu_bar = SMenuBar( SMenu( SGroup(TaskAction(name="Import", method='on_import', accelerator='Ctrl+I'), id='New', name='New'), SGroup(TaskAction(name="Open", method='on_open', accelerator='Ctrl+O'), id='Open', name='Open'), SGroup(TaskAction(name="Save", method='on_save', accelerator='Ctrl+S', enabled_name='dirty'), TaskAction(name="Save As...", method='on_save_as', accelerator='Ctrl+Shift+S', enabled_name='survey'), id='Save', name='Save'), id='File', name="&File", ), SMenu( # XXX can't integrate easily with TraitsUI editors :P SGroup( UndoAction(undo_manager=self.undo_manager, accelerator='Ctrl+Z'), RedoAction(undo_manager=self.undo_manager, accelerator='Ctrl+Shift+Z'), id='UndoGroup', name="Undo Group", ), SGroup( TaskCommandAction(name='New Group', method='on_new_group', accelerator='Ctrl+Shift+N', command_stack_name='command_stack'), TaskCommandAction(name='Delete Group', method='on_delete_group', accelerator='Ctrl+Delete', enabled_name='have_current_group', command_stack_name='command_stack'), id='LineGroupGroup', name="Line Group Group", ), id='Edit', name="&Edit", ), SMenu( SGroup( TaskAction(name='Next Line', method='on_next_line', enabled_name='survey.survey_lines', accelerator='Ctrl+Right'), TaskCommandAction(name='Previous Line', method='on_previous_line', enabled_name='survey.survey_lines', accelerator='Ctrl+Left'), id='LineGroup', name='Line Group', ), SGroup( CentralPaneAction(name='Location Data', method='on_show_location_data', enabled_name='show_view', accelerator='Ctrl+Shift+D'), CentralPaneAction(name='Plot View Selection', method='on_show_plot_view_selection', enabled_name='show_view', accelerator='Ctrl+Shift+S'), id='DataGroup', name='Data Group', ), DockPaneToggleGroup(), id='View', name="&View", ), SMenu( SGroup( CentralPaneAction(name='Image Adjustment', method='on_image_adjustment', enabled_name='show_view', accelerator='Ctrl+Shift+I'), CentralPaneAction(name='Change Colormap', method='on_change_colormap', enabled_name='show_view'), CentralPaneAction(name='Cursor Freeze Key = Alt+c', method='on_cursor_freeze', enabled_name='show_view'), CentralPaneAction(name='Box zoom enable = z'), id='ToolGroup', name='Tool Group', ), id='Tools', name="&Tools", ), ) return menu_bar
class PythonEditorTask(Task): """ A simple task for editing Python code. """ # 'Task' traits ----------------------------------------------------------- #: The unique id of the task. id = 'example.python_editor_task' #: The human-readable name of the task. name = u"Python Editor" #: The currently active editor in the editor area, if any. active_editor = Property(Instance(IEditor), depends_on='editor_area.active_editor') #: The editor area for this task. editor_area = Instance(IEditorAreaPane) #: The menu bar for the task. menu_bar = SMenuBar( SMenu( SGroup( TaskAction(name='New', method='new', accelerator='Ctrl+N'), id='new_group', ), SGroup( TaskAction(name='Open...', method='open', accelerator='Ctrl+O'), id='open_group', ), SGroup( TaskAction(name='Save', method='save', accelerator='Ctrl+S', enabled_name='active_editor.dirty'), TaskAction(name='Save As...', method='save_as', accelerator='Ctrl+Shift+S'), id='save_group', ), SGroup( TaskAction( name='Close Editor', method='close_editor', accelerator='Ctrl+W', ), id='close_group', ), id='File', name='&File', ), SMenu( SGroup( EditorAction( name='Undo', method='undo', enabled_name='can_undo', accelerator='Ctrl+Z', ), EditorAction( name='Redo', method='redo', enabled_name='can_redo', accelerator='Ctrl+Shift+Z', ), id='undo_group', ), SGroup( EditorAction( name='Go to Line...', method='go_to_line', accelerator='Ctrl+G', ), id='search_group', ), id='Edit', name='&Edit', ), SMenu( DockPaneToggleGroup(), id='View', name='&View', ), SMenu( SGroup( OpenURLAction( name='Python Documentation', id='python_docs', url=PYTHON_DOCS, ), id="documentation_group", ), id='Help', name='&Help', )) #: The tool bars for the task. tool_bars = [ SToolBar(TaskAction( method='new', tooltip='New file', image=ImageResource('document_new'), ), TaskAction(method='open', tooltip='Open a file', image=ImageResource('document_open')), TaskAction(method='save', tooltip='Save the current file', image=ImageResource('document_save'), enabled_name='active_editor.dirty'), image_size=(16, 16), show_tool_names=False), ] #: The status bar for the window when this task is active. status_bar = Instance(StatusBarManager, ()) # ------------------------------------------------------------------------- # 'PythonEditorTask' interface. # ------------------------------------------------------------------------- def create_editor(self, path=''): """ Create a new editor in the editor pane. Parameters ---------- path : path or '' The path to the file to edit, or '' for an empty editor. """ if path: path = os.path.abspath(path) use_existing = (path != '') self.editor_area.edit( path, factory=PythonEditor, use_existing=use_existing, ) if path: self.active_editor.load() def close_editor(self): """ Close the active editor, or if no editors, close the Task window. """ if self.editor_area.active_editor is not None: self.editor_area.remove_editor(self.editor_area.active_editor) else: self.window.close() def new(self): """ Open a new empty window """ self.create_editor() def open(self): """ Shows a dialog to open a Python file. """ dialog = FileDialog(parent=self.window.control, wildcard='*.py') if dialog.open() == OK: self.create_editor(dialog.path) def save(self): """ Save the current file. If needed, this code prompts for a path. Returns ------- saved : bool Whether or not the file was saved. """ editor = self.active_editor try: editor.save() except IOError: # If you are trying to save to a file that doesn't exist, open up a # FileDialog with a 'save as' action. dialog = FileDialog( parent=self.window.control, action='save as', wildcard='*.py', ) if dialog.open() == OK: editor.save(dialog.path) else: return False return True # ------------------------------------------------------------------------- # 'Task' interface. # ------------------------------------------------------------------------- def _default_layout_default(self): """ The default layout with the browser pane on the left. """ return TaskLayout( left=PaneItem('example.python_browser_pane', width=200)) def create_central_pane(self): """ Create the central pane: the script editor. """ self.editor_area = EditorAreaPane() return self.editor_area def create_dock_panes(self): """ Create the file browser and connect to its double click event. """ browser = PythonBrowserPane() def handler(): return self.create_editor(browser.selected_file) browser.on_trait_change(handler, 'activated') return [browser] # ------------------------------------------------------------------------- # Protected interface. # ------------------------------------------------------------------------- def _prompt_for_save(self): """ Prompts the user to save if necessary. Returns whether the dialog was cancelled. """ dirty_editors = { editor.name: editor for editor in self.editor_area.editors if editor.dirty and (editor.obj or editor.code) } if not dirty_editors: return True message = 'You have unsaved files. Would you like to save them?' dialog = ConfirmationDialog(parent=self.window.control, message=message, cancel=True, default=CANCEL, title='Save Changes?') result = dialog.open() if result == CANCEL: return False elif result == YES: for name, editor in dirty_editors.items(): editor.save(editor.path) return True # Trait change handlers -------------------------------------------------- @on_trait_change('window:closing') def _prompt_on_close(self, event): """ Prompt the user to save when exiting. """ close = self._prompt_for_save() event.veto = not close @on_trait_change('active_editor.name') def _change_title(self): """ Update the window title when the active editor changes. """ if self.window.active_task == self: if self.active_editor is not None: self.window.title = self.active_editor.name else: self.window.title = self.name @on_trait_change('active_editor.[line,column,selection_length]') def _update_status(self): if self.active_editor is not None: editor = self.active_editor if editor.selection_length: self.status_bar.messages = [ "Ln {}, Col {} ({} selected)".format( editor.line, editor.column, editor.selection_length) ] else: self.status_bar.messages = [ "Ln {}, Col {}".format(editor.line, editor.column) ] else: self.status_bar.messages = [] # Trait property getter/setters ------------------------------------------ @cached_property def _get_active_editor(self): if self.editor_area is not None: return self.editor_area.active_editor return None
class S4LVisualizationTask(Task): # pylint: disable=too-many-instance-attributes """ A task for visualizing Sim4Life EM fields from scES simulations """ #: The task's identifier. id = "s4l.main_task" #: The task's user-visible name. name = "S4L Visualization" #: Configuration parser. configuration = Instance(ConfigParser) #: Current participant's ID participant_id = Str() #: Temporary dictionary for editing user configuration _to_edit = Dict() #: Plane attributes dock pane. plane_attributes_pane = Instance(PlaneAttributes) #: Line attributes dock pane. line_attributes_pane = Instance(LineAttributes) #: Participant ID dock pane. part_id_pane = Instance(ParticipantIDPane) #: The currently active editor. active_editor = Property(Instance(IEditor), depends_on="editor_area.active_editor") #: The editor area in which the editor belongs. editor_area = Instance(IEditorAreaPane) #: The opening page's editor. start_page = Instance(StartPage) #: The object containing the field data. fields_model = Instance(EMFields) #: The 3D view panel. mayavi_scene = Instance(Mayavi3DScene) #: The slice figure panel. slice_figure = Instance(SliceFigureModel) #: The line figure panel. line_figure = Instance(LineFigureModel) #: Has the main window been initialized? model_initialized = Bool(False) #: Action to run :py:meth:`toggle_full_model`. toggle_model_action = TaskAction(name='Full Model', method='toggle_full_model', style='toggle', enabled_name='model_initialized') #: Action to run :py:meth:`change_cord_model`. new_cord_action = TaskAction(name='New Cord Model', method='change_cord_model', enabled_name='model_initialized') #: Action to run :py:meth:`toggle_log_scale`. toggle_scale_action = TaskAction(name='Log Scale', method='toggle_log_scale', style='toggle', checked=True, enabled_name='model_initialized') #: Action to run :py:meth:`toggle_line_cross_marker`. toggle_line_cross_action = TaskAction(name='Line Cross Marker', method='toggle_line_cross_marker', style='toggle', checked=True, enabled_name='model_initialized') #: The task's menu bar. menu_bar = SMenuBar( SMenu( TaskAction(name="&Open...", method="open", accelerator="Ctrl+O"), SMenu( TaskAction(name="Export &Slice", method="export_slice"), TaskAction(name="Export &Line", method="export_line"), id="File.Export", name="&Export", ), TaskAction(name="&Settings", method="edit_configuration"), id="File", name="&File", ), SMenu(SMenu(DockPaneToggleGroup(), id='View.Panes', name='&Panes'), toggle_model_action, toggle_scale_action, toggle_line_cross_action, id="View", name="&View"), SMenu( new_cord_action, SMenu(FieldSelectionGroup(), id='Edit.Fields', name='&Choose Field'), id='Edit', name='&Edit', ), ) # ------------------------------------------------------------------------ # 'Task' interface. # ------------------------------------------------------------------------ @observe('editor_area.active_tabwidget') def _update_tabwidgets(self, event): # pylint: disable=unused-argument try: self.editor_area.active_tabwidget.setTabsClosable(False) except AttributeError: pass def initialized(self): for tabwidget in self.editor_area.tabwidgets(): tabwidget.setTabsClosable(False) self.start_page = StartPage(task=self) self.editor_area.add_editor(self.start_page) self.editor_area.activate_editor(self.start_page) self.activated() def activated(self): self.editor_area.active_tabwidget.setTabsClosable(False) def create_central_pane(self): self.editor_area = SplitEditorAreaPane( callbacks={'open': self._new_file}) return self.editor_area def create_dock_panes(self): """ Create the attribute editor panes. """ self.plane_attributes_pane = PlaneAttributes( configuration=self.configuration) self.plane_attributes_pane.sync_trait('participant_id', self) self.line_attributes_pane = LineAttributes( configuration=self.configuration) self.line_attributes_pane.sync_trait('participant_id', self) self.part_id_pane = ParticipantIDPane() self.part_id_pane.sync_trait('participant_id', self) return [ self.plane_attributes_pane, self.line_attributes_pane, self.part_id_pane ] # ------------------------------------------------------------------------ # 'S4L_Visualization_task' interface. # ------------------------------------------------------------------------ def open(self): """ Show a dialog to open a new data source. """ dialog = FileDialog( title='Choose Data File', parent=self.window.control, wildcard=FileDialog.create_wildcard('Data Files', ['*.mat']) + FileDialog.WILDCARD_ALL) if dialog.open() == OK: if not self.model_initialized: self._new_file(dialog.path) def export_slice(self): """ Export data for current slice. """ dialog = FileDialog( title='Export Slice Plane', action='save as', parent=self.window.control, wildcard='' + FileDialog.create_wildcard('Excel Files', ['*.xlsx']) + FileDialog.create_wildcard('CSV Files', ['*.csv', '*.txt']) + FileDialog.WILDCARD_ALL) if dialog.open() == OK: self.slice_figure.export_slice(dialog.path) def export_line(self): """ Export data for current line. """ dialog = FileDialog( title='Export Line Data', action='save as', parent=self.window.control, wildcard='' + FileDialog.create_wildcard('Excel Files', ['*.xlsx']) + FileDialog.create_wildcard('CSV Files', ['*.csv', '*.txt']) + FileDialog.WILDCARD_ALL) if dialog.open() == OK: self.line_figure.export_line(dialog.path) def toggle_full_model(self): """ Toggle between showing the full spinal cord model and showing only below the cut plane. """ self.mayavi_scene.show_full_model = not self.mayavi_scene.show_full_model def toggle_log_scale(self): """ Toggle between using a logarithmic scale and a linear scale. """ self.mayavi_scene.log_scale = not self.mayavi_scene.log_scale self.slice_figure.log_scale = not self.slice_figure.log_scale def toggle_line_cross_marker(self): """ Toggle visibility of the line cross marker on the slice figure. """ self.slice_figure.draw_cross = not self.slice_figure.draw_cross def change_cord_model(self): """ Change the spinal cord model file used for the 3D display. """ dialog = FileDialog( title='Choose Spinal Cord Model', parent=self.window.control, wildcard=FileDialog.create_wildcard('VTK Model', ['*.vtk']) + FileDialog.WILDCARD_ALL) if dialog.open() == OK: self.mayavi_scene.csf_model = dialog.path def reset_camera(self): """ Set the camera for the Mayavi scene to a pre-determined perspective. """ self.mayavi_scene.initialize_camera() def edit_configuration(self): preferences = PreferenceDialog(configuration=self.configuration, title="S4L Visualization Preferences") ui = preferences.edit_traits(kind='modal') if ui.result: self.configuration.remove_section('') with open('config.ini', 'w') as out_file: self.configuration.write(out_file) def update_participant_id(self): if self.model_initialized: self.line_attributes_pane.set_participant_defaults() self.mayavi_scene.reset_participant_defaults() # ------------------------------------------------------------------------ # Protected interface. # ------------------------------------------------------------------------ def _new_file(self, filename): """ Change the data source to the file at the specified path Parameters ---------- filename : :py:class:`os.PathLike` Path to data source file """ GUI.set_busy(True) if m := re.search(r"\D(\d{3})\D", filename): self.participant_id = m.group(1) if self.participant_id is not None: if self.participant_id not in self.configuration: self.configuration[self.participant_id] = {} default_points = self.configuration[self.participant_id]['points'] self.line_attributes_pane.set_points(default_points) self.part_id_pane.participant_id = self.participant_id self.editor_area.remove_editor(self.start_page) self.window.set_layout( TaskLayout(bottom=PaneItem('s4l.plane_attributes'), left=VSplitter(PaneItem('s4l.line_attributes'), PaneItem('s4l.participant_id_pane')), top_left_corner='top', top_right_corner='top', bottom_left_corner='left', bottom_right_corner='right')) self.fields_model = EMFields(configuration=self.configuration, data_path=filename) self.fields_model.sync_trait('participant_id', self) self.plane_attributes_pane.fields_model = self.fields_model self.mayavi_scene = Mayavi3DScene(fields_model=self.fields_model, configuration=self.configuration) self.mayavi_scene.sync_trait('participant_id', self) self.mayavi_scene.sync_trait('normal', self.plane_attributes_pane) self.mayavi_scene.sync_trait('origin', self.plane_attributes_pane) self.line_attributes_pane.sync_trait('points', self.mayavi_scene, mutual=False) self.mayavi_scene.create_plot() editor = self.mayavi_scene self.editor_area.add_editor(editor) self.editor_area.activate_editor(editor) self.editor_area.active_tabwidget.setTabsClosable(False) self.activated() self.slice_figure = SliceFigureModel(fields_model=self.fields_model, mayavi_scene=self.mayavi_scene, configuration=self.configuration) self.slice_figure.sync_trait('participant_id', self) self.slice_figure.create_plot() self.editor_area.add_editor(self.slice_figure) self.editor_area.activate_editor(self.slice_figure) self.editor_area.active_tabwidget.setTabsClosable(False) self.activated() self.line_figure = LineFigureModel(fields_model=self.fields_model) self.line_figure.sync_trait('points', self.line_attributes_pane) self.line_figure.create_plot(None) self.editor_area.add_editor(self.line_figure) self.editor_area.activate_editor(self.line_figure) self.editor_area.active_tabwidget.setTabsClosable(False) self.activated() self.mayavi_scene.disable_widgets() while self.editor_area.active_tabwidget.parent().is_collapsible(): self.editor_area.active_tabwidget.parent().collapse() layout = Splitter( Tabbed(PaneItem(1), PaneItem(2), active_tab=0), Tabbed(PaneItem(0), active_tab=0), ) self.editor_area.set_layout(layout) self.editor_area.control.setSizes([900, 295]) self.editor_area.activate_editor(self.slice_figure) self.editor_area.active_tabwidget.setTabsClosable(False) for tabwidget in self.editor_area.tabwidgets(): tabwidget.setTabsClosable(False) self.model_initialized = True
def _menu_bar_default(self): menu_bar = SMenuBar( SMenu(SMenu(SGroup( TaskAction(name='New Simulation', method='new_simulation_from_datasource', image=ImageResource('office-chart-pie')), TaskAction(name='New Simulation from Experiment', method='new_simulation_from_experiments', image=ImageResource('kchart'), accelerator='Ctrl+N'), id='NewSimulationGroup', name='NewSimulationGroup', ), id='NewMenu', name='&New Simulation'), SGroup(TaskAction(name='Save Project', accelerator='Ctrl+S', method='save', image=ImageResource('document-save')), TaskAction(name='Save Project As...', accelerator='Ctrl+Shift+S', method='save_request', image=ImageResource('document-save-as')), id='SaveGroup', name='SaveGroup'), SGroup( TaskAction(name='Save User Data', method='save_user_ds', image=ImageResource('drive-harddisk')), TaskAction(name='Export User Data As...', method='request_export_user_ds', image=ImageResource('document-import')), id='SaveUserDataGroup', name='SaveUserDataGroup', ), SGroup( TaskWindowAction( name='Close', accelerator='Ctrl+W', method='close', ), id='CloseGroup', name='CloseGroup', ), id='File', name='&File'), SMenu(id='Edit', name='&Edit'), SMenu(DockPaneToggleGroup(), id='View', name='&View'), SMenu( SGroup( TaskAction(name='Parameter Explorer', accelerator='Ctrl+Shift+N', method='new_simulation_grid', enabled_name='simulations_exist'), TaskAction(name='Parameter Optimizer', accelerator='Ctrl+Shift+M', method='new_optimizer', enabled_name='experiments_and_sim_exist'), id='ParamExplorationGroup', name='ParamExplorationGroup', ), SGroup( TaskAction(name='Run Simulations', method='run_simulations', accelerator='Ctrl+R', enabled_name='simulations_exist', image=ImageResource('arrow-right')), TaskAction(name='Run Simulation Group', method='run_simulation_groups', accelerator='Ctrl+Shift+R', enabled_name='simulation_groups_exist', image=ImageResource('arrow-right-double')), id='RunSimulationGroup', name='RunSimulationGroup', ), SGroup( TaskAction(name='Plot Chomatogram(s)', method='new_model_calibration_plot', accelerator='Ctrl+P', image=ImageResource('office-chart-line')), TaskAction(name='Particle data animation', method='new_animation_plot'), id='PlotsGroup', name='PlotsGroup', ), SGroup( TaskAction(name=STRIP_TOOL_NAME, method='open_strip_fraction_editor', enabled_name='_strip_component_exist'), id='ConfigurationGroup', name='ConfigurationGroup', ), SGroup(TaskAction(name='Custom Python script...', accelerator='Ctrl+I', method='request_run_python_script', tooltip='Modify the current project with ' 'custom script.', image=ImageResource('text-x-python')), TaskAction(name='Interactive Python console...', accelerator='Ctrl+J', tooltip="(Jupyter) Python console to " "interactively explore Reveal's code " "and develop new tools/scripts.", method='request_launch_python_console', image=ImageResource('ipython_icon')), id='RunPythonGroup', name='RunPythonGroup'), id='Tools', name='&Tools', ), SMenu(id='Help', name='&Help')) return menu_bar