More cleanups in the kanji list editor dialog. Also removed some debug prints.
[jben2_gui.git] / python / jben / interface / gtk / window / main.py
blobd40b37b00ae54c7c54450586e39484f0d2ccf9ea
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
4 # Project: J-Ben, Python front-end
5 # File: window_kanjihwsearch.py
6 # Author: Paul Goins
7 # Created on: 25 Nov 2008
9 from __future__ import absolute_import
11 import gtk
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)
32 self.app = app
33 self.connect("show", self.on_show)
34 self.connect("destroy", self.on_destroy)
35 self._layout_window()
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.
41 downloaded = False
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?"),
46 default_button="yes")
47 if do_download:
48 # Code is a little unclear here...
49 mirror = DictMirrorSelect(self.app, self).run()
50 if mirror != None:
51 files = dictmgr.get_needed_dict_names()
52 DictDownload(self.app, self, mirror, files).run()
53 downloaded = True
54 # Post-DL...
55 dictmgr.find_databases() # try to reload DBs
56 if not dictmgr.all_dicts_found():
57 show_message(
58 self, _("Could not download all dictionaries"),
59 _("Could not download all needed files. "
60 "Some features may be disabled."))
61 else:
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):
74 gtk.main_quit()
76 def on_menu_file_quit(self, widget):
77 if not self.delete_event(None, None):
78 self.destroy()
80 def on_menu_edit_vocab(self, widget):
81 dialog = DialogVocabListEditor(self)
82 result = dialog.run()
83 dialog.destroy()
85 if result == gtk.RESPONSE_OK:
86 # If OK was pressed, update the WordDict GUI's current/max index.
87 pass
89 def on_menu_edit_kanji(self, widget):
90 dialog = DialogKanjiListEditor(self)
91 result = dialog.run()
92 dialog.destroy()
94 if result == gtk.RESPONSE_OK:
95 # If OK was pressed, update the KanjiDict GUI's current/max index.
96 pass
98 def on_menu_edit_prefs(self, widget):
99 dialog = DialogPreferences(self)
100 result = dialog.run()
101 dialog.destroy()
103 if result == gtk.RESPONSE_OK:
104 # If OK was pressed, refresh the UI.
105 pass
107 def on_menu_practice_kanji(self, widget):
108 print "on_menu_practice_kanji"
109 # Show test choice dialog ("pre-test")
110 # If "OK",
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"
130 "By %(author)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 "
149 "details."
151 args = {
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):
162 message = _(
163 "Program distributed under the GNU General Public License (GPL) "
164 "version 2:\n"
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 "
170 "at\n"
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\" "
185 "directory."
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)
197 self.add(layout)
199 def _create_menu(self):
200 ag = gtk.ActionGroup("jben.ag")
201 ag.add_actions(
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"),
208 None, None, None),
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(
243 "<ui>"
244 " <menubar name='MenuBar'>"
245 " <menu action='MenuFile'>"
246 " <menuitem action='MenuFileQuit'/>"
247 " </menu>"
248 " <menu action='MenuEdit'>"
249 " <menuitem action='MenuEditVocab'/>"
250 " <menuitem action='MenuEditKanji'/>"
251 " <separator/>"
252 " <menuitem action='MenuEditPrefs'/>"
253 " </menu>"
254 " <menu action='MenuPractice'>"
255 " <menuitem action='MenuPracticeKanji'/>"
256 " </menu>"
257 " <menu action='MenuTools'>"
258 " <menuitem action='MenuToolsHand'/>"
259 " <menuitem action='MenuToolsKanjiSearch'/>"
260 " </menu>"
261 " <menu action='MenuHelp'>"
262 " <menuitem action='MenuHelpAbout'/>"
263 " <menuitem action='MenuHelpLicense'/>"
264 " </menu>"
265 " </menubar>"
266 "</ui>")
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")))
278 return tabs