Skip to content

Commit 6b3c35c

Browse files
committed
PlaceCoordinateGramplet fix gpr to re-enable addon if prerequisites are ok
1 parent 7c59a7e commit 6b3c35c

File tree

2 files changed

+63
-63
lines changed

2 files changed

+63
-63
lines changed

PlaceCoordinateGramplet/PlaceCoordinateGramplet.gpr.py

Lines changed: 52 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
# set up logging
3939
#
4040
#-------------------------------------------------------------------------
41-
import logging
4241
_LOG = logging.getLogger("PlaceCoordinateGramplet")
4342

4443

@@ -47,75 +46,75 @@
4746
import importlib
4847
import traceback
4948

50-
try:
51-
if 'placecoordinategramplet_warn' not in sects \
52-
or not inifile.is_set('placecoordinategramplet_warn.missingmodules') \
53-
or inifile.get('placecoordinategramplet_warn.missingmodules') != 'False' \
54-
:
55-
_uistate = locals().get('uistate')
56-
else:
57-
_uistate = None
58-
59-
plugin_name = "Place Coordinate Gramplet"
60-
49+
# we should always try to see if prerequisites are there, in case they
50+
# appear at a later time than first run. But we still don't need to do
51+
# this if there is no GUI, as Gramplet and view are not necessary.
52+
_uistate = locals().get('uistate')
53+
some_import_error = False
54+
while _uistate:
55+
plugin_name = _("Place Coordinate Gramplet")
6156
try:
6257
import gi
6358
gi.require_version('GeocodeGlib', '1.0')
6459
from gi.repository import GeocodeGlib
65-
some_import_error = False
6660
except:
67-
message = _("Failed to load the required module {module_name}.").format(
68-
module_name="gi.repository.GeocodeGlib")
69-
logging.warning(plugin_name + ': ' + message)
61+
if('placecoordinategramplet_warn' not in sects or not
62+
inifile.is_set('placecoordinategramplet_warn.missingmodules') or
63+
inifile.get('placecoordinategramplet_warn.missingmodules') !=
64+
'False'):
65+
message = _(
66+
"Failed to load the required module {module_name}.").format(
67+
module_name="gi.repository.GeocodeGlib")
68+
logging.warning(plugin_name + ': ' + message)
7069

71-
if _uistate:
7270
from gramps.gui.dialog import QuestionDialog2
7371
warn_dialog = QuestionDialog2(
7472
plugin_name + ' Plugin',
7573
message,
7674
"Don't show again", "OK",
7775
parent=_uistate.window)
7876
if warn_dialog.run():
79-
inifile.register('placecoordinategramplet_warn.missingmodules', "")
80-
inifile.set('placecoordinategramplet_warn.missingmodules', "False")
77+
inifile.register(
78+
'placecoordinategramplet_warn.missingmodules', "")
79+
inifile.set(
80+
'placecoordinategramplet_warn.missingmodules', "False")
8181
inifile.save()
82-
8382
some_import_error = True
83+
break
8484

85-
if os.name == 'nt' and not some_import_error and ('placecoordinategramplet_warn' not in sects
86-
or not inifile.is_set('placecoordinategramplet_warn.connectivity')
87-
or inifile.get('placecoordinategramplet_warn.connectivity') != 'False'
88-
):
89-
85+
# now test to make sure that we can actually perform a search. If there
86+
# is a problem with connectivity this will fail
87+
try:
9088
location_ = GeocodeGlib.Forward.new_for_string("Berlin")
91-
try:
92-
result = location_.search()
93-
except Exception as e:
94-
result = None
95-
96-
message = _("Internet connectivity test failed for {module_name}.").format(
97-
module_name="gi.repository.GeocodeGlib") \
98-
+ "\n\n" + str(e)
89+
result = location_.search()
90+
break
91+
except Exception as e:
92+
result = None
93+
94+
if('placecoordinategramplet_warn' not in sects or not
95+
inifile.is_set('placecoordinategramplet_warn.connectivity') or
96+
inifile.get('placecoordinategramplet_warn.connectivity') !=
97+
'False'):
98+
message = _(
99+
"Internet connectivity test failed for {module_name}.").format(
100+
module_name="gi.repository.GeocodeGlib") + "\n\n" + str(e)
99101
logging.warning(plugin_name + ': ' + message)
100102

101-
if _uistate:
102-
from gramps.gui.dialog import QuestionDialog2
103-
warn_dialog = QuestionDialog2(
104-
plugin_name + ' Plugin',
105-
message,
106-
"Don't show again", "OK",
107-
parent=_uistate.window)
108-
if warn_dialog.run():
109-
logging.warning(plugin_name + ': ' + _('Warning disabled.'))
110-
inifile.register('placecoordinategramplet_warn.connectivity', "")
111-
inifile.set('placecoordinategramplet_warn.connectivity', "False")
112-
inifile.save()
113-
some_import_error = True
114-
115-
except Exception as e:
116-
some_import_error = True
117-
import_error_message = traceback.format_exc()
118-
logging.log(logging.ERROR, 'Failed to load PlaceCoordinateGramplet plugin.\n' + import_error_message)
103+
from gramps.gui.dialog import QuestionDialog2
104+
warn_dialog = QuestionDialog2(
105+
plugin_name + ' Plugin',
106+
message,
107+
"Don't show again", "OK",
108+
parent=_uistate.window)
109+
if warn_dialog.run():
110+
logging.warning(plugin_name + ': ' + _('Warning disabled.'))
111+
inifile.register(
112+
'placecoordinategramplet_warn.connectivity', "")
113+
inifile.set(
114+
'placecoordinategramplet_warn.connectivity', "False")
115+
inifile.save()
116+
some_import_error = True
117+
break
119118

120119
if locals().get('uistate') is None or not some_import_error:
121120
# Right after the download the plugin is loaded without uistate
@@ -129,7 +128,7 @@
129128
id='geoIDplaceCoordinateGramplet',
130129
name=_("Place Coordinate Gramplet view"),
131130
description=_("View for the place coordinate gramplet."),
132-
version = '1.1.10',
131+
version = '1.1.11',
133132
gramps_target_version="5.1",
134133
status=STABLE,
135134
fname='PlaceCoordinateGeoView.py',
@@ -146,7 +145,7 @@
146145
name=_("Place and Coordinates"),
147146
description=_(
148147
"Gramplet that simplifies setting the coordinates of a place"),
149-
version = '1.1.10',
148+
version = '1.1.11',
150149
gramps_target_version="5.1",
151150
status=STABLE,
152151
fname="PlaceCoordinateGramplet.py",

PlaceCoordinateGramplet/po/template.pot

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2020-08-26 11:18-0500\n"
11+
"POT-Creation-Date: 2020-09-02 16:40-0500\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <[email protected]>\n"
@@ -26,6 +26,7 @@ msgid "Places map"
2626
msgstr ""
2727

2828
#: PlaceCoordinateGramplet/PlaceCoordinateGeoView.py:264
29+
#: PlaceCoordinateGramplet/PlaceCoordinateGramplet.gpr.py:55
2930
msgid "Place Coordinate Gramplet"
3031
msgstr ""
3132

@@ -216,41 +217,41 @@ msgstr ""
216217
msgid "Center on this place"
217218
msgstr ""
218219

219-
#: PlaceCoordinateGramplet/PlaceCoordinateGramplet.gpr.py:67
220+
#: PlaceCoordinateGramplet/PlaceCoordinateGramplet.gpr.py:66
220221
#, python-brace-format
221222
msgid "Failed to load the required module {module_name}."
222223
msgstr ""
223224

224-
#: PlaceCoordinateGramplet/PlaceCoordinateGramplet.gpr.py:96
225+
#: PlaceCoordinateGramplet/PlaceCoordinateGramplet.gpr.py:99
225226
#, python-brace-format
226227
msgid "Internet connectivity test failed for {module_name}."
227228
msgstr ""
228229

229-
#: PlaceCoordinateGramplet/PlaceCoordinateGramplet.gpr.py:109
230+
#: PlaceCoordinateGramplet/PlaceCoordinateGramplet.gpr.py:110
230231
msgid "Warning disabled."
231232
msgstr ""
232233

233-
#: PlaceCoordinateGramplet/PlaceCoordinateGramplet.gpr.py:130
234+
#: PlaceCoordinateGramplet/PlaceCoordinateGramplet.gpr.py:129
234235
msgid "Place Coordinate Gramplet view"
235236
msgstr ""
236237

237-
#: PlaceCoordinateGramplet/PlaceCoordinateGramplet.gpr.py:131
238+
#: PlaceCoordinateGramplet/PlaceCoordinateGramplet.gpr.py:130
238239
msgid "View for the place coordinate gramplet."
239240
msgstr ""
240241

241-
#: PlaceCoordinateGramplet/PlaceCoordinateGramplet.gpr.py:138
242+
#: PlaceCoordinateGramplet/PlaceCoordinateGramplet.gpr.py:137
242243
msgid "Geography"
243244
msgstr ""
244245

245-
#: PlaceCoordinateGramplet/PlaceCoordinateGramplet.gpr.py:146
246+
#: PlaceCoordinateGramplet/PlaceCoordinateGramplet.gpr.py:145
246247
msgid "Place and Coordinates"
247248
msgstr ""
248249

249-
#: PlaceCoordinateGramplet/PlaceCoordinateGramplet.gpr.py:148
250+
#: PlaceCoordinateGramplet/PlaceCoordinateGramplet.gpr.py:147
250251
msgid "Gramplet that simplifies setting the coordinates of a place"
251252
msgstr ""
252253

253-
#: PlaceCoordinateGramplet/PlaceCoordinateGramplet.gpr.py:157
254+
#: PlaceCoordinateGramplet/PlaceCoordinateGramplet.gpr.py:156
254255
msgid "Place Coordinates"
255256
msgstr ""
256257

0 commit comments

Comments
 (0)