Beispiel #1
0
 def restyle(self, syntaxLang=None):
     self.apply_editor_style()
     if self.lang == 'python':
         parts_scanner, code_scanner, formats = \
             syntax_highlighter.load_syntax(python_syntax.syntax)
         self.highlighter = syntax_highlighter.SyntaxHighlighter(
             self.document(),
             parts_scanner, code_scanner, formats,
             errors=self.errors, pep8=self.pep8, migration=self.migration)
         if self._mini:
             self._mini.highlighter = syntax_highlighter.SyntaxHighlighter(
                 self._mini.document(), parts_scanner,
                 code_scanner, formats)
         return
     if self.highlighter is None or isinstance(self.highlighter,
        highlighter.EmpyHighlighter):
         self.highlighter = highlighter.Highlighter(self.document(),
             None, resources.CUSTOM_SCHEME, self.errors, self.pep8,
             self.migration)
     if not syntaxLang:
         ext = file_manager.get_file_extension(self.ID)
         self.highlighter.apply_highlight(
             settings.EXTENSIONS.get(ext, 'python'),
             resources.CUSTOM_SCHEME)
         if self._mini:
             self._mini.highlighter.apply_highlight(
                 settings.EXTENSIONS.get(ext, 'python'),
                 resources.CUSTOM_SCHEME)
     else:
         self.highlighter.apply_highlight(
             syntaxLang, resources.CUSTOM_SCHEME)
         if self._mini:
             self._mini.highlighter.apply_highlight(
                 syntaxLang, resources.CUSTOM_SCHEME)
Beispiel #2
0
 def restyle(self):
     self.apply_editor_style()
     parts_scanner, code_scanner, formats = \
         syntax_highlighter.load_syntax(python_syntax.syntax)
     self.highlighter = syntax_highlighter.SyntaxHighlighter(
         self.document(),
         parts_scanner, code_scanner, formats)
Beispiel #3
0
 def register_syntax(self, lang='', syntax=None):
     self.lang = settings.EXTENSIONS.get(lang, 'python')
     if self.lang == 'python':
         parts_scanner, code_scanner, formats = \
             syntax_highlighter.load_syntax(python_syntax.syntax)
         self.highlighter = syntax_highlighter.SyntaxHighlighter(
             self.document(),
             parts_scanner, code_scanner, formats, self._neditable)
         if self._mini:
             self._mini.highlighter = syntax_highlighter.SyntaxHighlighter(
                 self._mini.document(), parts_scanner,
                 code_scanner, formats)
     elif lang in settings.EXTENSIONS:
         self.highlighter = highlighter.Highlighter(self.document(),
             self.lang, resources.CUSTOM_SCHEME, self.errors, self.pep8,
             self.migration)
         if self._mini:
             self._mini.highlighter = highlighter.Highlighter(
                 self._mini.document(),
                 self.lang, resources.CUSTOM_SCHEME)
     elif syntax is not None:
         self.highlighter = highlighter.Highlighter(self.document(),
             None, resources.CUSTOM_SCHEME)
         self.highlighter.apply_highlight(lang, resources.CUSTOM_SCHEME,
             syntax)
         if self._mini:
             self._mini.highlighter = highlighter.Highlighter(
                 self.document(), None, resources.CUSTOM_SCHEME)
             self._mini.highlighter.apply_highlight(lang,
                 resources.CUSTOM_SCHEME, syntax)
     else:
         self.highlighter = highlighter.EmpyHighlighter(self.document())
         if self._mini:
             self._mini.highlighter = highlighter.EmpyHighlighter(
                 self.document())
Beispiel #4
0
    def __init__(self):
        QPlainTextEdit.__init__(self, '>>> ')
        self.setUndoRedoEnabled(False)
        self.apply_editor_style()
        self.setToolTip(self.tr("Show/Hide (F4)"))
        self.moveCursor(QTextCursor.EndOfLine)

        self._patIsWord = re.compile('\w+')
        self.prompt = '>>> '
        self._console = console.Console()
        self._history = []
        self.history_index = 0
        self._current_command = ''
        self._braces = None
        self.imports = ['import __builtin__']
        self.patFrom = re.compile('^(\\s)*from ((\\w)+(\\.)*(\\w)*)+ import')
        self.patImport = re.compile('^(\\s)*import (\\w)+')
        self.patObject = re.compile('[^a-zA-Z0-9_\\.]')
        self.completer = completer_widget.CompleterWidget(self)
        self.okPrefix = QRegExp('[.)}:,\]]')

        self._pre_key_press = {
            Qt.Key_Enter: self._enter_pressed,
            Qt.Key_Return: self._enter_pressed,
            Qt.Key_Tab: self._tab_pressed,
            Qt.Key_Home: self._home_pressed,
            Qt.Key_PageUp: lambda x: True,
            Qt.Key_PageDown: lambda x: True,
            Qt.Key_Left: self._left_pressed,
            Qt.Key_Up: self._up_pressed,
            Qt.Key_Down: self._down_pressed,
            Qt.Key_Backspace: self._backspace,
        }

        #Create Context Menu
        self._create_context_menu()

        #Set Font
        self.set_font()
        #Create Highlighter
        parts_scanner, code_scanner, formats = \
            syntax_highlighter.load_syntax(python_syntax.syntax)
        self.highlighter = syntax_highlighter.SyntaxHighlighter(
            self.document(),
            parts_scanner, code_scanner, formats)

        self.connect(self, SIGNAL("cursorPositionChanged()"),
            self.highlight_current_line)
        self.highlight_current_line()

        self._proc = QProcess(self)
        self.connect(self._proc, SIGNAL("readyReadStandardOutput()"),
            self._python_path_detected)
        self.connect(self._proc, SIGNAL("error(QProcess::ProcessError)"),
            self.process_error)
        self._add_system_path_for_frozen()
Beispiel #5
0
 def register_syntax(self, lang="", syntax=None):
     # self.lang = settings.EXTENSIONS.get(lang, 'python')
     # if self.lang == 'python':
     parts_scanner, code_scanner, formats = syntax_highlighter.load_syntax(python_syntax.syntax)
     self.highlighter = syntax_highlighter.SyntaxHighlighter(
         self.document(), parts_scanner, code_scanner, formats, self._neditable
     )
     if self._mini:
         self._mini.highlighter = syntax_highlighter.SyntaxHighlighter(
             self._mini.document(), parts_scanner, code_scanner, formats
         )