2 # -*- coding: utf-8 -*-
4 # Project: J-Ben, Python front-end
5 # File: window_kanjihwsearch.py
7 # Created on: 25 Nov 2008
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
)
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)
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)
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
== " ":
63 clipboard
= gtk
.Clipboard()
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
78 button
.set_sensitive(False)
80 button
.set_label(result
)
81 button
.set_sensitive(True)
83 map(assign_buttons
, results
, self
.buttons
)