コード例 #1
0
 def create_undo_group(self):
     return SGroup(UndoAction(undo_manager=self.undo_manager,
                              accelerator='Ctrl+Z'),
                   RedoAction(undo_manager=self.undo_manager,
                              accelerator='Ctrl+Shift+Z'),
                   id='UndoGroup',
                   name='Undo')
コード例 #2
0
    def _menu_bar_default(self):
        menu_bar = SMenuBar(
            SMenu(SGroup(group_factory=DockPaneToggleGroup,
                         id='tests.bogus_task.DockPaneToggleGroup'),
                  id='View',
                  name='&View'))

        return menu_bar
コード例 #3
0
 def create_recent_project_group(self):
     return SGroup(
         Action(name="Recent Projects...",
                on_perform=self.open_recent_project,
                image=ImageResource('document-open-recent.png')),
         id='RecentProjectGroup',
         name='NewStudy',
     )
コード例 #4
0
 def create_update_group(self):
     group = SGroup(
         Action(name='Check for updates...',
                on_perform=self.open_software_updater,
                image=ImageResource('system-software-update')),
         id='UpdateGroup',
         name='App Updater',
     )
     return group
コード例 #5
0
 def create_close_group(self):
     return SGroup(
         Action(name='Exit' if IS_WINDOWS else 'Quit',
                accelerator='Alt+F4' if IS_WINDOWS else 'Ctrl+Q',
                on_perform=self.exit,
                image=ImageResource('system-shutdown')),
         id='QuitGroup',
         name='Quit',
     )
コード例 #6
0
 def create_preference_group(self):
     from kromatography.ui.menu_entry_names import PREFERENCE_MENU_NAME
     return SGroup(
         Action(name=PREFERENCE_MENU_NAME,
                accelerator='Ctrl+,',
                on_perform=self.open_preferences,
                image=ImageResource('preferences-system')),
         id='PreferencesGroup',
         name='Preferences',
     )
コード例 #7
0
    def _menu_bar_default(self):
        menu_bar = SMenuBar(
            SMenu(
                SGroup(
                    group_factory=DockPaneToggleGroup,
                    id="tests.bogus_task.DockPaneToggleGroup",
                ),
                id="View",
                name="&View",
            ))

        return menu_bar
コード例 #8
0
 def create_documentation_group(self):
     group = SGroup(
         Action(name='Show sample input files...',
                on_perform=self.open_tutorial_files,
                image=ImageResource('help-browser')),
         Action(name='Open documentation...',
                on_perform=self.open_documentation,
                image=ImageResource('help-contents')),
         id='DocsGroup',
         name='Documentation',
     )
     return group
コード例 #9
0
    def create_bug_report_group(self):
        from kromatography.ui.menu_entry_names import \
            REPORT_ISSUE_FEEDBACK_MENU_NAME

        group = SGroup(
            Action(name=REPORT_ISSUE_FEEDBACK_MENU_NAME,
                   on_perform=self.open_bug_report,
                   image=ImageResource('mail-mark-important')),
            Action(name='Info about {} {}'.format(APP_FAMILY, APP_TITLE),
                   on_perform=self.open_about_dialog,
                   image=ImageResource('system-help')),
            id='HelpGroup',
            name='HelpGroup',
        )
        return group
コード例 #10
0
 def create_new_project_group(self):
     from kromatography.ui.menu_entry_names import (
         NEW_BLANK_PROJECT_MENU_NAME, NEW_PROJECT_FROM_EXPERIMENT_MENU_NAME,
         OPEN_PROJECT_MENU_NAME)
     return SGroup(
         Action(name=NEW_BLANK_PROJECT_MENU_NAME,
                on_perform=self.new_blank_project,
                image=ImageResource('document-new')),
         Action(name=NEW_PROJECT_FROM_EXPERIMENT_MENU_NAME,
                accelerator='Ctrl+L',
                on_perform=self.new_study_from_experimental_study_file,
                image=ImageResource('applications-science')),
         Action(name=OPEN_PROJECT_MENU_NAME,
                accelerator='Ctrl+O',
                on_perform=self.request_project_from_file,
                image=ImageResource('document-open')),
         id='NewStudyGroup',
         name='NewStudy',
     )
コード例 #11
0
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
コード例 #12
0
 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
コード例 #13
0
 def menu_factory():
     kernel = self.application.get_service(IPYTHON_KERNEL_PROTOCOL)
     return SGroup(StartQtConsoleAction(kernel=kernel), id="ipython")
コード例 #14
0
 def create_copy_group(self):
     return SGroup(Action(name='Cut', accelerator='Ctrl+X'),
                   Action(name='Copy', accelerator='Ctrl+C'),
                   Action(name='Paste', accelerator='Ctrl+V'),
                   id='CopyGroup',
                   name='Copy')
コード例 #15
0
 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