Added indexing to JMdict parser. Small changes to unit tests.
[jben2_gui.git] / window_kanjihwsearch.py
blobd4bf90a24f86d9d56393747350935f8d79f7aa3d
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 # Project: J-Ben, Python front-end
5 # File: window_kanjihwsearch.py
6 # Author: Paul Goins
7 # Created on: 25 Nov 2008
9 import gtk
11 from jben_global import *
12 from widget_hwpad import WidgetHWPad
13 from widget_storedsize import StoredSizeWindow
15 class WindowKanjiHWSearch(StoredSizeWindow):
16 def __init__(self, param="gui.kanjihwsearch.size"):
17 StoredSizeWindow.__init__(self, param, 200, 230, gtk.WINDOW_TOPLEVEL)
18 self.set_title(_("%s: Kanji Handwriting Pad") % PROGRAM_NAME)
19 self.set_border_width(5)
21 contents = gtk.VBox(spacing = 5)
23 drawing_frame = gtk.Frame(_("Draw Kanji (Right click erases)"))
24 drawing_frame.set_shadow_type(gtk.SHADOW_IN)
25 self.drawing_widget = WidgetHWPad()
26 drawing_frame.add(self.drawing_widget)
27 drawing_frame.connect("button-release-event",
28 self.on_hwpad_button_released)
30 self.buttons = []
31 for i in range(5):
32 button = gtk.Button(" ")
33 button.connect("clicked", self.on_kanji_clicked)
34 button.set_sensitive(False)
35 self.buttons.append(button)
37 btnbox = gtk.HBox(spacing = 5)
38 for button in self.buttons:
39 btnbox.pack_start(button)
41 # So our buttons won't stretch the full horizontal width, we wrap them
42 # in a gtk.Alignment object.
43 btnalign = gtk.Alignment(0.5, 0.5, 0.0, 0.0)
44 btnalign.add(btnbox)
46 self.clear = gtk.Button(_("Clear"))
47 self.clear.connect("clicked", self.on_clear_clicked)
48 btnbox2 = gtk.HButtonBox()
49 btnbox2.pack_start(self.clear)
51 contents.pack_start(drawing_frame)
52 contents.pack_start(btnalign, expand = False)
53 contents.pack_start(btnbox2, expand = False)
55 self.add(contents)
56 self.show_all()
58 def on_kanji_clicked(self, widget):
59 print "WindowKanjiHWSearch.on_kanji_clicked\n\t(%s)" % widget
60 s = widget.get_label()
61 if s == None or s == " ":
62 s = ""
63 clipboard = gtk.Clipboard()
64 clipboard.set_text(s)
66 def on_clear_clicked(self, widget):
67 print "WindowKanjiHWSearch.on_clear_clicked"
68 self.drawing_widget.clear()
70 def on_hwpad_button_released(self, widget, event):
71 print "WindowKanjiHWSearch.on_hwpad_button_released"
72 results = self.drawing_widget.get_results()
74 def assign_buttons(result, button):
75 if button is None: return
76 if result is None:
77 button.set_label(" ")
78 button.set_sensitive(False)
79 else:
80 button.set_label(result)
81 button.set_sensitive(True)
83 map(assign_buttons, results, self.buttons)
85 return True