[gtranslator] Port charmap plugin to python borrowed from gedit-plugins



commit 2fee306e940caaeeb9ab7e4092ddadbedb071e17
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Sun Mar 13 17:12:39 2011 +0100

    Port charmap plugin to python borrowed from gedit-plugins

 configure.ac                                  |   20 +--
 plugins/Makefile.am                           |    5 +-
 plugins/charmap/Makefile.am                   |   33 +---
 plugins/charmap/charmap/Makefile.am           |   11 +
 plugins/charmap/charmap/__init__.py           |  133 ++++++++++
 plugins/charmap/charmap/panel.py              |   71 +++++
 plugins/charmap/gtr-charmap-panel.c           |  153 -----------
 plugins/charmap/gtr-charmap-panel.h           |   67 -----
 plugins/charmap/gtr-charmap-plugin.c          |  338 -------------------------
 plugins/charmap/gtr-charmap-plugin.h          |   65 -----
 plugins/charmap/gtr-charmap.plugin.desktop.in |    3 +-
 plugins/charmap/gucharmap.ico                 |  Bin 9662 -> 0 bytes
 src/gtr-plugins-engine.c                      |    2 +
 13 files changed, 226 insertions(+), 675 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 434b1b3..50ef4ba 100644
--- a/configure.ac
+++ b/configure.ac
@@ -24,6 +24,8 @@ dnl -------------------------------------------------------------------
 AC_PROG_CC
 AC_PROG_INSTALL
 
+AM_PATH_PYTHON
+
 # Initialize libtool
 LT_PREREQ([2.2.6])
 LT_INIT
@@ -205,16 +207,6 @@ fi
 
 AM_CONDITIONAL(USE_DICTIONARY, test x"$have_gdict" = "xyes")
 
-# ================================================================
-# gucharmap
-# ================================================================
-have_gucharmap=no
-GUCHARMAP_OPTIONAL=2.33.0
-PKG_CHECK_MODULES([GUCHARMAP],[gucharmap-2.90 >= $GUCHARMAP_OPTIONAL],
-                  [have_gucharmap=yes],[have_gucharmap=no])
-
-AM_CONDITIONAL(USE_CHARMAP, test x"$have_gucharmap" = "xyes")
-
 dnl -------------------------------------------------------------------
 dnl Enable debug builds.
 dnl -------------------------------------------------------------------
@@ -269,6 +261,7 @@ po/Makefile.in
 plugins/Makefile
 plugins/alternate-language/Makefile
 plugins/charmap/Makefile
+plugins/charmap/charmap/Makefile
 plugins/dictionary/Makefile
 plugins/dictionary/org.gnome.gtranslator.plugins.dictionary.gschema.xml.in
 plugins/fullscreen/Makefile
@@ -302,13 +295,6 @@ GObject Introspection	  :	$enable_introspection
 ------------------------------------------------------------------
 "
 
-if [ test x"$have_gucharmap" = "xyes" ]; then
-	echo "Building charmap plugin: ...............................YES"
-else
-	echo "Building charmap plugin: ...............................NO"
-		echo "        Requires gucharmap >= $GUCHARMAP_OPTIONAL"
-fi
-
 if [ test x"$have_json_glib" = "xyes" ]; then
 	echo "Building open-tran plugin: .............................YES"
 else
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 098ed45..d01b7cc 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -1,13 +1,10 @@
 SUBDIRS = 					\
 	alternate-language			\
+	charmap					\
 	codeview				\
 	fullscreen				\
 	insert-params
 
-if USE_CHARMAP
-SUBDIRS += charmap
-endif
-
 if USE_LIBJSON_GLIB
 SUBDIRS += open-tran
 endif
diff --git a/plugins/charmap/Makefile.am b/plugins/charmap/Makefile.am
index 187f26f..84dc5a9 100644
--- a/plugins/charmap/Makefile.am
+++ b/plugins/charmap/Makefile.am
@@ -1,40 +1,13 @@
-# Charmap Panel plugin
+# Charmap Plugin
+SUBDIRS = charmap
 plugindir = $(libdir)/gtranslator/plugins
 
-INCLUDES = \
-	-I$(top_srcdir) 				\
-	-I$(top_srcdir)/src				\
-	$(GTRANSLATOR_CFLAGS) 				\
-	$(GUCHARMAP_CFLAGS)				\
-	$(WARN_CFLAGS)					\
-	$(DISABLE_DEPRECATED)
-
-plugin_LTLIBRARIES = libcharmap.la
-
-libcharmap_la_SOURCES = \
-	gtr-charmap-plugin.h				\
-	gtr-charmap-plugin.c				\
-	gtr-charmap-panel.h				\
-	gtr-charmap-panel.c
-
-libcharmap_la_LDFLAGS = \
-	$(PLUGIN_LIBTOOL_FLAGS)				\
-	$(GTRANSLATOR_LIBS)					\
-	$(GUCHARMAP_LIBS)
-
-pixmaps_dir = $(datadir)/pixmaps/gtranslator
-pixmaps__DATA = \
-        gucharmap.ico
-
-# Plugin Info
-
 plugin_in_files = gtr-charmap.plugin.desktop.in
-
 %.plugin: %.plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache
 
 plugin_DATA = $(plugin_in_files:.plugin.desktop.in=.plugin)
 
-EXTRA_DIST = $(pixmaps__DATA) $(plugin_in_files)
+EXTRA_DIST = $(plugin_in_files)
 
 CLEANFILES = $(plugin_DATA)
 DISTCLEANFILES = $(plugin_DATA)
diff --git a/plugins/charmap/charmap/Makefile.am b/plugins/charmap/charmap/Makefile.am
new file mode 100644
index 0000000..2934e77
--- /dev/null
+++ b/plugins/charmap/charmap/Makefile.am
@@ -0,0 +1,11 @@
+# Charmap Plugin
+#
+plugindir = $(libdir)/gtranslator/plugins/charmap
+plugin_PYTHON =		\
+	__init__.py	\
+	panel.py
+
+CLEANFILES =
+DISTCLEANFILES =
+
+-include $(top_srcdir)/git.mk
diff --git a/plugins/charmap/charmap/__init__.py b/plugins/charmap/charmap/__init__.py
new file mode 100644
index 0000000..9800701
--- /dev/null
+++ b/plugins/charmap/charmap/__init__.py
@@ -0,0 +1,133 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2006 Steve Frécinaux <steve istique net>
+#               2010 Ignacio Casal Quinteiro <icq gnome org>
+#
+# 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+from gi.repository import GObject, Gio, Pango, Gtk, Gtranslator, Gucharmap
+from panel import CharmapPanel
+import sys
+import gettext
+
+class CharmapPlugin(GObject.Object, Gtranslator.WindowActivatable):
+    __gtype_name__ = "CharmapPlugin"
+
+    window = GObject.property(type=Gtranslator.Window)
+
+    def __init__(self):
+        GObject.Object.__init__(self)
+
+    def do_activate(self):
+        self.editor_settings = Gio.Settings.new("org.gnome.gtranslator.preferences.editor")
+        self.editor_settings.connect("changed::use-custom-font", self.font_changed)
+        self.editor_settings.connect("changed::editor-font", self.font_changed)
+        self.system_settings = Gio.Settings.new("org.gnome.desktop.interface")
+        self.system_settings.connect("changed::monospace-font-name", self.font_changed)
+
+        self.create_charmap_panel()
+        self.window.add_widget(self.panel, "GtranslatorCharmapPanel", _("Character Map"),
+                               "accessories-character-map", Gtranslator.WindowPlacement.LEFT)
+
+        statusbar = self.window.get_statusbar()
+        self.context_id = statusbar.get_context_id("Character Description")
+
+    def do_deactivate(self):
+        self.window.remove_widget(self.panel)
+
+    def do_update_state(self):
+        self.panel.set_sensitive(len(self.window.get_documents()) >= 1)
+
+    def get_document_font(self):
+        if self.editor_settings.get_boolean("use-custom-font"):
+            font = self.editor_settings.get_string("editor-font")
+        else:
+            font = self.system_settings.get_string("monospace-font-name")
+
+        return font
+
+    def font_changed(self, settings=None, key=None):
+        font = self.get_document_font()
+        font_desc = Pango.font_description_from_string(font)
+
+        chartable = self.panel.get_chartable()
+        chartable.set_font_desc(font_desc)
+
+    def create_charmap_panel(self):
+        self.panel = CharmapPanel()
+        chartable = self.panel.get_chartable()
+
+        # Use the same font as the document
+        self.font_changed()
+
+        chartable.connect("notify::active-character", self.on_table_sync_active_char)
+        chartable.connect("focus-out-event", self.on_table_focus_out_event)
+        chartable.connect("status-message", self.on_table_status_message)
+        chartable.connect("activate", self.on_table_activate)
+
+        self.panel.show()
+
+    def on_table_sync_active_char(self, chartable, pspec):
+        uc = chartable.get_active_character()
+        text = "%s %s" % (uc, Gucharmap.get_unicode_name(uc))
+
+        a = Gucharmap.get_nameslist_equals(uc)
+        if a:
+            text += "   = %s" % a[0]
+            for i in range(len (a) - 1):
+                text += "; %s" % a[i + 1]
+
+        a = Gucharmap.get_nameslist_stars(uc)
+        if a:
+            text += "   \342\200\242 %s" % a[0]
+            for i in range(len (a) - 1):
+                text += "; %s" % a[i + 1]
+
+        self.on_table_status_message(chartable, text)
+
+    def on_table_focus_out_event(self, chartable, event):
+        self.on_table_status_message (chartable, None)
+
+        return False
+
+    def on_table_status_message(self, chartable, message):
+        statusbar = self.window.get_statusbar()
+
+        statusbar.pop(self.context_id)
+
+        if message:
+            statusbar.push(self.context_id, message)
+
+    def on_table_activate(self, chartable):
+        uc = chartable.get_active_character()
+        if not Gucharmap.unichar_validate(uc):
+            raise ValueError
+
+        view = self.window.get_active_view()
+        if not view or not view.get_editable():
+            return
+
+        document = view.get_buffer()
+
+        document.begin_user_action()
+        iters = document.get_selection_bounds()
+        if iters:
+            document.delete_interactive(iters[0], iters[1], view.get_editable())
+
+        document.insert_interactive_at_cursor(uc, -1, view.get_editable())
+
+        document.end_user_action()
+
+# ex:et:ts=4:
diff --git a/plugins/charmap/charmap/panel.py b/plugins/charmap/charmap/panel.py
new file mode 100644
index 0000000..c8d3254
--- /dev/null
+++ b/plugins/charmap/charmap/panel.py
@@ -0,0 +1,71 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2006 Steve Frécinaux <steve istique net>
+#               2010 Ignacio Casal Quinteiro <icq gnome org>
+#
+# 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+from gi.repository import Gtk, Gucharmap
+
+class CharmapPanel(Gtk.Box):
+    __gtype_name__ = "CharmapPanel"
+
+    def __init__(self):
+        Gtk.Box.__init__(self)
+
+        paned = Gtk.Paned.new(Gtk.Orientation.VERTICAL)
+
+        scrolled_window = Gtk.ScrolledWindow(None, None)
+        scrolled_window.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
+        scrolled_window.set_shadow_type(Gtk.ShadowType.ETCHED_IN)
+
+        self.view = Gucharmap.ChaptersView()
+        self.view.set_headers_visible (False)
+
+        model = Gucharmap.ScriptChaptersModel()
+        self.view.set_model(model)
+
+        selection = self.view.get_selection()
+        selection.connect("changed", self.on_chapter_view_selection_changed)
+
+        scrolled_window.add(self.view)
+        paned.pack1(scrolled_window, False, True)
+
+        scrolled_window = Gtk.ScrolledWindow(None, None)
+        scrolled_window.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
+        scrolled_window.set_shadow_type(Gtk.ShadowType.ETCHED_IN)
+
+        self.chartable = Gucharmap.Chartable()
+
+        scrolled_window.add(self.chartable)
+        paned.pack2(scrolled_window, True, True)
+
+        self.view.select_locale()
+
+        paned.set_position(150)
+        paned.show_all()
+
+        self.pack_start(paned, True, True, 0)
+
+    def on_chapter_view_selection_changed(self, selection):
+        model, it = selection.get_selected()
+        if it:
+            codepoint_list = self.view.get_codepoint_list()
+            self.chartable.set_codepoint_list(codepoint_list)
+
+    def get_chartable(self):
+        return self.chartable
+
+# ex:et:ts=4:
diff --git a/plugins/charmap/gtr-charmap.plugin.desktop.in b/plugins/charmap/gtr-charmap.plugin.desktop.in
index 79cbe93..84cf7bb 100644
--- a/plugins/charmap/gtr-charmap.plugin.desktop.in
+++ b/plugins/charmap/gtr-charmap.plugin.desktop.in
@@ -1,9 +1,10 @@
 [Plugin]
+Loader=python
 Module=charmap
 IAge=2
 _Name=Character Map
 _Description=Insert special characters just by clicking on them.
 Icon=gucharmap
-Authors=Steve Frécinaux <steve istique net>
+Authors=Steve Frécinaux <steve istique net>\nIgnacio Casal Quinteiro <icq gnome org>
 Copyright=Copyright @ 2006 Steve Frécinaux
 Website=http://www.gtranslator.org
diff --git a/src/gtr-plugins-engine.c b/src/gtr-plugins-engine.c
index 2b341ed..68e69c2 100644
--- a/src/gtr-plugins-engine.c
+++ b/src/gtr-plugins-engine.c
@@ -64,6 +64,8 @@ gtr_plugins_engine_init (GtrPluginsEngine * engine)
                                               GTR_TYPE_PLUGINS_ENGINE,
                                               GtrPluginsEnginePrivate);
 
+  peas_engine_enable_loader (PEAS_ENGINE (engine), "python");
+
   engine->priv->plugin_settings = g_settings_new ("org.gnome.gtranslator.plugins");
 
   /* Require gtr's typelib. */



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