2 # -*- coding: utf-8 -*-
4 # Project: J-Ben, Python front-end
5 # File: window_kanjihwsearch.py
7 # Created on: 25 Nov 2008
9 from __future__
import absolute_import
13 from jben
import jben_globals
14 from ..widget
.hwpad
import WidgetHWPad
15 from ..widget
.storedsize
import StoredSizeWindow
18 class WindowKanjiHWSearch(StoredSizeWindow
):
19 def __init__(self
, param
="gui.kanjihwsearch.size"):
20 StoredSizeWindow
.__init
__(self
, param
, 200, 230, gtk
.WINDOW_TOPLEVEL
)
21 self
.set_title(_("%s: Kanji Handwriting Pad")
22 % jben_globals
.PROGRAM_NAME
)
23 self
.set_border_width(5)
25 contents
= gtk
.VBox(spacing
= 5)
27 drawing_frame
= gtk
.Frame(_("Draw Kanji (Right click erases)"))
28 drawing_frame
.set_shadow_type(gtk
.SHADOW_IN
)
29 self
.drawing_widget
= WidgetHWPad()
30 drawing_frame
.add(self
.drawing_widget
)
31 drawing_frame
.connect("button-release-event",
32 self
.on_hwpad_button_released
)
36 button
= gtk
.Button(" ")
37 button
.connect("clicked", self
.on_kanji_clicked
)
38 button
.set_sensitive(False)
39 self
.buttons
.append(button
)
41 btnbox
= gtk
.HBox(spacing
= 5)
42 for button
in self
.buttons
:
43 btnbox
.pack_start(button
)
45 # So our buttons won't stretch the full horizontal width, we wrap them
46 # in a gtk.Alignment object.
47 btnalign
= gtk
.Alignment(0.5, 0.5, 0.0, 0.0)
50 self
.clear
= gtk
.Button(_("Clear"))
51 self
.clear
.connect("clicked", self
.on_clear_clicked
)
52 btnbox2
= gtk
.HButtonBox()
53 btnbox2
.pack_start(self
.clear
)
55 contents
.pack_start(drawing_frame
)
56 contents
.pack_start(btnalign
, expand
= False)
57 contents
.pack_start(btnbox2
, expand
= False)
62 def on_kanji_clicked(self
, widget
):
63 print "WindowKanjiHWSearch.on_kanji_clicked\n\t(%s)" % widget
64 s
= widget
.get_label()
65 if s
== None or s
== " ":
67 clipboard
= gtk
.Clipboard()
70 def on_clear_clicked(self
, widget
):
71 print "WindowKanjiHWSearch.on_clear_clicked"
72 self
.drawing_widget
.clear()
74 def on_hwpad_button_released(self
, widget
, event
):
75 print "WindowKanjiHWSearch.on_hwpad_button_released"
76 results
= self
.drawing_widget
.get_results()
78 def assign_buttons(result
, button
):
79 if button
is None: return
82 button
.set_sensitive(False)
84 button
.set_label(result
)
85 button
.set_sensitive(True)
87 map(assign_buttons
, results
, self
.buttons
)