def error_handler(message=None, exc_info=None): exc_type, exc_value, exc_traceback = exc_info or sys.exc_info() if not exc_type: return if not message: message = _('An error occured.') buttons = gtk.BUTTONS_OK message = '%s\n\nTechnical details:\n\t%s\n\t%s' % (message, exc_type, exc_value) if __debug__ and sys.stdin.isatty(): buttons = gtk.BUTTONS_YES_NO message += _( '\n\nDo you want to debug?\n(Gaphor should have been started from the command line)' ) dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, buttons, message) answer = dialog.run() dialog.destroy() if answer == gtk.RESPONSE_YES: pdb.post_mortem(exc_traceback)
def error_handler(message=None, exc_info=None): exc_type, exc_value, exc_traceback = exc_info or sys.exc_info() if not exc_type: return if not message: message = _("An error occurred.") buttons = Gtk.ButtonsType.OK message = "%s\n\nTechnical details:\n\t%s\n\t%s" % (message, exc_type, exc_value) if __debug__ and sys.stdin.isatty(): buttons = Gtk.ButtonsType.YES_NO message += _( "\n\nDo you want to debug?\n(Gaphor should have been started from the command line)" ) dialog = Gtk.MessageDialog( None, Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, Gtk.MessageType.ERROR, buttons, message, ) answer = dialog.run() dialog.destroy() if answer == Gtk.ResponseType.YES: pdb.post_mortem(exc_traceback)
def error_handler(message=None, exc_info=None): exc_type, exc_value, exc_traceback = exc_info or sys.exc_info() if not exc_type: return if not message: message = _('An error occured.') buttons = gtk.BUTTONS_OK message = '%s\n\nTechnical details:\n\t%s\n\t%s' % (message, exc_type, exc_value) if __debug__ and sys.stdin.isatty(): buttons = gtk.BUTTONS_YES_NO message += _('\n\nDo you want to debug?\n(Gaphor should have been started from the command line)') dialog = gtk.MessageDialog(None, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, buttons, message) answer = dialog.run() dialog.destroy() if answer == gtk.RESPONSE_YES: pdb.post_mortem(exc_traceback)
def load_elements_generator(elements, factory, gaphor_version=None): """ Load a file and create a model if possible. Exceptions: IOError, ValueError. """ # TODO: restructure loading code, first load model, then add canvas items log.debug(_("Loading %d elements...") % len(elements)) # The elements are iterated three times: size = len(elements) * 3 def update_status_queue(_n=[0]): n = _n[0] = _n[0] + 1 if n % 30 == 0: return (n * 100) / size # First create elements and canvas items in the factory # The elements are stored as attribute 'element' on the parser objects: def create_canvasitems(canvas, canvasitems, parent=None): """ Canvas is a read gaphas.Canvas, items is a list of parser.canvasitem's """ for item in canvasitems: cls = getattr(items, item.type) item.element = diagram.create_as(cls, item.id) canvas.add(item.element, parent=parent) assert canvas.get_parent(item.element) is parent create_canvasitems(canvas, item.canvasitems, parent=item.element) for id, elem in list(elements.items()): st = update_status_queue() if st: yield st if isinstance(elem, parser.element): cls = getattr(UML, elem.type) # log.debug('Creating UML element for %s (%s)' % (elem, elem.id)) elem.element = factory.create_as(cls, id) if elem.canvas is not None: elem.element.canvas.block_updates = True create_canvasitems(elem.element.canvas, elem.canvas.canvasitems) elif not isinstance(elem, parser.canvasitem): raise ValueError( 'Item with id "%s" and type %s can not be instantiated' % (id, type(elem)) ) # load attributes and create references: for id, elem in list(elements.items()): st = update_status_queue() if st: yield st # Ensure that all elements have their element instance ready... assert hasattr(elem, "element") # load attributes and references: for name, value in list(elem.values.items()): try: elem.element.load(name, value) except: log.error( "Loading value %s (%s) for element %s failed." % (name, value, elem.element) ) raise for name, refids in list(elem.references.items()): if isinstance(refids, list): for refid in refids: try: ref = elements[refid] except: raise ValueError( "Invalid ID for reference (%s) for element %s.%s" % (refid, elem.type, name) ) else: try: elem.element.load(name, ref.element) except: log.error( "Loading %s.%s with value %s failed" % (type(elem.element).__name__, name, ref.element.id) ) raise else: try: ref = elements[refids] except: raise ValueError("Invalid ID for reference (%s)" % refids) else: try: elem.element.load(name, ref.element) except: log.error( "Loading %s.%s with value %s failed" % (type(elem.element).__name__, name, ref.element.id) ) raise # Before version 0.7.2 there was only decision node (no merge nodes). # This node could have many incoming and outgoing flows (edges). # According to UML specification decision node has no more than one # incoming node. # # Now, we have implemented merge node, which can have many incoming # flows. We also support combining of decision and merge nodes as # described in UML specification. # # Data model, loaded from file, is updated automatically, so there is # no need for special function. for d in factory.select(lambda e: isinstance(e, UML.Diagram)): # update_now() is implicitly called when lock is released d.canvas.block_updates = False # do a postload: for id, elem in list(elements.items()): st = update_status_queue() if st: yield st elem.element.postload()
def load_elements_generator(elements, factory, gaphor_version=None): """ Load a file and create a model if possible. Exceptions: IOError, ValueError. """ # TODO: restructure loading code, first load model, then add canvas items log.debug(_('Loading %d elements...') % len(elements)) # The elements are iterated three times: size = len(elements) * 3 def update_status_queue(_n=[0]): n = _n[0] = _n[0] + 1 if n % 30 == 0: return (n * 100) / size #log.info('0%') # Fix version inconsistencies version_0_6_2(elements, factory, gaphor_version) version_0_7_2(elements, factory, gaphor_version) version_0_9_0(elements, factory, gaphor_version) version_0_14_0(elements, factory, gaphor_version) version_0_15_0_pre(elements, factory, gaphor_version) #log.debug("Still have %d elements" % len(elements)) # First create elements and canvas items in the factory # The elements are stored as attribute 'element' on the parser objects: def create_canvasitems(canvas, canvasitems, parent=None): """ Canvas is a read gaphas.Canvas, items is a list of parser.canvasitem's """ for item in canvasitems: cls = getattr(items, item.type) item.element = diagram.create_as(cls, item.id) canvas.add(item.element, parent=parent) assert canvas.get_parent(item.element) is parent create_canvasitems(canvas, item.canvasitems, parent=item.element) for id, elem in elements.items(): st = update_status_queue() if st: yield st if isinstance(elem, parser.element): cls = getattr(UML, elem.type) #log.debug('Creating UML element for %s (%s)' % (elem, elem.id)) elem.element = factory.create_as(cls, id) if elem.canvas: elem.element.canvas.block_updates = True create_canvasitems(elem.element.canvas, elem.canvas.canvasitems) elif not isinstance(elem, parser.canvasitem): raise ValueError, 'Item with id "%s" and type %s can not be instantiated' % (id, type(elem)) # load attributes and create references: for id, elem in elements.items(): st = update_status_queue() if st: yield st # Ensure that all elements have their element instance ready... assert hasattr(elem, 'element') # load attributes and references: for name, value in elem.values.items(): try: elem.element.load(name, value) except: log.error('Loading value %s (%s) for element %s failed.' % (name, value, elem.element)) raise for name, refids in elem.references.items(): if type(refids) == type([]): for refid in refids: try: ref = elements[refid] except: raise ValueError, 'Invalid ID for reference (%s) for element %s.%s' % (refid, elem.type, name) else: try: elem.element.load(name, ref.element) except: log.error('Loading %s.%s with value %s failed' % (type(elem.element).__name__, name, ref.element.id)) raise else: try: ref = elements[refids] except: raise ValueError, 'Invalid ID for reference (%s)' % refids else: try: elem.element.load(name, ref.element) except: log.error('Loading %s.%s with value %s failed' % (type(elem.element).__name__, name, ref.element.id)) raise # Fix version inconsistencies version_0_5_2(elements, factory, gaphor_version) version_0_7_1(elements, factory, gaphor_version) version_0_15_0_post(elements, factory, gaphor_version) # Before version 0.7.2 there was only decision node (no merge nodes). # This node could have many incoming and outgoing flows (edges). # According to UML specification decision node has no more than one # incoming node. # # Now, we have implemented merge node, which can have many incoming # flows. We also support combining of decision and merge nodes as # described in UML specification. # # Data model, loaded from file, is updated automatically, so there is # no need for special function. for d in factory.select(lambda e: isinstance(e, UML.Diagram)): # update_now() is implicitly called when lock is released d.canvas.block_updates = False # do a postload: for id, elem in elements.items(): st = update_status_queue() if st: yield st elem.element.postload() factory.notify_model()