def load_components(self, filename): old_comps = self.get_selected_objects() if old_comps: num_oc = len(old_comps) new_comps = list() for comp in Component.load_components(filename, parent=self.model): comp.resolve_json_references() new_comps.append(comp) num_nc = len(new_comps) if num_oc != num_nc: DialogFactory.get_information_dialog( "The number of components to import must equal the number of selected components!" ).run() return else: self.select_object(None) logger.info("Importing components...") # replace component(s): for old_comp, new_comp in zip(old_comps, new_comps): i = self.model.components.index(old_comp) self.model.components[i] = new_comp else: DialogFactory.get_information_dialog( "No components selected to replace!" ).run()
def on_composition_clicked(self, widget, *args): comp = "The composition of the specimens in this mixture:\n\n\n" comp += "<span font-family=\"monospace\">" # get the composition matrix (first columns contains strings with elements, others are specimen compositions) import re for row in self.model.get_composition_matrix(): comp += "%s %s\n" % (re.sub(r'(\d+)', r'<sub>\1</sub>', row[0]), " ".join(row[1:])) comp += "</span>" DialogFactory.get_information_dialog( comp, parent=self.view.get_toplevel()).run()
def on_composition_clicked(self, widget, *args): comp = "The composition of the specimens in this mixture:\n\n\n" comp += "<span font-family=\"monospace\">" # get the composition matrix (first columns contains strings with elements, others are specimen compositions) import re for row in self.model.get_composition_matrix(): comp += "%s %s\n" % (re.sub(r'(\d+)', r'<sub>\1</sub>', row[0]), " ".join(row[1:])) comp += "</span>" DialogFactory.get_information_dialog( comp, parent=self.view.get_toplevel() ).run()
def on_accept(dialog): filename = dialog.filename parser = dialog.parser try: line.save_data(parser, filename, **self.model.get_export_meta_data()) except Exception: message = "An unexpected error has occured when trying to save to '%s'." % os.path.basename( filename) DialogFactory.get_information_dialog( message=message, parent=self.view.get_toplevel()).run() raise
def on_accept(dialog): filename = dialog.filename parser = dialog.parser try: self.model.raw_pattern.load_data(parser, filename, clear=True) except Exception: message = "An unexpected error has occured when trying to parse '%s'.\n" % os.path.basename( filename) message += "This is most likely caused by an invalid or unsupported file format." DialogFactory.get_information_dialog( message=message, parent=self.view.get_toplevel()).run() raise
def parse_x_pos(x_pos, event): # Clear the eye dropper controller self.edc.enabled = False self.edc.disconnect() del self.edc # Get experimental data at the sampled point exp_y = self.model.current_specimen.experimental_pattern.get_y_at_x(x_pos) message = "Sampled point:\n" message += "\tExperimental data:\t( %.4f , %.4f )\n" % (x_pos, exp_y) # Get calculated data if applicable if self.model.current_project.layout_mode == "FULL": calc_y = self.model.current_specimen.calculated_pattern.get_y_at_x(x_pos) message += "\tCalculated data:\t\t( %.4f , %.4f )" % (x_pos, calc_y) # Display message dialog DialogFactory.get_information_dialog( message, parent=self.view.get_toplevel() ).run()
def on_refine_clicked(self, event): with self.model.mixture.needs_update.hold(): with self.model.mixture.data_changed.hold(): if len(self.model.mixture.specimens) > 0: # Create the refiner object with DialogFactory.error_dialog_handler( "There was an error when creating the refinement setup:\n{}", parent=self.view.get_toplevel(), reraise=False): refiner = self.model.get_refiner() # Setup results controller self.results_view = RefinerView( parent=self.view.parent) self.results_controller = RefinerController( refiner=refiner, model=self.model, view=self.results_view, parent=self) # Gtk timeout loop for our GUI updating: gui_timeout_id = self._launch_gui_updater(refiner) # This creates a thread that will run the refiner.refine method: thread = self._launch_refine_thread( refiner, gui_timeout_id) # Connect the cancel button: self._connect_cancel_button(refiner, gui_timeout_id, thread) # Show the context updates in the gui: self.view.show_refinement_info() self.view.start_spinner() else: DialogFactory.get_information_dialog( "Cannot refine an empty mixture!", parent=self.view.get_toplevel()).run()
def on_refine_clicked(self, event): with self.model.mixture.needs_update.hold(): with self.model.mixture.data_changed.hold(): if len(self.model.mixture.specimens) > 0: # Create the refiner object with DialogFactory.error_dialog_handler( "There was an error when creating the refinement setup:\n{}", parent=self.view.get_toplevel(), reraise=False): refiner = self.model.get_refiner() # Setup results controller self.results_view = RefinerView(parent=self.view.parent) self.results_controller = RefinerController( refiner=refiner, model=self.model, view=self.results_view, parent=self ) # Gtk timeout loop for our GUI updating: gui_timeout_id = self._launch_gui_updater(refiner) # This creates a thread that will run the refiner.refine method: thread = self._launch_refine_thread(refiner, gui_timeout_id) # Connect the cancel button: self._connect_cancel_button(refiner, gui_timeout_id, thread) # Show the context updates in the gui: self.view.show_refinement_info() self.view.start_spinner() else: DialogFactory.get_information_dialog( "Cannot refine an empty mixture!", parent=self.view.get_toplevel() ).run()
def run_dialog(): DialogFactory.get_information_dialog( message=message, parent=self.view.get_top_widget()).run() return False
def _run_gui(project=None): # Display a splash screen showing the loading status... from pkg_resources import resource_filename # @UnresolvedImport from pyxrd.application.splash import SplashScreen from pyxrd import __version__ filename = resource_filename(__name__, "application/icons/pyxrd.png") splash = SplashScreen(filename, __version__) # Run GUI: splash.set_message("Checking for updates ...") update_available, nv, cv = check_for_updates() splash.set_message("Loading GUI ...") # Now we can load these: from pyxrd.data import settings from pyxrd.file_parsers.json_parser import JSONParser from pyxrd.application.models import AppModel from pyxrd.application.views import AppView from pyxrd.application.controllers import AppController # TODO move this to mvc: from pyxrd.generic.gtk_tools.gtkexcepthook import plugin_gtk_exception_hook filename = settings.ARGS.filename #@UndefinedVariable # Check if a filename was passed, if so try to load it if filename != "": try: logging.info("Opening project: %s" % filename) project = JSONParser.parse(filename) except IOError: logging.info("Could not load project file %s: IOError" % filename) # FIXME the user should be informed of this in a dialog... # Disable unity overlay scrollbars as they cause bugs with modal windows os.environ['LIBOVERLAY_SCROLLBAR'] = '0' os.environ['UBUNTU_MENUPROXY'] = "" if not settings.DEBUG: warnings.filterwarnings(action='ignore', category=Warning) # Close splash screen if splash: splash.close() # Nice GUI error handler: gtk_exception_hook = plugin_gtk_exception_hook() # setup MVC: m = AppModel(project=project) v = AppView() AppController(m, v, gtk_exception_hook=gtk_exception_hook) # Free this before continuing del splash if update_available: from mvc.adapters.gtk_support.dialogs.dialog_factory import DialogFactory DialogFactory.get_information_dialog( "An update is available (%s) - consider upgrading!" % nv, False, v.get_toplevel(), title = "Update available" ).run() else: print("PyXRD is up to date (current = %s)" % cv) # lets get this show on the road: start_event_loop()
def _run_gui(project=None): # Display a splash screen showing the loading status... from pkg_resources import resource_filename # @UnresolvedImport from pyxrd.application.splash import SplashScreen from pyxrd import __version__ filename = resource_filename(__name__, "application/icons/pyxrd.png") splash = SplashScreen(filename, __version__) # Run GUI: splash.set_message("Checking for updates ...") update_available, nv, cv = check_for_updates() splash.set_message("Loading GUI ...") # Now we can load these: from pyxrd.data import settings from pyxrd.file_parsers.json_parser import JSONParser from pyxrd.application.models import AppModel from pyxrd.application.views import AppView from pyxrd.application.controllers import AppController # TODO move this to mvc: from pyxrd.generic.gtk_tools.gtkexcepthook import plugin_gtk_exception_hook filename = settings.ARGS.filename #@UndefinedVariable # Check if a filename was passed, if so try to load it if filename != "": try: logging.info("Opening project: %s" % filename) project = JSONParser.parse(filename) except IOError: logging.info("Could not load project file %s: IOError" % filename) # FIXME the user should be informed of this in a dialog... # Disable unity overlay scrollbars as they cause bugs with modal windows os.environ['LIBOVERLAY_SCROLLBAR'] = '0' os.environ['UBUNTU_MENUPROXY'] = "" if not settings.DEBUG: warnings.filterwarnings(action='ignore', category=Warning) # Close splash screen if splash: splash.close() # Nice GUI error handler: gtk_exception_hook = plugin_gtk_exception_hook() # setup MVC: m = AppModel(project=project) v = AppView() AppController(m, v, gtk_exception_hook=gtk_exception_hook) # Free this before continuing del splash if update_available: from mvc.adapters.gtk_support.dialogs.dialog_factory import DialogFactory DialogFactory.get_information_dialog( "An update is available (%s) - consider upgrading!" % nv, False, v.get_toplevel(), title="Update available").run() else: print("PyXRD is up to date (current = %s)" % cv) # lets get this show on the road: start_event_loop()