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 dialog
= DialogVocabListEditor(self
)
85 if result
== gtk
.RESPONSE_OK
:
86 # If OK was pressed, update the WordDict GUI's current/max index.
89 def on_menu_edit_kanji(self
, widget
):
90 dialog
= DialogKanjiListEditor(self
)
94 if result
== gtk
.RESPONSE_OK
:
95 # If OK was pressed, update the KanjiDict GUI's current/max index.
98 def on_menu_edit_prefs(self
, widget
):
99 dialog
= DialogPreferences(self
)
100 result
= dialog
.run()
103 if result
== gtk
.RESPONSE_OK
:
104 # If OK was pressed, refresh the UI.
107 def on_menu_practice_kanji(self
, widget
):
108 print "on_menu_practice_kanji"
109 # Show test choice dialog ("pre-test")
111 # * clear dictionary panels (no cheating, at least not that easily!)
112 # * show main test dialog
113 # * show test results dialog ("post-test")
114 show_message(self
, _("Not yet implemented"),
115 _("Sorry, this has not yet been re-implemented."))
117 def on_menu_tools_hand(self
, widget
):
118 # Show kanji handwriting pad... no real reason to make it modal; allow
119 # the user to open multiple ones if they desire.
120 hwpad
= WindowKanjiHWSearch()
122 def on_menu_tools_kanji_search(self
, widget
):
123 print "on_menu_tools_kanji_search"
124 show_message(self
, _("Not yet implemented"),
125 _("Sorry, this has not yet been re-implemented."))
127 def on_menu_help_about(self
, widget
):
128 message_template
= _(
129 "%(package_name)s %(package_version)s\n"
131 "Copyright %(copyright)s\n\n"
132 "Inspired in large by JWPce and JFC by Glenn Rosenthal:\n"
133 "http://www.physics.ucla.edu/~grosenth/\n\n"
135 "Powered by the many Japanese dictionary files from Monash "
136 "University, many thanks to Jim Breen:\n"
137 "http://www.csse.monash.edu.au/~jwb/japanese.html\n"
138 "Thanks also to Jim Rose of kanjicafe.com for his extended "
139 "RADKFILE2/KRADFILE2 databases and derived database files.\n\n"
141 "Built using PyGTK: http://www.pygtk.org/\n\n"
143 "Hand writing recognition is based upon code from im-ja "
144 "(http://im-ja.sourceforge.net/) and KanjiPad "
145 "(http://fishsoup.net/software/kanjipad/). KanjiPad was "
146 "written by Owen Taylor.\n\n"
148 "See \"Help->License Information...\" for important license "
152 "package_name": configure
.PACKAGE_NAME
,
153 "package_version": configure
.PACKAGE_VERSION
,
154 "author": jben_globals
.AUTHOR_NAME
,
155 "copyright": jben_globals
.COPYRIGHT_DATE
,
158 message
= message_template
% args
159 show_message(self
, _("About %s") % configure
.PACKAGE_NAME
, message
)
161 def on_menu_help_license(self
, widget
):
163 "Program distributed under the GNU General Public License (GPL) "
165 "http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt\n\n"
167 "The included dictionary data files, with the exception of the "
168 "handwriting databases and Jim Rose's extensions to the radical "
169 "databases, are distributed under a separate license specified "
171 "http://www.csse.monash.edu.au/~jwb/edrdg/license.htm\n\n"
173 "Jim Rose's extended databases are licensed to Monash University "
174 "with permission to modify and redistribute the files, as long as "
175 "his copyright notices are preserved.\n\n"
177 "The SKIP (System of Kanji Indexing by Patterns) system for "
178 "ordering kanji was developed by Jack Halpern (Kanji Dictionary "
179 "Publishing Society at http://www.kanji.org/), and is used with "
180 "his permission.\n\n"
182 "Copies of the GNU General Public License, Monash University's "
183 "license for the dictionary files and documentation for the "
184 "dictionary files are contained in this program's \"license\" "
188 show_message(self
, _("License Information"), message
)
190 def _layout_window(self
):
191 self
.set_title(configure
.PACKAGE_NAME
)
192 self
.menu
= self
._create
_menu
()
193 children
= self
._create
_children
()
194 layout
= gtk
.VBox(spacing
= 5)
195 layout
.pack_start(self
.menu
, expand
=False)
196 layout
.pack_start(children
)
199 def _create_menu(self
):
200 ag
= gtk
.ActionGroup("jben.ag")
202 [("MenuFile", None, _("_File"), None, None, None),
204 ("MenuFileQuit", gtk
.STOCK_QUIT
, None,
205 None, None, self
.on_menu_file_quit
),
207 ("MenuEdit", None, _("_Edit"),
210 ("MenuEditVocab", None, _("_Vocab Study List"),
211 None, None, self
.on_menu_edit_vocab
),
213 ("MenuEditKanji", None, _("_Kanji Study List"),
214 None, None, self
.on_menu_edit_kanji
),
216 ("MenuEditPrefs", gtk
.STOCK_PREFERENCES
, None,
217 None, None, self
.on_menu_edit_prefs
),
219 ("MenuPractice", None, _("_Practice"), None, None, None),
221 ("MenuPracticeKanji", None, _("_Kanji"),
222 None, None, self
.on_menu_practice_kanji
),
224 ("MenuTools", None, _("_Tools"), None, None, None),
226 ("MenuToolsHand", None, _("_Handwriting Recognition for Kanji"),
227 None, None, self
.on_menu_tools_hand
),
229 ("MenuToolsKanjiSearch", None, _("_Kanji Search"),
230 None, None, self
.on_menu_tools_kanji_search
),
232 ("MenuHelp", None, _("_Help"), None, None, None),
234 ("MenuHelpAbout", gtk
.STOCK_ABOUT
,
235 None, None, None, self
.on_menu_help_about
),
237 ("MenuHelpLicense", None, _("_License Information..."),
238 None, None, self
.on_menu_help_license
)])
240 uim
= gtk
.UIManager()
241 uim
.insert_action_group(ag
, -1)
242 uim
.add_ui_from_string(
244 " <menubar name='MenuBar'>"
245 " <menu action='MenuFile'>"
246 " <menuitem action='MenuFileQuit'/>"
248 " <menu action='MenuEdit'>"
249 " <menuitem action='MenuEditVocab'/>"
250 " <menuitem action='MenuEditKanji'/>"
252 " <menuitem action='MenuEditPrefs'/>"
254 " <menu action='MenuPractice'>"
255 " <menuitem action='MenuPracticeKanji'/>"
257 " <menu action='MenuTools'>"
258 " <menuitem action='MenuToolsHand'/>"
259 " <menuitem action='MenuToolsKanjiSearch'/>"
261 " <menu action='MenuHelp'>"
262 " <menuitem action='MenuHelpAbout'/>"
263 " <menuitem action='MenuHelpLicense'/>"
267 self
.add_accel_group(uim
.get_accel_group())
268 return uim
.get_widget("/MenuBar")
270 def _create_children(self
):
271 tabs
= gtk
.Notebook()
272 self
.worddict
= TabWordDict()
273 self
.kanjidict
= TabKanjiDict()
274 for obj
in (self
.worddict
, self
.kanjidict
):
275 obj
.set_sensitive(False)
276 tabs
.append_page(self
.worddict
, gtk
.Label(_("Word Dictionary")))
277 tabs
.append_page(self
.kanjidict
, gtk
.Label(_("Kanji Dictionary")))