[gedit-plugins] Port charmap plugin to python.



commit fcd3c40ff6cc897519cd12ae852f7c2af8f2e264
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Mon Dec 20 21:56:15 2010 +0100

    Port charmap plugin to python.

 configure.ac                                 |   16 +-
 plugins/charmap/Makefile.am                  |   24 +--
 plugins/charmap/charmap.plugin.desktop.in.in |    3 +-
 plugins/charmap/charmap/Makefile.am          |   11 +
 plugins/charmap/charmap/__init__.py          |  144 +++++++++
 plugins/charmap/charmap/panel.py             |   70 +++++
 plugins/charmap/gedit-charmap-panel.c        |  153 ----------
 plugins/charmap/gedit-charmap-panel.h        |   82 ------
 plugins/charmap/gedit-charmap-plugin.c       |  401 --------------------------
 plugins/charmap/gedit-charmap-plugin.h       |   61 ----
 10 files changed, 236 insertions(+), 729 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 209c20b..ea67f69 100644
--- a/configure.ac
+++ b/configure.ac
@@ -88,13 +88,13 @@ GEDIT_HAS_PYTHON=1
 
 AC_MSG_CHECKING([which plugins to build])
 
-ALL_PLUGINS="bookmarks charmap drawspaces wordcompletion taglist"
-USEFUL_PLUGINS="bookmarks charmap drawspaces wordcompletion taglist"
-DEFAULT_PLUGINS="bookmarks charmap drawspaces wordcompletion taglist"
+ALL_PLUGINS="bookmarks drawspaces wordcompletion taglist"
+USEFUL_PLUGINS="bookmarks drawspaces wordcompletion taglist"
+DEFAULT_PLUGINS="bookmarks drawspaces wordcompletion taglist"
 
-PYTHON_ALL_PLUGINS="bracketcompletion codecomment colorpicker commander joinlines multiedit textsize sessionsaver smartspaces terminal synctex"
-PYTHON_USEFUL_PLUGINS="bracketcompletion codecomment colorpicker commander joinlines multiedit textsize sessionsaver smartspaces terminal synctex"
-PYTHON_DEFAULT_PLUGINS="bracketcompletion codecomment colorpicker commander joinlines multiedit textsize sessionsaver smartspaces terminal synctex"
+PYTHON_ALL_PLUGINS="bracketcompletion charmap codecomment colorpicker commander joinlines multiedit textsize sessionsaver smartspaces terminal synctex"
+PYTHON_USEFUL_PLUGINS="bracketcompletion charmap codecomment colorpicker commander joinlines multiedit textsize sessionsaver smartspaces terminal synctex"
+PYTHON_DEFAULT_PLUGINS="bracketcompletion charmap codecomment colorpicker commander joinlines multiedit textsize sessionsaver smartspaces terminal synctex"
 
 DIST_PLUGINS="$ALL_PLUGINS $PYTHON_ALL_PLUGINS"
 
@@ -228,9 +228,6 @@ then
 		[gucharmap-2.90 >= $GUCHARMAP_REQUIRED],
 		[have_gucharmap=yes],[have_gucharmap=no])
 
-	AC_SUBST([GUCHARMAP_CFLAGS])
-	AC_SUBST([GUCHARMAP_LIBS])
-
 	if test "$have_gucharmap" = "no"; then
 		plugin_defined_explicit charmap
 		if test "$?" = 1
@@ -350,6 +347,7 @@ plugins/bracketcompletion/bracketcompletion.plugin.desktop.in
 plugins/bracketcompletion/Makefile
 plugins/charmap/charmap.plugin.desktop.in
 plugins/charmap/Makefile
+plugins/charmap/charmap/Makefile
 plugins/codecomment/codecomment.plugin.desktop.in
 plugins/codecomment/Makefile
 plugins/colorpicker/colorpicker.plugin.desktop.in
diff --git a/plugins/charmap/Makefile.am b/plugins/charmap/Makefile.am
index c557181..af8f951 100644
--- a/plugins/charmap/Makefile.am
+++ b/plugins/charmap/Makefile.am
@@ -1,28 +1,8 @@
-# Charmap Panel plugin
+# Charmap Plugin
+SUBDIRS = charmap
 plugindir = $(GEDIT_PLUGINS_LIBS_DIR)
 
-INCLUDES = \
-	-I$(top_srcdir) 				\
-	$(GEDIT_CFLAGS) 				\
-	$(GUCHARMAP_CFLAGS)				\
-	$(WARN_CFLAGS)					\
-	$(DISABLE_DEPRECATED_CFLAGS)
-
-plugin_LTLIBRARIES = libcharmap.la
-
-libcharmap_la_SOURCES = \
-	gedit-charmap-plugin.h				\
-	gedit-charmap-plugin.c				\
-	gedit-charmap-panel.h				\
-	gedit-charmap-panel.c
-
-libcharmap_la_LDFLAGS = $(PLUGIN_LIBTOOL_FLAGS)
-libcharmap_la_LIBADD = $(GEDIT_LIBS) $(GUCHARMAP_LIBS)
-
-# Plugin Info
-
 plugin_in_files = 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)
diff --git a/plugins/charmap/charmap.plugin.desktop.in.in b/plugins/charmap/charmap.plugin.desktop.in.in
index 94a5d99..ff0b52e 100644
--- a/plugins/charmap/charmap.plugin.desktop.in.in
+++ b/plugins/charmap/charmap.plugin.desktop.in.in
@@ -1,10 +1,11 @@
 [Plugin]
+Loader=python
 Module=charmap
 IAge=3
 _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.gedit.org
 Version= VERSION@
diff --git a/plugins/charmap/charmap/Makefile.am b/plugins/charmap/charmap/Makefile.am
new file mode 100644
index 0000000..d6bfddf
--- /dev/null
+++ b/plugins/charmap/charmap/Makefile.am
@@ -0,0 +1,11 @@
+# Charmap Plugin
+#
+plugindir = $(GEDIT_PLUGINS_LIBS_DIR)/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..ae0577a
--- /dev/null
+++ b/plugins/charmap/charmap/__init__.py
@@ -0,0 +1,144 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 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, Gedit, Gucharmap
+from panel import CharmapPanel
+import sys
+
+class CharmapPlugin(GObject.Object, Gedit.WindowActivatable):
+    __gtype_name__ = "CharmapPlugin"
+
+    window = GObject.property(type=GObject.Object)
+
+    def __init__(self):
+        GObject.Object.__init__(self)
+
+    def do_activate(self):
+        self.editor_settings = Gio.Settings.new("org.gnome.gedit.preferences.editor")
+        self.editor_settings.connect("changed::use-default-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)
+
+        panel = self.window.get_side_panel()
+        theme = Gtk.IconTheme.get_default()
+
+        if theme.has_icon("accessories-character-map"):
+            image = Gtk.Image.new_from_icon_name("accessories-character-map", Gtk.IconSize.MENU)
+        else:
+            image = Gtk.Image.new_from_icon_name("gucharmap", Gtk.IconSize.MENU)
+
+        self.create_charmap_panel()
+        panel.add_item(self.panel, "GeditCharmapPanel", _("Character Map"), image)
+
+        statusbar = self.window.get_statusbar()
+        self.context_id = statusbar.get_context_id("Character Description")
+
+    def do_deactivate(self):
+        panel = self.window.get_side_panel()
+        panel.remove_item(self.panel)
+
+    def do_update_state(self):
+        pass
+
+    def get_document_font(self):
+        if self.editor_settings.get_boolean("use-default-font"):
+            font = self.system_settings.get_string("monospace-font-name")
+        else:
+            font = self.editor_settings.get_string("editor-font")
+
+        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], True)
+            start = iters[0]
+        else:
+            insert = document.get_insert()
+            start = document.get_iter_at_mark(insert)
+
+        if start.editable(True):
+            document.insert(start, uc)
+
+        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..65512e6
--- /dev/null
+++ b/plugins/charmap/charmap/panel.py
@@ -0,0 +1,70 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 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:



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