def RunReport(dbstate, uistate, mod_str, name, trans_name, report_str, options_str): dialog_class = TextReportDialog mod = __import__(mod_str) report_class = getattr(mod, report_str) options_class = getattr(mod, options_str) dialog = dialog_class(dbstate, uistate, options_class, name, trans_name) while True: response = dialog.window.run() if response == Gtk.ResponseType.OK: dialog.close() try: user = User() MyReport = report_class(dialog.db, dialog.options, user) def do_report(): MyReport.doc.init() MyReport.begin_report() MyReport.write_report() MyReport.end_report() do_report() if dialog.open_with_app.get_active(): out_file = dialog.options.get_output() open_file_with_default_application(out_file) except Errors.FilterError as msg: (m1, m2) = msg.messages() ErrorDialog(m1, m2) except IOError as msg: ErrorDialog(_("Report could not be created"), str(msg)) except Errors.ReportError as msg: (m1, m2) = msg.messages() ErrorDialog(m1, m2) except Errors.DatabaseError as msg: ErrorDialog(_("Report could not be created"), str(msg)) raise except: LOG.error("Failed to run report.", exc_info=True) break elif response == Gtk.ResponstType.CANCEL: dialog.close() break elif response == Gtk.ResponseType.DELETE_EVENT: #just stop, in ManagedWindow, delete-event is already coupled to #correct action. break #do needed cleanup dialog.db = None dialog.options = None if hasattr(dialog, 'window'): delattr(dialog, 'window') if hasattr(dialog, 'notebook'): delattr(dialog, 'notebook') del dialog
def view_media(self, *obj): """ Launch external viewers for the selected objects. """ for handle in self.selected_handles(): ref_obj = self.dbstate.db.get_media_from_handle(handle) mpath = media_path_full(self.dbstate.db, ref_obj.get_path()) open_file_with_default_application(mpath, self.uistate)
def view_media(self, obj): """ Launch external viewers for the selected objects. """ for handle in self.selected_handles(): ref_obj = self.dbstate.db.get_object_from_handle(handle) mpath = media_path_full(self.dbstate.db, ref_obj.get_path()) open_file_with_default_application(mpath)
def open_containing_folder(self, *obj): """ Launch external viewers for the selected objects. """ for handle in self.selected_handles(): ref_obj = self.dbstate.db.get_media_from_handle(handle) mpath = media_path_full(self.dbstate.db, ref_obj.get_path()) if mpath: mfolder, mfile = os.path.split(mpath) open_file_with_default_application(mfolder, self.uistate)
def open_containing_folder(self, obj): """ Launch external viewers for the selected objects. """ for handle in self.selected_handles(): ref_obj = self.dbstate.db.get_object_from_handle(handle) mpath = media_path_full(self.dbstate.db, ref_obj.get_path()) if mpath: mfolder, mfile = os.path.split(mpath) open_file_with_default_application(mfolder)
def __edit(self, _obj, list_obj): """ Callback function from the "Edit" button """ selection = list_obj.get_selection() model, node = selection.get_selected() if not node: return pid = model.get_value(node, R_ID) pdata = self._preg.get_plugin(pid) if pdata.fpath and pdata.fname: open_file_with_default_application( os.path.join(pdata.fpath, pdata.fname), self.uistate)
def display(self, path): """ Display the given file. """ full_path = media_path_full(self.db, path) open_file_with_default_application(full_path)
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( _(u"GoogleEarth not installed!"), (_(u"Create kmz/kml file ''%s''\n" u"in user directory ''%s''?")\ % (default_filename, home_dir)), _(u"Yes"), _(u"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((_(u"Failure writing to %s") % base), _(u"Directory does not exist")) return full_filename = filename + ".kml" zip_filename = filename + ".kmz" home_dir = conv_to_unicode(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( _(u"GoogleEarth file exists!"), (_(u"Overwrite kmz/kml file ''%s''\n" u"in user home directory ''%s''?")\ % (default_filename, home_dir)), _(u"Yes"), _(u"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) else: open_file_with_default_application(full_filename) # Remove the unzipped file. if _ZIP_OK: os.remove(full_filename) return
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
def display(self, path): """ Display the given file. """ full_path = media_path_full(self.db, path) open_file_with_default_application(full_path, self.uistate)
def view_photo(self, photo): """ Open this picture in the default picture viewer. """ photo_path = media_path_full(self.dbstate.db, photo.get_path()) open_file_with_default_application(photo_path, self.uistate)