def __init__(self, *args, **kwargs): super(RefinementView, self).__init__(*args, **kwargs) # Add the status box self._builder.add_from_file(self.refine_status_builder) self._add_child_view(self[self.refine_status_toplevel], self[self.refine_status_container]) # Add the method and options box self._builder.add_from_file(self.refine_method_builder) self._add_child_view(self[self.refine_method_toplevel], self[self.refine_method_container]) # Add the refinement thread box self.refine_spin_box = ThreadedTaskBox() self._add_child_view(self.refine_spin_box, self[self.refine_spin_container]) self.hide_refinement_info()
def on_accept(dialog): ## TODO MOVE THIS (PARTIALLY?) TO THE MODEL LEVEL ## filenames = dialog.get_filenames() parser = dialog.get_filter().get_data("parser") task = ThreadedTaskBox() window = DialogFactory.get_custom_dialog( task, parent=self.view.get_top_widget()) # Status: status_dict = dict(total_files=len(filenames), current_file=0, specimens=[]) # Task: def load_specimens(stop=None): for filename in filenames: if stop is not None and stop.is_set(): return try: specimens = Specimen.from_experimental_data( filename=filename, parent=self.model, parser=parser) except Exception as msg: message = "An unexpected error has occurred when trying to parse %s:\n\n<i>" % os.path.basename( filename) message += str(msg) + "</i>\n\n" message += "This is most likely caused by an invalid or unsupported file format." logger.exception(message) @run_when_idle def run_dialog(): DialogFactory.get_information_dialog( message=message, parent=self.view.get_top_widget()).run() return False run_dialog() else: status_dict["specimens"] += specimens status_dict["current_file"] += 1 # Cancel & stop events: def on_interrupted(*args, **kwargs): window.hide() # Status label update: def gui_callback(): task.set_status( "Loading file %d/%d ..." % (status_dict["current_file"], status_dict["total_files"])) return True gui_timeout_id = gobject.timeout_add(250, gui_callback) # Complete event: @run_when_idle def on_complete(*args, **kwargs): last_iter = None for specimen in status_dict["specimens"]: last_iter = self.model.specimens.append(specimen) if last_iter is not None: self.view["project_specimens"].set_cursor(last_iter) gobject.source_remove(gui_timeout_id) window.hide() window.destroy() # Run task box: task.connect("cancelrequested", on_interrupted) task.connect("stoprequested", on_interrupted) task.set_status("Loading ...") task.start() window.show_all() # Run thread: self.thread = CancellableThread(load_specimens, on_complete) self.thread.start()
class RefinementView(DialogView): title = "Refine Phase Parameters" subview_builder = resource_filename(__name__, "glade/refinement.glade") subview_toplevel = "refine_params" modal = True refine_status_builder = resource_filename(__name__, "glade/refine_status.glade") refine_status_toplevel = "tbl_refine_info" refine_status_container = "refine_status_box" refine_spin_container = "refine_spin_box" refine_spin_box = None refine_method_builder = resource_filename(__name__, "glade/refine_method.glade") refine_method_toplevel = "tbl_refine_method" refine_method_container = "refine_method_box" def __init__(self, *args, **kwargs): super(RefinementView, self).__init__(*args, **kwargs) # Add the status box self._builder.add_from_file(self.refine_status_builder) self._add_child_view(self[self.refine_status_toplevel], self[self.refine_status_container]) # Add the method and options box self._builder.add_from_file(self.refine_method_builder) self._add_child_view(self[self.refine_method_toplevel], self[self.refine_method_container]) # Add the refinement thread box self.refine_spin_box = ThreadedTaskBox() self._add_child_view(self.refine_spin_box, self[self.refine_spin_container]) self.hide_refinement_info() def connect_cancel_request(self, callback): return self.refine_spin_box.connect("cancelrequested", callback) def show_refinement_info(self,): self["hbox_actions"].set_sensitive(False) self["btn_auto_restrict"].set_sensitive(False) self[self.refine_method_toplevel].set_sensitive(False) self["refinables"].set_visible(False) self["refinables"].set_no_show_all(True) self[self.refine_status_toplevel].show_all() def hide_refinement_info(self): self[self.refine_status_toplevel].hide() self["hbox_actions"].set_sensitive(True) self["btn_auto_restrict"].set_sensitive(True) self[self.refine_method_toplevel].set_sensitive(True) self["refinables"].set_visible(True) self["refinables"].set_no_show_all(False) def update_refinement_info(self, current_rp=None, message=None): if not isnan(current_rp): self["current_residual"].set_text("%.2f" % current_rp) self["message"].set_text(not_none(message, "")) def update_refinement_status(self, status): self.refine_spin_box.set_status(status) def start_spinner(self): self.refine_spin_box.start() def stop_spinner(self): self.refine_spin_box.stop() pass # end of class
def on_accept(dialog): ## TODO MOVE THIS (PARTIALLY?) TO THE MODEL LEVEL ## filenames = dialog.get_filenames() parser = dialog.get_filter().get_data("parser") task = ThreadedTaskBox() window = self.get_custom_dialog(task, parent=self.view.get_top_widget()) # Status: status_dict = dict( total_files=len(filenames), current_file=0, specimens=[] ) # Task: def load_specimens(stop=None): for filename in filenames: if stop is not None and stop.is_set(): return try: specimens = Specimen.from_experimental_data(filename=filename, parent=self.model, parser=parser) except Exception as msg: message = "An unexpected error has occurred when trying to parse %s:\n\n<i>" % os.path.basename(filename) message += str(msg) + "</i>\n\n" message += "This is most likely caused by an invalid or unsupported file format." logger.exception(message) @run_when_idle def run_dialog(): self.run_information_dialog( message=message, parent=self.view.get_top_widget() ) return False run_dialog() else: status_dict["specimens"] += specimens status_dict["current_file"] += 1 # Cancel & stop events: def on_interrupted(*args, **kwargs): window.hide() # Status label update: def gui_callback(): task.set_status("Loading file %d/%d ..." % ( status_dict["current_file"], status_dict["total_files"] )) return True gui_timeout_id = gobject.timeout_add(250, gui_callback) # Complete event: @run_when_idle def on_complete(*args, **kwargs): last_iter = None for specimen in status_dict["specimens"]: last_iter = self.model.specimens.append(specimen) if last_iter is not None: self.view["project_specimens"].set_cursor(last_iter) gobject.source_remove(gui_timeout_id) window.hide() window.destroy() # Run task box: task.connect("cancelrequested", on_interrupted) task.connect("stoprequested", on_interrupted) task.set_status("Loading ...") task.start() window.show_all() # Run thread: self.thread = CancellableThread(load_specimens, on_complete) self.thread.start()
class RefinementView(DialogView): title = "Refine Phase Parameters" subview_builder = resource_filename(__name__, "glade/refinement.glade") subview_toplevel = "refine_params" modal = True refine_status_builder = resource_filename(__name__, "glade/refine_status.glade") refine_status_toplevel = "tbl_refine_info" refine_status_container = "refine_status_box" refine_spin_container = "refine_spin_box" refine_spin_box = None refine_method_builder = resource_filename(__name__, "glade/refine_method.glade") refine_method_toplevel = "tbl_refine_method" refine_method_container = "refine_method_box" def __init__(self, *args, **kwargs): super(RefinementView, self).__init__(*args, **kwargs) # Add the status box self._builder.add_from_file(self.refine_status_builder) self._add_child_view(self[self.refine_status_toplevel], self[self.refine_status_container]) # Add the method and options box self._builder.add_from_file(self.refine_method_builder) self._add_child_view(self[self.refine_method_toplevel], self[self.refine_method_container]) # Add the refinement thread box self.refine_spin_box = ThreadedTaskBox() self._add_child_view(self.refine_spin_box, self[self.refine_spin_container]) self.hide_refinement_info() def connect_cancel_request(self, callback): return self.refine_spin_box.connect("cancelrequested", callback) def show_refinement_info(self, ): self["hbox_actions"].set_sensitive(False) self["btn_auto_restrict"].set_sensitive(False) self[self.refine_method_toplevel].set_sensitive(False) self["refinables"].set_visible(False) self["refinables"].set_no_show_all(True) self[self.refine_status_toplevel].show_all() def hide_refinement_info(self): self[self.refine_status_toplevel].hide() self["hbox_actions"].set_sensitive(True) self["btn_auto_restrict"].set_sensitive(True) self[self.refine_method_toplevel].set_sensitive(True) self["refinables"].set_visible(True) self["refinables"].set_no_show_all(False) def update_refinement_info(self, current_rp=None, message=None, server_status=None): if not isnan(current_rp): self["current_residual"].set_text("%.2f" % current_rp) self["message"].set_text(not_none(message, "")) self.update_server_status(server_status) def update_server_status(self, server_status): color, title, descr = server_status self["lbl_server_status"].set_markup( "<span foreground=\"%s\">%s</span>" % (color, title)) self["lbl_server_status"].set_property("tooltip-text", descr) self["lbl_server_status"].set_property("tooltip-text", descr) self["lbl_server_status"].set_tooltip_text(descr) def update_refinement_status(self, status): self.refine_spin_box.set_status(status) def start_spinner(self): self.refine_spin_box.start() def stop_spinner(self): self.refine_spin_box.stop() pass # end of class