Code reorg in interface.gtk.window.main
[jben2_gui.git] / jben / jben / interface / gtk / window / main.py
blobdd5d0d5caa8c24e5f3a1c9036b3e2cdcde364f8f
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
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 ..dialog.vocablisteditor import DialogVocabListEditor
20 from ..dialog.kanjilisteditor import DialogKanjiListEditor
21 from ..dialog.preferences import DialogPreferences
24 class Main(StoredSizeWindow):
25 """The main GUI of J-Ben."""
27 def __init__(self, app, param="gui.main.size"):
28 StoredSizeWindow.__init__(self, param, 600, 400, gtk.WINDOW_TOPLEVEL)
29 self.app = app
30 self.connect("show", self.on_show)
31 self.connect("destroy", self.on_destroy)
32 self._layout_window()
34 def on_show(self, widget):
35 wdict_avail, kdict_avail = self.app.dictmgr.check_dicts()
36 if not all((wdict_avail, kdict_avail)):
37 show_message(self, _("Dictionaries not found"),
38 _("Could not find some needed dictionary files. "
39 "The relevant tabs will be disabled."))
40 if wdict_avail:
41 self.children.get_nth_page(0).set_sensitive(True)
42 if kdict_avail:
43 self.children.get_nth_page(1).set_sensitive(True)
44 self.set_sensitive(True)
46 def on_destroy(self, widget):
47 gtk.main_quit()
49 def on_menu_file_quit(self, widget):
50 if not self.delete_event(None, None):
51 self.destroy(None)
53 def on_menu_edit_vocab(self, widget):
54 print "on_menu_edit_vocab"
56 dialog = DialogVocabListEditor(self)
57 result = dialog.run()
58 dialog.destroy()
60 if result == gtk.RESPONSE_OK:
61 print "OK was clicked."
62 # If OK was pressed, update the WordDict GUI's current/max index.
63 else:
64 print "Cancel was clicked; dialog input discarded."
66 def on_menu_edit_kanji(self, widget):
67 print "on_menu_edit_kanji"
69 dialog = DialogKanjiListEditor(self)
70 result = dialog.run()
71 dialog.destroy()
73 if result == gtk.RESPONSE_OK:
74 print "OK was clicked."
75 # If OK was pressed, update the KanjiDict GUI's current/max index.
76 else:
77 print "Cancel was clicked; dialog input discarded."
79 def on_menu_edit_prefs(self, widget):
80 print "on_menu_edit_prefs"
82 dialog = DialogPreferences(self)
83 result = dialog.run()
84 dialog.destroy()
86 if result == gtk.RESPONSE_OK:
87 print "OK was clicked."
88 else:
89 print "Cancel was clicked; dialog input discarded."
91 def on_menu_practice_kanji(self, widget):
92 print "on_menu_practice_kanji"
93 # Show test choice dialog ("pre-test")
94 # If "OK",
95 # * clear dictionary panels (no cheating, at least not that easily!)
96 # * show main test dialog
97 # * show test results dialog ("post-test")
98 show_message(self, _("Not yet implemented"),
99 _("Sorry, this has not yet been re-implemented."))
101 def on_menu_tools_hand(self, widget):
102 print "on_menu_tools_hand"
103 # Show kanji handwriting pad... no real reason to make it modal; allow
104 # the user to open multiple ones if they desire.
105 hwpad = WindowKanjiHWSearch()
107 def on_menu_tools_kanji_search(self, widget):
108 print "on_menu_tools_kanji_search"
109 show_message(self, _("Not yet implemented"),
110 _("Sorry, this has not yet been re-implemented."))
112 def on_menu_help_about(self, widget):
113 message = _(
114 "%s %s\n"
115 "By %s\n"
116 "Copyright %s\n\n"
117 "Inspired in large by JWPce and JFC by Glenn Rosenthal:\n"
118 "http://www.physics.ucla.edu/~grosenth/\n\n"
120 "Powered by the many Japanese dictionary files from Monash "
121 "University, many thanks to Jim Breen:\n"
122 "http://www.csse.monash.edu.au/~jwb/japanese.html\n"
123 "Thanks also to Jim Rose of kanjicafe.com for his extended "
124 "RADKFILE2/KRADFILE2 databases and derived database files.\n\n"
126 "Built using PyGTK: http://www.pygtk.org/\n\n"
128 "Hand writing recognition is based upon code from im-ja "
129 "(http://im-ja.sourceforge.net/) and KanjiPad "
130 "(http://fishsoup.net/software/kanjipad/). KanjiPad was "
131 "written by Owen Taylor.\n\n"
133 "See \"Help->License Information...\" for important license "
134 "details."
135 ) % (jben_globals.PROGRAM_NAME,
136 jben_globals.VERSION_STR,
137 jben_globals.AUTHOR_NAME,
138 jben_globals.COPYRIGHT_DATE)
140 show_message(self, _("About %s") % jben_globals.PROGRAM_NAME, message)
142 def on_menu_help_license(self, widget):
143 message = _(
144 "Program distributed under the GNU General Public License (GPL) "
145 "version 2:\n"
146 "http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt\n\n"
148 "The included dictionary data files, with the exception of the "
149 "handwriting databases and Jim Rose's extensions to the radical "
150 "databases, are distributed under a separate license specified "
151 "at\n"
152 "http://www.csse.monash.edu.au/~jwb/edrdg/license.htm\n\n"
154 "Jim Rose's extended databases are licensed to Monash University "
155 "with permission to modify and redistribute the files, as long as "
156 "his copyright notices are preserved.\n\n"
158 "The SKIP (System of Kanji Indexing by Patterns) system for "
159 "ordering kanji was developed by Jack Halpern (Kanji Dictionary "
160 "Publishing Society at http://www.kanji.org/), and is used with "
161 "his permission.\n\n"
163 "Copies of the GNU General Public License, Monash University's "
164 "license for the dictionary files and documentation for the "
165 "dictionary files are contained in this program's \"license\" "
166 "directory."
169 show_message(self, _("License Information"), message)
171 def _layout_window(self)
172 self.set_title(jben_globals.PROGRAM_NAME)
173 self.menu = self._create_menu()
174 self.children = self._create_children()
175 layout = gtk.VBox(spacing = 5)
176 layout.pack_start(self.menu, expand = False)
177 layout.pack_start(self.children)
178 self.add(layout)
180 def _create_menu(self):
181 ag = gtk.ActionGroup("jben.ag")
182 ag.add_actions(
183 [("MenuFile", None, _("_File"), None, None, None),
185 ("MenuFileQuit", gtk.STOCK_QUIT, None,
186 None, None, self.on_menu_file_quit),
188 ("MenuEdit", None, _("_Edit"),
189 None, None, None),
191 ("MenuEditVocab", None, _("_Vocab Study List"),
192 None, None, self.on_menu_edit_vocab),
194 ("MenuEditKanji", None, _("_Kanji Study List"),
195 None, None, self.on_menu_edit_kanji),
197 ("MenuEditPrefs", gtk.STOCK_PREFERENCES, None,
198 None, None, self.on_menu_edit_prefs),
200 ("MenuPractice", None, _("_Practice"), None, None, None),
202 ("MenuPracticeKanji", None, _("_Kanji"),
203 None, None, self.on_menu_practice_kanji),
205 ("MenuTools", None, _("_Tools"), None, None, None),
207 ("MenuToolsHand", None, _("_Handwriting Recognition for Kanji"),
208 None, None, self.on_menu_tools_hand),
210 ("MenuToolsKanjiSearch", None, _("_Kanji Search"),
211 None, None, self.on_menu_tools_kanji_search),
213 ("MenuHelp", None, _("_Help"), None, None, None),
215 ("MenuHelpAbout", gtk.STOCK_ABOUT,
216 None, None, None, self.on_menu_help_about),
218 ("MenuHelpLicense", None, _("_License Information..."),
219 None, None, self.on_menu_help_license)])
221 uim = gtk.UIManager()
222 uim.insert_action_group(ag, -1)
223 uim.add_ui_from_string(
224 "<ui>"
225 " <menubar name='MenuBar'>"
226 " <menu action='MenuFile'>"
227 " <menuitem action='MenuFileQuit'/>"
228 " </menu>"
229 " <menu action='MenuEdit'>"
230 " <menuitem action='MenuEditVocab'/>"
231 " <menuitem action='MenuEditKanji'/>"
232 " <separator/>"
233 " <menuitem action='MenuEditPrefs'/>"
234 " </menu>"
235 " <menu action='MenuPractice'>"
236 " <menuitem action='MenuPracticeKanji'/>"
237 " </menu>"
238 " <menu action='MenuTools'>"
239 " <menuitem action='MenuToolsHand'/>"
240 " <menuitem action='MenuToolsKanjiSearch'/>"
241 " </menu>"
242 " <menu action='MenuHelp'>"
243 " <menuitem action='MenuHelpAbout'/>"
244 " <menuitem action='MenuHelpLicense'/>"
245 " </menu>"
246 " </menubar>"
247 "</ui>")
248 self.add_accel_group(uim.get_accel_group())
249 return uim.get_widget("/MenuBar")
251 def _create_children(self):
252 tabs = gtk.Notebook()
253 worddict = TabWordDict()
254 kanjidict = TabKanjiDict()
255 for obj in (worddict, kanjidict):
256 obj.set_sensitive(False)
257 tabs.append_page(worddict, gtk.Label(_("Word Dictionary")))
258 tabs.append_page(kanjidict, gtk.Label(_("Kanji Dictionary")))
259 return tabs