-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainframe.py
1154 lines (861 loc) · 33.1 KB
/
mainframe.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import sys
import os
from util.debug import dprint, MESSAGE, ERROR, WARNING, is_debugging
import wx
from wx import xrc
dprint(MESSAGE, "importing sword")
from swlib import pysw
from swlib.pysw import SW
dprint(MESSAGE, "/importing sword")
dprint(MESSAGE, "Other imports")
from backend.bibleinterface import biblemgr
from backend import filterutils
dprint(MESSAGE, "Importing frames")
from bibleframe import BibleFrame, bible_settings
from bookframe import BookFrame
from bookframe import CommentaryFrame
from bookframe import DictionaryFrame
from displayframe import IN_MENU, DisplayFrameManager
from genbookframe import GenBookFrame, HarmonyFrame
from auilayer import AuiLayer
from util.observerlist import ObserverList
from util import osutils
import versetree
import copyverses
import config
import guiconfig
from module_tree import ModuleTree
from pathmanager import PathManager
from module_manager import ModuleManagerDialog
dprint(MESSAGE, "Importing gui")
from gui import guiutil
from gui import fonts
from gui.guiutil import bmp
from gui.menu import Separator
from search.searchpanel import (BibleSearchPanel, GenbookSearchPanel,
HarmonySearchPanel, DailyDevotionalSearchPanel,
DictionarySearchPanel, CommentarySearchPanel)
from fontchoice import FontChoiceDialog
from versecompare import VerseCompareFrame
from htmlide import HtmlIde
import events
from events import BibleEvent
from history import History, HistoryTree
from util.configmgr import config_manager
from install_manager.install_drop_target import ModuleDropTarget
import passage_list
from error_handling import ErrorDialog
from util.i18n import N_
import util.i18n
from preview_window import PreviewWindow
import display_options
settings = config_manager.add_section("BPBible")
settings.add_item("layout", {}, item_type="pickle")
settings.add_item("bibleref", "Genesis 1:1")
settings.add_item("bible", "ESV")
settings.add_item("dictionary", "ISBE")
settings.add_item("dictref", "")
settings.add_item("commentary", "TSK")
settings.add_item("genbook", "Josephus")
settings.add_item("harmony", "CompositeGospel")
settings.add_item("daily_devotional", "Daily")
settings.add_item("zoom_level", 0)
settings.add_item("copy_verse", "Default",
item_type="pickle")
settings.add_item("options", None, item_type="pickle")
settings.add_item("size", None, item_type="pickle")
settings.add_item("maximized", False, item_type=bool)
settings.add_item("last_book_directory", "", item_type=str)
dprint(MESSAGE, "/Other imports")
XRC_DIRECTORY = 'xrc'
class MainFrame(wx.Frame, AuiLayer):
"""MainFrame: The main frame containing everything."""
def __init__(self, parent):
super(MainFrame, self).__init__(self, parent, -1, config.name(),
wx.DefaultPosition, size=(1024, 768))
self.setup()
def setup(self):
self.on_close = ObserverList()
dprint(MESSAGE, "Setting up")
# Use the standard BPBible title to prevent the title from changing
# from "Bible" to "<Reference> - BPBible".
self.SetTitle(config.name())
# use this dialog to catch all our errors
self.error_dialog = ErrorDialog(self)
self.error_dialog.install()
self.on_close += self.error_dialog.uninstall
guiconfig.mainfrm = self
self.toplevels = []
self.currentverse = ""
self.zoomlevel = 0
self.bible_observers = ObserverList()
self.bible_observers += self.set_title
self.add_observer_removed_on_close(biblemgr.bible.observers, self.bible_version_changed)
self.add_observer_removed_on_close(biblemgr.commentary.observers, self.commentary_version_changed)
self.add_observer_removed_on_close(biblemgr.on_after_reload, self.on_modules_reloaded)
self.lost_focus = False
self.history = History()
self.bible_observers += self.add_history_item
self.load_data()
# issue 142 - devenagari text shows up too small in windows 7,
# increase the base window font size.
if osutils.is_win7() and pysw.locale_lang in ('ne', 'hi'):
self.SetFont(wx.Font(11, wx.SWISS, wx.NORMAL, wx.NORMAL, False, fonts.default_fonts()[1][0]))
self.make_toolbars()
self.create_searchers()
dprint(MESSAGE, "Setting AUI up")
self.create_aui_items()
super(MainFrame, self).setup()
self.set_aui_items_up()
dprint(MESSAGE, "Binding events")
self.bind_events()
dprint(MESSAGE, "Setting up frames")
self.setup_frames()
self.bibleref.SetFocus()
for display_frame in (self.bibletext, self.commentarytext, self.dictionarytext, self.genbooktext, self.harmony_frame, self.daily_devotional_frame):
self.add_observer_removed_on_close(
display_options.display_option_changed_observers,
display_frame.change_display_option
)
self.add_observer_removed_on_close(
fonts.fonts_changed,
display_frame.fonts_changed
)
self.add_observer_removed_on_close(fonts.fonts_changed, self.verse_compare.fonts_changed)
dprint(MESSAGE, "Setting menus up")
self.set_menus_up()
wx.CallAfter(dprint, MESSAGE, "Constructed")
dprint(MESSAGE, "Done first round of setting up")
self.drop_target = ModuleDropTarget(self)
self.SetDropTarget(self.drop_target)
wx.CallAfter(self.Show)
wx.CallAfter(self.bibletext.SetFocus)
if guiconfig.app.splash:
wx.CallAfter(guiconfig.app.splash.Destroy)
def make_toolbars(self):
dprint(MESSAGE, "Making toolbars")
toolbar_style = wx.TB_FLAT|wx.TB_NODIVIDER|wx.TB_HORZ_TEXT
if not guiconfig.use_one_toolbar:
toolbars = [
wx.ToolBar(self, wx.ID_ANY, style=toolbar_style)
for i in range(3)
]
else:
tb = self.CreateToolBar(wx.TB_TEXT|wx.TB_FLAT)
toolbars = tb, tb, tb
(self.main_toolbar, self.zoom_toolbar,
self.history_toolbar) = toolbars
for toolbar in toolbars:
toolbar.SetToolBitmapSize((16, 16))
if not guiconfig.use_versetree:
self.bibleref = wx.ComboBox(self.main_toolbar,
# TODO: add to this list
choices=["Genesis 1:1"],
style=wx.TE_PROCESS_ENTER)
else:
self.bibleref = versetree.VerseTree(self.main_toolbar)
self.bible_observers += self.bibleref.set_current_verse
self.bibleref.SetSize((140, -1))
self.main_toolbar.AddControl(self.bibleref)
self.tool_go = self.main_toolbar.AddLabelTool(wx.ID_ANY,
_("Go to verse"), bmp("accept.png"),
shortHelp=_("Go to this verse"))
self.tool_search = self.main_toolbar.AddLabelTool(wx.ID_ANY,
_("Search"), bmp("find.png"),
shortHelp=_("Search in the current book"))
self.tool_copy_verses = self.main_toolbar.AddLabelTool(wx.ID_ANY,
_("Copy Verses"), bmp("page_copy.png"),
shortHelp=_("Open the Copy Verses dialog"))
if guiconfig.use_one_toolbar: self.ToolBar.AddSeparator()
self.tool_back = self.history_toolbar.AddLabelTool(wx.ID_ANY,
_("Back"), bmp("go-previous.png"),
shortHelp=_("Go back a verse"))
self.tool_forward = self.history_toolbar.AddLabelTool(wx.ID_ANY,
_("Forward"), bmp("go-next.png"),
shortHelp=_("Go forward a verse"))
if guiconfig.use_one_toolbar: self.ToolBar.AddSeparator()
self.tool_zoom_in = self.zoom_toolbar.AddLabelTool(wx.ID_ANY,
_("Zoom In"), bmp("magnifier_zoom_in.png"),
shortHelp=_("Make text bigger"))
self.tool_zoom_default = self.zoom_toolbar.AddLabelTool(wx.ID_ANY,
_("Default Zoom"), bmp("magnifier.png"),
shortHelp=_("Return text to default size"))
self.tool_zoom_out = self.zoom_toolbar.AddLabelTool(wx.ID_ANY,
_("Zoom Out"), bmp("magifier_zoom_out.png"),
shortHelp=_("Make text smaller"))
for toolbar in toolbars:
toolbar.Realize()
if osutils.is_win2000():
# this is what the minimum size should be
# however, adding controls to toolbars breaks their length :(
best_size = (
self.main_toolbar.BestSize[0] + self.bibleref.Size[0] +
self.main_toolbar.Margins[0],
-1#self.main_toolbar.BestSize[1]
)
else:
best_size = self.main_toolbar.BestSize
for toolbar in toolbars:
toolbar.Bind(wx.EVT_CONTEXT_MENU, self.show_toolbar_popup)
toolbar.Bind(wx.EVT_RIGHT_UP, self.show_toolbar_popup)
self.Bind(wx.EVT_CONTEXT_MENU, self.show_toolbar_popup)
self.Bind(wx.EVT_RIGHT_UP, self.show_toolbar_popup)
self.toolbars = ([self.main_toolbar, N_("Navigation"),
("BestSize", best_size)],
[self.zoom_toolbar, N_("Zoom"),
["Hide"]],
[self.history_toolbar, N_("History toolbar"),
["Row", 0]])
def load_data(self):
dprint(MESSAGE, "Loading data")
if settings["options"]:
for item, value in settings["options"].iteritems():
biblemgr.set_option(item, value)
for option_name, sword_option_name in display_options.sword_options_map.iteritems():
biblemgr.set_option(sword_option_name, display_options.options[option_name])
for option_name, value in display_options.sword_options_with_fixed_values.iteritems():
biblemgr.set_option(option_name, value)
if settings["size"]:
self.SetSize(settings["size"])
if settings["maximized"]:
self.Maximize(True)
filterutils.set_headwords_module_from_conf(biblemgr)
def set_mod(book, mod_name):
if book.ModuleExists(mod_name):
book.SetModule(mod_name, notify=False)
set_mod(biblemgr.bible, settings["bible"])
set_mod(biblemgr.dictionary, settings["dictionary"])
set_mod(biblemgr.commentary, settings["commentary"])
set_mod(biblemgr.genbook, settings["genbook"])
set_mod(biblemgr.harmony, settings["harmony"])
set_mod(biblemgr.daily_devotional, settings["daily_devotional"])
def capture_size(self, set_back=True):
"""Capture the real size, not including maximization or minimization
of the window.
This will cause the screen to flash if minimized/maximized"""
i = self.IsIconized()
if i:
self.Iconize(False)
w = self.IsMaximized()
if w:
self.Maximize(False)
size = self.Size
if set_back:
if w:
self.Maximize(w)
if i:
self.Iconize(i)
return w, size
def save_data(self):
settings["layout"][util.i18n.langid] = self.save_layout()
current_reference, _ref_to_scroll_to = self.bibletext.GetCurrentReferenceAndPosition()
settings["bibleref"] = current_reference or self.currentverse
settings["bible"] = biblemgr.bible.version
settings["commentary"] = biblemgr.commentary.version
settings["genbook"] = biblemgr.genbook.version
settings["dictionary"] = biblemgr.dictionary.version
settings["harmony"] = biblemgr.harmony.version
settings["daily_devotional"] = biblemgr.daily_devotional.version
settings["options"] = biblemgr.save_state()
settings["maximized"], settings["size"] = \
self.capture_size(set_back=False)
try:
config_manager.save()
except (OSError, EnvironmentError), e:
wx.MessageBox("OSError on saving settings\n%s" % str(e))
except Exception, e:
wx.MessageBox("Error on saving settings\n%s" % str(e))
def copy(self, text):
if wx.TheClipboard.Open():
if osutils.is_gtk():
wx.TheClipboard.UsePrimarySelection(False)
tdo = wx.TextDataObject()
tdo.SetText(text)
wx.TheClipboard.SetData(tdo)
wx.TheClipboard.Close()
else:
dprint(ERROR, "Could not open the clipboard")
def create_searchers(self):
self.search_panel = BibleSearchPanel(self)
self.genbook_search_panel = GenbookSearchPanel(self)
#self.harmony_search_panel = HarmonySearchPanel(self)
self.dictionary_search_panel = DictionarySearchPanel(self)
self.daily_devotional_search_panel = DailyDevotionalSearchPanel(self)
self.commentary_search_panel = CommentarySearchPanel(self)
def make_closure(item):
def version_changed(version=None):
wx.CallAfter(item.set_version, item.book.version)
def callback(toggle):
wx.CallAfter(item.on_show, toggle)
def remove_observer():
item.book.observers.remove(version_changed)
return version_changed, callback, remove_observer
self.searchers = (
self.search_panel,
self.genbook_search_panel,
self.dictionary_search_panel,
self.commentary_search_panel,
#self.harmony_search_panel,
self.daily_devotional_search_panel,
)
self.aui_callbacks = {}
for item in self.searchers:
version_changed, callback, remove_observer = make_closure(item)
self.aui_callbacks[item.id] = callback
item.book.observers += version_changed
self.on_close += remove_observer
version_changed()
self.bible_observers += self.search_panel.versepreview.RefreshUI
def add_observer_removed_on_close(self, observerlist, callback):
observerlist.add_observer(callback)
self.on_close += lambda: observerlist.remove(callback)
def create_aui_items(self):
self.version_tree = ModuleTree(self)
self.version_tree.on_module_choice += self.set_module_from_module_choice
self.preview_window = PreviewWindow(self)
self.genbooktext = GenBookFrame(self, biblemgr.genbook)
self.harmony_frame = HarmonyFrame(self)
self.bibletext = BibleFrame(self)
self.bibletext.SetBook(biblemgr.bible)
# set a watch on the bibletext to update the reference in text box
# every time new page is loaded
self.bibletext.observers += self.set_bible_ref
self.commentarytext = CommentaryFrame(self, biblemgr.commentary)
self.dictionarytext = DictionaryFrame(self, biblemgr.dictionary)
self.daily_devotional_frame = DictionaryFrame(self,
biblemgr.daily_devotional)
self.daily_devotional_frame.id = "Daily Devotional"
self.daily_devotional_frame.has_menu = False
self.verse_compare = VerseCompareFrame(self, biblemgr.bible)
self.history_pane = wx.Panel(self)
self.history_tree = HistoryTree(self.history_pane, self.history)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.history_tree, 1, wx.GROW)
self.history_pane.SetSizer(sizer)
def set_module_from_module_choice(self, mod):
book = biblemgr.get_module_book_wrapper(mod.Name())
self.set_module(book.mod, book)
def set_module(self, module, book):
# if the pane is not shown, show it
for frame in self.frames:
if hasattr(frame, "book") and frame.book == book:
pane = self.get_pane_for_frame(frame)
if not pane.IsShown():
self.show_panel(pane.name)
break
# set the module afterwards so that the pane size will be correctly
# set
book.SetModule(module)
def on_copy_button(self, event=None):
text = self.bibletext.get_quick_selected()
cvd = copyverses.CopyVerseDialog(self)
cvd.ShowDialog(text)
def bind_events(self):
#self.Bind(wx.EVT_KILL_FOCUS, self.OffFocus)
#self.Bind(wx.EVT_SET_FOCUS, self.OnFocus)
self.Bind(wx.EVT_CLOSE, self.MainFrameClose)
self.Bind(wx.EVT_MENU, self.on_path_manager,
id = xrc.XRCID('pathmanager'))
self.Bind(wx.EVT_MENU, self.on_install_module,
id=xrc.XRCID('installmodule'))
self.Bind(wx.EVT_MENU, self.on_manage_books,
id=xrc.XRCID('manage_books'))
self.Bind(wx.EVT_MENU, self.load_default_perspective,
id=xrc.XRCID('menu_default_layout'))
self.Bind(wx.EVT_MENU, self.on_font_choice,
id=xrc.XRCID('fontchoice'))
self.Bind(wx.EVT_MENU, self.on_html_ide,
id=xrc.XRCID('gui_html_ide'))
self.Bind(wx.EVT_MENU, self.on_widget_inspector,
id=xrc.XRCID('gui_widget_inspector'))
self.Bind(wx.EVT_MENU, self.on_error_console,
id=xrc.XRCID('gui_error_console'))
self.locales_menu_lookup = {}
for item in "gather diff compile confirm".split():
id = xrc.XRCID('gui_locale_%s' % item)
self.Bind(wx.EVT_MENU, self.on_locale_menu,
id=id)
self.locales_menu_lookup[id] = item
self.Bind(wx.EVT_MENU, self.on_locale_restart,
id=xrc.XRCID('gui_locale_restart'))
self.Bind(wx.EVT_MENU, self.on_reload,
id=xrc.XRCID('gui_reload'))
self.Bind(wx.EVT_MENU, self.on_reload_chrome,
id=xrc.XRCID('gui_reload_chrome'))
self.Bind(wx.EVT_MENU, id = wx.ID_EXIT, handler = self.ExitClick)
self.Bind(wx.EVT_MENU, id = wx.ID_ABOUT, handler = self.AboutClick)
web_links = dict(
gui_website="http://bpbible.com",
gui_documentation="http://code.google.com/p/bpbible/w/list?q=label:user-documentation&sort=pagename",
gui_issues="http://code.google.com/p/bpbible/issues/list",
gui_books="http://code.google.com/p/bpbible/wiki/InstallingBooks",
)
def weblink_handler(weblink):
def handle_event(event):
guiutil.open_web_browser(weblink)
return handle_event
for xrcid, website in web_links.items():
self.Bind(wx.EVT_MENU, weblink_handler(website),
id=xrc.XRCID(xrcid))
self.bibleref.Bind(wx.EVT_TEXT_ENTER, self.BibleRefEnter)
# if it is selected in the drop down tree, go straight there
# use callafter so that our text in the control isn't changed straight
# back
if guiconfig.use_versetree:
self.bibleref.on_selected_in_tree += lambda text: \
wx.CallAfter(self.set_bible_ref, text,
userInput=True, source=events.VERSE_TREE)
else:
self.bibleref.Bind(wx.EVT_COMBOBOX, self.BibleRefEnter)
self.Bind(wx.EVT_TOOL, self.on_copy_button,
self.tool_copy_verses)
self.Bind(wx.EVT_TOOL, self.BibleRefEnter, self.tool_go)
self.Bind(wx.EVT_TOOL, self.do_search, self.tool_search)
self.Bind(wx.EVT_TOOL, lambda x:DisplayFrameManager.zoom(1),
self.tool_zoom_in)
self.Bind(wx.EVT_TOOL, lambda x:DisplayFrameManager.zoom(-1),
self.tool_zoom_out)
self.Bind(wx.EVT_TOOL, lambda x:DisplayFrameManager.reset_zoom_level(),
self.tool_zoom_default)
self.Bind(wx.EVT_TOOL, lambda x:self.move_history(-1),
self.tool_back)
#self.Bind(wx.EVT_TOOL, lambda x:self.show_history(),
# self.tool_history)
self.Bind(wx.EVT_TOOL, lambda x:self.move_history(1),
self.tool_forward)
self.Bind(wx.EVT_UPDATE_UI,
lambda event:event.Enable(self.history.can_back()),
self.tool_back)
self.Bind(wx.EVT_UPDATE_UI,
lambda event:event.Enable(self.history.can_forward()),
self.tool_forward)
if osutils.is_msw():
# if we try binding to this under gtk, other key up events
# propagate up, so we get them where we shouldn't
self.Bind(wx.EVT_KEY_UP, self.on_char)
self.Bind(wx.EVT_ACTIVATE, self.on_activate)
super(MainFrame, self).bind_events()
def show_history(self):
self.show_panel("History")
def on_locale_menu(self, event):
from locales.doi18n import main
text = self.locales_menu_lookup[event.Id]
main([text])
def on_locale_restart(self, event):
import gettext
# kill gettext's cache
gettext._translations.clear()
self.restart()
def on_reload_chrome(self, event):
print "Reloading all"
guiconfig.app.reload_restarting = True
guiconfig.app.restarting = True
self.MainFrameClose(None)
def on_reload(self, event):
import reload_util
reload(reload_util)
reload_util.reboot_section("filtering")
reload_util.reboot_section("copying")
def add_history_item(self, event):
if event.source != events.HISTORY:
self.history.new_location(event.ref)
def move_history(self, direction):
history_item = self.history.go(direction)
self.set_bible_ref(history_item.ref, ref_to_scroll_to=history_item.ref_to_scroll_to, source=events.HISTORY)
def on_html_ide(self, event):
ide = HtmlIde(self)
ide.Show()
def on_widget_inspector(self, event):
wx.GetApp().ShowInspectionTool()
def on_error_console(self, event):
self.bibletext.show_error_console()
def on_path_manager(self, event):
PathManager(self).ShowModal()
def on_manage_books(self, event):
ModuleManagerDialog(self).ShowModal()
def on_install_module(self, event):
fd = wx.FileDialog(self,
wildcard=_("Installable books") + " (*.zip)|*.zip",
style=wx.FD_DEFAULT_STYLE|wx.FD_MULTIPLE|wx.FD_MULTIPLE|wx.FD_OPEN,
defaultDir=settings["last_book_directory"],
message=_("Choose books")
)
if fd.ShowModal() == wx.ID_OK:
self.drop_target.handle_dropped_files(fd.Paths, self)
settings["last_book_directory"] = fd.GetDirectory()
fd.Destroy()
def on_modules_reloaded(self, biblemgr):
# as this will have refreshed the manager, refresh everything
self.version_tree.recreate()
self.fill_options_menu()
self.refresh_all_pages()
def on_font_choice(self, event):
dialog = FontChoiceDialog(self)
ansa = dialog.ShowModal()
dialog.Destroy()
if ansa == wx.ID_OK:
fonts.fonts_changed()
def get_menu(self, label):
for idx, (menu, menu_name) in enumerate(self.MenuBar.Menus):
if self.MenuBar.GetMenuLabel(idx) == label:
break
else:
menu = None
return menu
def on_bookname_language_choice(self, event):
print self.language_bookname_mapping[event.Id]
util.i18n.locale_settings["language_book_names"][util.i18n.langid] = self.language_bookname_mapping[event.Id]
self.restart()
def on_language_choice(self, event):
util.i18n.locale_settings["language"] = self.language_mapping[event.Id]
self.restart()
def fill_language_menu(self, menu, data, current, func, mapping):
for text, display_name in sorted(data, key=lambda (t, d): d):
result = util.i18n.get_locale(text)
if result:
worked, own_locale, own_encoding = result
own_key = display_name.encode(own_encoding)
own_trans = own_locale.translate(own_key)
own_trans = own_trans.decode(own_encoding)
else:
own_trans = None
key = display_name.encode(pysw.locale_encoding)
trans = pysw.locale.translate(key)
trans = trans.decode(pysw.locale_encoding)
if trans != own_trans and own_trans:
trans += " - %s" % own_trans
menu_item = menu.AppendRadioItem(wx.ID_ANY, trans)
menu_item.Check(text == current)
mapping[menu_item.Id] = text
self.Bind(wx.EVT_MENU, func, menu_item)
def set_menus_up(self):
self.file_menu = self.MenuBar.GetMenu(0)
for item in self.file_menu.MenuItems:
if item.ItemLabel == _("&Language"):
language_menu = item.SubMenu
for iitem in language_menu.MenuItems:
if iitem.ItemLabel == _("&Bible book names"):
bible_book_name_menu = iitem.SubMenu
break
else:
assert False, "Bible book name menu could not be found"
break
else:
assert False, "Language menu could not be found"
self.language_mapping = {}
self.fill_language_menu(language_menu,
[(text, display_name) for text, (display_name, x, y, z)
in util.i18n.languages.items()],
util.i18n.locale_settings["language"],
self.on_language_choice, self.language_mapping)
self.language_bookname_mapping = {}
self.fill_language_menu(bible_book_name_menu,
[(text, display_name) for text, (display_name, x, y)
in util.i18n.get_bookname_languages()],
util.i18n.locale_settings["language_book_names"].get(
util.i18n.locale_settings["language"],
util.i18n.locale_settings["language"]
),
self.on_bookname_language_choice, self.language_bookname_mapping)
#self.edit_menu
self.options_menu = self.get_menu(_("&Display"))
assert self.options_menu, "Display menu could not be found"
self.fill_options_menu()
self.windows_menu = self.get_menu(_("&Windows"))
assert self.windows_menu, "Window menu could not be found"
mi = list(self.windows_menu.MenuItems)
for idx, item in enumerate(mi):
if item.Label == _("Toolbars"):
self.toolbar_menu = item.SubMenu
if guiconfig.use_one_toolbar:
self.windows_menu.DeleteItem(item)
#self.windows_menu.RemoveItem(mi[idx])
break
else:
assert False, "Toolbars menu could not be found"
if not guiconfig.use_one_toolbar:
self.windows_menu.AppendSeparator()
for pane in self.aui_mgr.GetAllPanes():
if pane.name in ("Bible",):
continue
for title, id in self.pane_titles.items():
if id == pane.name:
break
else:
dprint(WARNING, "Couldn't find pane title", pane.name)
continue
if pane.IsToolbar():
item = self.toolbar_menu.AppendCheckItem(wx.ID_ANY,
title,
help=_("Show the %s toolbar")%title)
else:
item = self.windows_menu.AppendCheckItem(wx.ID_ANY,
title,
help=_("Show the %s pane")%title)
if pane.IsShown():
item.Check()
self.Bind(wx.EVT_MENU, self.on_window, item)
for idx, frame in enumerate(self.frames):
if not frame.has_menu: continue
items = [x for (x, where_shown) in frame.get_menu_items()
if where_shown & IN_MENU]
menu = self.make_menu(items)
self.MenuBar.Insert(2+idx, menu, "&" + frame.title)
for idx, (menu, menu_name) in enumerate(self.MenuBar.Menus):
if self.MenuBar.GetMenuLabel(idx) == _("Debug"):
if is_debugging():
for option in display_options.debug_options_menu:
option.add_to_menu(self, menu)
else:
self.MenuBar.Remove(idx)
break
def make_menu(self, items, is_popup=False):
menu = wx.Menu()
for item in items:
if item == Separator:
menu.AppendSeparator()
continue
item.create_item(self, menu, is_popup=is_popup)
return menu
def fill_options_menu(self):
while self.options_menu.MenuItems:
self.options_menu.DestroyItem(
self.options_menu.FindItemByPosition(0)
)
for option in display_options.options_menu:
option.add_to_menu(self, self.options_menu)
#if options:
# self.options_menu.AppendSeparator()
cross_references = self.options_menu.InsertCheckItem(
7,
wx.ID_ANY,
_("Expand cross-references"),
_("Display cross references partially expanded")
)
display_tags = self.options_menu.InsertCheckItem(
9,
wx.ID_ANY,
_("Topic Tags"),
_("Display the topics that each verse is tagged with.")
)
"""
expand_topic_passages = self.options_menu.AppendCheckItem(
wx.ID_ANY,
_("Expand Topic Passages"),
_("Display the complete passage text for passages in the topic tooltip")
)
"""
self.Bind(wx.EVT_MENU, self.toggle_expand_cross_references,
cross_references)
self.Bind(wx.EVT_MENU, self.toggle_display_tags, display_tags)
#self.Bind(wx.EVT_MENU, self.toggle_expand_topic_passages, expand_topic_passages)
filter_settings = config_manager["Filter"]
cross_references.Check(filter_settings["footnote_ellipsis_level"])
display_tags.Check(passage_list.settings.display_tags)
#expand_topic_passages.Check(passage_list.settings.expand_topic_passages)
def toggle_expand_cross_references(self, event):
filter_settings = config_manager["Filter"]
filter_settings["footnote_ellipsis_level"] = \
event.IsChecked() * filterutils.default_ellipsis_level
self.UpdateBibleUI(settings_changed=True, source=events.EXPAND_CROSS_REFERENCES_TOGGLED)
def toggle_display_tags(self, event):
passage_list.settings.display_tags = event.IsChecked()
self.UpdateBibleUI(settings_changed=True, source=events.DISPLAY_TAGS_TOGGLED)
"""
def toggle_expand_topic_passages(self, event):
passage_list.settings.expand_topic_passages = event.IsChecked()
"""
def do_search(self, event):
"""Search in the currently selected book, defaulting to the Bible if
no book window is selected.
"""
selected_frame = self.get_selected_frame()
if (selected_frame is None or
(not isinstance(selected_frame, BookFrame)) or
(not selected_frame.allow_search)):
selected_frame = self.bibletext
selected_frame.search()
def on_window(self, event):
obj = event.GetEventObject()
menuitem = obj.MenuBar.FindItemById(event.Id)
self.show_panel(self.pane_titles[menuitem.Label], event.Checked())
def on_activate(self, event):
# call our hiding event afterwards when focus has been updated
# wx.CallAfter(self.on_after_activate)
# I don't think we need to hide everything as they are no longer
# absolutely top. If they become that again, they will float above
# other windows, which is undesirable
pass
def on_after_activate(self):
# if we don't have focus at all, hide all tooltips and don't let any
# more appear yet.
if not wx.Window.FindFocus():
self.hide_tooltips()
self.lost_focus = True
else:
self.lost_focus = False
def hide_tooltips(self, exceptions=[]):
# remove dead objects
self.toplevels = [item for item in self.toplevels if item]
for item in self.toplevels:
if item not in exceptions:
item.Stop()
def add_toplevel(self, toplevel):
toplevel.Bind(wx.EVT_ACTIVATE, self.on_activate)
self.toplevels.append(toplevel)
#def remove_toplevel(self, toplevel):
# if toplevel:
# toplevel.Unbind(wx.EVT_ACTIVATE)
# self.toplevels.remove(toplevel)
def on_char(self, event):
# just pass the event on for now
self.bibletext.on_char(event)
def setup_frames(self):
self.frames = [self.bibletext, self.commentarytext, self.dictionarytext,
self.daily_devotional_frame, self.harmony_frame, self.genbooktext,
self.verse_compare]
for frame in self.frames:
name = self.get_pane_for_frame(frame).name
self.aui_callbacks[name] = frame.on_shown
dprint(MESSAGE, "Setting initial bibleref")
self.set_bible_ref(settings["bibleref"] or "Genesis 1:1",
events.LOADING_SETTINGS, userInput=False)
self.dictionarytext.UpdateUI()
self.daily_devotional_frame.UpdateUI()
self.version_tree.recreate()
def restart(self, event=None):
guiconfig.app.restarting = True
wx.MessageBox(
_("BPBible will now quickly restart to change your language."),
_("Restarting")
)
self.MainFrameClose(None)