def request(self, module_name, module_version, source_link): """ Request a module. Either it is available, or it will be downloaded and loaded. Args: module_name (str): module name module_version (str): module version source_link (str): http address of the wheel Returns: Module: the loaded module """ import os import logging from gramps.gen.const import USER_PLUGINS module = self.check_for(module_name, module_version) if module: return module # Users often refuse to download the modules. However, the modules # are required, so the user can only choose between installing the # requirements or uninstall the plugin. If this warning would be # deactivated but the requirements are not available, then an # ImportError Exception will be caused. So deactivating this warning # will cause another one. message = ( _("Failed to load the required module {module_name} " "version {module_version}.") + _("\n\nIt is not possible to use {self.plugin_name} " "without this module. You can either uninstall this plugin, " "or download the module.")).format(**locals()) logging.warning(self.plugin_name + ': ' + message) if self.uistate: from gramps.gui.dialog import QuestionDialog2 ok_cancel = QuestionDialog2( _(self.plugin_name + ' Plugin'), _(message), _("Download module"), _("_Cancel"), parent=self.uistate.window) prompt = ok_cancel.run() if prompt == False: #cancel logging.info(self.plugin_name + ': ' + _('The user chose to ignore the warning once.')) return None elif prompt == True: logging.info(self.plugin_name + ': ' + _('The user chose to install the module.')) output_path = os.path.join(USER_PLUGINS, self.plugin_name) self.load_addon_file(source_link, output_path=output_path, callback=print) module = self.check_for(module_name, module_version) return module return None
def remove(self, obj): from gramps.gui.dialog import QuestionDialog2 from gramps.gen.utils.string import data_recover_msg msg = _('Deleting item will remove it from the database.') msg = msg + '\n' + data_recover_msg q = QuestionDialog2( _('Delete %s?') % _('family'), msg, _('_Delete Item'), _('Cancel')) if q.run(): self.uistate.set_busy_cursor(True) list( map(self.dbstate.db.remove_family_relationships, self.selected_handles())) self.build_tree() self.uistate.set_busy_cursor(False)
def delete(self, _button): """ process the delete button """ if self.r_indx == 99: # not a custom type row return (attr, _name, _obj, _srcobj) = self.t_table[self.r_indx] refs = self.types_dict[self.t_table[self.r_indx][2]][self.name] # warn if there are refs... if refs: warn_dialog = QuestionDialog2( self.window_name, _("Removing this custom type will eliminate it from the type " "selection drop down lists\nand further runs of this tool.\n" "\nHowever, it will not remove it from the referenced items " "in the database.\nIf you want to change it in referenced " "items, use 'Rename'."), _('_Remove'), _('_Stop'), parent=self.window) if not warn_dialog.run(): return False # actually remove from the db types = getattr(self.db, attr, None) types.remove(self.name) self.model.remove(self.iter_)
def __populate_reg_list(self): """ Build list of plugins""" self.addons = [] new_addons_file = os.path.join(VERSION_DIR, "new_addons.txt") if not os.path.isfile(new_addons_file) and not static.check_done: if QuestionDialog2(TITLE, _("3rd party addons are not shown until the " "addons update list is downloaded. Would " "you like to check for updated addons now?"), _("Yes"), _("No"), parent=self.window).run(): self._check_for_updates() else: static.check_done = True try: with open(new_addons_file, encoding='utf-8') as filep: for line in filep: try: plugin_dict = safe_eval(line) if not isinstance(plugin_dict, dict): raise TypeError("Line with addon metadata is not " "a dictionary") except: # pylint: disable=bare-except LOG.warning("Skipped a line in the addon listing: " + str(line)) continue self.addons.append(plugin_dict) except FileNotFoundError: pass except Exception as err: # pylint: disable=broad-except LOG.warning("Failed to open addon status file: %s", err) addons = [] updateable = [] for plugin_dict in self.addons: pid = plugin_dict["i"] plugin = self._pmgr.get_plugin(pid) if plugin: # check for an already registered plugin LOG.debug("Comparing %s > %s", version_str_to_tup(plugin_dict["v"], 3), version_str_to_tup(plugin.version, 3)) # Check for a update if (version_str_to_tup(plugin_dict["v"], 3) > version_str_to_tup(plugin.version, 3)): LOG.debug("Update for '%s'...", plugin_dict["z"]) updateable.append(pid) else: # current plugin is up to date. LOG.debug(" '%s' is up to date", plugin_dict["n"]) else: # new addon LOG.debug(" '%s' is not installed", plugin_dict["n"]) hidden = pid in self.hidden status_str = _("*Available") status = AVAILABLE if hidden: status_str = "<s>%s</s>" % status_str status |= HIDDEN row = [_(plugin_dict["t"]), status_str, markup_escape_text(plugin_dict["n"]), markup_escape_text(plugin_dict["d"]), plugin_dict["i"], status] addons.append(row) fail_list = self._pmgr.get_fail_list() for (_type, typestr) in PTYPE_STR.items(): for pdata in self._preg.type_plugins(_type): # model: plugintype, hidden, pluginname, plugindescr, pluginid if 'gramps/plugins' in pdata.fpath.replace('\\', '/'): status_str = _("Built-in") status = BUILTIN if not self._show_builtins: continue else: status_str = _("*Installed") status = INSTALLED # i = (filename, (exception-type, exception, traceback), pdata) for i in fail_list: if pdata == i[2]: status_str += ', ' + '<span color="red">%s</span>' % \ _("Failed") break if pdata.id in updateable: status_str += ', ' + _("Update Available") status |= UPDATE hidden = pdata.id in self.hidden if hidden: status_str = "<s>%s</s>" % status_str status |= HIDDEN addons.append([typestr, status_str, markup_escape_text(pdata.name), markup_escape_text(pdata.description), pdata.id, status]) for row in sorted(addons, key=itemgetter(R_TYPE, R_NAME)): if self._show_hidden or (row[R_ID] not in self.hidden): self._model_reg.append(row) self._selection_reg.select_path('0')
"required for this view to work") logging.log(logging.WARNING, warn_msg) # don't start GUI if in CLI mode, just ignore if not (_GOO and _DOT) and locals().get('uistate'): from gramps.gui.dialog import QuestionDialog2 if 'graphviewwarn' not in sects: yes_no = QuestionDialog2( _("Graphview Failed to Load"), _("\n\nGraphview is missing python modules or programs.\n" "%smust be installed.\n\n" "For now, it may be possible to install the files manually." " See\n<a href=\"https://gramps-project.org/wiki/index.php?" "title=Graph_View\" " "title=\"https://gramps-project.org/wiki/index.php?" "title=Graph_View\">https://gramps-project.org/wiki/index.php?" "title=Graph_View</a> \n\n" "To dismiss all future Graphview warnings click Dismiss.") % ('' if _DOT else "GraphViz (<a href=\"http://www.graphviz.org\" " "title=\"http://www.graphviz.org\">" "http://www.graphviz.org</a>)\n") + ('' if _GOO else "Goocanvas 2 (<a " "href=\"https://wiki.gnome.org/action/show/Projects/GooCanvas\" " "title=\"https://wiki.gnome.org/action/show/Projects/GooCanvas\">" "https://wiki.gnome.org/action/show/Projects/GooCanvas</a>)\n"), _(" Dismiss "), _("Continue"), parent=uistate.window) prompt = yes_no.run() if prompt is True: inifile.register('graphviewwarn.MissingModules', "") inifile.set('graphviewwarn.MissingModules', "True") inifile.save()
from gramps.gen.config import logging if not module1: warn_msg = _( "NetworkChart Warning: Python networkx module not found.") logging.log(logging.WARNING, warn_msg) if not (module2 or module3): warn_msg = _( "NetworkChart Warning: NetworkChart needs one of the following to work: \n" " Python module pydotplus OR\n" " Python module pygraphviz OR\n") logging.log(logging.WARNING, warn_msg) inifile = config.register_manager("networkchartwarn") inifile.load() sects = inifile.get_sections() if 'networkchartwarn' not in sects: yes_no = QuestionDialog2( _("NetworkChart Failed to Load"), _("\n\nNetworkChart is missing python modules or programs. Networkx AND at\n" "least one of (pydotplus OR pygraphviz) must be\n" "installed. For now, it may be possible to install the files manually. See\n\n" "https://gramps-project.org/wiki/index.php?title=NetworkChart \n\n" "To dismiss all future NetworkChart warnings click Dismiss."), _(" Dismiss "), _("Continue"), parent=uistate.window) prompt = yes_no.run() if prompt is True: inifile.register('networkchartwarn.MissingModules', "") inifile.set('networkchartwarn.MissingModules', "True") inifile.save()
) from gramps.gen.config import logging if not dbfavailable: warn_msg = _("TMG Importer Warning: DBF " "(https://pypi.python.org/pypi/dbf)" " is required for this importer to work") logging.log(logging.WARNING, warn_msg) # don't start GUI if in CLI mode, just ignore if not dbfavailable and locals().get('uistate'): from gramps.gui.dialog import QuestionDialog2 if 'tmgimporterwarn' not in sects: yes_no = QuestionDialog2( _("TMG Importer Failed to Load"), _("\n\nTMG Importer is missing the DBF python module.\n" "DBF must be installed ( https://pypi.python.org/pypi/dbf ).\n\n" "For more information see\n<a href=\"https://gramps-project.org/wiki/index.php?" "title=Addon:TMGimporter\" " "title=\"https://gramps-project.org/wiki/index.php?" "title=Addon:TMGimporter\">https://gramps-project.org/wiki/index.php?" "title=Addon:TMGimporter</a> \n\n" "To dismiss all future TMG Importer warnings click Dismiss."), _(" Dismiss "), _("Continue"), parent=uistate.window) prompt = yes_no.run() if prompt is True: inifile.register('tmgimporterwarn.MissingModules', "") inifile.set('tmgimporterwarn.MissingModules', "True") inifile.save()
def calc_url(self): """ Creates a file for use with GoogleEarth and launches GoogleEarth if in system """ home_dir = os.path.expanduser("~") default_filename = 'GrampsPlacesForGoogleEarth' filename = os.path.join(home_dir, default_filename) if not _GOOGLEEARTH_OK: qd2 = QuestionDialog2( _("GoogleEarth not installed!"), (_("Create kmz/kml file ''%s''\n" "in user directory ''%s''?")\ % (default_filename, home_dir)), _("Yes"), _("No")) if not qd2.run(): return base = os.path.dirname(filename) # Check if directory exists if not os.path.exists(os.path.normpath(base)): ErrorDialog((_("Failure writing to %s") % base), _("Directory does not exist")) return full_filename = filename + ".kml" zip_filename = filename + ".kmz" home_dir = home_dir #get_unicode_path_from_env_var(home_dir) # Check if kml/kmz file exits if os.path.exists(full_filename) or os.path.exists(zip_filename): qd2 = QuestionDialog2( _("GoogleEarth file exists!"), (_("Overwrite kmz/kml file ''%s''\n" "in user home directory ''%s''?")\ % (default_filename, home_dir)), _("Yes"), _("No")) if not qd2.run(): return # Delete olf zipped file before a new kmz. elif os.path.exists(zip_filename): os.remove(zip_filename) kml_file = open(full_filename, "wb") self.kml_file = codecs.getwriter("utf8")(kml_file) self.write_kml_head() self.write_kml_point_data() self.write_kml_tail() kml_file.close() if _ZIP_OK: os.system("zip -q %s %s" % (zip_filename, full_filename)) # Run GoogleEarth if on system, else keep created file if _GOOGLEEARTH_OK: if _ZIP_OK: open_file_with_default_application(zip_filename, self.uistate) else: open_file_with_default_application(full_filename, self.uistate) # Remove the unzipped file. if _ZIP_OK: os.remove(full_filename) return
status=STABLE, fname='postgresql.py', databaseclass='PostgreSQL', authors=['Doug Blank'], authors_email=['*****@*****.**']) elif locals().get('uistate'): # don't start GUI if in CLI mode, just ignore from gramps.gen.config import config from gramps.gui.dialog import QuestionDialog2 from gramps.gen.config import logging if not module1: warn_msg = _("PostgreSQL Warning: Python psycopg2 module not found.") logging.log(logging.WARNING, warn_msg) inifile = config.register_manager("postgresqlwarn") inifile.load() sects = inifile.get_sections() if 'postgresqlwarn' not in sects: yes_no = QuestionDialog2( _("PostgreSQL Failed to Load"), _("\n\nPostgreSQL is missing the psycopg2 python module.\n" "For now, it may be possible to install the files manually. See\n\n" "https://gramps-project.org/wiki/index.php?title=PostgreSQL \n\n" "To dismiss all future PostgreSQL warnings click Dismiss."), _(" Dismiss "), _("Continue"), parent=uistate.window) prompt = yes_no.run() if prompt is True: inifile.register('postgresqlwarn.MissingModules', "") inifile.set('postgresqlwarn.MissingModules', "True") inifile.save()
import gi gi.require_version('GeocodeGlib', '1.0') from gi.repository import GeocodeGlib except: if ('placecoordinategramplet_warn' not in sects or not inifile.is_set( 'placecoordinategramplet_warn.missingmodules') or inifile.get('placecoordinategramplet_warn.missingmodules') != 'False'): message = _("Failed to load the required module {module_name}." ).format(module_name="gi.repository.GeocodeGlib") logging.warning(plugin_name + ': ' + message) from gramps.gui.dialog import QuestionDialog2 warn_dialog = QuestionDialog2(plugin_name + ' Plugin', message, _("Don't show again"), _("OK"), parent=_uistate.window) if warn_dialog.run(): inifile.register('placecoordinategramplet_warn.missingmodules', "") inifile.set('placecoordinategramplet_warn.missingmodules', "False") inifile.save() some_import_error = True # break # # now test to make sure that we can actually perform a search. If there # # is a problem with connectivity this will fail # try: # location_ = GeocodeGlib.Forward.new_for_string("Berlin")