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
, configure
14 from .kanjihwsearch
import WindowKanjiHWSearch
15 from ..widget
.worddict
import TabWordDict
16 from ..widget
.kanjidict
import TabKanjiDict
17 from ..widget
.storedsize
import StoredSizeWindow
18 from ..widget
.infomessage
import show_message
19 from ..widget
.yesnodialog
import show_message_yn
20 from ..dialog
.vocablisteditor
import DialogVocabListEditor
21 from ..dialog
.kanjilisteditor
import DialogKanjiListEditor
22 from ..dialog
.preferences
import DialogPreferences
23 from ..dialog
.dict_mirror_select
import DictMirrorSelect
24 from ..dialog
.dict_download
import DictDownload
27 class Main(StoredSizeWindow
):
28 """The main GUI of J-Ben."""
30 def __init__(self
, app
, param
="gui.main.size"):
31 StoredSizeWindow
.__init
__(self
, param
, 600, 400, gtk
.WINDOW_TOPLEVEL
)
33 self
.connect("show", self
.on_show
)
34 self
.connect("destroy", self
.on_destroy
)
37 def on_show(self
, widget
):
38 dictmgr
= self
.app
.dictmgr
39 if not dictmgr
.all_dicts_found():
40 # Ask if we should download dictionaries from the internet.
42 do_download
= show_message_yn(
43 self
, _("Dictionaries not found"),
44 _("Could not find some needed dictionary files. "
45 "Do you wish to download them from the Internet?"),
48 # Code is a little unclear here...
49 mirror
= DictMirrorSelect(self
.app
, self
).run()
51 files
= dictmgr
.get_needed_dict_names()
52 DictDownload(self
.app
, self
, mirror
, files
).run()
55 dictmgr
.find_databases() # try to reload DBs
56 if not dictmgr
.all_dicts_found():
58 self
, _("Could not download all dictionaries"),
59 _("Could not download all needed files. "
60 "Some features may be disabled."))
62 show_message(self
, _("Not downloading dictionaries"),
63 _("Not downloading dictionaries. "
64 "Some features may be disabled."))
65 if dictmgr
.jmdict_found():
66 self
.worddict
.set_dict(dictmgr
.jmdict
)
67 self
.worddict
.set_sensitive(True)
68 if dictmgr
.kd2_found():
69 self
.kanjidict
.set_dict(dictmgr
.kd2
)
70 self
.kanjidict
.set_sensitive(True)
71 self
.set_sensitive(True)
73 def on_destroy(self
, widget
):
76 def on_menu_file_quit(self
, widget
):
77 if not self
.delete_event(None, None):
80 def on_menu_edit_vocab(self
, widget
):
81 print "on_menu_edit_vocab"
83 dialog
= DialogVocabListEditor(self
)
87 if result
== gtk
.RESPONSE_OK
:
88 print "OK was clicked."
89 # If OK was pressed, update the WordDict GUI's current/max index.
91 print "Cancel was clicked; dialog input discarded."
93 def on_menu_edit_kanji(self
, widget
):
94 print "on_menu_edit_kanji"
96 dialog
= DialogKanjiListEditor(self
)
100 if result
== gtk
.RESPONSE_OK
:
101 print "OK was clicked."
102 # If OK was pressed, update the KanjiDict GUI's current/max index.
104 print "Cancel was clicked; dialog input discarded."
106 def on_menu_edit_prefs(self
, widget
):
107 print "on_menu_edit_prefs"
109 dialog
= DialogPreferences(self
)
110 result
= dialog
.run()
113 if result
== gtk
.RESPONSE_OK
:
114 print "OK was clicked."
116 print "Cancel was clicked; dialog input discarded."
118 def on_menu_practice_kanji(self
, widget
):
119 print "on_menu_practice_kanji"
120 # Show test choice dialog ("pre-test")
122 # * clear dictionary panels (no cheating, at least not that easily!)
123 # * show main test dialog
124 # * show test results dialog ("post-test")
125 show_message(self
, _("Not yet implemented"),
126 _("Sorry, this has not yet been re-implemented."))
128 def on_menu_tools_hand(self
, widget
):
129 print "on_menu_tools_hand"
130 # Show kanji handwriting pad... no real reason to make it modal; allow
131 # the user to open multiple ones if they desire.
132 hwpad
= WindowKanjiHWSearch()
134 def on_menu_tools_kanji_search(self
, widget
):
135 print "on_menu_tools_kanji_search"
136 show_message(self
, _("Not yet implemented"),
137 _("Sorry, this has not yet been re-implemented."))
139 def on_menu_help_about(self
, widget
):
140 message_template
= _(
141 "%(package_name)s %(package_version)s\n"
143 "Copyright %(copyright)s\n\n"
144 "Inspired in large by JWPce and JFC by Glenn Rosenthal:\n"
145 "http://www.physics.ucla.edu/~grosenth/\n\n"
147 "Powered by the many Japanese dictionary files from Monash "
148 "University, many thanks to Jim Breen:\n"
149 "http://www.csse.monash.edu.au/~jwb/japanese.html\n"
150 "Thanks also to Jim Rose of kanjicafe.com for his extended "
151 "RADKFILE2/KRADFILE2 databases and derived database files.\n\n"
153 "Built using PyGTK: http://www.pygtk.org/\n\n"
155 "Hand writing recognition is based upon code from im-ja "
156 "(http://im-ja.sourceforge.net/) and KanjiPad "
157 "(http://fishsoup.net/software/kanjipad/). KanjiPad was "
158 "written by Owen Taylor.\n\n"
160 "See \"Help->License Information...\" for important license "
164 "package_name": configure
.PACKAGE_NAME
,
165 "package_version": configure
.PACKAGE_VERSION
,
166 "author": jben_globals
.AUTHOR_NAME
,
167 "copyright": jben_globals
.COPYRIGHT_DATE
,
170 message
= message_template
% args
171 show_message(self
, _("About %s") % configure
.PACKAGE_NAME
, message
)
173 def on_menu_help_license(self
, widget
):
175 "Program distributed under the GNU General Public License (GPL) "
177 "http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt\n\n"
179 "The included dictionary data files, with the exception of the "
180 "handwriting databases and Jim Rose's extensions to the radical "
181 "databases, are distributed under a separate license specified "
183 "http://www.csse.monash.edu.au/~jwb/edrdg/license.htm\n\n"
185 "Jim Rose's extended databases are licensed to Monash University "
186 "with permission to modify and redistribute the files, as long as "
187 "his copyright notices are preserved.\n\n"
189 "The SKIP (System of Kanji Indexing by Patterns) system for "
190 "ordering kanji was developed by Jack Halpern (Kanji Dictionary "
191 "Publishing Society at http://www.kanji.org/), and is used with "
192 "his permission.\n\n"
194 "Copies of the GNU General Public License, Monash University's "
195 "license for the dictionary files and documentation for the "
196 "dictionary files are contained in this program's \"license\" "
200 show_message(self
, _("License Information"), message
)
202 def _layout_window(self
):
203 self
.set_title(configure
.PACKAGE_NAME
)
204 self
.menu
= self
._create
_menu
()
205 children
= self
._create
_children
()
206 layout
= gtk
.VBox(spacing
= 5)
207 layout
.pack_start(self
.menu
, expand
=False)
208 layout
.pack_start(children
)
211 def _create_menu(self
):
212 ag
= gtk
.ActionGroup("jben.ag")
214 [("MenuFile", None, _("_File"), None, None, None),
216 ("MenuFileQuit", gtk
.STOCK_QUIT
, None,
217 None, None, self
.on_menu_file_quit
),
219 ("MenuEdit", None, _("_Edit"),
222 ("MenuEditVocab", None, _("_Vocab Study List"),
223 None, None, self
.on_menu_edit_vocab
),
225 ("MenuEditKanji", None, _("_Kanji Study List"),
226 None, None, self
.on_menu_edit_kanji
),
228 ("MenuEditPrefs", gtk
.STOCK_PREFERENCES
, None,
229 None, None, self
.on_menu_edit_prefs
),
231 ("MenuPractice", None, _("_Practice"), None, None, None),
233 ("MenuPracticeKanji", None, _("_Kanji"),
234 None, None, self
.on_menu_practice_kanji
),
236 ("MenuTools", None, _("_Tools"), None, None, None),
238 ("MenuToolsHand", None, _("_Handwriting Recognition for Kanji"),
239 None, None, self
.on_menu_tools_hand
),
241 ("MenuToolsKanjiSearch", None, _("_Kanji Search"),
242 None, None, self
.on_menu_tools_kanji_search
),
244 ("MenuHelp", None, _("_Help"), None, None, None),
246 ("MenuHelpAbout", gtk
.STOCK_ABOUT
,
247 None, None, None, self
.on_menu_help_about
),
249 ("MenuHelpLicense", None, _("_License Information..."),
250 None, None, self
.on_menu_help_license
)])
252 uim
= gtk
.UIManager()
253 uim
.insert_action_group(ag
, -1)
254 uim
.add_ui_from_string(
256 " <menubar name='MenuBar'>"
257 " <menu action='MenuFile'>"
258 " <menuitem action='MenuFileQuit'/>"
260 " <menu action='MenuEdit'>"
261 " <menuitem action='MenuEditVocab'/>"
262 " <menuitem action='MenuEditKanji'/>"
264 " <menuitem action='MenuEditPrefs'/>"
266 " <menu action='MenuPractice'>"
267 " <menuitem action='MenuPracticeKanji'/>"
269 " <menu action='MenuTools'>"
270 " <menuitem action='MenuToolsHand'/>"
271 " <menuitem action='MenuToolsKanjiSearch'/>"
273 " <menu action='MenuHelp'>"
274 " <menuitem action='MenuHelpAbout'/>"
275 " <menuitem action='MenuHelpLicense'/>"
279 self
.add_accel_group(uim
.get_accel_group())
280 return uim
.get_widget("/MenuBar")
282 def _create_children(self
):
283 tabs
= gtk
.Notebook()
284 self
.worddict
= TabWordDict()
285 self
.kanjidict
= TabKanjiDict()
286 for obj
in (self
.worddict
, self
.kanjidict
):
287 obj
.set_sensitive(False)
288 tabs
.append_page(self
.worddict
, gtk
.Label(_("Word Dictionary")))
289 tabs
.append_page(self
.kanjidict
, gtk
.Label(_("Kanji Dictionary")))