forked from gramps-project/gramps
/
_windows.py
2263 lines (2008 loc) · 79.9 KB
/
_windows.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
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2006 Donald N. Allingham
# Copyright (C) 2008 Brian G. Matherly
# Copyright (C) 2010 Jakim Friant
# Copyright (C) 2011 Paul Franklin
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# -------------------------------------------------------------------------
#
# Python modules
#
# -------------------------------------------------------------------------
import traceback
import os
from html import escape
import threading
import sys
import subprocess
# -------------------------------------------------------------------------
#
# set up logging
#
# -------------------------------------------------------------------------
import logging
LOG = logging.getLogger(".gui.plug")
# -------------------------------------------------------------------------
#
# GTK modules
#
# -------------------------------------------------------------------------
from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GLib
from gi.repository import Pango
from gi.repository import GObject
# -------------------------------------------------------------------------
#
# Gramps modules
#
# -------------------------------------------------------------------------
from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext
ngettext = glocale.translation.ngettext # else "nearby" comments are ignored
from ..managedwindow import ManagedWindow
from gramps.gen.errors import UnavailableError, WindowActiveError
from gramps.gen.plug import (
PluginRegister,
PTYPE_STR,
load_addon_file,
AUDIENCETEXT,
STATUSTEXT,
)
from ..utils import open_file_with_default_application
from ..pluginmanager import GuiPluginManager
from . import tool
from ._guioptions import add_gui_options
from ..dialog import InfoDialog, OkDialog, QuestionDialog2
from ..editors import EditPerson
from ..glade import Glade
from ..listmodel import ListModel, NOSORT, TOGGLE
from gramps.gen.const import URL_WIKISTRING, USER_HOME, WIKI_EXTRAPLUGINS_RAWDATA, COLON
from gramps.gen.config import config
from ..widgets.progressdialog import LongOpStatus, ProgressMonitor, GtkProgressDialog
from gramps.gen.plug.utils import get_all_addons, available_updates
from ..display import display_help, display_url
from gramps.gui.widgets import BasicLabel, SimpleButton
from gramps.gen.utils.requirements import Requirements
from gramps.gen.const import USER_PLUGINS
def display_message(message):
"""
A default callback for displaying messages.
"""
print(message)
RELOAD = 777 # A custom Gtk response_type for the Reload button
# -------------------------------------------------------------------------
#
# GetAddons
#
# -------------------------------------------------------------------------
class GetAddons(threading.Thread):
"""
A class for retrieving a list of addons as a background task.
"""
def __init__(self, callback):
threading.Thread.__init__(self)
self.callback = callback
self.addon_list = []
self.__pmgr = GuiPluginManager.get_instance()
def emit_signal(self):
self.callback(self.addon_list)
def run(self):
self.addon_list = self.__get_addon_list()
GLib.idle_add(self.emit_signal)
def __get_addon_list(self):
return get_all_addons()
# -------------------------------------------------------------------------
#
# ProjectRow
#
# -------------------------------------------------------------------------
class ProjectRow(Gtk.ListBoxRow):
"""
A class to display an external addons repository.
"""
def __init__(self, manager, project):
Gtk.ListBoxRow.__init__(self)
self.manager = manager
self.project = project
hbox = Gtk.Box()
hbox.set_spacing(12)
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
vbox.set_spacing(6)
self.check = Gtk.CheckButton()
hbox.pack_start(self.check, False, False, 0)
hbox.pack_start(vbox, True, True, 0)
self.name = Gtk.Label()
self.name.set_use_markup(True)
self.name.set_halign(Gtk.Align.START)
self.url = Gtk.Label()
self.url.set_halign(Gtk.Align.START)
vbox.pack_start(self.name, False, False, 0)
vbox.pack_start(self.url, False, False, 0)
self.add(hbox)
self.show_all()
self.update()
self.check.connect("toggled", self.__check_toggled)
def __check_toggled(self, check):
self.project[2] = check.get_active()
projects = [row.project for row in self.manager.project_list]
config.set("behavior.addons-projects", projects)
self.manager.refresh()
def update(self):
"""
Update the row when the project data has been updated.
"""
text = self.project[0]
self.name.set_markup('<span weight="bold">%s</span>' % text)
self.url.set_text(self.project[1])
self.check.set_active(self.project[2])
# -------------------------------------------------------------------------
#
# AddonManager
#
# -------------------------------------------------------------------------
class AddonRow(Gtk.ListBoxRow):
"""
A class representing an addon in the Addon Manager.
"""
def __init__(self, manager, addon, req, window):
Gtk.ListBoxRow.__init__(self)
self.manager = manager
self.addon = addon
self.req = req
self.window = window
context = self.get_style_context()
context.add_class("addon-row")
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
vbox.set_spacing(6)
text = escape(addon["n"])
title = Gtk.Label()
title.set_text('<span size="larger" weight="bold">%s</span>' % text)
title.set_use_markup(True)
title.set_halign(Gtk.Align.CENTER)
vbox.pack_start(title, False, False, 0)
hbox = Gtk.Box()
hbox.set_spacing(6)
lozenge = self.__create_lozenge(_("Project"), addon["_p"])
hbox.pack_start(lozenge, False, False, 0)
lozenge = self.__create_lozenge(_("Type"), PTYPE_STR[addon["t"]])
hbox.pack_start(lozenge, False, False, 0)
lozenge = self.__create_lozenge(_("Audience"), AUDIENCETEXT[addon["a"]])
hbox.pack_start(lozenge, False, False, 0)
lozenge = self.__create_lozenge(_("Status"), STATUSTEXT[addon["s"]])
hbox.pack_start(lozenge, False, False, 0)
lozenge = self.__create_lozenge(_("Version"), addon["v"])
hbox.pack_start(lozenge, False, False, 0)
if "_v" in addon:
lozenge = self.__create_lozenge(_("Installed version"), addon["_v"])
hbox.pack_end(lozenge, False, False, 0)
vbox.pack_start(hbox, False, False, 0)
text = addon["d"]
descr = Gtk.Label()
descr.set_text(text)
descr.set_halign(Gtk.Align.START)
descr.set_hexpand(False)
descr.set_line_wrap(True)
descr.set_line_wrap_mode(Pango.WrapMode.WORD)
vbox.pack_start(descr, False, False, 0)
bb = Gtk.Box()
bb.set_spacing(6)
if "_v" not in addon and req.check_addon(addon, install=True):
b1 = Gtk.Button(label=_("Install"))
b1.set_label(_("Install"))
b1.connect("clicked", self.__on_install_clicked, addon)
bb.pack_end(b1, False, False, 0)
if addon["h"]:
b2 = Gtk.Button(label=_("Wiki"))
b2.connect("clicked", self.__on_wiki_clicked, addon["h"])
bb.pack_start(b2, False, False, 0)
if not req.check_addon(addon):
b3 = Gtk.Button(label=_("Requires"))
b3.connect("clicked", self.__on_requires_clicked, addon)
bb.pack_start(b3, False, False, 0)
if "_v" in addon and addon["_v"] != addon["v"]:
b4 = Gtk.Button(label=_("Update"))
b4.connect("clicked", self.__on_update_clicked, addon)
bb.pack_end(b4, False, False, 0)
vbox.pack_start(bb, False, False, 0)
self.add(vbox)
self.show_all()
def __on_install_clicked(self, button, addon):
"""
Install the addon and possibly some required python modules.
"""
# Install required modules
for package in self.req.install(addon):
try:
subprocess.check_output(
[sys.executable, "-m", "pip", "install", package],
stderr=subprocess.STDOUT,
)
except subprocess.CalledProcessError as err:
button.set_sensitive(False)
InfoDialog(
_("Module installation failed"),
err.output.decode("utf-8"),
parent=self.window,
)
return
# Install addon
path = addon["_u"] + "/download/" + addon["z"]
load_addon_file(path)
self.manager.install_addon(addon["i"])
self.manager.refresh()
def __on_wiki_clicked(self, button, url):
"""
Display the wiki page for the addon.
"""
if url.startswith(("http://", "https://")):
display_url(url)
else:
display_help(url)
def __on_requires_clicked(self, button, addon):
"""
Display the requirements for the addon.
"""
InfoDialog(_("Requirements"), self.req.info(addon), parent=self.window)
def __on_update_clicked(self, button, addon):
"""
Update the addon.
"""
path = addon["_u"] + "/download/" + addon["z"]
load_addon_file(path)
self.manager.update_addon(addon["i"])
self.manager.refresh()
def __create_lozenge(self, description, text):
"""
Create a lozenge shaped label to display addon information.
"""
label = Gtk.Label()
label.set_tooltip_text(description)
context = label.get_style_context()
context.add_class("lozenge")
label.set_text(text)
label.set_margin_start(6)
return label
# -------------------------------------------------------------------------
#
# AddonManager
#
# -------------------------------------------------------------------------
class AddonManager(ManagedWindow):
"""
A class to allow the user to easily select addons to install.
"""
def __init__(self, dbstate, uistate, track):
self.dbstate = dbstate
self.title = _("Addon Manager")
ManagedWindow.__init__(self, uistate, [], self)
self.__pmgr = GuiPluginManager.get_instance()
self.__preg = PluginRegister.get_instance()
dialog = Gtk.Dialog(
title="", transient_for=uistate.window, destroy_with_parent=True
)
dialog.add_button(_("Refresh"), RELOAD)
dialog.add_button(_("_Close"), Gtk.ResponseType.CLOSE)
dialog.add_button(_("_Help"), Gtk.ResponseType.HELP)
self.set_window(dialog, None, self.title)
self.req = Requirements()
self.setup_configs("interface.addonmanager", 750, 400)
self.window.connect("response", self.__on_dialog_button)
book = Gtk.Notebook()
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
vbox.set_spacing(6)
vbox.set_margin_start(6)
vbox.set_margin_end(6)
vbox.set_margin_top(6)
vbox.set_margin_bottom(6)
self.search = Gtk.Entry()
self.search.set_icon_from_icon_name(
Gtk.EntryIconPosition.SECONDARY, "system-search"
)
self.search.connect("changed", self.__combo_changed)
vbox.pack_start(self.search, False, False, 0)
hbox = Gtk.Box()
hbox.set_spacing(6)
self.lb = Gtk.ListBox()
self.lb.set_activate_on_single_click(False)
label = Gtk.Label(label=_("Filters") + COLON)
label.set_margin_end(12)
hbox.pack_start(label, False, False, 0)
self.addon_combo = Gtk.ComboBoxText()
self.addon_combo.set_entry_text_column(0)
self.addon_combo.append_text(_("All addons"))
self.addon_combo.append_text(_("Uninstalled"))
self.addon_combo.append_text(_("Installed"))
self.addon_combo.append_text(_("Update"))
self.addon_combo.set_active(0)
self.addon_combo.connect("changed", self.__combo_changed)
hbox.pack_start(self.addon_combo, False, False, 0)
self.projects = config.get("behavior.addons-projects")
self.project_combo = Gtk.ComboBoxText()
self.project_combo.set_entry_text_column(0)
self.project_combo.connect("changed", self.__combo_changed)
hbox.pack_start(self.project_combo, False, False, 0)
type_store = Gtk.ListStore(int, str)
type_store.append([-1, _("All types")])
entries = list(PTYPE_STR.items())
for entry in sorted(entries, key=lambda item: item[1]):
type_store.append(entry)
self.type_combo = self.__create_filter_combo(type_store, 0)
hbox.pack_start(self.type_combo, False, False, 0)
audience_store = Gtk.ListStore(int, str)
audience_store.append([-1, _("All audiences")])
for key, value in AUDIENCETEXT.items():
audience_store.append([key, value])
self.audience_combo = self.__create_filter_combo(audience_store, 1)
hbox.pack_start(self.audience_combo, False, False, 0)
status_store = Gtk.ListStore(int, str)
status_store.append([-1, _("All statuses")])
entries = list(STATUSTEXT.items())
for entry in sorted(entries, reverse=True):
status_store.append(entry)
self.status_combo = self.__create_filter_combo(status_store, 1)
hbox.pack_start(self.status_combo, False, False, 0)
clear = Gtk.Button.new_from_icon_name("edit-clear", Gtk.IconSize.BUTTON)
clear.connect("clicked", self.__clear_filters)
hbox.pack_start(clear, False, False, 0)
vbox.pack_start(hbox, False, False, 0)
sw = Gtk.ScrolledWindow()
sw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
sw.add(self.lb)
vbox.pack_start(sw, True, True, 0)
book.append_page(vbox, Gtk.Label(_("Addons")))
grid = self.create_settings_panel()
book.append_page(grid, Gtk.Label(_("Settings")))
grid = self.create_projects_panel()
book.append_page(grid, Gtk.Label(_("Projects")))
for project in self.projects:
self.project_list.add(ProjectRow(self, project))
self.update_project_list()
self.window.get_content_area().pack_start(book, True, True, 0)
self.lb.set_sort_func(self.__sort_func)
self.lb.set_filter_func(self.__filter_func)
self.show()
self.refresh()
def help(self):
"""
Display the Addon Manager help page.
"""
display_help("Addon_Manager")
def __create_filter_combo(self, store, default):
"""
Create a ComboBox for filters.
"""
combo = Gtk.ComboBox()
combo.set_model(store)
combo.set_entry_text_column(1)
combo.connect("changed", self.__combo_changed)
combo.set_active(default)
renderer_text = Gtk.CellRendererText()
combo.pack_start(renderer_text, True)
combo.add_attribute(renderer_text, "text", 1)
return combo
def update_project_list(self):
"""
Update the project list after it has been changed.
"""
self.projects = [row.project for row in self.project_list]
config.set("behavior.addons-projects", self.projects)
self.project_combo.remove_all()
self.project_combo.append_text(_("All projects"))
for project in self.projects:
self.project_combo.append_text(project[0])
self.project_combo.set_active(0)
def refresh(self):
"""
Refresh the addons list.
"""
for child in self.lb.get_children():
self.lb.remove(child)
self.__placeholder(_("Loading..."))
thread = GetAddons(self.load_addons)
thread.start()
def update_addon(self, addon_id):
"""
Update the given addon.
"""
pdata = self.__preg.get_plugin(addon_id)
self.__pmgr.reg_plugin_dir(
pdata.directory, self.dbstate, self.uistate, load_on_reg=True
)
pdata = self.__preg.get_plugin(addon_id)
self.__pmgr.load_plugin(pdata)
def install_addon(self, addon_id):
"""
Install the given addon.
"""
self.__pmgr.reg_plugins(
USER_PLUGINS, self.dbstate, self.uistate, load_on_reg=True
)
pdata = self.__preg.get_plugin(addon_id)
self.__pmgr.load_plugin(pdata)
def build_menu_names(self, obj):
return (self.title, self.title)
def __placeholder(self, text):
"""
A placeholder label if no addons are listed.
"""
label = Gtk.Label('<span size="larger" weight="bold">%s</span>' % text)
label.set_use_markup(True)
label.show()
self.lb.set_placeholder(label)
def load_addons(self, addon_list):
"""
Populate the list box.
"""
for addon in addon_list:
self.lb.add(AddonRow(self, addon, self.req, self.window))
self.__placeholder(_("No matching addons found."))
def __clear_filters(self, combo):
"""
Reset the filters back to their defaults.
"""
self.search.set_text("")
self.type_combo.set_active(0)
self.addon_combo.set_active(0)
self.project_combo.set_active(0)
self.audience_combo.set_active(1)
self.status_combo.set_active(1)
def __combo_changed(self, combo):
"""
Called when a filter is changed.
"""
self.lb.invalidate_filter()
def __sort_func(self, row1, row2):
"""
Sort the addons by name.
"""
value1 = row1.addon["n"]
value2 = row2.addon["n"]
if value1 > value2:
return 1
elif value1 < value2:
return -1
else:
return 0
def __filter_func(self, row):
"""
Filter the addons list according to the user selection.
"""
search_text = self.search.get_text()
addon_text = self.addon_combo.get_active_text()
project_text = self.project_combo.get_active_text()
type_iter = self.type_combo.get_active_iter()
audience_iter = self.audience_combo.get_active_iter()
status_iter = self.status_combo.get_active_iter()
if addon_text == _("Uninstalled"):
if "_v" in row.addon:
return False
if addon_text == _("Installed"):
if "_v" not in row.addon:
return False
if addon_text == _("Update"):
if "_v" not in row.addon:
return False
if row.addon["v"] == row.addon["_v"]:
return False
if project_text != _("All projects"):
if row.addon["_p"] != project_text:
return False
model = self.type_combo.get_model()
value = model.get_value(type_iter, 0)
if value != -1 and row.addon["t"] != value:
return False
model = self.audience_combo.get_model()
value = model.get_value(audience_iter, 0)
if value != -1 and row.addon["a"] != value:
return False
model = self.status_combo.get_model()
value = model.get_value(status_iter, 0)
if value != -1 and row.addon["s"] != value:
return False
if search_text:
search_text = search_text.lower()
if (
search_text not in row.addon["n"].lower()
and search_text not in row.addon["d"].lower()
and search_text not in row.addon["i"].lower()
):
return False
return True
def __on_dialog_button(self, dialog, response_id):
"""
Handle a main dialog button click.
"""
if response_id == Gtk.ResponseType.CLOSE:
self.close(dialog)
elif response_id == RELOAD:
self.refresh()
elif response_id == Gtk.ResponseType.HELP:
self.help()
def create_projects_panel(self):
"""
Configuration tab with addons projects.
"""
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
vbox.set_spacing(6)
vbox.set_margin_start(6)
vbox.set_margin_end(6)
vbox.set_margin_top(6)
vbox.set_margin_bottom(6)
self.project_list = Gtk.ListBox()
self.project_list.set_activate_on_single_click(False)
self.project_list.set_selection_mode(Gtk.SelectionMode.SINGLE)
self.project_list.connect("row-activated", self.__edit_project)
self.project_list.connect("row-selected", self.__project_selected)
self.project_list.set_margin_start(6)
sw = Gtk.ScrolledWindow()
sw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
sw.add(self.project_list)
vbox.pack_start(sw, True, True, 0)
hbox = Gtk.Box()
add_btn = SimpleButton("list-add", self.__add_project)
del_btn = SimpleButton("list-remove", self.__remove_project)
up_btn = SimpleButton("go-up", self.__move_up)
down_btn = SimpleButton("go-down", self.__move_down)
restore_btn = SimpleButton("document-revert", self.__restore_defaults)
self.buttons = [add_btn, del_btn, up_btn, down_btn, restore_btn]
for button in self.buttons:
hbox.pack_start(button, False, False, 0)
self.buttons[1].set_sensitive(False)
self.buttons[2].set_sensitive(False)
self.buttons[3].set_sensitive(False)
vbox.pack_start(hbox, False, False, 0)
return vbox
def create_settings_panel(self):
"""
Configuration tab with addons settings.
"""
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
vbox.set_spacing(6)
vbox.set_margin_start(6)
vbox.set_margin_end(6)
vbox.set_margin_top(6)
vbox.set_margin_bottom(6)
heading1 = Gtk.Label()
text = _("General")
heading1.set_text('<span weight="bold">%s</span>' % text)
heading1.set_use_markup(True)
heading1.set_halign(Gtk.Align.START)
vbox.pack_start(heading1, False, False, 0)
grid = Gtk.Grid()
grid.set_row_spacing(6)
grid.set_margin_start(6)
grid.set_margin_bottom(12)
vbox.pack_start(grid, False, False, 0)
row = 1
install = Gtk.CheckButton()
install.set_label(_("Allow Gramps to install required python modules"))
active = config.get("behavior.addons-allow-install")
install.set_active(active)
install.connect("toggled", self.install_changed)
grid.attach(install, 1, row, 1, 1)
heading2 = Gtk.Label()
text = _("Updates")
heading2.set_text('<span weight="bold">%s</span>' % text)
heading2.set_use_markup(True)
heading2.set_halign(Gtk.Align.START)
vbox.pack_start(heading2, False, False, 0)
grid = Gtk.Grid()
grid.set_row_spacing(6)
grid.set_margin_start(6)
vbox.pack_start(grid, False, False, 0)
# Check for addon updates:
row = 1
obox = Gtk.ComboBoxText()
formats = [
_("Never"),
_("Once a month"),
_("Once a week"),
_("Once a day"),
_("Always"),
]
list(map(obox.append_text, formats))
active = config.get("behavior.check-for-addon-updates")
obox.set_active(active)
obox.connect("changed", self.check_for_updates_changed)
lwidget = BasicLabel(_("%s: ") % _("Check for addon updates"))
grid.attach(lwidget, 1, row, 1, 1)
grid.attach(obox, 2, row, 1, 1)
row += 1
self.whattype_box = Gtk.ComboBoxText()
formats = [
_("Updated addons only"),
_("New addons only"),
_("New and updated addons"),
]
list(map(self.whattype_box.append_text, formats))
whattype = config.get("behavior.check-for-addon-update-types")
if "new" in whattype and "update" in whattype:
self.whattype_box.set_active(2)
elif "new" in whattype:
self.whattype_box.set_active(1)
elif "update" in whattype:
self.whattype_box.set_active(0)
self.whattype_box.connect("changed", self.check_for_type_changed)
lwidget = BasicLabel(_("%s: ") % _("What to check"))
grid.attach(lwidget, 1, row, 1, 1)
grid.attach(self.whattype_box, 2, row, 1, 1)
row += 1
previous = Gtk.CheckButton()
previous.set_label(_("Do not ask about previously notified addons"))
active = config.get("behavior.do-not-show-previously-seen-addon-updates")
previous.set_active(active)
previous.connect("toggled", self.previous_changed)
grid.attach(previous, 1, row, 1, 1)
row += 1
button = Gtk.Button(label=_("Check for updated addons now"))
button.connect("clicked", self.check_for_updates)
button.set_hexpand(False)
button.set_halign(Gtk.Align.CENTER)
grid.attach(button, 1, row, 2, 1)
return vbox
def edit_project(self, row):
"""
Add or edit a project
"""
if row.project[0] == "":
title = _("New Project")
else:
title = _("Edit Project")
dialog = Gtk.Dialog(title=title, transient_for=self.window)
dialog.set_border_width(6)
dialog.vbox.set_spacing(6)
grid = Gtk.Grid()
grid.set_row_spacing(6)
grid.set_column_spacing(6)
label = Gtk.Label(label=_("%s: ") % _("Project name"))
label.set_halign(Gtk.Align.END)
grid.attach(label, 0, 0, 1, 1)
name = Gtk.Entry()
name.set_hexpand(True)
name.set_text(row.project[0])
name.set_activates_default(True)
grid.attach(name, 1, 0, 1, 1)
label = Gtk.Label(label=_("%s: ") % _("Url"))
label.set_halign(Gtk.Align.END)
grid.attach(label, 0, 1, 1, 1)
url = Gtk.Entry()
url.set_hexpand(True)
url.set_text(row.project[1])
grid.attach(url, 1, 1, 1, 1)
dialog.vbox.pack_start(grid, True, True, 0)
dialog.add_buttons(
_("_Cancel"), Gtk.ResponseType.CANCEL, _("_OK"), Gtk.ResponseType.OK
)
dialog.set_default_response(Gtk.ResponseType.OK)
dialog.vbox.show_all()
if dialog.run() == Gtk.ResponseType.OK:
if row.project[0] == "":
self.project_list.add(row)
row.project[0] = name.get_text()
row.project[1] = url.get_text()
row.update()
self.update_project_list()
self.refresh()
dialog.destroy()
def __add_project(self, button):
"""
Add a project
"""
self.edit_project(ProjectRow(self, ["", "", False]))
def __remove_project(self, button):
"""
Remove a project
"""
row = self.project_list.get_selected_row()
if row:
self.project_list.remove(row)
self.update_project_list()
self.refresh()
def __move_up(self, button):
row = self.project_list.get_selected_row()
index = row.get_index()
if index > 1:
self.project_list.unselect_row(row)
self.project_list.remove(row)
self.project_list.insert(row, index - 1)
self.project_list.select_row(row)
self.update_project_list()
def __move_down(self, button):
row = self.project_list.get_selected_row()
index = row.get_index()
if index > 0 and index < len(self.project_list) - 1:
self.project_list.unselect_row(row)
self.project_list.remove(row)
self.project_list.insert(row, index + 1)
self.project_list.select_row(row)
self.update_project_list()
def __project_selected(self, listbox, row):
if row:
index = row.get_index()
if index == 0:
self.buttons[1].set_sensitive(False)
self.buttons[2].set_sensitive(False)
self.buttons[3].set_sensitive(False)
elif index == 1:
self.buttons[1].set_sensitive(True)
self.buttons[2].set_sensitive(False)
self.buttons[3].set_sensitive(True)
elif index < len(self.project_list) - 1:
self.buttons[1].set_sensitive(True)
self.buttons[2].set_sensitive(True)
self.buttons[3].set_sensitive(True)
else:
self.buttons[1].set_sensitive(True)
self.buttons[2].set_sensitive(True)
self.buttons[3].set_sensitive(False)
else:
self.buttons[1].set_sensitive(False)
self.buttons[2].set_sensitive(False)
self.buttons[3].set_sensitive(False)
def __restore_defaults(self, button):
"""
Restore project defaults.
"""
dlg = QuestionDialog2(
_("Restore project defaults"),
_("Are you sure?"),
_("Yes"),
_("No"),
parent=self.window,
)
if dlg.run():
for row in self.project_list.get_children():
self.project_list.remove(row)
projects = [["Gramps", config.get("behavior.addons-url"), True]]
self.project_list.add(ProjectRow(self, projects[0]))
self.update_project_list()
self.refresh()
def __edit_project(self, listbox, row):
"""
Edit a project
"""
self.edit_project(row)
def check_for_updates(self, button):
try:
addon_update_list = available_updates()
except:
OkDialog(
_("Checking Addons Failed"),
_(
"The addon repository appears to be unavailable. "
"Please try again later."
),
parent=self.window,
)
return
if len(addon_update_list) > 0:
rescan = UpdateAddons(self.uistate, self.track, addon_update_list).rescan
self.uistate.viewmanager.do_reg_plugins(
self.dbstate, self.uistate, rescan=rescan
)
else:
check_types = config.get("behavior.check-for-addon-update-types")
OkDialog(
_("There are no available addons of this type"),
_("Checked for '%s'") % _("' and '").join([_(t) for t in check_types]),
parent=self.window,
)
# List of translated strings used here
# Dead code for l10n
_("new"), _("update")
def check_for_type_changed(self, obj):
active = obj.get_active()
if active == 0: # update
config.set("behavior.check-for-addon-update-types", ["update"])
elif active == 1: # update
config.set("behavior.check-for-addon-update-types", ["new"])
elif active == 2: # update
config.set("behavior.check-for-addon-update-types", ["update", "new"])
def check_for_updates_changed(self, obj):
"""
Save "Check for addon updates" option.
"""
active = obj.get_active()
config.set("behavior.check-for-addon-updates", active)
def previous_changed(self, obj):
active = obj.get_active()
config.set("behavior.do-not-show-previously-seen-addon-updates", active)
def install_changed(self, obj):
active = obj.get_active()
config.set("behavior.addons-allow-install", active)
# -------------------------------------------------------------------------
#
# PluginStatus: overview of all plugins
#
# -------------------------------------------------------------------------
class PluginStatus(ManagedWindow):
"""Displays a dialog showing the status of loaded plugins"""
HIDDEN = '<span color="red">%s</span>' % _("Hidden")
AVAILABLE = '<span weight="bold" color="blue">%s</span>' % _("Visible")
def __init__(self, dbstate, uistate, track=[]):
self.dbstate = dbstate
self.__uistate = uistate
self.title = _("Plugin Manager")
ManagedWindow.__init__(self, uistate, track, self.__class__)
self.__pmgr = GuiPluginManager.get_instance()
self.__preg = PluginRegister.get_instance()
dialog = Gtk.Dialog(
title="", transient_for=uistate.window, destroy_with_parent=True
)
dialog.add_button(_("_Close"), Gtk.ResponseType.CLOSE)
self.set_window(dialog, None, self.title)
self.setup_configs("interface.pluginstatus", 750, 400)
self.window.connect("response", self.__on_dialog_button)
notebook = Gtk.Notebook()
# first page with all registered plugins
vbox_reg = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
scrolled_window_reg = Gtk.ScrolledWindow()
self.list_reg = Gtk.TreeView()
# model: plugintype, hidden, pluginname, plugindescr, pluginid
self.model_reg = Gtk.ListStore(
GObject.TYPE_STRING,
GObject.TYPE_STRING,
GObject.TYPE_STRING,