[gedit-latex] Use a singleton class Resources to find files
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit-latex] Use a singleton class Resources to find files
- Date: Wed, 29 Jun 2011 13:38:52 +0000 (UTC)
commit 3acda4d95349469c9a55e5dfa0e6f12d2fe82d13
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Wed Jun 29 14:42:22 2011 +0200
Use a singleton class Resources to find files
latex/__init__.py | 2 +
latex/base/Makefile.am | 1 +
latex/base/appactivatable.py | 43 +++++++++++++++
latex/base/resources.py | 115 ++++++++++++---------------------------
latex/base/windowactivatable.py | 4 +-
latex/bibtex/completion.py | 8 ++-
latex/bibtex/dialogs.py | 7 ++-
latex/bibtex/model.py | 4 +-
latex/bibtex/validator.py | 1 -
latex/bibtex/views.py | 13 +++--
latex/latex/actions.py | 45 ++++++++++++----
latex/latex/completion.py | 14 ++++-
latex/latex/dialogs.py | 47 ++++++++++++----
latex/latex/model.py | 11 ++--
latex/latex/views.py | 36 ++++++-------
latex/outline.py | 4 +-
latex/preferences/__init__.py | 1 -
latex/preferences/dialog.py | 13 +++--
latex/preferences/tools.py | 13 +++--
latex/tools/__init__.py | 6 +-
latex/tools/views.py | 15 +++---
latex/views.py | 12 ++--
22 files changed, 244 insertions(+), 171 deletions(-)
---
diff --git a/latex/__init__.py b/latex/__init__.py
index 62c5d45..19febc6 100644
--- a/latex/__init__.py
+++ b/latex/__init__.py
@@ -18,5 +18,7 @@
# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
# Street, Fifth Floor, Boston, MA 02110-1301, USA
+from base.appactivatable import LaTeXAppActivatable
from base.windowactivatable import LaTeXWindowActivatable
+
# ex:ts=4:et:
diff --git a/latex/base/Makefile.am b/latex/base/Makefile.am
index 99fd4c3..b724bea 100644
--- a/latex/base/Makefile.am
+++ b/latex/base/Makefile.am
@@ -1,6 +1,7 @@
plugindir = $(libdir)/gedit/plugins/latex/base
plugin_PYTHON = \
+ appactivatable.py \
completion.py \
config.py \
decorators.py \
diff --git a/latex/base/appactivatable.py b/latex/base/appactivatable.py
new file mode 100644
index 0000000..0875ac3
--- /dev/null
+++ b/latex/base/appactivatable.py
@@ -0,0 +1,43 @@
+# Gedit latex plugin
+# Copyright (C) 2011 Ignacio Casal Quinteiro
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+import sys
+import os
+
+import glib
+
+from gi.repository import Gedit, GObject
+from resources import Resources
+import platform
+
+class LaTeXAppActivatable(GObject.Object, Gedit.AppActivatable):
+ __gtype_name__ = "GeditLaTeXAppActivatable"
+
+ app = GObject.property(type=Gedit.App)
+
+ def __init__(self):
+ GObject.Object.__init__(self)
+
+ def do_activate(self):
+ if platform.platform() == 'Windows':
+ latexdir = os.path.expanduser('~/gedit/latex')
+ else:
+ latexdir = os.path.join(glib.get_user_config_dir(), 'gedit/latex')
+
+ Resources().set_dirs(latexdir, self.plugin_info.get_data_dir())
+
+# vi:ex:ts=4:et
diff --git a/latex/base/resources.py b/latex/base/resources.py
index 6b5d252..fbf4eb2 100644
--- a/latex/base/resources.py
+++ b/latex/base/resources.py
@@ -3,6 +3,7 @@
# This file is part of the Gedit LaTeX Plugin
#
# Copyright (C) 2010 Michael Zeising
+# 2011 Ignacio Casal Quinteiro
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public Licence as published by the Free Software
@@ -23,89 +24,45 @@ base.resources
"""
import logging
-import os.path
-import shutil
-
-from ..util import open_error
+import os
_log = logging.getLogger("resources")
-_PATH_ME = os.path.realpath(os.path.dirname(__file__))
-_PATH_SYSTEM = "/usr/share/gedit/plugins/latex"
-_PATH_USER = os.path.expanduser("~/.local/share/gedit/plugins/latex")
-_PATH_SRCDIR = os.path.abspath(os.path.join(_PATH_ME,"..","..","data"))
+class Singleton(object):
+ _instance = None
-# the order is important, for development it is useful to symlink
-# the plugin into ~/.local/share/gedit/plugin and run it. In that case
-# the first location to check for resources is the data dir in the
-# source directory
-#
-# beyond that case, by preferring the local copy to the system one, it
-# allows the user to customize things cleanly
-_PATH_RO_RESOURCES = [p for p in (
- _PATH_SRCDIR, _PATH_USER, _PATH_SYSTEM) if os.path.exists(p)]
-
-_log.debug("RO locations: %s" % ",".join(_PATH_RO_RESOURCES ))
-_log.debug("RW location: %s" % _PATH_SYSTEM)
-
-_installed_system_wide = os.path.exists(_PATH_SYSTEM)
-if _installed_system_wide:
- # ensure that we have a user plugin dir
- if not os.path.exists(_PATH_USER):
- _log.debug("Creating %s" % _PATH_USER)
- os.makedirs(_PATH_USER)
- PLUGIN_PATH = _PATH_SYSTEM # FIXME: only used by build to expand $plugin
-else:
- PLUGIN_PATH = _PATH_USER
-
-MODE_READONLY, MODE_READWRITE = 1, 2
-
-def find_resource(relative_path, access_mode=MODE_READONLY):
- """
- This locates a resource used by the plugin. The access mode determines where to
- search for the relative path.
-
- @param relative_path: a relative path like 'icons/smiley.png'
- @param access_mode: MODE_READONLY|MODE_READWRITE
-
- @return: the full filename of the resource
- """
- _log.debug("Finding: %s (%d)" % (relative_path, access_mode))
- if access_mode == MODE_READONLY:
- # locate a resource for read-only access. Prefer user files
- # to system ones. See comment above
- for p in _PATH_RO_RESOURCES:
- path = "%s/%s" % (p, relative_path)
- if os.path.exists(path):
- return path
-
- _log.critical("File not found: %s" % path)
- return None
-
- elif access_mode == MODE_READWRITE:
- # locate a user-specific resource for read/write access
- path = "%s/%s" % (_PATH_USER, relative_path)
- if os.path.exists(path):
- return path
-
- if _installed_system_wide:
- # resource doesn't exist yet in the user's directory
- # copy the system-wide version
- rw_source = "%s/%s" % (_PATH_SYSTEM, relative_path)
- else:
- # we are in the sourcedir
- rw_source = "%s/%s" % (_PATH_SRCDIR, relative_path)
-
- try:
- _log.info("Copying file to user path %s -> %s" % (rw_source, path))
- assert(rw_source != path)
- shutil.copyfile(rw_source, path)
- except IOError:
- _log.critical("Failed to copy resource to user directory: %s -> %s" % (rw_source, path))
- except AssertionError:
- _log.critical("Source and dest are the same. Bad programmer")
-
- return path
+ def __new__(cls, *args, **kwargs):
+ if not cls._instance:
+ cls._instance = super(Singleton, cls).__new__(
+ cls, *args, **kwargs)
+ cls._instance.__init_once__()
+
+ return cls._instance
+
+class Resources(Singleton):
+ def __init_once__(self):
+ pass
+
+ def set_dirs(self, userdir, systemdir):
+ self.userdir = userdir
+ self.systemdir = systemdir
+
+ def get_user_dir(self):
+ return self.userdir
+
+ def get_system_dir(self):
+ return self.systemdir
+
+ def get_user_file(self, user_file):
+ return os.path.join(self.userdir, user_file)
+
+ def get_ui_file(self, ui_name):
+ return os.path.join(self.systemdir, "ui", ui_name)
+
+ def get_icon(self, icon_name):
+ return os.path.join(self.systemdir, "icons", icon_name)
+ def get_data_file(self, data_name):
+ return os.path.join(self.systemdir, data_name)
# ex:ts=4:et:
diff --git a/latex/base/windowactivatable.py b/latex/base/windowactivatable.py
index 6f99a2f..fc3d3b1 100644
--- a/latex/base/windowactivatable.py
+++ b/latex/base/windowactivatable.py
@@ -35,7 +35,7 @@ from ..tools import ToolAction
from ..tools.views import ToolView
from .config import WINDOW_SCOPE_VIEWS, EDITOR_SCOPE_VIEWS, ACTIONS
from .decorators import GeditTabDecorator
-from .resources import find_resource
+from .resources import Resources
from . import File, SideView, BottomView, WindowContext
class LaTeXWindowActivatable(GObject.Object, Gedit.WindowActivatable, PeasGtk.Configurable):
@@ -216,7 +216,7 @@ class LaTeXWindowActivatable(GObject.Object, Gedit.WindowActivatable, PeasGtk.Co
# merge ui
self._ui_manager.insert_action_group(self._action_group, -1)
- self._ui_id = self._ui_manager.add_ui_from_file(find_resource("ui/ui.builder"))
+ self._ui_id = self._ui_manager.add_ui_from_file(Resources().get_ui_file("ui.builder"))
# hook the toolbar
self._toolbar = self._ui_manager.get_widget("/LaTeXToolbar")
diff --git a/latex/bibtex/completion.py b/latex/bibtex/completion.py
index 59b9b8f..8676687 100644
--- a/latex/bibtex/completion.py
+++ b/latex/bibtex/completion.py
@@ -26,7 +26,7 @@ from logging import getLogger
from gi.repository import Gdk, GdkPixbuf
from ..preferences import Preferences
-from ..base.resources import find_resource
+from ..base.resources import Resources
from ..base import ICompletionHandler, Proposal, Template
from ..issues import MockIssueHandler
from model import BibTeXModel
@@ -36,7 +36,6 @@ from parser import BibTeXParser
class BibTeXEntryTypeProposal(Proposal):
"""
"""
- icon = GdkPixbuf.Pixbuf.new_from_file(find_resource("icons/document.png"))
_color = Preferences().get("light-foreground-color")
@@ -49,6 +48,7 @@ class BibTeXEntryTypeProposal(Proposal):
self._type = type
self._details = None
self._source = None
+ self._icon = GdkPixbuf.Pixbuf.new_from_file(Resources().get_icon("document.png"))
def _generate(self):
"""
@@ -80,6 +80,10 @@ class BibTeXEntryTypeProposal(Proposal):
return self._details
@property
+ def icon(self):
+ return self._icon
+
+ @property
def overlap(self):
return self._overlap
diff --git a/latex/bibtex/dialogs.py b/latex/bibtex/dialogs.py
index fd68558..1400fb5 100644
--- a/latex/bibtex/dialogs.py
+++ b/latex/bibtex/dialogs.py
@@ -26,15 +26,18 @@ from logging import getLogger
from gi.repository import Gtk
from ..util import GladeInterface
-from ..base.resources import find_resource
+from ..base.resources import Resources
from model import BibTeXModel
class InsertBibTeXEntryDialog(GladeInterface):
- filename = find_resource("ui/insert_bibtex_entry.ui")
_dialog = None
+ def __init__(self):
+ super(GladeInterface, self).__init__()
+ self.filename = Resources().get_ui_file("insert_bibtex_entry.ui")
+
def run(self):
dialog = self._getDialog()
diff --git a/latex/bibtex/model.py b/latex/bibtex/model.py
index 02cbc69..611b05b 100644
--- a/latex/bibtex/model.py
+++ b/latex/bibtex/model.py
@@ -25,7 +25,7 @@ The model of BibTeX read from an XML file.
"""
import xml.etree.ElementTree as ElementTree
-from ..base.resources import find_resource
+from ..base.resources import Resources
class Type(object):
@@ -65,7 +65,7 @@ class BibTeXModel(object):
self._types = {}
# parse bibtex.xml
- self._bibtex = ElementTree.parse(find_resource("bibtex.xml")).getroot()
+ self._bibtex = ElementTree.parse(Resources().get_data_file("bibtex.xml")).getroot()
for field_e in self._bibtex.findall("fields/field"):
id = field_e.get("id")
diff --git a/latex/bibtex/validator.py b/latex/bibtex/validator.py
index 2bcb5e6..6681d56 100644
--- a/latex/bibtex/validator.py
+++ b/latex/bibtex/validator.py
@@ -23,7 +23,6 @@ bibtex.validator
"""
from logging import getLogger
-from ..base.resources import find_resource
from ..issues import Issue
from model import BibTeXModel
diff --git a/latex/bibtex/views.py b/latex/bibtex/views.py
index 48e4329..13624fe 100644
--- a/latex/bibtex/views.py
+++ b/latex/bibtex/views.py
@@ -32,7 +32,7 @@ from logging import getLogger
import time
from ..outline import OutlineOffsetMap, BaseOutlineView
-from ..base.resources import find_resource
+from ..base.resources import Resources
from ..preferences import Preferences
from parser import Entry
@@ -143,11 +143,12 @@ class OutlineConverter(object):
grouping feature
"""
- _ICON_ENTRY = GdkPixbuf.Pixbuf.new_from_file(find_resource("icons/document.png"))
- _ICON_FIELD = GdkPixbuf.Pixbuf.new_from_file(find_resource("icons/field.png"))
- _ICON_AUTHOR = GdkPixbuf.Pixbuf.new_from_file(find_resource("icons/users.png"))
- _ICON_YEAR = GdkPixbuf.Pixbuf.new_from_file(find_resource("icons/calendar.png"))
- _ICON_TYPE = GdkPixbuf.Pixbuf.new_from_file(find_resource("icons/documents.png"))
+ def __init__(self):
+ self._ICON_ENTRY = GdkPixbuf.Pixbuf.new_from_file(Resources().get_icon("document.png"))
+ self._ICON_FIELD = GdkPixbuf.Pixbuf.new_from_file(Resources().get_icon("field.png"))
+ self._ICON_AUTHOR = GdkPixbuf.Pixbuf.new_from_file(Resources().get_icon("users.png"))
+ self._ICON_YEAR = GdkPixbuf.Pixbuf.new_from_file(Resources().get_icon("calendar.png"))
+ self._ICON_TYPE = GdkPixbuf.Pixbuf.new_from_file(Resources().get_icon("documents.png"))
def convert(self, tree_store, document, offset_map, grouping=GROUP_NONE):
"""
diff --git a/latex/latex/actions.py b/latex/latex/actions.py
index 4757181..1bbfc83 100644
--- a/latex/latex/actions.py
+++ b/latex/latex/actions.py
@@ -26,7 +26,7 @@ from gi.repository import Gtk
from logging import getLogger
from ..base import Action, Template, File
-from ..base.resources import find_resource
+from ..base.resources import Resources
from ..preferences import Preferences
from ..util import IconAction
from ..issues import MockIssueHandler
@@ -58,7 +58,7 @@ class LaTeXTemplateAction(LaTeXIconAction):
@property
def icon(self):
- return File(find_resource("icons/%s.png" % self.icon_name))
+ return File(Resources().get_icon("%s.png" % self.icon_name))
def activate(self, context):
context.active_editor.insert(LaTeXSource(Template(self.template_source), self.packages))
@@ -127,10 +127,13 @@ class LaTeXCloseEnvironmentAction(LaTeXIconAction):
_log = getLogger("LaTeXCloseEnvironmentAction")
label = "Close Nearest Environment"
- icon = File(find_resource("icons/close_env.png"))
accelerator = "<Ctrl><Alt>E"
tooltip = "Close the nearest TeX environment at left of the cursor"
+ @property
+ def icon(self):
+ return File(Resources().get_icon("close_env.png"))
+
def activate(self, context):
# FIXME: use the document model of the Editor
@@ -181,12 +184,15 @@ class LaTeXUseBibliographyAction(LaTeXIconAction):
_log = getLogger("LaTeXUseBibliographyAction")
label = "Use Bibliography..."
- icon = File(find_resource("icons/bib.png"))
accelerator = None
tooltip = "Use Bibliography"
_dialog = None
+ @property
+ def icon(self):
+ return File(Resources().get_icon("bib.png"))
+
def activate(self, context):
if not self._dialog:
self._dialog = UseBibliographyDialog()
@@ -206,12 +212,14 @@ class LaTeXFontFamilyAction(LaTeXIconAction):
label = "Font Family"
accelerator = None
tooltip = "Font Family"
- icon = File(find_resource("icons/bf.png"))
+
+ @property
+ def icon(self):
+ return File(Resources().get_icon("bf.png"))
def activate(self, context):
pass
-
class LaTeXFontFamilyMenuAction(LaTeXAction):
label = "Font Family"
accelerator = None
@@ -328,7 +336,10 @@ class LaTeXStructureAction(LaTeXIconAction):
label = "Structure"
accelerator = None
tooltip = "Structure"
- icon = File(find_resource("icons/section.png"))
+
+ @property
+ def icon(self):
+ return File(Resources().get_icon("section.png"))
def activate(self, context):
pass
@@ -390,10 +401,13 @@ class LaTeXGraphicsAction(LaTeXIconAction):
label = "Insert Graphics"
accelerator = None
tooltip = "Insert Graphics"
- icon = File(find_resource("icons/graphics.png"))
dialog = None
+ @property
+ def icon(self):
+ return File(Resources().get_icon("graphics.png"))
+
def activate(self, context):
if not self.dialog:
self.dialog = InsertGraphicsDialog()
@@ -406,10 +420,13 @@ class LaTeXTableAction(LaTeXIconAction):
label = "Insert Table or Matrix"
accelerator = None
tooltip = "Insert Table or Matrix"
- icon = File(find_resource("icons/table.png"))
dialog = None
+ @property
+ def icon(self):
+ return File(Resources().get_icon("table.png"))
+
def activate(self, context):
if not self.dialog:
self.dialog = InsertTableDialog()
@@ -422,10 +439,13 @@ class LaTeXListingAction(LaTeXIconAction):
label = "Insert Source Code Listing"
accelerator = None
tooltip = "Insert Source Code Listing"
- icon = File(find_resource("icons/listing.png"))
dialog = None
+ @property
+ def icon(self):
+ return File(Resources().get_icon("listing.png"))
+
def activate(self, context):
if not self.dialog:
self.dialog = InsertListingDialog()
@@ -458,10 +478,13 @@ class LaTeXBuildImageAction(LaTeXIconAction):
label = "Build Image"
accelerator = None
tooltip = "Build an image from the LaTeX document"
- icon = File(find_resource("icons/build-image.png"))
dialog = None
+ @property
+ def icon(self):
+ return File(Resources().get_icon("build-image.png"))
+
def activate(self, context):
if not self.dialog:
self.dialog = BuildImageDialog()
diff --git a/latex/latex/completion.py b/latex/latex/completion.py
index 8a1b15c..94aba7b 100644
--- a/latex/latex/completion.py
+++ b/latex/latex/completion.py
@@ -27,7 +27,7 @@ LaTeX-specific completion classes
from logging import getLogger
from gi.repository import Gdk, GdkPixbuf
-from ..base.resources import find_resource
+from ..base.resources import Resources
from ..base import ICompletionHandler, Proposal, Template
@@ -35,12 +35,12 @@ class LaTeXCommandProposal(Proposal):
"""
A proposal inserting a Template when activated
"""
- icon = GdkPixbuf.Pixbuf.new_from_file(find_resource("icons/i_command.png"))
def __init__(self, overlap, template, label):
self._template = template
self._label = label
self._overlap = overlap
+ self._icon = GdkPixbuf.Pixbuf.new_from_file(Resources().get_icon("i_command.png"))
@property
def source(self):
@@ -55,6 +55,10 @@ class LaTeXCommandProposal(Proposal):
return None
@property
+ def icon(self):
+ return self.icon
+
+ @property
def overlap(self):
return self._overlap
@@ -63,13 +67,13 @@ class LaTeXChoiceProposal(Proposal):
"""
A proposal inserting a simple string when activated
"""
- icon = GdkPixbuf.Pixbuf.new_from_file(find_resource("icons/i_choice.png"))
def __init__(self, overlap, source, label, details):
self._source = source
self._details = details
self._overlap = overlap
self._label = label
+ self._icon = GdkPixbuf.Pixbuf.new_from_file(Resources().get_icon("i_choice.png"))
@property
def source(self):
@@ -84,6 +88,10 @@ class LaTeXChoiceProposal(Proposal):
return self._details
@property
+ def icon(self):
+ return self._icon
+
+ @property
def overlap(self):
return self._overlap
diff --git a/latex/latex/dialogs.py b/latex/latex/dialogs.py
index cf3876d..4c6d308 100644
--- a/latex/latex/dialogs.py
+++ b/latex/latex/dialogs.py
@@ -32,7 +32,7 @@ from gi.repository import Gtk, GdkPixbuf
from ..preferences import Preferences
from ..util import GladeInterface
-from ..base.resources import find_resource, MODE_READWRITE
+from ..base.resources import Resources
from ..base import Template, File, Folder
from .preview import PreviewRenderer, ImageToolGenerator
@@ -158,7 +158,10 @@ class ChooseMasterDialog(GladeInterface):
"""
Dialog for choosing a master file to a LaTeX fragment file
"""
- filename = find_resource("ui/choose_master_dialog.ui")
+
+ def __init__(self):
+ super(GladeInterface, self).__init__()
+ self.filename = Resources().get_ui_file("choose_master_dialog.ui")
def run(self, folder):
"""
@@ -182,7 +185,6 @@ class NewDocumentDialog(GladeInterface):
"""
Dialog for creating the body of a new LaTeX document
"""
- filename = find_resource("ui/new_document_template_dialog.ui")
_log = logging.getLogger("NewDocumentWizard")
@@ -314,6 +316,10 @@ class NewDocumentDialog(GladeInterface):
dialog = None
+ def __init__(self):
+ super(GladeInterface, self).__init__()
+ self.filename = Resources().get_ui_file("new_document_template_dialog.ui")
+
def get_dialog(self):
"""
Build and return the dialog
@@ -555,7 +561,6 @@ class UseBibliographyDialog(GladeInterface, PreviewRenderer):
"""
Dialog for inserting a reference to a bibliography
"""
- filename = find_resource("ui/use_bibliography_dialog.ui")
_log = logging.getLogger("UseBibliographyWizard")
@@ -572,6 +577,10 @@ class UseBibliographyDialog(GladeInterface, PreviewRenderer):
dialog = None
+ def __init__(self):
+ super(GladeInterface, self).__init__()
+ self.filename = Resources().get_ui_file("use_bibliography_dialog.ui")
+
def run_dialog(self, edited_file):
"""
Run the dialog
@@ -670,9 +679,12 @@ class UseBibliographyDialog(GladeInterface, PreviewRenderer):
class InsertGraphicsDialog(GladeInterface):
_PREVIEW_WIDTH, _PREVIEW_HEIGHT = 128, 128
- filename = find_resource("ui/insert_graphics_dialog.ui")
_dialog = None
+ def __init__(self):
+ super(GladeInterface, self).__init__()
+ self.filename = Resources().get_ui_file("insert_graphics_dialog.ui")
+
def run(self, edited_file):
"""
@param edited_file: the File currently edited
@@ -788,9 +800,12 @@ class InsertTableDialog(GladeInterface):
This is used to include tables and matrices
"""
- filename = find_resource("ui/insert_table_dialog.ui")
_dialog = None
+ def __init__(self):
+ super(GladeInterface, self).__init__()
+ self.filename = Resources().get_ui_file("insert_table_dialog.ui")
+
def run(self):
dialog = self.__get_dialog()
@@ -861,7 +876,7 @@ class InsertTableDialog(GladeInterface):
("dvbars", "Double Vertical Bars", "Vmatrix")]
for d in delimiters:
- pixbuf = GdkPixbuf.Pixbuf.new_from_file(find_resource("icons/%s.png" % d[0]))
+ pixbuf = GdkPixbuf.Pixbuf.new_from_file(Resources().get_icon("%s.png" % d[0]))
self._storeDelims.append([pixbuf, d[1], d[2]])
self._comboDelims = self.find_widget("comboDelims")
@@ -905,9 +920,12 @@ class InsertListingDialog(GladeInterface):
"""
"""
- filename = find_resource("ui/insert_listing_dialog.ui")
_dialog = None
+ def __init__(self):
+ super(GladeInterface, self).__init__()
+ self.filename = Resources().get_ui_file("insert_listing_dialog.ui")
+
def run(self, edited_file):
"""
@param edited_file: the File currently edited
@@ -960,7 +978,7 @@ class InsertListingDialog(GladeInterface):
#
self._languages = []
parser = LanguagesParser()
- parser.parse(self._languages, find_resource("listings.xml"))
+ parser.parse(self._languages, Resources().get_data_file("listings.xml"))
recentLanguage = Preferences().get("RecentListingLanguage", "Java")
@@ -1041,10 +1059,13 @@ class BuildImageDialog(GladeInterface):
Render the document to an image
"""
- filename = find_resource("ui/build_image_dialog.ui")
_dialog = None
_generator = ImageToolGenerator()
+ def __init__(self):
+ super(GladeInterface, self).__init__()
+ self.filename = Resources().get_ui_file("build_image_dialog.ui")
+
def run(self):
dialog = self._getDialog()
@@ -1119,9 +1140,13 @@ class BuildImageDialog(GladeInterface):
class SaveAsTemplateDialog(GladeInterface):
- filename = find_resource("ui/save_as_template_dialog.ui")
+
_dialog = None
+ def __init__(self):
+ super(GladeInterface, self).__init__()
+ self.filename = Resources().get_ui_file("save_as_template_dialog.ui")
+
def get_dialog(self):
self._folder = Preferences().TEMPLATE_DIR
diff --git a/latex/latex/model.py b/latex/latex/model.py
index 587d3d8..77f3a0c 100644
--- a/latex/latex/model.py
+++ b/latex/latex/model.py
@@ -26,6 +26,8 @@ The LaTeX language model used for code completion.
from logging import getLogger
+from ..base.resources import Resources
+
class Element(object):
"""
@@ -241,7 +243,6 @@ class LanguageModelParser(sax.ContentHandler):
from copy import deepcopy
import pickle
-from ..base.resources import find_resource, MODE_READWRITE
from ..base import File
@@ -268,8 +269,8 @@ class LanguageModelFactory(object):
if pickled_object:
self.__language_model = pickled_object
else:
- pkl_filename = find_resource("latex.pkl", MODE_READWRITE)
- xml_filename = find_resource("latex.xml")
+ pkl_filename = Resources().get_user_file("latex.pkl")
+ xml_filename = Resources().get_data_file("latex.xml")
self.__language_model = LanguageModel()
parser = LanguageModelParser()
@@ -280,8 +281,8 @@ class LanguageModelFactory(object):
self._ready = True
def __find_pickled_object(self):
- pkl_file = File(find_resource("latex.pkl", MODE_READWRITE))
- xml_file = File(find_resource("latex.xml"))
+ pkl_file = File(Resources().get_user_file("latex.pkl"))
+ xml_file = File(Resources().get_data_file("latex.xml"))
if pkl_file.exists:
if xml_file.mtime > pkl_file.mtime:
diff --git a/latex/latex/views.py b/latex/latex/views.py
index f7cc054..f119088 100755
--- a/latex/latex/views.py
+++ b/latex/latex/views.py
@@ -25,14 +25,13 @@ LaTeX-specific views
"""
from gi.repository import Gtk, GdkPixbuf
-#from Gtk.gdk import Pixbuf, pixbuf_new_from_file
from gobject import GError
from logging import getLogger
import xml.etree.ElementTree as ElementTree
from ..preferences import Preferences
from ..base import View, SideView
-from ..base.resources import find_resource, MODE_READWRITE
+from ..base.resources import Resources
from ..base.templates import Template
from ..issues import Issue
@@ -65,7 +64,7 @@ class SymbolCollection(object):
def __init__(self):
- filename = find_resource("symbols.xml")
+ filename = Resources().get_data_file("symbols.xml")
self.groups = []
@@ -73,7 +72,7 @@ class SymbolCollection(object):
for group_el in symbols_el.findall("group"):
group = self.Group(group_el.get("label"))
for symbol_el in group_el.findall("symbol"):
- symbol = self.Symbol(Template(symbol_el.text.strip()), find_resource("icons/%s" % symbol_el.get("icon")))
+ symbol = self.Symbol(Template(symbol_el.text.strip()), Resources().get_icon("%s" % symbol_el.get("icon")))
group.symbols.append(symbol)
self.groups.append(group)
@@ -198,7 +197,7 @@ class LaTeXOutlineView(BaseOutlineView):
@property
def icon(self):
image = Gtk.Image()
- image.set_from_file(find_resource("icons/outline.png"))
+ image.set_from_file(Resources().get_icon("outline.png"))
return image
def init(self, context):
@@ -208,12 +207,12 @@ class LaTeXOutlineView(BaseOutlineView):
# additional toolbar buttons
btn_graphics = Gtk.ToggleToolButton()
- btn_graphics.set_icon_widget(Gtk.Image.new_from_file(find_resource("icons/tree_includegraphics.png")))
+ btn_graphics.set_icon_widget(Gtk.Image.new_from_file(Resources().get_icon("tree_includegraphics.png")))
btn_graphics.set_tooltip_text("Show graphics")
self._toolbar.insert(btn_graphics, -1)
btn_tables = Gtk.ToggleToolButton()
- btn_tables.set_icon_widget(Gtk.Image.new_from_file(find_resource("icons/tree_table.png")))
+ btn_tables.set_icon_widget(Gtk.Image.new_from_file(Resources().get_icon("tree_table.png")))
btn_tables.set_tooltip_text("Show tables")
self._toolbar.insert(btn_tables, -1)
@@ -313,20 +312,19 @@ class OutlineConverter(object):
This creates a Gtk.TreeStore object from a LaTeX outline model
"""
- _ICON_LABEL = GdkPixbuf.Pixbuf.new_from_file(find_resource("icons/label.png"))
- _ICON_TABLE = GdkPixbuf.Pixbuf.new_from_file(find_resource("icons/tree_table.png"))
- _ICON_GRAPHICS = GdkPixbuf.Pixbuf.new_from_file(find_resource("icons/tree_includegraphics.png"))
-
- _LEVEL_ICONS = { 1 : GdkPixbuf.Pixbuf.new_from_file(find_resource("icons/tree_part.png")),
- 2 : GdkPixbuf.Pixbuf.new_from_file(find_resource("icons/tree_chapter.png")),
- 3 : GdkPixbuf.Pixbuf.new_from_file(find_resource("icons/tree_section.png")),
- 4 : GdkPixbuf.Pixbuf.new_from_file(find_resource("icons/tree_subsection.png")),
- 5 : GdkPixbuf.Pixbuf.new_from_file(find_resource("icons/tree_subsubsection.png")),
- 6 : GdkPixbuf.Pixbuf.new_from_file(find_resource("icons/tree_paragraph.png")),
- 7 : GdkPixbuf.Pixbuf.new_from_file(find_resource("icons/tree_paragraph.png")) }
-
def __init__(self):
self._preferences = Preferences()
+ self._ICON_LABEL = GdkPixbuf.Pixbuf.new_from_file(Resources().get_icon("label.png"))
+ self._ICON_TABLE = GdkPixbuf.Pixbuf.new_from_file(Resources().get_icon("tree_table.png"))
+ self._ICON_GRAPHICS = GdkPixbuf.Pixbuf.new_from_file(Resources().get_icon("tree_includegraphics.png"))
+
+ self._LEVEL_ICONS = { 1 : GdkPixbuf.Pixbuf.new_from_file(Resources().get_icon("tree_part.png")),
+ 2 : GdkPixbuf.Pixbuf.new_from_file(Resources().get_icon("tree_chapter.png")),
+ 3 : GdkPixbuf.Pixbuf.new_from_file(Resources().get_icon("tree_section.png")),
+ 4 : GdkPixbuf.Pixbuf.new_from_file(Resources().get_icon("tree_subsection.png")),
+ 5 : GdkPixbuf.Pixbuf.new_from_file(Resources().get_icon("tree_subsubsection.png")),
+ 6 : GdkPixbuf.Pixbuf.new_from_file(Resources().get_icon("tree_paragraph.png")),
+ 7 : GdkPixbuf.Pixbuf.new_from_file(Resources().get_icon("tree_paragraph.png")) }
def convert(self, tree_store, outline, offset_map, file):
"""
diff --git a/latex/outline.py b/latex/outline.py
index 39a419f..b945150 100644
--- a/latex/outline.py
+++ b/latex/outline.py
@@ -29,7 +29,7 @@ from gi.repository import Gtk, GdkPixbuf
from base import View, SideView
from preferences import Preferences
-from base.resources import find_resource
+from base.resources import Resources
class BaseOutlineView(SideView):
@@ -50,7 +50,7 @@ class BaseOutlineView(SideView):
@property
def icon(self):
image = Gtk.Image()
- image.set_from_file(find_resource("icons/outline.png"))
+ image.set_from_file(Resources().get_icon("outline.png"))
return image
def init(self, context):
diff --git a/latex/preferences/__init__.py b/latex/preferences/__init__.py
index 9de281e..d7f196e 100644
--- a/latex/preferences/__init__.py
+++ b/latex/preferences/__init__.py
@@ -27,7 +27,6 @@ from gi.repository import GObject, Gio, GLib
import os.path
import logging
-from ..base.resources import find_resource, MODE_READWRITE
from ..util import singleton
@singleton
diff --git a/latex/preferences/dialog.py b/latex/preferences/dialog.py
index 43261dc..aa9fb34 100644
--- a/latex/preferences/dialog.py
+++ b/latex/preferences/dialog.py
@@ -26,7 +26,7 @@ from logging import getLogger
from gi.repository import Gtk
from gi.repository import Gdk
-from ..base.resources import find_resource, MODE_READWRITE
+from ..base.resources import Resources
from ..util import GladeInterface
from ..tools import Tool, Job
@@ -64,10 +64,12 @@ class ConfigureToolDialog(GladeInterface):
Wraps the dialog for setting up a Tool
"""
- filename = find_resource("ui/configure_tool.ui")
-
_dialog = None
+ def __init__(self):
+ super(GladeInterface, self,).__init__()
+ self.filename = Resources().get_ui_file("configure_tool.ui")
+
def run(self, tool):
"""
Runs the dialog and returns the updated Tool or None on abort
@@ -316,9 +318,12 @@ class PreferencesDialog(GladeInterface):
_log = getLogger("PreferencesWizard")
- filename = find_resource("ui/configure.ui")
_dialog = None
+ def __init__(self):
+ super(GladeInterface, self,).__init__()
+ self.filename = Resources().get_ui_file("configure.ui")
+
@property
def dialog(self):
if not self._dialog:
diff --git a/latex/preferences/tools.py b/latex/preferences/tools.py
index ebc1da4..80a98e6 100644
--- a/latex/preferences/tools.py
+++ b/latex/preferences/tools.py
@@ -23,8 +23,9 @@ from gi.repository import GObject
from logging import getLogger
from uuid import uuid4
import xml.etree.ElementTree as ElementTree
+import os
-from ..base.resources import find_resource, MODE_READWRITE
+from ..base.resources import Resources
from ..tools import Tool, Job
from ..tools.postprocess import GenericPostProcessor, RubberPostProcessor, LaTeXPostProcessor
from ..util import singleton
@@ -63,8 +64,12 @@ class ToolPreferences(GObject.GObject):
self.__tool_objects = None
self.__tool_ids = None
self.__tools_changed = False
- self.__tools = ElementTree.parse(
- find_resource("tools.xml", MODE_READWRITE)).getroot()
+
+ filename = Resources().get_user_file("tools.xml")
+ if not os.path.exists(filename):
+ filename = Resources().get_data_file("tools.xml")
+
+ self.__tools = ElementTree.parse(filename).getroot()
self._log.debug("Constructed")
def __notify_tools_changed(self):
@@ -228,7 +233,7 @@ class ToolPreferences(GObject.GObject):
self._log.debug("Saving tools...")
tree = ElementTree.ElementTree(self.__tools)
- tree.write(find_resource("tools.xml", MODE_READWRITE), encoding="utf-8")
+ tree.write(Resources().get_user_file("tools.xml"), encoding="utf-8")
self.__tools_changed = False
diff --git a/latex/tools/__init__.py b/latex/tools/__init__.py
index 7d4ec94..2374dd3 100644
--- a/latex/tools/__init__.py
+++ b/latex/tools/__init__.py
@@ -27,6 +27,8 @@ It can be used for cleaning up, converting files, for building PDFs etc.
from logging import getLogger
+from ..base.resources import Resources
+
class Tool(object):
"""
@@ -137,8 +139,6 @@ from os import chdir
from util import Process
from string import Template
-from ..base.resources import PLUGIN_PATH
-
class ToolRunner(Process):
"""
@@ -183,7 +183,7 @@ class ToolRunner(Process):
command = command_template.safe_substitute({"filename" : self._file.path,
"shortname" : self._file.shortname,
"directory" : self._file.dirname,
- "plugin_path" : PLUGIN_PATH})
+ "plugin_path" : Resources().get_system_dir()})
self._issue_handler.set_partition_state(self._issue_partitions[self._job], "running")
diff --git a/latex/tools/views.py b/latex/tools/views.py
index 7b0f07c..d545122 100755
--- a/latex/tools/views.py
+++ b/latex/tools/views.py
@@ -28,7 +28,7 @@ from logging import getLogger
from gi.repository import Gtk, GdkPixbuf
-from ..base.resources import find_resource
+from ..base.resources import Resources
from ..base import View, BottomView
from ..issues import Issue, IStructuredIssueHandler
@@ -43,16 +43,15 @@ class ToolView(BottomView, IStructuredIssueHandler):
icon = Gtk.Image.new_from_stock(Gtk.STOCK_CONVERT, Gtk.IconSize.MENU)
scope = View.SCOPE_WINDOW
- _ICON_RUN = GdkPixbuf.Pixbuf.new_from_file(find_resource("icons/run.png"))
- _ICON_FAIL = GdkPixbuf.Pixbuf.new_from_file(find_resource("icons/error.png"))
- _ICON_SUCCESS = GdkPixbuf.Pixbuf.new_from_file(find_resource("icons/okay.png"))
- _ICON_ERROR = GdkPixbuf.Pixbuf.new_from_file(find_resource("icons/error.png"))
- _ICON_WARNING = GdkPixbuf.Pixbuf.new_from_file(find_resource("icons/warning.png"))
- _ICON_ABORT = GdkPixbuf.Pixbuf.new_from_file(find_resource("icons/abort.png"))
-
def __init__(self, context):
BottomView.__init__(self, context)
self._handlers = {}
+ self._ICON_RUN = GdkPixbuf.Pixbuf.new_from_file(Resources().get_icon("run.png"))
+ self._ICON_FAIL = GdkPixbuf.Pixbuf.new_from_file(Resources().get_icon("error.png"))
+ self._ICON_SUCCESS = GdkPixbuf.Pixbuf.new_from_file(Resources().get_icon("okay.png"))
+ self._ICON_ERROR = GdkPixbuf.Pixbuf.new_from_file(Resources().get_icon("error.png"))
+ self._ICON_WARNING = GdkPixbuf.Pixbuf.new_from_file(Resources().get_icon("warning.png"))
+ self._ICON_ABORT = GdkPixbuf.Pixbuf.new_from_file(Resources().get_icon("abort.png"))
def init(self, context):
self._log.debug("init")
diff --git a/latex/views.py b/latex/views.py
index a9747fa..99aec90 100644
--- a/latex/views.py
+++ b/latex/views.py
@@ -26,7 +26,7 @@ from gi.repository import Gtk, GdkPixbuf
from logging import getLogger
from preferences import Preferences
-from base.resources import find_resource
+from base.resources import Resources
from base import View, BottomView
from issues import Issue
from util import escape
@@ -57,10 +57,10 @@ class IssueView(BottomView):
self._context = context
- self._icons = { Issue.SEVERITY_WARNING : GdkPixbuf.Pixbuf.new_from_file(find_resource("icons/warning.png")),
- Issue.SEVERITY_ERROR : GdkPixbuf.Pixbuf.new_from_file(find_resource("icons/error.png")),
+ 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")),
Issue.SEVERITY_INFO : None,
- Issue.SEVERITY_TASK : GdkPixbuf.Pixbuf.new_from_file(find_resource("icons/task.png")) }
+ Issue.SEVERITY_TASK : GdkPixbuf.Pixbuf.new_from_file(Resources().get_icon("task.png")) }
self._store = Gtk.ListStore(GdkPixbuf.Pixbuf, str, str, object)
@@ -100,7 +100,7 @@ class IssueView(BottomView):
self._button_warnings = Gtk.ToggleToolButton()
self._button_warnings.set_tooltip_text("Show/Hide Warnings")
image = Gtk.Image()
- image.set_from_file(find_resource("icons/warning.png"))
+ image.set_from_file(Resources().get_icon("warning.png"))
self._button_warnings.set_icon_widget(image)
self._button_warnings.set_active(self._show_warnings)
self._handlers[self._button_warnings] = self._button_warnings.connect("toggled", self.__on_warnings_toggled)
@@ -108,7 +108,7 @@ class IssueView(BottomView):
self._button_tasks = Gtk.ToggleToolButton()
self._button_tasks.set_tooltip_text("Show/Hide Tasks")
imageTask = Gtk.Image()
- imageTask.set_from_file(find_resource("icons/task.png"))
+ imageTask.set_from_file(Resources().get_icon("task.png"))
self._button_tasks.set_icon_widget(imageTask)
self._button_tasks.set_active(self._show_tasks)
self._handlers[self._button_tasks] = self._button_tasks.connect("toggled", self.__on_tasks_toggled)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]