Beispiel #1
0
 def create(self, parent):
     self.editor = PythonEditor(parent)
     self.control = self.editor.control
Beispiel #2
0
    def init(self, parent):
        """ Finishes initializing the editor by creating the underlying toolkit
            widget.
        """
        factory = self.factory
        self._editor = editor = PythonEditor(
            parent, show_line_numbers=factory.show_line_numbers)
        self.control = control = editor.control

        # There are a number of events which aren't well documented that look
        # to be useful in future implmentations, below are a subset of the
        # events that look interesting:
        #    EVT_STC_AUTOCOMP_SELECTION
        #    EVT_STC_HOTSPOT_CLICK
        #    EVT_STC_HOTSPOT_DCLICK
        #    EVT_STC_DOUBLECLICK
        #    EVT_STC_MARGINCLICK

        control.SetSize(wx.Size(300, 124))

        # Clear out the goofy hotkeys for zooming text
        control.CmdKeyClear(ord('B'), stc.STC_SCMOD_CTRL)
        control.CmdKeyClear(ord('N'), stc.STC_SCMOD_CTRL)

        # Set up the events
        wx.EVT_KILL_FOCUS(control, self.wx_update_object)
        stc.EVT_STC_CALLTIP_CLICK(control, control.GetId(),
                                  self._calltip_clicked)

        if factory.auto_scroll and (factory.selected_line != ''):
            wx.EVT_SIZE(control, self._update_selected_line)

        if factory.auto_set:
            editor.on_trait_change(self.update_object,
                                   'changed',
                                   dispatch='ui')

        if factory.key_bindings is not None:
            editor.on_trait_change(self.key_pressed,
                                   'key_pressed',
                                   dispatch='ui')

        if self.readonly:
            control.SetReadOnly(True)

        # Set up the lexer
        control.SetLexer(stc.STC_LEX_CONTAINER)
        control.Bind(stc.EVT_STC_STYLENEEDED, self._style_needed)
        try:
            self.lexer = getattr(stc, 'STC_LEX_' + self.factory.lexer.upper())
        except AttributeError:
            self.lexer = stc.STC_LEX_NULL

        # Define the markers we use:
        control.MarkerDefine(MARK_MARKER,
                             stc.STC_MARK_BACKGROUND,
                             background=factory.mark_color_)
        control.MarkerDefine(SEARCH_MARKER,
                             stc.STC_MARK_BACKGROUND,
                             background=factory.search_color_)
        control.MarkerDefine(SELECTED_MARKER,
                             stc.STC_MARK_BACKGROUND,
                             background=factory.selected_color_)

        # Make sure the editor has been initialized:
        self.update_editor()

        # Set up any event listeners:
        self.sync_value(factory.mark_lines, 'mark_lines', 'from', is_list=True)
        self.sync_value(factory.selected_line, 'selected_line', 'from')
        self.sync_value(factory.selected_text, 'selected_text', 'to')
        self.sync_value(factory.line, 'line')
        self.sync_value(factory.column, 'column')
        self.sync_value(factory.calltip_clicked, 'calltip_clicked')

        self.sync_value(factory.dim_lines, 'dim_lines', 'from', is_list=True)
        if self.factory.dim_color == '':
            self.dim_color = 'dark grey'
        else:
            self.sync_value(factory.dim_color, 'dim_color', 'from')

        self.sync_value(factory.squiggle_lines,
                        'squiggle_lines',
                        'from',
                        is_list=True)
        if factory.squiggle_color == '':
            self.squiggle_color = 'red'
        else:
            self.sync_value(factory.squiggle_color, 'squiggle_color', 'from')

        # Check if we need to monitor the line or column position being
        # changed:
        if (factory.line != '') or (factory.column != '') or \
                (factory.selected_text != ''):
            stc.EVT_STC_UPDATEUI(control, control.GetId(),
                                 self._position_changed)
        self.set_tooltip()
Beispiel #3
0
    def _create_contents(self, parent):
        """ Create the editor. """

        self._editor = PythonEditor(parent)

        return self._editor.control
Beispiel #4
0
    def init(self, parent):
        """ Finishes initializing the editor by creating the underlying toolkit
            widget.
        """
        factory = self.factory
        self._editor = editor = PythonEditor(
            parent, show_line_numbers=factory.show_line_numbers)
        self.control = control = editor.control

        # There are a number of events which aren't well documented that look
        # to be useful in future implmentations, below are a subset of the
        # events that look interesting:
        #    EVT_STC_AUTOCOMP_SELECTION
        #    EVT_STC_HOTSPOT_CLICK
        #    EVT_STC_HOTSPOT_DCLICK
        #    EVT_STC_DOUBLECLICK
        #    EVT_STC_MARGINCLICK

        control.SetSize(wx.Size(300, 124))

        # Clear out the goofy hotkeys for zooming text
        control.CmdKeyClear(ord("B"), stc.STC_SCMOD_CTRL)
        control.CmdKeyClear(ord("N"), stc.STC_SCMOD_CTRL)

        # Set up the events
        control.Bind(wx.EVT_KILL_FOCUS, self.wx_update_object)
        control.Bind(stc.EVT_STC_CALLTIP_CLICK, self._calltip_clicked)

        if factory.auto_scroll and (factory.selected_line != ""):
            control.Bind(wx.EVT_SIZE, self._update_selected_line)

        if factory.auto_set:
            editor.on_trait_change(self.update_object,
                                   "changed",
                                   dispatch="ui")

        if factory.key_bindings is not None:
            editor.on_trait_change(self.key_pressed,
                                   "key_pressed",
                                   dispatch="ui")

        if self.readonly:
            control.SetReadOnly(True)

        # Set up the lexer
        control.SetLexer(stc.STC_LEX_CONTAINER)
        control.Bind(stc.EVT_STC_STYLENEEDED, self._style_needed)
        try:
            self.lexer = getattr(stc, "STC_LEX_" + self.factory.lexer.upper())
        except AttributeError:
            self.lexer = stc.STC_LEX_NULL

        # Define the markers we use:
        control.MarkerDefine(
            MARK_MARKER,
            stc.STC_MARK_BACKGROUND,
            background=wx.Colour(factory.mark_color_),
        )
        control.MarkerDefine(
            SEARCH_MARKER,
            stc.STC_MARK_BACKGROUND,
            background=wx.Colour(factory.search_color_),
        )
        control.MarkerDefine(
            SELECTED_MARKER,
            stc.STC_MARK_BACKGROUND,
            background=wx.Colour(factory.selected_color_),
        )

        # Make sure the editor has been initialized:
        self.update_editor()

        # Set up any event listeners:
        self.sync_value(factory.mark_lines, "mark_lines", "from", is_list=True)
        self.sync_value(factory.selected_line, "selected_line", "from")
        self.sync_value(factory.selected_text, "selected_text", "to")
        self.sync_value(factory.line, "line")
        self.sync_value(factory.column, "column")
        self.sync_value(factory.calltip_clicked, "calltip_clicked")

        self.sync_value(factory.dim_lines, "dim_lines", "from", is_list=True)
        if self.factory.dim_color == "":
            self.dim_color = "dark grey"
        else:
            self.sync_value(factory.dim_color, "dim_color", "from")

        self.sync_value(factory.squiggle_lines,
                        "squiggle_lines",
                        "from",
                        is_list=True)
        if factory.squiggle_color == "":
            self.squiggle_color = "red"
        else:
            self.sync_value(factory.squiggle_color, "squiggle_color", "from")

        # Check if we need to monitor the line or column position being
        # changed:
        if ((factory.line != "") or (factory.column != "")
                or (factory.selected_text != "")):
            control.Bind(stc.EVT_STC_UPDATEUI, self._position_changed)
        self.set_tooltip()