1
# -*- coding: utf-8 -*-
3
# Copyright (C) 2006 Steve Frécinaux <steve@istique.net>
4
# 2010 Ignacio Casal Quinteiro <icq@gnome.org>
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2, or (at your option)
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
from gi.repository import GObject, Gio, Pango, Gtk, Gedit, Gucharmap
21
from panel import CharmapPanel
27
gettext.bindtextdomain(GETTEXT_PACKAGE, GP_LOCALEDIR)
28
_ = lambda s: gettext.dgettext(GETTEXT_PACKAGE, s);
32
class CharmapPlugin(GObject.Object, Gedit.WindowActivatable):
33
__gtype_name__ = "CharmapPlugin"
35
window = GObject.property(type=Gedit.Window)
38
GObject.Object.__init__(self)
40
def do_activate(self):
41
self.editor_settings = Gio.Settings.new("org.gnome.gedit.preferences.editor")
42
self.editor_settings.connect("changed::use-default-font", self.font_changed)
43
self.editor_settings.connect("changed::editor-font", self.font_changed)
44
self.system_settings = Gio.Settings.new("org.gnome.desktop.interface")
45
self.system_settings.connect("changed::monospace-font-name", self.font_changed)
47
panel = self.window.get_side_panel()
48
image = Gtk.Image.new_from_icon_name("accessories-character-map", Gtk.IconSize.MENU)
50
self.create_charmap_panel()
51
panel.add_item(self.panel, "GeditCharmapPanel", _("Character Map"), image)
53
statusbar = self.window.get_statusbar()
54
self.context_id = statusbar.get_context_id("Character Description")
56
def do_deactivate(self):
57
panel = self.window.get_side_panel()
58
panel.remove_item(self.panel)
60
def do_update_state(self):
61
self.panel.set_sensitive(len(self.window.get_documents()) >= 1)
63
def get_document_font(self):
64
if self.editor_settings.get_boolean("use-default-font"):
65
font = self.system_settings.get_string("monospace-font-name")
67
font = self.editor_settings.get_string("editor-font")
71
def font_changed(self, settings=None, key=None):
72
font = self.get_document_font()
73
font_desc = Pango.font_description_from_string(font)
75
chartable = self.panel.get_chartable()
76
chartable.set_font_desc(font_desc)
78
def create_charmap_panel(self):
79
self.panel = CharmapPanel()
80
chartable = self.panel.get_chartable()
82
# Use the same font as the document
85
chartable.connect("notify::active-character", self.on_table_sync_active_char)
86
chartable.connect("focus-out-event", self.on_table_focus_out_event)
87
chartable.connect("status-message", self.on_table_status_message)
88
chartable.connect("activate", self.on_table_activate)
92
def on_table_sync_active_char(self, chartable, pspec):
93
uc = chartable.get_active_character()
94
text = "%s %s" % (uc, Gucharmap.get_unicode_name(uc))
96
a = Gucharmap.get_nameslist_equals(uc)
98
text += " = %s" % a[0]
99
for i in range(len (a) - 1):
100
text += "; %s" % a[i + 1]
102
a = Gucharmap.get_nameslist_stars(uc)
104
text += " \342\200\242 %s" % a[0]
105
for i in range(len (a) - 1):
106
text += "; %s" % a[i + 1]
108
self.on_table_status_message(chartable, text)
110
def on_table_focus_out_event(self, chartable, event):
111
self.on_table_status_message (chartable, None)
115
def on_table_status_message(self, chartable, message):
116
statusbar = self.window.get_statusbar()
118
statusbar.pop(self.context_id)
121
statusbar.push(self.context_id, message)
123
def on_table_activate(self, chartable):
124
uc = chartable.get_active_character()
125
if not Gucharmap.unichar_validate(uc):
128
view = self.window.get_active_view()
129
if not view or not view.get_editable():
132
document = view.get_buffer()
134
document.begin_user_action()
135
iters = document.get_selection_bounds()
137
document.delete_interactive(iters[0], iters[1], view.get_editable())
139
document.insert_interactive_at_cursor(uc, -1, view.get_editable())
141
document.end_user_action()