[gedit-latex/doc-prefs: 1/3] tidy prefs, remove get_bool, defaults, etc



commit b5c138f95e7216659b66a7212801e1c39ef26c4f
Author: John Stowers <john stowers gmail com>
Date:   Tue Aug 16 11:09:07 2011 +1200

    tidy prefs, remove get_bool, defaults, etc

 latex/base/windowactivatable.py |    3 +--
 latex/bibtex/editor.py          |    2 +-
 latex/bibtex/views.py           |    2 +-
 latex/latex/dialogs.py          |   17 ++++++++++++-----
 latex/latex/editor.py           |    9 ++-------
 latex/latex/outline.py          |    6 +++---
 latex/latex/views.py            |    8 ++++----
 latex/outline.py                |    2 +-
 latex/preferences/__init__.py   |   33 +++++++++++++++++++--------------
 latex/preferences/dialog.py     |    4 ++--
 latex/tools/postprocess.py      |    2 +-
 latex/views.py                  |    4 ++--
 12 files changed, 49 insertions(+), 43 deletions(-)
---
diff --git a/latex/base/windowactivatable.py b/latex/base/windowactivatable.py
index 329e232..390d3cc 100644
--- a/latex/base/windowactivatable.py
+++ b/latex/base/windowactivatable.py
@@ -107,7 +107,6 @@ class LaTeXWindowActivatable(GObject.Object, Gedit.WindowActivatable, PeasGtk.Co
         Called when the window extension is deactivated
         """
         # save preferences and stop listening
-        self._preferences.save()
         self._tool_preferences.save()
 
         # destroy tab decorators
@@ -414,7 +413,7 @@ class LaTeXWindowActivatable(GObject.Object, Gedit.WindowActivatable, PeasGtk.Co
         self._log.debug("---------- ADJUST: %s" % (extension))
 
         latex_extensions = self._preferences.get("latex-extensions").split(",")
-        show_toolbar = self._preferences.get_bool("show-latex-toolbar")
+        show_toolbar = self._preferences.get ("show-latex-toolbar")
         if show_toolbar and extension in latex_extensions:
             self.show_toolbar()
         else:
diff --git a/latex/bibtex/editor.py b/latex/bibtex/editor.py
index 0fe7663..0d84cc1 100644
--- a/latex/bibtex/editor.py
+++ b/latex/bibtex/editor.py
@@ -193,7 +193,7 @@ class BibTeXEditor(Editor, IIssueHandler, JobChangeListener):
         """
         The cursor has moved
         """
-        if self._preferences.get_bool("outline-connect-to-editor"):
+        if self._preferences.get("outline-connect-to-editor"):
             self._outline_view.select_path_by_offset(offset)
 
     def destroy(self):
diff --git a/latex/bibtex/views.py b/latex/bibtex/views.py
index 279004a..c776a56 100644
--- a/latex/bibtex/views.py
+++ b/latex/bibtex/views.py
@@ -63,7 +63,7 @@ class BibTeXOutlineView(BaseOutlineView):
 
         self._preferences = Preferences()
 
-        grouping = self._preferences.get("BibtexOutlineGrouping", GROUP_NONE)
+        grouping = self._preferences.get("bibtex-outline-grouping")
         if grouping == GROUP_NONE:
             self._item_none.set_active(True)
         elif grouping == GROUP_TYPE:
diff --git a/latex/latex/dialogs.py b/latex/latex/dialogs.py
index 258a3b7..e78cdcb 100644
--- a/latex/latex/dialogs.py
+++ b/latex/latex/dialogs.py
@@ -100,7 +100,10 @@ class ComboBoxProxy(AbstractProxy):
         self._options = []
 
     def restore(self, default):
-        restored_value = self._preferences.get(self._key, default)
+        if default != None:
+            restored_value = default
+        else:
+            restored_value = self._preferences.get(self._key)
         restored_index = 0
         i = 0
         for value, label in self._options:
@@ -147,8 +150,12 @@ class EntryProxy(AbstractProxy):
     def __init__(self, widget, key):
         AbstractProxy.__init__(self, widget, key)
 
-    def restore(self, default):
-        self._widget.set_text(self._preferences.get(self._key, default))
+    def restore(self, default=None):
+        if default != None:
+            txt = default
+        else:
+            txt = self._preferences.get(self._key, default)
+        self._widget.set_text(txt)
 
     @property
     def value(self):
@@ -356,7 +363,7 @@ class NewDocumentDialog(GladeInterface):
             #
             self._entry_title = self.find_widget("entryTitle")
             self._entry_author = self.find_widget("entryAuthor")
-            self._entry_author.set_text(preferences.get("RecentAuthor", environment.username))
+            self._entry_author.set_text(environment.username)
             self._radio_date_custom = self.find_widget("radioCustom")
             self._entry_date = self.find_widget("entryDate")
 
@@ -381,7 +388,7 @@ class NewDocumentDialog(GladeInterface):
 
 
             self._check_landscape = self.find_widget("checkLandscape")
-            self._check_landscape.set_active(preferences.get_bool("RecentPaperLandscape", False))
+            self._check_landscape.set_active(False)
 
             #
             # font size
diff --git a/latex/latex/editor.py b/latex/latex/editor.py
index 7f7a497..b35e431 100644
--- a/latex/latex/editor.py
+++ b/latex/latex/editor.py
@@ -52,7 +52,6 @@ class LaTeXEditor(Editor, IIssueHandler):
 
     _log = getLogger("LaTeXEditor")
 
-    #extensions = [".tex"]
     extensions = Preferences().get("latex-extensions").split(",")
 
     dnd_extensions = [".png", ".pdf", ".bib", ".tex"]
@@ -87,8 +86,6 @@ class LaTeXEditor(Editor, IIssueHandler):
         self._validator = LaTeXValidator()
         self._document = None
 
-        self._document_dirty = True
-
         # if the document is no master we display an info message on the packages to
         # include - _ensured_packages holds the already mentioned packages to not
         # annoy the user
@@ -113,7 +110,7 @@ class LaTeXEditor(Editor, IIssueHandler):
                 # so we may not use it for regenerating the outline here
                 self.__parse()
         elif key == "show-latex-toolbar":
-            show_toolbar = self._preferences.get_bool("show-latex-toolbar")
+            show_toolbar = self._preferences.get("show-latex-toolbar")
             if show_toolbar:
                 self._window_context._window_decorator.show_toolbar()
             else:
@@ -342,8 +339,6 @@ class LaTeXEditor(Editor, IIssueHandler):
 
         property_file = PropertyFile(self._file)
         try:
-            #return File(property_file["MasterFilename"])
-
             path = property_file["MasterFilename"]
             # the property file may contain absolute and relative paths
             # because we switched in 0.2rc2
@@ -384,7 +379,7 @@ class LaTeXEditor(Editor, IIssueHandler):
         """
         The cursor has moved
         """
-        if self._preferences.get_bool("outline-connect-to-editor"):
+        if self._preferences.get("outline-connect-to-editor"):
             self._outline_view.select_path_by_offset(offset)
 
     @property
diff --git a/latex/latex/outline.py b/latex/latex/outline.py
index 5b1e4dc..2b62228 100644
--- a/latex/latex/outline.py
+++ b/latex/latex/outline.py
@@ -102,9 +102,9 @@ class LaTeXOutlineGenerator(object):
         """
 
         # setup
-        self.cfgLabelsInTree = Preferences().get_bool("outline-show-labels")
-        self.cfgTablesInTree = Preferences().get_bool("outline-show-tables")
-        self.cfgGraphicsInTree = Preferences().get_bool("outline-show-graphics")
+        self.cfgLabelsInTree = Preferences().get("outline-show-labels")
+        self.cfgTablesInTree = Preferences().get("outline-show-tables")
+        self.cfgGraphicsInTree = Preferences().get("outline-show-graphics")
 
         self._outline = Outline()
         self._stack = [self._outline.rootNode]
diff --git a/latex/latex/views.py b/latex/latex/views.py
index 0b53798..b56bd55 100644
--- a/latex/latex/views.py
+++ b/latex/latex/views.py
@@ -112,7 +112,7 @@ class LaTeXSymbolMapView(PanelView):
         return Gtk.Image.new_from_stock(Gtk.STOCK_INDEX,Gtk.IconSize.MENU)
 
     def _load_collection(self, collection):
-        self._expanded_groups = set(self._preferences.get("expanded-symbol-groups", "").split(","))
+        self._expanded_groups = set(self._preferences.get("expanded-symbol-groups").split(","))
 
         for group in collection.groups:
             self._add_group(group)
@@ -208,8 +208,8 @@ class LaTeXOutlineView(BaseOutlineView):
         btn_tables.set_tooltip_text(_("Show tables"))
         self._toolbar.insert(btn_tables, -1)
 
-        btn_graphics.set_active(Preferences().get_bool("outline-show-graphics"))
-        btn_tables.set_active(Preferences().get_bool("outline-show-tables"))
+        btn_graphics.set_active(Preferences().get("outline-show-graphics"))
+        btn_tables.set_active(Preferences().get("outline-show-tables"))
 
         self._handlers[btn_graphics] = btn_graphics.connect("toggled", self._on_graphics_toggled)
         self._handlers[btn_tables] = btn_tables.connect("toggled", self._on_tables_toggled)
@@ -233,7 +233,7 @@ class LaTeXOutlineView(BaseOutlineView):
         """
         An outline node has been selected
         """
-        if Preferences().get_bool("outline-connect-to-editor"):
+        if Preferences().get("outline-connect-to-editor"):
             if node.file == self._editor.edited_file:
                 self._editor.select(node.start, node.end)
 
diff --git a/latex/outline.py b/latex/outline.py
index 3861af0..360b0a4 100644
--- a/latex/outline.py
+++ b/latex/outline.py
@@ -52,7 +52,7 @@ class BaseOutlineView(PanelView):
 
         btn_follow = Gtk.ToggleToolButton.new_from_stock(Gtk.STOCK_CONNECT)
         btn_follow.set_tooltip_text(_("Follow Editor"))
-        btn_follow.set_active(self._preferences.get_bool("outline-connect-to-editor"))
+        btn_follow.set_active(self._preferences.get("outline-connect-to-editor"))
         self._base_handlers[btn_follow] = btn_follow.connect("toggled", self._on_follow_toggled)
 
         btn_expand = Gtk.ToolButton.new_from_stock(Gtk.STOCK_ZOOM_IN)
diff --git a/latex/preferences/__init__.py b/latex/preferences/__init__.py
index d7f196e..4f1ac0c 100644
--- a/latex/preferences/__init__.py
+++ b/latex/preferences/__init__.py
@@ -29,40 +29,45 @@ import logging
 
 from ..util import singleton
 
- singleton
-class Preferences(GObject.GObject):
+LOG = logging.getLogger(__name__)
+
+class _Preferences(GObject.GObject):
 
     __gsignals__ = {
         "preferences-changed": (
             GObject.SignalFlags.RUN_LAST, None, [str, str]),
     }
 
+    def __init__(self):
+        GObject.GObject.__init__(self)
+
+    def get(self, key, default=None):
+        raise NotImplementedError
+
+    def set(self, key, value):
+        pass
+
+ singleton
+class Preferences(_Preferences):
     """
     A simple map storing preferences as key-value-pairs
     """
 
-    _log = logging.getLogger("Preferences")
-
     TEMPLATE_DIR = os.path.join(GLib.get_user_data_dir(), "gedit", "latex", "templates")
 
     def __init__(self):
-        GObject.GObject.__init__(self)
+        _Preferences.__init__(self)
         self._settings = Gio.Settings("org.gnome.gedit.plugins.latex")
-        self._log.debug("Constructed")
+        
+        LOG.debug("Prefs singleton constructed")
 
-    def get(self, key, default=None):
-        if default:
-            return default
-        return self._settings[key]
-
-    def get_bool(self, key):
+    def get(self, key):
         return self._settings[key]
 
     def set(self, key, value):
         self._settings[key] = value
         self.emit("preferences-changed", str(key), str(value))
 
-    def save(self):
-        pass
+
 
 # ex:ts=4:et:
diff --git a/latex/preferences/dialog.py b/latex/preferences/dialog.py
index fcf5579..fa07c6e 100644
--- a/latex/preferences/dialog.py
+++ b/latex/preferences/dialog.py
@@ -353,11 +353,11 @@ class PreferencesDialog(GladeInterface):
 
             # misc
             check_hide_box = self.find_widget("checkHideBox")
-            check_hide_box.set_active(self._preferences.get_bool("hide-box-warnings"))
+            check_hide_box.set_active(self._preferences.get("hide-box-warnings"))
 
 
             check_show_toolbar = self.find_widget("checkShowToolbar")
-            check_show_toolbar.set_active(self._preferences.get_bool("show-latex-toolbar"))
+            check_show_toolbar.set_active(self._preferences.get("show-latex-toolbar"))
 
 
             filechooser_tmp = self.find_widget("filechooserTemplates")
diff --git a/latex/tools/postprocess.py b/latex/tools/postprocess.py
index db3e2b2..838fa62 100644
--- a/latex/tools/postprocess.py
+++ b/latex/tools/postprocess.py
@@ -173,7 +173,7 @@ class RubberPostProcessor(PostProcessor):
         # FIXME: circ dep
         from ..preferences import Preferences
 
-        self._hide_box_warnings = Preferences().get_bool("hide-box-warnings")
+        self._hide_box_warnings = Preferences().get("hide-box-warnings")
 
     @property
     def successful(self):
diff --git a/latex/views.py b/latex/views.py
index 2457d37..89ad197 100644
--- a/latex/views.py
+++ b/latex/views.py
@@ -48,8 +48,8 @@ class IssueView(PanelView):
         self._preferences = Preferences()
 
         self._preferences.connect("preferences-changed", self._on_preferences_changed)
-        self._show_tasks = self._preferences.get_bool("issues-show-tasks")
-        self._show_warnings = self._preferences.get_bool("issues-show-warnings")
+        self._show_tasks = self._preferences.get("issues-show-tasks")
+        self._show_warnings = self._preferences.get("issues-show-warnings")
 
         self._icons = { Issue.SEVERITY_WARNING : GdkPixbuf.Pixbuf.new_from_file(Resources().get_icon("warning.png")),
                         Issue.SEVERITY_ERROR : GdkPixbuf.Pixbuf.new_from_file(Resources().get_icon("error.png")),



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]