Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def verify_element(name, value):
"""
Store the element id.
"""
if isinstance(value, (UML.Element, gaphas.Item)):
verify_reference(name, value)
elif isinstance(value, collection):
verify_collection(name, value)
elif isinstance(value, gaphas.Canvas):
value.save(verify_canvasitem)
def connected_to_folded_interface(self):
assert isinstance(self.canvas, gaphas.Canvas)
connection = self.canvas.get_connection(self.head)
return (
connection
and isinstance(connection.port, InterfacePort)
and connection.connected.folded != Folded.NONE
)
w, h = view.bounding_box.width, view.bounding_box.height
surface = cairo.SVGSurface(filename, w, h)
cr = cairo.Context(surface)
view.matrix.translate(-view.bounding_box.x0, -view.bounding_box.y0)
view.paint(cr)
cr.show_page()
surface.flush()
surface.finish()
if __name__ == '__main__':
from gaphor.diagram import items
from gaphor.ui.mainwindow import MainWindow
import gaphas
canvas = gaphas.Canvas()
canvas.add(items.ClassItem())
export = SVGExportAction()
export.save('svgexport.svg', canvas)
def connected_to_folded_interface(self):
assert isinstance(self.canvas, gaphas.Canvas)
connection = self.canvas.get_connection(self.head)
return (
connection
and isinstance(connection.port, InterfacePort)
and connection.connected.folded != Folded.NONE
)
def save_element(name, value):
"""
Save attributes and references from items in the gaphor.UML module.
A value may be a primitive (string, int), a gaphor.UML.collection
(which contains a list of references to other UML elements) or a
gaphas.Canvas (which contains canvas items).
"""
# log.debug('saving element: %s|%s %s' % (name, value, type(value)))
if isinstance(value, (uml2.Element, gaphas.Item)):
save_reference(name, value)
elif isinstance(value, collection):
save_collection(name, value)
elif isinstance(value, gaphas.Canvas):
writer.startElement('canvas', {})
value.save(save_canvasitem)
writer.endElement('canvas')
else:
save_value(name, value)
def save_element(name, value):
"""
Save attributes and references from items in the gaphor.UML module.
A value may be a primitive (string, int), a gaphor.UML.collection
(which contains a list of references to other UML elements) or a
gaphas.Canvas (which contains canvas items).
"""
if isinstance(value, (UML.Element, gaphas.Item)):
save_reference(name, value)
elif isinstance(value, collection):
save_collection(name, value)
elif isinstance(value, gaphas.Canvas):
writer.startElement("canvas", {})
value.save(save_canvasitem)
writer.endElement("canvas")
else:
save_value(name, value)
"""This module contains a model element Diagram which is the abstract
representation of a UML diagram. Diagrams can be visualized and edited.
The DiagramCanvas class extends the gaphas.Canvas class."""
from __future__ import absolute_import
import uuid
import gaphas
from six.moves import filter
from gaphor.UML.uml2 import Namespace, PackageableElement
class DiagramCanvas(gaphas.Canvas):
"""DiagramCanvas extends the gaphas.Canvas class. Updates to the canvas
can be blocked by setting the block_updates property to true. A save
function can be applied to all root canvas items. Canvas items can be
selected with an optional expression filter."""
def __init__(self, diagram):
"""Initialize the diagram canvas with the supplied diagram. By default,
updates are not blocked."""
super(DiagramCanvas, self).__init__()
self._diagram = diagram
self._block_updates = False
diagram = property(lambda s: s._diagram)
def _set_block_updates(self, block):
The DiagramCanvas class extends the gaphas.Canvas class.
"""
import logging
import uuid
import gaphas
from gaphor.UML.event import DiagramItemCreated
from gaphor.UML.properties import umlproperty
from gaphor.UML.uml2 import Namespace, PackageableElement
log = logging.getLogger(__name__)
class DiagramCanvas(gaphas.Canvas):
"""DiagramCanvas extends the gaphas.Canvas class. Updates to the canvas
can be blocked by setting the block_updates property to true. A save
function can be applied to all root canvas items. Canvas items can be
selected with an optional expression filter."""
def __init__(self, diagram):
"""Initialize the diagram canvas with the supplied diagram. By default,
updates are not blocked."""
super().__init__()
self._diagram = diagram
self._block_updates = False
diagram = property(lambda s: s._diagram)
def _set_block_updates(self, block):
shape_tail=None,
):
super().__init__(id, model)
self._style = {"dash-style": (), "line-width": 2, **style}
self.shape_head = shape_head
self.shape_middle = shape_middle
self.shape_tail = shape_tail
self.fuzziness = 2
self._shape_head_rect = None
self._shape_middle_rect = None
self._shape_tail_rect = None
canvas: Optional[gaphas.Canvas]
head = property(lambda self: self._handles[0])
tail = property(lambda self: self._handles[-1])
def _set_style(self, style):
self._style.update(style)
style = property(
lambda self: self._style.__getitem__,
_set_style,
doc="""A line, contrary to an element, has some styling of it's own.""",
)
def post_update(self, context):
def shape_bounds(shape, align):
if shape: