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 tab_worddict
import TabWordDict
14 from tab_kanjidict
import TabKanjiDict
15 from window_kanjihwsearch
import WindowKanjiHWSearch
16 from dialog_vocablisteditor
import DialogVocabListEditor
17 from dialog_kanjilisteditor
import DialogKanjiListEditor
18 from dialog_preferences
import DialogPreferences
19 from widget_storedsize
import StoredSizeWindow
21 class InfoMessage(gtk
.MessageDialog
):
22 def __init__(self
, parent
=None, title
="", message
="",
23 type=gtk
.MESSAGE_INFO
, buttons
=gtk
.BUTTONS_OK
):
24 gtk
.MessageDialog
.__init
__(self
, parent
,
25 gtk
.DIALOG_MODAL
, type,
29 class WindowMain(StoredSizeWindow
):
30 """The main GUI of J-Ben."""
32 def __init__(self
, param
="gui.main.size"):
33 StoredSizeWindow
.__init
__(self
, param
, 600, 400, gtk
.WINDOW_TOPLEVEL
)
34 self
.connect("destroy", self
.destroy
)
35 self
.set_title(PROGRAM_NAME
)
37 self
.menu
= self
.create_menu()
38 self
.children
= self
.create_children()
40 layout
= gtk
.VBox(spacing
= 5)
41 layout
.pack_start(self
.menu
, expand
= False)
42 layout
.pack_start(self
.children
)
46 def destroy(self
, widget
, data
= None):
49 def create_menu(self
):
50 ag
= gtk
.ActionGroup("jben.ag")
52 [("MenuFile", None, _("_File"), None, None, None),
54 ("MenuFileQuit", gtk
.STOCK_QUIT
, None,
55 None, None, self
.on_menu_file_quit
),
57 ("MenuEdit", None, _("_Edit"),
60 ("MenuEditVocab", None, _("_Vocab Study List"),
61 None, None, self
.on_menu_edit_vocab
),
63 ("MenuEditKanji", None, _("_Kanji Study List"),
64 None, None, self
.on_menu_edit_kanji
),
66 ("MenuEditPrefs", gtk
.STOCK_PREFERENCES
, None,
67 None, None, self
.on_menu_edit_prefs
),
69 ("MenuPractice", None, _("_Practice"), None, None, None),
71 ("MenuPracticeKanji", None, _("_Kanji"),
72 None, None, self
.on_menu_practice_kanji
),
74 ("MenuTools", None, _("_Tools"), None, None, None),
76 ("MenuToolsHand", None, _("_Handwriting Recognition for Kanji"),
77 None, None, self
.on_menu_tools_hand
),
79 ("MenuToolsKanjiSearch", None, _("_Kanji Search"),
80 None, None, self
.on_menu_tools_kanji_search
),
82 ("MenuHelp", None, _("_Help"), None, None, None),
84 ("MenuHelpAbout", gtk
.STOCK_ABOUT
,
85 None, None, None, self
.on_menu_help_about
),
87 ("MenuHelpLicense", None, _("_License Information..."),
88 None, None, self
.on_menu_help_license
)])
91 uim
.insert_action_group(ag
, -1)
92 uim
.add_ui_from_string(
94 " <menubar name='MenuBar'>"
95 " <menu action='MenuFile'>"
96 " <menuitem action='MenuFileQuit'/>"
98 " <menu action='MenuEdit'>"
99 " <menuitem action='MenuEditVocab'/>"
100 " <menuitem action='MenuEditKanji'/>"
102 " <menuitem action='MenuEditPrefs'/>"
104 " <menu action='MenuPractice'>"
105 " <menuitem action='MenuPracticeKanji'/>"
107 " <menu action='MenuTools'>"
108 " <menuitem action='MenuToolsHand'/>"
109 " <menuitem action='MenuToolsKanjiSearch'/>"
111 " <menu action='MenuHelp'>"
112 " <menuitem action='MenuHelpAbout'/>"
113 " <menuitem action='MenuHelpLicense'/>"
117 self
.add_accel_group(uim
.get_accel_group())
118 return uim
.get_widget("/MenuBar")
120 def create_children(self
):
121 tabs
= gtk
.Notebook()
122 worddict
= TabWordDict()
123 kanjidict
= TabKanjiDict()
124 tabs
.append_page(worddict
, gtk
.Label(_("Word Dictionary")))
125 tabs
.append_page(kanjidict
, gtk
.Label(_("Kanji Dictionary")))
128 def on_menu_file_quit(self
, widget
):
129 if not self
.delete_event(None, None):
132 def on_menu_edit_vocab(self
, widget
):
133 print "on_menu_edit_vocab"
135 dialog
= DialogVocabListEditor(self
)
136 result
= dialog
.run()
139 if result
== gtk
.RESPONSE_OK
:
140 print "OK was clicked."
141 # If OK was pressed, update the WordDict GUI's current/max index.
143 print "Cancel was clicked; dialog input discarded."
145 def on_menu_edit_kanji(self
, widget
):
146 print "on_menu_edit_kanji"
148 dialog
= DialogKanjiListEditor(self
)
149 result
= dialog
.run()
152 if result
== gtk
.RESPONSE_OK
:
153 print "OK was clicked."
154 # If OK was pressed, update the KanjiDict GUI's current/max index.
156 print "Cancel was clicked; dialog input discarded."
158 def on_menu_edit_prefs(self
, widget
):
159 print "on_menu_edit_prefs"
161 dialog
= DialogPreferences(self
)
162 result
= dialog
.run()
165 if result
== gtk
.RESPONSE_OK
:
166 print "OK was clicked."
168 print "Cancel was clicked; dialog input discarded."
170 def on_menu_practice_kanji(self
, widget
):
171 print "on_menu_practice_kanji"
172 # Show test choice dialog ("pre-test")
174 # * clear dictionary panels (no cheating, at least not that easily!)
175 # * show main test dialog
176 # * show test results dialog ("post-test")
177 im
= InfoMessage(self
, _("Not yet implemented"),
178 _("Sorry, this has not yet been re-implemented."))
182 def on_menu_tools_hand(self
, widget
):
183 print "on_menu_tools_hand"
184 # Show kanji handwriting pad... no real reason to make it modal; allow
185 # the user to open multiple ones if they desire.
186 hwpad
= WindowKanjiHWSearch()
188 def on_menu_tools_kanji_search(self
, widget
):
189 print "on_menu_tools_kanji_search"
190 im
= InfoMessage(self
, _("Not yet implemented"),
191 _("Sorry, this has not yet been re-implemented."))
195 def on_menu_help_about(self
, widget
):
200 "Inspired in large by JWPce and JFC by Glenn Rosenthal:\n"
201 "http://www.physics.ucla.edu/~grosenth/\n\n"
203 "Powered by the many Japanese dictionary files from Monash "
204 "University, many thanks to Jim Breen:\n"
205 "http://www.csse.monash.edu.au/~jwb/japanese.html\n"
206 "Thanks also to Jim Rose of kanjicafe.com for his extended "
207 "RADKFILE2/KRADFILE2 databases and derived database files.\n\n"
209 "Built using PyGTK: http://www.pygtk.org/\n\n"
211 "Hand writing recognition is based upon code from im-ja "
212 "(http://im-ja.sourceforge.net/) and KanjiPad "
213 "(http://fishsoup.net/software/kanjipad/). KanjiPad was "
214 "written by Owen Taylor.\n\n"
216 "See \"Help->License Information...\" for important license "
218 ) % (PROGRAM_NAME
, VERSION_STR
, AUTHOR_NAME
, COPYRIGHT_DATE
)
220 im
= InfoMessage(self
, _("About %s") % PROGRAM_NAME
, message
)
224 def on_menu_help_license(self
, widget
):
226 "Program distributed under the GNU General Public License (GPL) "
228 "http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt\n\n"
230 "The included dictionary data files, with the exception of the "
231 "handwriting databases and Jim Rose's extensions to the radical "
232 "databases, are distributed under a separate license specified "
234 "http://www.csse.monash.edu.au/~jwb/edrdg/license.htm\n\n"
236 "Jim Rose's extended databases are licensed to Monash University "
237 "with permission to modify and redistribute the files, as long as "
238 "his copyright notices are preserved.\n\n"
240 "The SKIP (System of Kanji Indexing by Patterns) system for "
241 "ordering kanji was developed by Jack Halpern (Kanji Dictionary "
242 "Publishing Society at http://www.kanji.org/), and is used with "
243 "his permission.\n\n"
245 "Copies of the GNU General Public License, Monash University's "
246 "license for the dictionary files and documentation for the "
247 "dictionary files are contained in this program's \"license\" "
251 im
= InfoMessage(self
, _("License Information"), message
)