Permalink
Browse files

Fixed issue #974 Margin line length did not update at startup. Refact…

…ored pep8mod patching
  • Loading branch information...
1 parent 2cd1e02 commit 083b5b229fa18557f7de0f0385babe9ca04e10c2 @malderete committed Feb 4, 2013
Showing with 48 additions and 10 deletions.
  1. +40 −1 ninja_ide/core/settings.py
  2. +8 −9 ninja_ide/gui/dialogs/preferences.py
@@ -265,6 +265,45 @@ def get_toolbar_item_for_plugins():
###############################################################################
+# Utility functions to update (patch at runtime) pep8mod.py
+###############################################################################
+
+def pep8mod_refresh_checks():
+ """
+ Force to reload all checks in pep8mod.py
+ """
+ pep8mod.refresh_checks()
+
+
+def pep8mod_add_ignore(ignore_code):
+ """
+ Patch pep8mod.py to ignore a given check by code
+ EXAMPLE:
+ pep8mod_add_ignore('W191')
+ 'W1919': 'indentation contains tabs'
+ """
+ pep8mod.options.ignore.append(ignore_code)
+
+
+def pep8mod_remove_ignore(ignore_code):
+ """
+ Patch pep8mod.py to remove the ignore of a give check
+ EXAMPLE:
+ pep8mod_remove_ignore('W191')
+ 'W1919': 'indentation contains tabs'
+ """
+ if ignore_code in pep8mod.options.ignore:
+ pep8mod.options.ignore.remove(ignore_code)
+
+
+def pep8mod_update_margin_line_length(new_margin_line):
+ """
+ Patch pep8mod.py to update the margin line length with a new value
+ """
+ pep8mod.MAX_LINE_LENGTH = new_margin_line
+ pep8mod.options.max_line_length = new_margin_line
+
+###############################################################################
# LOAD SETTINGS
###############################################################################
@@ -376,7 +415,7 @@ def load_settings():
INDENT = int(qsettings.value('preferences/editor/indent', 4))
END_OF_LINE = qsettings.value('preferences/editor/endOfLine', EOL_DEFAULT)
MARGIN_LINE = int(qsettings.value('preferences/editor/marginLine', 80))
- pep8mod.MAX_LINE_LENGTH = MARGIN_LINE
+ pep8mod_update_margin_line_length(MARGIN_LINE)
REMOVE_TRAILING_SPACES = qsettings.value(
'preferences/editor/removeTrailingSpaces', 'true') == 'true'
SHOW_TABS_AND_SPACES = qsettings.value(
@@ -66,7 +66,6 @@
from ninja_ide.gui.misc import plugin_preferences
from ninja_ide.gui.main_panel import main_container
from ninja_ide.gui.explorer import explorer_container
-from ninja_ide.dependencies import pep8mod
from ninja_ide.core import settings
from ninja_ide.core import file_manager
from ninja_ide.tools import ui_tools
@@ -1086,10 +1085,10 @@ def save(self):
settings.INDENT = self._spin.value()
qsettings.setValue('endOfLine', self._comboEndOfLine.currentText())
settings.END_OF_LINE = self._comboEndOfLine.currentText()
- qsettings.setValue('marginLine', self._spinMargin.value())
- settings.MARGIN_LINE = self._spinMargin.value()
- pep8mod.MAX_LINE_LENGTH = settings.MARGIN_LINE - 1
- pep8mod.options.max_line_length = settings.MARGIN_LINE
+ margin_line = self._spinMargin.value()
+ qsettings.setValue('marginLine', margin_line)
+ settings.MARGIN_LINE = margin_line
+ settings.pep8mod_update_margin_line_length(margin_line)
qsettings.setValue('showMarginLine', self._checkShowMargin.isChecked())
settings.SHOW_MARGIN_LINE = self._checkShowMargin.isChecked()
settings.UNDERLINE_NOT_BACKGROUND = \
@@ -1130,10 +1129,10 @@ def save(self):
action.reset_editor_flags()
action.call_editors_function("set_tab_usage")
if settings.USE_TABS:
- pep8mod.options.ignore.append("W191")
- elif "W191" in pep8mod.options.ignore:
- pep8mod.options.ignore.remove("W191")
- pep8mod.refresh_checks()
+ settings.pep8mod_add_ignore("W191")
+ else:
+ settings.pep8mod_remove_ignore("W191")
+ settings.pep8mod_refresh_checks()
main_container.MainContainer().update_editor_margin_line()

0 comments on commit 083b5b2

Please sign in to comment.