コード例 #1
0
ファイル: python_editor_wx.py プロジェクト: jdeschenes/pyface
    def _create_control(self, parent):
        """ Creates the toolkit-specific control for the widget. """

        # Base-class constructor.
        self.control = stc = PythonSTC(parent, -1)

        # No folding!
        stc.SetProperty("fold", "0")

        # Mark the maximum line size.
        stc.SetEdgeMode(wx.stc.STC_EDGE_LINE)
        stc.SetEdgeColumn(79)

        stc.SetMarginType(1, wx.stc.STC_MARGIN_NUMBER)
        stc.SetMarginMask(1, ~wx.stc.STC_MASK_FOLDERS)
        # Display line numbers in the margin.
        if self.show_line_numbers:
            stc.SetMarginWidth(1, 45)
            self.set_style(wx.stc.STC_STYLE_LINENUMBER, "#000000", "#c0c0c0")
        else:
            stc.SetMarginWidth(1, 4)
            self.set_style(wx.stc.STC_STYLE_LINENUMBER, "#ffffff", "#ffffff")

        # Create 'tabs' out of spaces!
        stc.SetUseTabs(False)

        # One 'tab' is 4 spaces.
        stc.SetIndent(4)

        # Line ending mode.
        stc.SetEOLMode(wx.stc.STC_EOL_LF)  # Unix
        #self.SetEOLMode(wx.stc.STC_EOL_CR) # Apple Mac
        #self.SetEOLMode(wx.stc.STC_EOL_CRLF) # Windows

        ##########################################
        # Global styles for all languages.
        ##########################################

        self.set_style(wx.stc.STC_STYLE_DEFAULT, "#000000", "#ffffff")
        self.set_style(wx.stc.STC_STYLE_CONTROLCHAR, "#000000", "#ffffff")
        self.set_style(wx.stc.STC_STYLE_BRACELIGHT, "#000000", "#ffffff")
        self.set_style(wx.stc.STC_STYLE_BRACEBAD, "#000000", "#ffffff")

        ##########################################
        # Python styles.
        ##########################################

        # White space
        self.set_style(wx.stc.STC_P_DEFAULT, "#000000", "#ffffff")

        # Comment
        self.set_style(wx.stc.STC_P_COMMENTLINE, "#007f00", "#ffffff")

        # Number
        self.set_style(wx.stc.STC_P_NUMBER, "#007f7f", "#ffffff")

        # String
        self.set_style(wx.stc.STC_P_STRING, "#7f007f", "#ffffff")

        # Single quoted string
        self.set_style(wx.stc.STC_P_CHARACTER, "#7f007f", "#ffffff")

        # Keyword
        self.set_style(wx.stc.STC_P_WORD, "#00007f", "#ffffff")

        # Triple quotes
        self.set_style(wx.stc.STC_P_TRIPLE, "#7f0000", "#ffffff")

        # Triple double quotes
        self.set_style(wx.stc.STC_P_TRIPLEDOUBLE, "#ff0000", "#ffffff")

        # Class name definition
        self.set_style(wx.stc.STC_P_CLASSNAME, "#0000ff", "#ffffff")

        # Function or method name definition
        self.set_style(wx.stc.STC_P_DEFNAME, "#007f7f", "#ffffff")

        # Operators
        self.set_style(wx.stc.STC_P_OPERATOR, "#000000", "#ffffff")

        # Identifiers
        self.set_style(wx.stc.STC_P_IDENTIFIER, "#000000", "#ffffff")

        # Comment-blocks
        self.set_style(wx.stc.STC_P_COMMENTBLOCK, "#007f00", "#ffffff")

        # End of line where string is not closed
        self.set_style(wx.stc.STC_P_STRINGEOL, "#000000", "#ffffff")

        ##########################################
        # Events.
        ##########################################

        # By default, the will fire EVT_STC_CHANGE evented for all mask values
        # (STC_MODEVENTMASKALL). This generates too many events.
        stc.SetModEventMask(wx.stc.STC_MOD_INSERTTEXT
                            | wx.stc.STC_MOD_DELETETEXT
                            | wx.stc.STC_PERFORMED_UNDO
                            | wx.stc.STC_PERFORMED_REDO)

        # Listen for changes to the file.
        wx.stc.EVT_STC_CHANGE(stc, stc.GetId(), self._on_stc_changed)

        # Listen for key press events.
        wx.EVT_CHAR(stc, self._on_char)

        # Load the editor's contents.
        self.load()

        return stc
コード例 #2
0
    def buildSheet(self, name):
        p = wx.Panel(self.notebookEditor,
                     -1,
                     style=wx.NO_FULL_REPAINT_ON_RESIZE)
        self.onglet.append(p)

        stc = wx.stc.StyledTextCtrl(
            id=wx.NewId(),
            name='styledTextCtrl1',
            parent=p,  # pos=wx.Point(0, 35),
            size=wx.Size(-1, -1),
            style=wx.SUNKEN_BORDER)

        stc.SetUseTabs(False)

        self.loadConfig()
        try:
            tabSize = self.getConfig("Source", "tabSize")
            stc.SetTabWidth(tabSize)
        except:
            tabSize = 4
            self.setConfig("Source", "tabSize", tabSize)
            stc.SetTabWidth(tabSize)

        self.saveConfig()

        stc.SetLexer(wx.stc.STC_LEX_CPP)

        stc.SetMargins(2, 2)

        stc.SetMarginType(1, wx.stc.STC_MARGIN_NUMBER)
        stc.SetMarginWidth(1, 40)
        stc.SetMarginWidth(2, 10)

        stc.StyleSetSpec(wx.stc.STC_STYLE_LINENUMBER,
                         "fore:#000000,back:#afc8e1ff,size:500")

        stc.SetMarginSensitive(1, True)
        stc.SetMarginSensitive(2, True)

        stc.SetMarginType(3, wx.stc.STC_MARGIN_SYMBOL)
        stc.SetMarginMask(3, wx.stc.STC_MASK_FOLDERS)
        stc.SetMarginSensitive(3, True)
        stc.SetMarginWidth(3, 12)

        stc.SetProperty("fold", "1")
        stc.SetProperty("tab.timmy.whinge.level", "1")

        stc.MarkerDefine(wx.stc.STC_MARKNUM_FOLDEROPEN,
                         wx.stc.STC_MARK_BOXMINUS, "white", "#808080")
        stc.MarkerDefine(wx.stc.STC_MARKNUM_FOLDER, wx.stc.STC_MARK_BOXPLUS,
                         "white", "#808080")
        stc.MarkerDefine(wx.stc.STC_MARKNUM_FOLDERSUB, wx.stc.STC_MARK_VLINE,
                         "white", "#808080")
        stc.MarkerDefine(wx.stc.STC_MARKNUM_FOLDERTAIL,
                         wx.stc.STC_MARK_LCORNER, "white", "#808080")
        stc.MarkerDefine(wx.stc.STC_MARKNUM_FOLDEREND,
                         wx.stc.STC_MARK_BOXPLUSCONNECTED, "white", "#808080")
        stc.MarkerDefine(wx.stc.STC_MARKNUM_FOLDEROPENMID,
                         wx.stc.STC_MARK_BOXMINUSCONNECTED, "white", "#808080")
        stc.MarkerDefine(wx.stc.STC_MARKNUM_FOLDERMIDTAIL,
                         wx.stc.STC_MARK_TCORNER, "white", "#808080")

        self.stcpage.append(stc)
        stc.SetMinSize(wx.Size(-1, -1))

        p.SetAutoLayout(True)
        p.Layout()

        boxSizer = wx.BoxSizer(orient=wx.VERTICAL)
        boxSizer.Fit(p)
        boxSizer.SetSizeHints(p)
        p.SetSizer(boxSizer)
        boxSizer.AddWindow(stc,
                           1,
                           border=0,
                           flag=wx.EXPAND | wx.ADJUST_MINSIZE)

        self.notebookEditor.AddPage(p, os.path.split(name)[1])
        self.SendSizeEvent()
        #        self._mgr.Update()
        self.panelEditor.Layout()
        self.sheetFunctions.append({})