--- /dev/null
+#!/usr/bin/env python
+# -*- coding:utf-8 -*-
+
+import gtk
+import os
+import pygtk
+
+
+class Controller:
+ def __init__(self, glade_file_path):
+ builder = gtk.Builder()
+ builder.add_from_file(glade_file_path)
+ builder.connect_signals(self)
+
+ self.entries = dict([(nm, builder.get_object("entry_%s" % nm)) \
+ for nm in ['search', 'code', 'name']])
+ self.search_action = SearchAction(self.entries['search'])
+ self.label_char = builder.get_object('label_char')
+ self.menu_label_char = builder.get_object('menu_label_char')
+ self.font_name = None
+ self.font_dialog = builder.get_object('fontselectiondialog')
+ self.window = builder.get_object('window_main')
+ self.window.show()
+
+ gtk.main()
+
+ def end_application(self, widget, data=None):
+ gtk.main_quit()
+ return False
+
+ def on_button_search_clicked(self, widget, data=None):
+ a = self.search_action
+ a.set_next()
+ a.put_code(self.entries['code'])
+ a.put_char(self.label_char, self.font_name)
+
+ return False
+
+ def on_entry_search_activate(self, widget, data=None):
+ self.on_button_search_clicked(widget, data)
+
+ return False
+
+ def on_label_char_button_press_event(self, widget, event=None):
+ if event.button == 3:
+ self.menu_label_char.popup(None, None, None, event.button, event.time)
+ return True
+ return False
+
+ def on_menuitem_font_activate(self, widget, event=None):
+ self.font_dialog.show()
+
+ return False
+
+ def on_fontsel_cancel_button_clicked(self, widget, data=None):
+ self.font_dialog.hide()
+
+ return False
+
+ def on_fontsel_ok_button_clicked(self, widget, data=None):
+ self.font_name = self.font_dialog.get_font_name()
+ self.font_dialog.hide()
+ self.search_action.put_char(self.label_char, self.font_name)
+
+ return False
+
+
+class SearchAction:
+ def __init__(self, entry_search):
+ self.entry_search = entry_search
+ self.code = None
+ self.char = ''
+
+ def set_next(self):
+ en = self.entry_search
+ buf = en.get_text().decode('utf-8')
+ pos = en.get_position()
+ if pos == len(buf): pos = 0
+ en.select_region(pos, pos + 1)
+ ch = buf[pos:pos + 1]
+
+ self.code = hex(ord(ch))
+ self.char = ch
+
+ def put_code(self, entry):
+ if not self.code: return
+
+ entry.set_text(self.code)
+
+ def put_char(self, label, font_name):
+ if not self.char: return
+ if not font_name: font_name = '80'
+
+ mu = '<span font="%s">%s</span>' % (font_name, self.char)
+ label.set_markup(mu)
+
+
+if __name__ == '__main__':
+ path = os.path.abspath(os.path.dirname(__file__))
+ Controller(os.path.join(path, 'window_main.glade'))
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.0 -->
+ <!-- interface-naming-policy toplevel-contextual -->
+ <object class="GtkFontSelectionDialog" id="fontselectiondialog">
+ <property name="can_focus">False</property>
+ <property name="border_width">5</property>
+ <property name="destroy_with_parent">True</property>
+ <property name="type_hint">dialog</property>
+ <child internal-child="font_selection">
+ <object class="GtkFontSelection" id="fontsel-font_selection1">
+ <property name="can_focus">False</property>
+ </object>
+ </child>
+ <action-widgets>
+ <action-widget response="0">fontsel_ok_button</action-widget>
+ <action-widget response="0">fontsel_apply_button1</action-widget>
+ <action-widget response="0">fontsel_cancel_button</action-widget>
+ </action-widgets>
+ <child internal-child="cancel_button">
+ <object class="GtkButton" id="fontsel_cancel_button">
+ <property name="can_focus">False</property>
+ <property name="receives_default">False</property>
+ <property name="use_action_appearance">False</property>
+ <signal name="clicked" handler="on_fontsel_cancel_button_clicked" swapped="no"/>
+ </object>
+ </child>
+ <action-widgets>
+ <action-widget response="0">fontsel_ok_button</action-widget>
+ <action-widget response="0">fontsel_apply_button1</action-widget>
+ <action-widget response="0">fontsel_cancel_button</action-widget>
+ </action-widgets>
+ <child internal-child="apply_button">
+ <object class="GtkButton" id="fontsel_apply_button1">
+ <property name="can_focus">False</property>
+ <property name="receives_default">False</property>
+ <property name="use_action_appearance">False</property>
+ </object>
+ </child>
+ <action-widgets>
+ <action-widget response="0">fontsel_ok_button</action-widget>
+ <action-widget response="0">fontsel_apply_button1</action-widget>
+ <action-widget response="0">fontsel_cancel_button</action-widget>
+ </action-widgets>
+ <child internal-child="ok_button">
+ <object class="GtkButton" id="fontsel_ok_button">
+ <property name="can_focus">False</property>
+ <property name="receives_default">False</property>
+ <property name="use_action_appearance">False</property>
+ <signal name="clicked" handler="on_fontsel_ok_button_clicked" swapped="no"/>
+ </object>
+ </child>
+ <action-widgets>
+ <action-widget response="0">fontsel_ok_button</action-widget>
+ <action-widget response="0">fontsel_apply_button1</action-widget>
+ <action-widget response="0">fontsel_cancel_button</action-widget>
+ </action-widgets>
+ </object>
+ <object class="GtkMenu" id="menu_label_char">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="ubuntu_local">True</property>
+ <child>
+ <object class="GtkMenuItem" id="menuitem_font">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="use_action_appearance">False</property>
+ <property name="label" translatable="yes">Font...</property>
+ <property name="use_underline">True</property>
+ <signal name="activate" handler="on_menuitem_font_activate" swapped="no"/>
+ </object>
+ </child>
+ </object>
+ <object class="GtkWindow" id="window_main">
+ <property name="width_request">439</property>
+ <property name="height_request">138</property>
+ <property name="can_focus">False</property>
+ <property name="title" translatable="yes">chartool</property>
+ <property name="default_height">138</property>
+ <signal name="destroy-event" handler="end_application" swapped="no"/>
+ <signal name="delete-event" handler="end_application" swapped="no"/>
+ <child>
+ <object class="GtkHBox" id="box_root">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">2</property>
+ <child>
+ <object class="GtkLabel" id="label_char">
+ <property name="width_request">128</property>
+ <property name="height_request">128</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="yalign">0.25</property>
+ <property name="selectable">True</property>
+ <property name="track_visited_links">False</property>
+ <attributes>
+ <attribute name="style" value="normal"/>
+ <attribute name="weight" value="thin"/>
+ </attributes>
+ <signal name="button-press-event" handler="on_label_char_button_press_event" swapped="no"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkVSeparator" id="separator1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkVBox" id="box_detail">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">5</property>
+ <child>
+ <object class="GtkHBox" id="box_search">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">5</property>
+ <child>
+ <object class="GtkEntry" id="entry_search">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="primary_icon_activatable">False</property>
+ <property name="secondary_icon_activatable">False</property>
+ <property name="primary_icon_sensitive">True</property>
+ <property name="secondary_icon_sensitive">True</property>
+ <signal name="activate" handler="on_entry_search_activate" swapped="no"/>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="button_search">
+ <property name="label" translatable="yes">Search</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="receives_default">True</property>
+ <property name="use_action_appearance">False</property>
+ <property name="focus_on_click">False</property>
+ <signal name="clicked" handler="on_button_search_clicked" swapped="no"/>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkHBox" id="box_code">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">5</property>
+ <child>
+ <object class="GtkLabel" id="label2">
+ <property name="width_request">64</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Code:</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="entry_code">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="editable">False</property>
+ <property name="primary_icon_activatable">False</property>
+ <property name="secondary_icon_activatable">False</property>
+ <property name="primary_icon_sensitive">True</property>
+ <property name="secondary_icon_sensitive">True</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="button_code_script">
+ <property name="label" translatable="yes">S</property>
+ <property name="width_request">24</property>
+ <property name="height_request">24</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="receives_default">True</property>
+ <property name="use_action_appearance">False</property>
+ <property name="focus_on_click">False</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkHBox" id="box_name">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">5</property>
+ <child>
+ <object class="GtkLabel" id="label3">
+ <property name="width_request">64</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Name:</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="entry_name">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="editable">False</property>
+ <property name="primary_icon_activatable">False</property>
+ <property name="secondary_icon_activatable">False</property>
+ <property name="primary_icon_sensitive">True</property>
+ <property name="secondary_icon_sensitive">True</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="button_name_script">
+ <property name="label" translatable="yes">S</property>
+ <property name="width_request">24</property>
+ <property name="height_request">24</property>
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="receives_default">True</property>
+ <property name="use_action_appearance">False</property>
+ <property name="focus_on_click">False</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="padding">5</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+</interface>