|
38 | 38 | # set up logging
|
39 | 39 | #
|
40 | 40 | #-------------------------------------------------------------------------
|
41 |
| -import logging |
42 | 41 | _LOG = logging.getLogger("PlaceCoordinateGramplet")
|
43 | 42 |
|
44 | 43 |
|
|
47 | 46 | import importlib
|
48 | 47 | import traceback
|
49 | 48 |
|
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") |
61 | 56 | try:
|
62 | 57 | import gi
|
63 | 58 | gi.require_version('GeocodeGlib', '1.0')
|
64 | 59 | from gi.repository import GeocodeGlib
|
65 |
| - some_import_error = False |
66 | 60 | 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) |
70 | 69 |
|
71 |
| - if _uistate: |
72 | 70 | from gramps.gui.dialog import QuestionDialog2
|
73 | 71 | warn_dialog = QuestionDialog2(
|
74 | 72 | plugin_name + ' Plugin',
|
75 | 73 | message,
|
76 | 74 | "Don't show again", "OK",
|
77 | 75 | parent=_uistate.window)
|
78 | 76 | 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") |
81 | 81 | inifile.save()
|
82 |
| - |
83 | 82 | some_import_error = True
|
| 83 | + break |
84 | 84 |
|
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: |
90 | 88 | 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) |
99 | 101 | logging.warning(plugin_name + ': ' + message)
|
100 | 102 |
|
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 |
119 | 118 |
|
120 | 119 | if locals().get('uistate') is None or not some_import_error:
|
121 | 120 | # Right after the download the plugin is loaded without uistate
|
|
129 | 128 | id='geoIDplaceCoordinateGramplet',
|
130 | 129 | name=_("Place Coordinate Gramplet view"),
|
131 | 130 | description=_("View for the place coordinate gramplet."),
|
132 |
| - version = '1.1.10', |
| 131 | + version = '1.1.11', |
133 | 132 | gramps_target_version="5.1",
|
134 | 133 | status=STABLE,
|
135 | 134 | fname='PlaceCoordinateGeoView.py',
|
|
146 | 145 | name=_("Place and Coordinates"),
|
147 | 146 | description=_(
|
148 | 147 | "Gramplet that simplifies setting the coordinates of a place"),
|
149 |
| - version = '1.1.10', |
| 148 | + version = '1.1.11', |
150 | 149 | gramps_target_version="5.1",
|
151 | 150 | status=STABLE,
|
152 | 151 | fname="PlaceCoordinateGramplet.py",
|
|
0 commit comments