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
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
)
30 self
.connect("show", self
.on_show
)
31 self
.connect("destroy", self
.on_destroy
)
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."))
41 self
.children
.get_nth_page(0).set_sensitive(True)
43 self
.children
.get_nth_page(1).set_sensitive(True)
44 self
.set_sensitive(True)
46 def on_destroy(self
, widget
):
49 def on_menu_file_quit(self
, widget
):
50 if not self
.delete_event(None, None):
53 def on_menu_edit_vocab(self
, widget
):
54 print "on_menu_edit_vocab"
56 dialog
= DialogVocabListEditor(self
)
60 if result
== gtk
.RESPONSE_OK
:
61 print "OK was clicked."
62 # If OK was pressed, update the WordDict GUI's current/max index.
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
)
73 if result
== gtk
.RESPONSE_OK
:
74 print "OK was clicked."
75 # If OK was pressed, update the KanjiDict GUI's current/max index.
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
)
86 if result
== gtk
.RESPONSE_OK
:
87 print "OK was clicked."
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")
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
):
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 "
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
):
144 "Program distributed under the GNU General Public License (GPL) "
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 "
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\" "
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
)
180 def _create_menu(self
):
181 ag
= gtk
.ActionGroup("jben.ag")
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"),
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(
225 " <menubar name='MenuBar'>"
226 " <menu action='MenuFile'>"
227 " <menuitem action='MenuFileQuit'/>"
229 " <menu action='MenuEdit'>"
230 " <menuitem action='MenuEditVocab'/>"
231 " <menuitem action='MenuEditKanji'/>"
233 " <menuitem action='MenuEditPrefs'/>"
235 " <menu action='MenuPractice'>"
236 " <menuitem action='MenuPracticeKanji'/>"
238 " <menu action='MenuTools'>"
239 " <menuitem action='MenuToolsHand'/>"
240 " <menuitem action='MenuToolsKanjiSearch'/>"
242 " <menu action='MenuHelp'>"
243 " <menuitem action='MenuHelpAbout'/>"
244 " <menuitem action='MenuHelpLicense'/>"
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")))