def _on_done(self, source, condition): #print >> sys.stderr, "ZEOBUILDER, _on_done" self.response_active = True for button in self.buttons: button.set_sensitive(True) # make sure there is not output is left unnoticed. try: while True: self._on_receive_out(0, 0) except EOFError: pass try: while True: self._on_receive_err(0, 0) except EOFError: pass retcode = self.process.wait() if retcode != 0: ok_error( "An error occured in the child process.", "\n".join(self.error_lines) ) if self.auto_close: #print >> sys.stderr, "ZEOBUILDER, auto_close dialog" self.dialog.response(gtk.RESPONSE_OK) #print >> sys.stderr, "ZEOBUILDER, release io_watch" for source in self.event_sources: gobject.source_remove(source) return False
def _on_done(self, source, condition): #print >> sys.stderr, "ZEOBUILDER, _on_done" self.response_active = True for button in self.buttons: button.set_sensitive(True) # make sure there is not output is left unnoticed. try: while True: self._on_receive_out(0, 0) except EOFError: pass try: while True: self._on_receive_err(0, 0) except EOFError: pass retcode = self.process.wait() if retcode != 0: ok_error("An error occured in the child process.", "\n".join(self.error_lines)) if isinstance(context.application, TestApplication): #print >> sys.stderr, "ZEOBUILDER, auto_close dialog" self.dialog.response(gtk.RESPONSE_OK) #print >> sys.stderr, "ZEOBUILDER, release io_watch" for source in self.event_sources: gobject.source_remove(source) return False
def on_key_edited(self, cell, path, new_text): iter = self.list_store.get_iter_from_string(path) iter_test = self.list_store.get_iter_first() while iter_test is not None: path_test = self.list_store.get_string_from_iter(iter_test) if path != path_test and self.list_store.get_value(iter_test, 0) == new_text: ok_error("The keys must be unique.") return iter_test = self.list_store.iter_next(iter_test) self.list_store.set_value(iter, 0, new_text)
def select_path(self, path): node = context.application.model[path][0] is_selected = self.tree_selection.path_is_selected(path) try: if not (is_selected or (not self.filter_active) or self.filter_expression(node)): return False except Exception, e: ok_error( "An error occured while evaluating the filter expression.", "This is probably due to a mistake in the expression you entered. The selection filter will be deactivated.\n\n%s\n%s" % (e.__class__, e)) self.filter_active = False
def select_path(self, path): node = context.application.model[path][0] is_selected = self.tree_selection.path_is_selected(path) try: if not ( is_selected or (not self.filter_active) or self.filter_expression(node) ): return False except Exception, e: ok_error( "An error occured while evaluating the filter expression.", "This is probably due to a mistake in the expression you entered. The selection filter will be deactivated.\n\n%s\n%s" % (e.__class__, e) ) self.filter_active = False
def do_expressions(self): atom_values = [] try: for atom in self.graph.nodes: atom_values.append(self.atom_expression(atom, self.graph)) except: exc_type, exc_value, tb = sys.exc_info() err_msg = "".join(traceback.format_exception(exc_type, exc_value, tb)) ok_error( "An error occured while evaluating the shell and atom expressions.", err_msg, line_wrap=False ) self.hide = False return None return atom_values
def do_expressions(self): atom_values = [] try: for atom in self.graph.nodes: atom_values.append(self.atom_expression(atom, self.graph)) except: exc_type, exc_value, tb = sys.exc_info() err_msg = "".join( traceback.format_exception(exc_type, exc_value, tb)) ok_error( "An error occured while evaluating the shell and atom expressions.", err_msg, line_wrap=False) self.hide = False return None return atom_values
def run_file_dialog(file_dialog, file_function, *args): from zeobuilder.models import FilenameError from zeobuilder.gui.simple import ok_error success = False current_dir = context.application.main.get_current_directory() if current_dir is not None: file_dialog.set_current_folder(current_dir) if file_dialog.get_property("action") == gtk.FILE_CHOOSER_ACTION_SAVE: current_filename = context.application.model.filename if current_filename is not None: file_dialog.set_current_name(os.path.basename(current_filename)) while file_dialog.run() == gtk.RESPONSE_OK: filename = file_dialog.get_filename() try: file_function(filename, *args) success = True break except (FilterError, FilenameError), e: ok_error(str(e))
class CloneOrder(Immediate): description = "Apply the order of the first selection to all the other." menu_info = MenuInfo("default/_Object:tools/_Molecular:rearrange", "_Clone order", order=(0, 4, 1, 5, 0, 3)) authors = [authors.toon_verstraelen] @staticmethod def analyze_selection(): if not Immediate.analyze_selection(): return False cache = context.application.cache if len(cache.nodes) < 2: return False Frame = context.application.plugins.get_node("Frame") for cls in cache.classes: if not issubclass(cls, Frame): return False return True def do(self): frame_ref = context.application.cache.nodes[0] graph_ref = create_molecular_graph([frame_ref]) try: match_generator = GraphSearch(EqualPattern(graph_ref)) except GraphError, e: raise UserError( "Could not setup a graph match definition to clone the order.") some_failed = False all_failed = True for frame_other in context.application.cache.nodes[1:]: graph_other = create_molecular_graph([frame_other]) try: match = match_generator(graph_other).next() all_failed = False except (StopIteration, GraphError): some_failed = True continue moves = [(index1, graph_other.molecule.atoms[index2]) for index1, index2 in match.forward.iteritems()] moves.sort() for new_index, atom2 in moves: primitive.Move(atom2, frame_other, new_index) if all_failed: raise UserError("None of the atom orders could be cloned.") elif some_failed: ok_error( "Some molecules/frames did not match the first frame, so they are not reordered." )
def show_message(self): ok_error(self.message, self.details, line_wrap=False)