Exemple #1
0
class MainWindow(ApplicationWindow):
    """ The main application window. """

    ###########################################################################
    # 'object' interface.
    ###########################################################################

    def __init__(self, **traits):
        """ Creates a new application window. """

        # Base class constructor.
        super(MainWindow, self).__init__(**traits)

        # Add a menu bar.
        self.menu_bar_manager = MenuBarManager(
            MenuManager(Action(name='&Open...', on_perform=self._open_file),
                        Action(name='&Save', on_perform=self._save_file),
                        Action(name='E&xit', on_perform=self.close),
                        name='&File'))

        return

    ###########################################################################
    # Protected 'IApplication' interface.
    ###########################################################################

    def _create_contents(self, parent):
        """ Create the editor. """

        self._editor = PythonEditor(parent)

        return self._editor.control

    ###########################################################################
    # Private interface.
    ###########################################################################

    def _open_file(self):
        """ Open a new file. """

        if self.control:
            dlg = FileDialog(parent=self.control, wildcard="*.py")

            if dlg.open() == OK:
                self._editor.path = dlg.path

    def _save_file(self):
        """ Save the file. """

        if self.control:
            try:
                self._editor.save()
            except IOError, e:
                # If you are trying to save to a file that doesn't exist,
                # open up a FileDialog with a 'save as' action.
                dlg = FileDialog(parent=self.control,
                                 action='save as',
                                 wildcard="*.py")
                if dlg.open() == OK:
                    self._editor.save(dlg.path)
class MainWindow(ApplicationWindow):
    """ The main application window. """

    ###########################################################################
    # 'object' interface.
    ###########################################################################

    def __init__(self, **traits):
        """ Creates a new application window. """

        # Base class constructor.
        super(MainWindow, self).__init__(**traits)

        # Add a menu bar.
        self.menu_bar_manager = MenuBarManager(MenuManager(
                    Action(name='&Open...', on_perform=self._open_file),
                    Action(name='&Save', on_perform=self._save_file),
                    Action(name='E&xit', on_perform=self.close),
                name='&File'))

        return

    ###########################################################################
    # Protected 'IApplication' interface.
    ###########################################################################

    def _create_contents(self, parent):
        """ Create the editor. """

        self._editor = PythonEditor(parent)

        return self._editor.control

    ###########################################################################
    # Private interface.
    ###########################################################################

    def _open_file(self):
        """ Open a new file. """

        if self.control:
            dlg = FileDialog(parent=self.control, wildcard=WILDCARD)

            if dlg.open() == OK:
                self._editor.path = dlg.path

    def _save_file(self):
        """ Save the file. """

        if self.control:
            try:
                self._editor.save()
            except IOError, e:
                # If you are trying to save to a file that doesn't exist,
                # open up a FileDialog with a 'save as' action.
                dlg = FileDialog(parent=self.control, action='save as', wildcard=WILDCARD)
                if dlg.open() == OK:
                    self._editor.save(dlg.path)
    def create_control(self, parent):
        """ Creates the toolkit-specific control that represents the
            editor. 'parent' is the toolkit-specific control that is
            the editor's parent.
        """
        ed = PythonEditor(parent, show_line_numbers=False)

        # FIXME: Implement toolkit specific Python editor subclass
        import wx
        styles = [
            wx.stc.STC_STYLE_DEFAULT,
            wx.stc.STC_STYLE_CONTROLCHAR,
            wx.stc.STC_STYLE_BRACELIGHT,
            wx.stc.STC_STYLE_BRACEBAD,
            wx.stc.STC_P_DEFAULT,
            wx.stc.STC_P_COMMENTLINE,
            wx.stc.STC_P_NUMBER,
            wx.stc.STC_P_STRING,
            wx.stc.STC_P_CHARACTER,
            wx.stc.STC_P_WORD,
            wx.stc.STC_P_TRIPLE,
            wx.stc.STC_P_TRIPLEDOUBLE,
            wx.stc.STC_P_CLASSNAME,
            wx.stc.STC_P_DEFNAME,
            wx.stc.STC_P_OPERATOR,
            wx.stc.STC_P_IDENTIFIER,
            wx.stc.STC_P_COMMENTBLOCK,
            wx.stc.STC_P_STRINGEOL
        ]

        for style in styles:
            ed.control.StyleSetFaceName(style, "monospace")
            ed.control.StyleSetSize(style, 10)

        path = self.obj.path
        if exists(path):
            ed.path = path
            ed.load()

        return ed.control
Exemple #4
0
class PythonEditorPane(TaskPane):
    """ A wrapper around the Pyface Python editor.
    """

    #### TaskPane interface ###################################################

    id = 'example.python_editor_pane'
    name = 'Python Editor'

    #### PythonEditorPane interface ###########################################

    editor = Instance(PythonEditor)

    ###########################################################################
    # 'ITaskPane' interface.
    ###########################################################################

    def create(self, parent):
        self.editor = PythonEditor(parent)
        self.control = self.editor.control

    def destroy(self):
        self.editor.destroy()
        self.control = self.editor = None
    def _create_contents(self, parent):
        """ Create the editor. """

        self._editor = PythonEditor(parent)

        return self._editor.control
Exemple #6
0
 def create(self, parent):
     self.editor = PythonEditor(parent)
     self.control = self.editor.control
Exemple #7
0
    def _create_contents(self, parent):
        """ Create the editor. """

        self._editor = PythonEditor(parent)

        return self._editor.control