diff --git a/src/calibre/gui2/tweak_book/__init__.py b/src/calibre/gui2/tweak_book/__init__.py index 0af48bb02e..afb7ca1f3d 100644 --- a/src/calibre/gui2/tweak_book/__init__.py +++ b/src/calibre/gui2/tweak_book/__init__.py @@ -12,6 +12,7 @@ tprefs = JSONConfig('tweak_book_gui') tprefs.defaults['editor_theme'] = None tprefs.defaults['editor_font_family'] = None tprefs.defaults['editor_font_size'] = 12 +tprefs.defaults['editor_line_wrap'] = True _current_container = None diff --git a/src/calibre/gui2/tweak_book/editor/text.py b/src/calibre/gui2/tweak_book/editor/text.py index 61e1f9eef7..d8e1ecb8cd 100644 --- a/src/calibre/gui2/tweak_book/editor/text.py +++ b/src/calibre/gui2/tweak_book/editor/text.py @@ -49,7 +49,7 @@ class TextEdit(QPlainTextEdit): def __init__(self, parent=None): QPlainTextEdit.__init__(self, parent) self.highlighter = SyntaxHighlighter(self) - self.apply_theme() + self.apply_settings() self.setMouseTracking(True) self.cursorPositionChanged.connect(self.highlight_cursor_line) self.blockCountChanged[int].connect(self.update_line_number_area_width) @@ -59,10 +59,15 @@ class TextEdit(QPlainTextEdit): def sizeHint(self): return self.size_hint - def apply_theme(self): # {{{ - theme = THEMES.get(tprefs['editor_theme'], None) + def apply_settings(self, prefs=None): # {{{ + prefs = prefs or tprefs + self.setLineWrapMode(QPlainTextEdit.WidgetWidth if prefs['editor_line_wrap'] else QPlainTextEdit.NoWrap) + theme = THEMES.get(prefs['editor_theme'], None) if theme is None: theme = THEMES[DEFAULT_THEME] + self.apply_theme(theme) + + def apply_theme(self, theme): self.theme = theme pal = self.palette() pal.setColor(pal.Base, theme_color(theme, 'Normal', 'bg'))