[gedit-latex] Move action ifaces to action.py



commit 003c4059b25017c2661972b45120c0ef65665fad
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Fri Jul 15 14:45:58 2011 +0200

    Move action ifaces to action.py

 latex/base/Makefile.am  |    1 +
 latex/base/__init__.py  |   66 -----------------------------------
 latex/base/action.py    |   88 +++++++++++++++++++++++++++++++++++++++++++++++
 latex/bibtex/actions.py |    3 +-
 latex/latex/actions.py  |    4 ++-
 latex/tools/__init__.py |   11 +-----
 latex/util.py           |    2 +-
 7 files changed, 97 insertions(+), 78 deletions(-)
---
diff --git a/latex/base/Makefile.am b/latex/base/Makefile.am
index f943dfb..0261a20 100644
--- a/latex/base/Makefile.am
+++ b/latex/base/Makefile.am
@@ -1,6 +1,7 @@
 plugindir = $(libdir)/gedit/plugins/latex/base
 
 plugin_PYTHON = \
+	action.py \
 	appactivatable.py \
 	completion.py \
 	config.py \
diff --git a/latex/base/__init__.py b/latex/base/__init__.py
index eeef8b5..c299de2 100644
--- a/latex/base/__init__.py
+++ b/latex/base/__init__.py
@@ -83,72 +83,6 @@ class Template(object):
 from gi.repository import GObject
 
 
-class GeditLaTeXPlugin_MenuToolAction(Gtk.Action):
-    __gtype_name__ = "GeditLaTeXPlugin_MenuToolAction"
-
-    def do_create_tool_item(self):
-        return Gtk.MenuToolButton()
-
-
-class Action(object):
-    """
-    """
-
-    menu_tool_action = False    # if True a MenuToolAction is created and hooked for this action
-                                # instead of Gtk.Action
-
-    extensions = [None]            # a list of file extensions for which this action should be enabled
-                                # [None] indicates that this action is to be enabled for all extensions
-
-    def __init__(self, *args, **kwargs):
-        pass
-
-    def hook(self, action_group, window_context):
-        """
-        Create an internal action object (Gtk.Action or MenuToolAction), listen to it and
-        hook it in an action group
-
-        @param action_group: a Gtk.ActionGroup object
-        @param window_context: a WindowContext object to pass when this action is activated
-        """
-        if self.menu_tool_action:
-            action_clazz = GeditLaTeXPlugin_MenuToolAction
-        else:
-            action_clazz = Gtk.Action
-        self._internal_action = action_clazz(self.__class__.__name__, self.label, self.tooltip, self.stock_id)
-        self._handler = self._internal_action.connect("activate", lambda gtk_action, action: action.activate(window_context), self)
-        action_group.add_action_with_accel(self._internal_action, self.accelerator)
-
-    @property
-    def label(self):
-        raise NotImplementedError
-
-    @property
-    def stock_id(self):
-        raise NotImplementedError
-
-    @property
-    def accelerator(self):
-        raise NotImplementedError
-
-    @property
-    def tooltip(self):
-        raise NotImplementedError
-
-    def activate(self, context):
-        """
-        @param context: the current WindowContext instance
-        """
-        raise NotImplementedError
-
-    def unhook(self, action_group):
-        self._internal_action.disconnect(self._handler)
-        action_group.remove_action(self._internal_action)
-
-    #~ def __del__(self):
-        #~ print "Properly destroyed Action %s" % self
-
-
 class WindowContext(object):
     """
     The WindowContext is passed to Editors and is used to
diff --git a/latex/base/action.py b/latex/base/action.py
new file mode 100644
index 0000000..cc4f4d3
--- /dev/null
+++ b/latex/base/action.py
@@ -0,0 +1,88 @@
+# -*- coding: utf-8 -*-
+
+# This file is part of the Gedit LaTeX Plugin
+#
+# Copyright (C) 2010 Michael Zeising
+#
+# 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
+# Foundation; either version 2 of the Licence, 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 Licence for more
+# details.
+#
+# You should have received a copy of the GNU General Public Licence along with
+# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
+# Street, Fifth Floor, Boston, MA  02110-1301, USA
+
+from gi.repository import Gtk
+
+class GeditLaTeXPlugin_MenuToolAction(Gtk.Action):
+    __gtype_name__ = "GeditLaTeXPlugin_MenuToolAction"
+
+    def do_create_tool_item(self):
+        return Gtk.MenuToolButton()
+
+
+class Action(object):
+    """
+    """
+
+    menu_tool_action = False    # if True a MenuToolAction is created and hooked for this action
+                                # instead of Gtk.Action
+
+    extensions = [None]            # a list of file extensions for which this action should be enabled
+                                # [None] indicates that this action is to be enabled for all extensions
+
+    def __init__(self, *args, **kwargs):
+        pass
+
+    def hook(self, action_group, window_context):
+        """
+        Create an internal action object (Gtk.Action or MenuToolAction), listen to it and
+        hook it in an action group
+
+        @param action_group: a Gtk.ActionGroup object
+        @param window_context: a WindowContext object to pass when this action is activated
+        """
+        if self.menu_tool_action:
+            action_clazz = GeditLaTeXPlugin_MenuToolAction
+        else:
+            action_clazz = Gtk.Action
+        self._internal_action = action_clazz(self.__class__.__name__, self.label, self.tooltip, self.stock_id)
+        self._handler = self._internal_action.connect("activate", lambda gtk_action, action: action.activate(window_context), self)
+        action_group.add_action_with_accel(self._internal_action, self.accelerator)
+
+    @property
+    def label(self):
+        raise NotImplementedError
+
+    @property
+    def stock_id(self):
+        raise NotImplementedError
+
+    @property
+    def accelerator(self):
+        raise NotImplementedError
+
+    @property
+    def tooltip(self):
+        raise NotImplementedError
+
+    def activate(self, context):
+        """
+        @param context: the current WindowContext instance
+        """
+        raise NotImplementedError
+
+    def unhook(self, action_group):
+        self._internal_action.disconnect(self._handler)
+        action_group.remove_action(self._internal_action)
+
+    #~ def __del__(self):
+        #~ print "Properly destroyed Action %s" % self
+
+# ex:ts=4:et:
diff --git a/latex/bibtex/actions.py b/latex/bibtex/actions.py
index 462dfa9..e1e0557 100644
--- a/latex/bibtex/actions.py
+++ b/latex/bibtex/actions.py
@@ -25,7 +25,7 @@ latex.actions
 from logging import getLogger
 from gi.repository import Gtk
 
-from ..base import Action
+from ..base.action import Action
 from dialogs import InsertBibTeXEntryDialog
 
 
@@ -56,4 +56,5 @@ class BibTeXNewEntryAction(Action):
         source = self._dialog.run()
         if not source is None:
             context.active_editor.append(source)
+
 # ex:ts=4:et:
diff --git a/latex/latex/actions.py b/latex/latex/actions.py
index 1bbfc83..188752c 100644
--- a/latex/latex/actions.py
+++ b/latex/latex/actions.py
@@ -25,7 +25,9 @@ from gi.repository import Gtk
 
 from logging import getLogger
 
-from ..base import Action, Template, File
+from ..base import Template
+from ..base.action import Action
+from ..base.file import File
 from ..base.resources import Resources
 from ..preferences import Preferences
 from ..util import IconAction
diff --git a/latex/tools/__init__.py b/latex/tools/__init__.py
index 5efc38a..ae4b36f 100644
--- a/latex/tools/__init__.py
+++ b/latex/tools/__init__.py
@@ -26,8 +26,9 @@ It can be used for cleaning up, converting files, for building PDFs etc.
 """
 
 from logging import getLogger
-from gi.repository import Gedit
+from gi.repository import Gtk, Gedit
 from ..base.resources import Resources
+from ..base.action import Action
 
 
 class Tool(object):
@@ -87,11 +88,6 @@ class Job(object):
         return self._post_processor
 
 
-from gi.repository import Gtk
-
-from ..base import Action
-
-
 class ToolAction(Action):
     """
     This hooks Tools in the UI. A ToolAction is instantiated for each registered Tool.
@@ -272,7 +268,4 @@ class ToolRunner(Process):
         To be overridden by subclass
         """
 
-
-
-
 # ex:ts=4:et:
diff --git a/latex/util.py b/latex/util.py
index fc763ea..5fed99e 100644
--- a/latex/util.py
+++ b/latex/util.py
@@ -205,7 +205,7 @@ class GladeInterface(object):
 from uuid import uuid1
 from gi.repository import Gtk, Gdk
 
-from base import Action
+from base.action import Action
 
 
 class IconAction(Action):



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