Permalink
Browse files

Fixed Issue #1071

  • Loading branch information...
1 parent b474688 commit 6b98ed53110c569c016af54aa49bf0bb3606b3ba @diegosarmentero diegosarmentero committed Mar 12, 2013
Showing with 67 additions and 44 deletions.
  1. +34 −38 ninja_ide/gui/editor/editor.py
  2. +31 −5 ninja_ide/gui/editor/syntax_highlighter.py
  3. +2 −1 ninja_ide/resources.py
@@ -60,6 +60,7 @@
from ninja_ide.gui.editor import errors_checker
from ninja_ide.gui.editor import migration_2to3
from ninja_ide.gui.editor import sidebar_widget
+from ninja_ide.gui.editor import python_syntax
from ninja_ide.tools.logger import NinjaLogger
@@ -73,22 +74,6 @@
python3 = False
-scheme = {
- "syntax_comment": dict(color="#80FF80", italic=True),
- "syntax_string": "#B369BF",
- "syntax_builtin": "#ee8859",
- "syntax_keyword": ("#6EC7D7", True),
- "syntax_definition": ("#F6EC2A", True),
- "syntax_braces": "#FFFFFF",
- "syntax_number": "#F8A008",
- "syntax_proper_object": "#6EC7D7",
- "syntax_operators": "#FFFFFF",
- "syntax_spaces": "#7b7b7b",
- "syntax_highlight_word": dict(color="red", background="blue"),
-}
-from ninja_ide.gui.editor import python_syntax
-
-
class Editor(QPlainTextEdit, itab_item.ITabItem):
###############################################################################
@@ -388,26 +373,38 @@ def has_write_permission(self):
def restyle(self, syntaxLang=None):
self.apply_editor_style()
- #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)
+ 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)
def apply_editor_style(self):
css = 'QPlainTextEdit {color: %s; background-color: %s;' \
@@ -433,8 +430,7 @@ 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, scheme)
+ syntax_highlighter.load_syntax(python_syntax.syntax)
self.highlighter = syntax_highlighter.SyntaxHighlighter(
self.document(),
parts_scanner, code_scanner, formats,
@@ -467,11 +467,37 @@ def rehighlight_lines(self, lines, errors=True):
def _create_scheme():
- pass
-
-
-def load_syntax(syntax, context=None):
- context = context or {}
+ scheme = {
+ "syntax_comment": dict(color=resources.CUSTOM_SCHEME.get(
+ "comment", resources.COLOR_SCHEME["comment"]), italic=True),
+ "syntax_string": resources.CUSTOM_SCHEME.get(
+ "string", resources.COLOR_SCHEME["string"]),
+ "syntax_builtin": resources.CUSTOM_SCHEME.get(
+ "extras", resources.COLOR_SCHEME["extras"]),
+ "syntax_keyword": (resources.CUSTOM_SCHEME.get(
+ "keyword", resources.COLOR_SCHEME["keyword"]), True),
+ "syntax_definition": (resources.CUSTOM_SCHEME.get(
+ "definition", resources.COLOR_SCHEME["definition"]), True),
+ "syntax_braces": resources.CUSTOM_SCHEME.get(
+ "brace", resources.COLOR_SCHEME["brace"]),
+ "syntax_number": resources.CUSTOM_SCHEME.get(
+ "numbers", resources.COLOR_SCHEME["numbers"]),
+ "syntax_proper_object": resources.CUSTOM_SCHEME.get(
+ "properObject", resources.COLOR_SCHEME["properObject"]),
+ "syntax_operators": resources.CUSTOM_SCHEME.get(
+ "operator", resources.COLOR_SCHEME["operator"]),
+ "syntax_highlight_word": dict(color=resources.CUSTOM_SCHEME.get(
+ "selected-word", resources.COLOR_SCHEME["selected-word"]),
+ background=resources.CUSTOM_SCHEME.get(
+ "selected-word-background",
+ resources.COLOR_SCHEME["selected-word-background"])),
+ }
+
+ return scheme
+
+
+def load_syntax(syntax):
+ context = _create_scheme() or {}
partition_scanner = PartitionScanner(syntax.get("partitions", []))
View
@@ -204,7 +204,8 @@
"editor-selection-background": "#437DCD",
"editor-text": "#B3BFA7",
"current-line": "#858585",
- "selected-word": "#009B00",
+ "selected-word": "red",
+ "selected-word-background": "#009B00",
"fold-area": "#FFFFFF",
"fold-arrow": "#454545",
"linkNavigate": "orange",

0 comments on commit 6b98ed5

Please sign in to comment.