How to use gaphas - 10 common examples

To help you get started, we’ve selected a few gaphas examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DLR-RM / RAFCON / tests / user_input / test_user_input_gaphas.py View on Github external
state_view_for_root_state = graphical_editor_controller.canvas.get_view_for_model(sm_model.root_state)
    from rafcon.gui.mygaphas.items.state import StateView
    assert isinstance(state_view_for_root_state, StateView)
    # print state_view_for_root_state
    # p = state_view_for_root_state.position
    # print state_view_for_root_state.position
    # print state_view_for_root_state.matrix
    # print state_view_for_root_state.handles()
    # print state_view_for_root_state.handles()[NW].pos.x
    # print state_view_for_root_state.handles()[NW].pos.y
    # print state_view_for_root_state.handles()[SE].pos.x
    # print state_view_for_root_state.handles()[SE].pos.y

    # self.view.get_matrix_i2v(self).transform_distance(width, height)
    from gaphas.view import View
    assert isinstance(state_view_for_root_state.view, View)

    v2i = state_view_for_root_state.view.get_matrix_v2i(state_view_for_root_state)
    i2v = state_view_for_root_state.view.get_matrix_i2v(state_view_for_root_state)
    c2i = state_view_for_root_state.canvas.get_matrix_c2i(state_view_for_root_state)
    i2c = state_view_for_root_state.canvas.get_matrix_i2c(state_view_for_root_state)

    # item_base_x, item_base_y = v2i.transform_point(p[0], p[1])
    # item_base_x, item_base_y = i2v.transform_point(p[0], p[1])
    #
    # item_base_x, item_base_y = i2c.tranform_point(v2i.transform_point(0, 0))
    # item_base_x, item_base_y = 0, 0

    se_x, se_y = i2v.transform_point(state_view_for_root_state.handles()[SE].pos.x.value,
                                     state_view_for_root_state.handles()[SE].pos.y.value)

    main_w = rafcon.gui.singleton.main_window_controller.view.get_top_widget()
github DLR-RM / RAFCON / tests / user_input / test_user_input_gaphas.py View on Github external
def south_east_coordinates_of_model(gaphas_view):
    from gaphas.item import Element, NW, NE, SE, SW
    i2v = gaphas_view.view.get_matrix_i2v(gaphas_view)
    x, y = i2v.transform_point(gaphas_view.handles()[SE].pos.x.value,
                               gaphas_view.handles()[SE].pos.y.value)
    return x, y
github gaphor / gaphor / gaphor / diagram / presentation.py View on Github external
def shape_bounds(shape, align):
            if shape:
                size = shape.size(cr)
                x, y = text_point_at_line(points, size, align)
                return Rectangle(x, y, *size)
github gaphor / gaphor / gaphor / diagram / shapes.py View on Github external
def draw(self, context, bounding_box):
        padding = self.style("padding")
        vertical_spacing = self.style("vertical-spacing")
        x = bounding_box.x + padding[Padding.LEFT]
        y = bounding_box.y + padding[Padding.TOP]
        w = bounding_box.width - padding[Padding.RIGHT] - padding[Padding.LEFT]
        h = bounding_box.height - padding[Padding.TOP] - padding[Padding.BOTTOM]
        self.icon.draw(context, Rectangle(x, y, w, h))
        y = y + bounding_box.height + vertical_spacing
        for c, (cw, ch) in zip(self.children, self.sizes):
            mw = max(w, cw)
            c.draw(context, Rectangle(x - (mw - w) / 2, y, mw, ch))
            y += ch
github gaphor / gaphor / gaphor / diagram / classes / association.py View on Github external
def __init__(self, owner, end=None):
        super().__init__(id=False)  # Transient object
        self.canvas = None
        self._owner = owner
        self._end = end

        # Rendered text for name and multiplicity
        self._name = None
        self._mult = None

        self._name_bounds = Rectangle()
        self._mult_bounds = Rectangle()
        self.font = "sans 10"
github gaphor / gaphor / gaphor / diagram / classes / association.py View on Github external
align_left = (h and not r) or (r and not h)
            align_bottom = (v and not r) or (r and not v)
            if align_left:
                name_dx = ofs
                mult_dx = ofs
            else:
                name_dx = -ofs - name_w
                mult_dx = -ofs - mult_w
            if align_bottom:
                name_dy = -ofs - name_h
                mult_dy = -ofs - name_h - mult_h
            else:
                name_dy = ofs 
                mult_dy = ofs + mult_h

        self._name_bounds = Rectangle(p1[0] + name_dx,
                                      p1[1] + name_dy,
                                      width=name_w,
                                      height=name_h)

        self._mult_bounds = Rectangle(p1[0] + mult_dx,
                                      p1[1] + mult_dy,
                                      width=mult_w,
                                      height=mult_h)
github gaphor / gaphor / gaphor / diagram / textelement.py View on Github external
def __init__(self, attr, style=None, pattern=None, visible=None, editable=False):
        """
        Create new text element with bounds (0, 0, 10, 10) and empty text.

        Parameters:
         - visible: function, which evaluates to True/False if text should
                    be visible
        """
        super(TextElement, self).__init__()

        self._bounds = Rectangle(0, 0, width=15, height=10)

        # create default style for a text element
        self._style = Style()
        self._style.add("text-padding", (2, 2, 2, 2))
        self._style.add("text-align", (ALIGN_CENTER, ALIGN_TOP))
        self._style.add("text-outside", False)
        self._style.add("text-rotated", False)
        self._style.add("text-align-str", None)
        self._style.add("font", DEFAULT_TEXT_FONT)
        if style:
            self._style.update(style)

        self.attr = attr
        self._text = ""

        if visible:
github gaphor / gaphor / gaphor / diagram / classes / association.py View on Github external
mult_dx = ofs
            else:
                name_dx = -ofs - name_w
                mult_dx = -ofs - mult_w
            if align_bottom:
                name_dy = -ofs - name_h
                mult_dy = -ofs - name_h - mult_h
            else:
                name_dy = ofs
                mult_dy = ofs + mult_h

        self._name_bounds = Rectangle(
            p1[0] + name_dx, p1[1] + name_dy, width=name_w, height=name_h
        )

        self._mult_bounds = Rectangle(
            p1[0] + mult_dx, p1[1] + mult_dy, width=mult_w, height=mult_h
        )
github gaphor / gaphor / gaphor / diagram / classes / association.py View on Github external
def __init__(self, owner, end=None):
        super().__init__(id=False)  # Transient object
        self.canvas = None
        self._owner = owner
        self._end = end

        # Rendered text for name and multiplicity
        self._name = None
        self._mult = None

        self._name_bounds = Rectangle()
        self._mult_bounds = Rectangle()
        self.font = "sans 10"
github gaphor / gaphor / gaphor / diagram / inlineeditors.py View on Github external
def find(*shapes):
        for shape in shapes:
            if isinstance(shape, (_shapes.Box, _shapes.IconBox)):
                box = find(*shape.children)
                if box:
                    return box
            elif isinstance(shape, _shapes.EditableText):
                box = shape.bounding_box
                i2v = view.get_matrix_i2v(item)
                x, y = i2v.transform_point(box.x, box.y)
                w, h = i2v.transform_distance(box.width, box.height)
                # Add a little bit of padding, 'cause that makes it look so good
                return Rectangle(x - 6, y - 6, w + 12, h + 12)