How to use the gaphas.item.Element function in gaphas

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 / source / rafcon / mvc / mygaphas / items / state.py View on Github external
from gaphas.connector import Position
from gaphas.matrix import Matrix

from rafcon.mvc.mygaphas.constraint import KeepRectangleWithinConstraint, PortRectConstraint
from rafcon.mvc.mygaphas.items.ports import IncomeView, OutcomeView, InputPortView, OutputPortView, \
    ScopedVariablePortView
from rafcon.mvc.mygaphas.items.connection import TransitionView
from rafcon.mvc.mygaphas.utils.enums import SnappedSide
from rafcon.mvc.mygaphas.utils.gap_draw_helper import get_col_rgba
from rafcon.mvc.mygaphas.utils import gap_draw_helper
from rafcon.mvc.mygaphas.utils.cache.image_cache import ImageCache

logger = log.get_logger(__name__)


class StateView(Element):
    """ A State has 4 handles (for a start):
     NW +---+ NE
     SW +---+ SE
    """

    _map_handles_port_v = {}

    def __init__(self, state_m, size, hierarchy_level):
        super(StateView, self).__init__(size[0], size[1])
        assert isinstance(state_m, AbstractStateModel)

        self._state_m = ref(state_m)
        self.hierarchy_level = hierarchy_level

        self.min_width = 0.0001
        self.min_height = 0.0001
github DLR-RM / RAFCON / source / rafcon / mvc / mygaphas / items / state.py View on Github external
new_rel_pos = calc_new_rel_pos(meta_rel_pos, old_size, new_size)

                        child_state_v.matrix.translate(*new_rel_pos)

                        old_size = child_state_v.model.meta['gui']['editor_gaphas']['size']

                    new_size = (old_size[0] * width_factor, old_size[1] * height_factor)
                    child_state_v.width = new_size[0]
                    child_state_v.height = new_size[1]

                    resize_child(child_state_v, old_size, new_size, paste)

        resize_child(self, old_size, new_size, paste)


class NameView(Element):

    def __init__(self, name, size):
        super(NameView, self).__init__(size[0], size[1])

        self._name = None
        self.name = name

        self.min_width = 0.0001
        self.min_height = 0.0001

        self.moving = False

        self._image_cache = ImageCache(multiplicator=1.5)

    @property
    def name(self):
github DLR-RM / RAFCON / source / awesome_tool / mvc / views / gap / scope.py View on Github external
from weakref import ref

from gaphas.item import Element, NW, NE, SW, SE
from gaphas.connector import PointPort, Handle

from awesome_tool.mvc.models.scoped_variable import ScopedVariableModel


class ScopedVariableView(Element):
    """ A scoped variable has 4 handles (for a start):
     NW +---+ NE
     SW +---+ SE
    """

    def __init__(self, scoped_variable_m, size):
        super(ScopedVariableView, self).__init__(size[0], size[1])
        assert isinstance(scoped_variable_m, ScopedVariableModel)

        self._scoped_variable_m = ref(scoped_variable_m)

        self.min_width = 0.0001
        self.min_height = 0.0001
        self.width = size[0]
        self.height = size[1]
github DLR-RM / RAFCON / source / rafcon / gui / mygaphas / items / state.py View on Github external
state_v.set_enable_flag_keep_rect_within_constraints(enable=True)

        # Deactivate KeepRectangleWithin constraints for child states
        self.set_enable_flag_keep_rect_within_constraints(enable=False)
        # Now we can solve the KeepRectangleWithin constraints of this state without being called recursively
        # We also force the solving of the minimal size constraints
        if self.parent:
            self.view.canvas.resolve_constraint((self.parent.keep_rect_constraints[self], self._c_min_w, self._c_min_h))
        else:
            self.view.canvas.resolve_constraint((self._c_min_w, self._c_min_h))
        new_size = (self.width, self.height)
        resize_state_v(self, old_size, new_size, paste)



class NameView(Element):

    def __init__(self, name, size):
        super(NameView, self).__init__(size[0], size[1])
        # Reapply size, as Gaphas sets default minimum size to 1, which is too large for highly nested states
        self.min_width = self.min_height = 0
        self.width = size[0]
        self.height = size[1]

        self._name = None
        self.name = name

        self.moving = False

        self._view = None

        self._image_cache = ImageCache(multiplicator=1.5)
github DLR-RM / RAFCON / source / rafcon / gui / mygaphas / view.py View on Github external
def queue_draw_item(self, *items):
        """Extends the base class method to allow Ports to be passed as item

        :param items: Items that are to be redrawn
        """
        gaphas_items = []
        for item in items:
            if isinstance(item, Element):
                gaphas_items.append(item)
            else:
                try:
                    gaphas_items.append(item.parent)
                except AttributeError:
                    pass
        super(ExtendedGtkView, self).queue_draw_item(*gaphas_items)
github DLR-RM / RAFCON / source / rafcon / gui / mygaphas / view.py View on Github external
def queue_draw_item(self, *items):
        """Extends the base class method to allow Ports to be passed as item

        :param items: Items that are to be redrawn
        """
        gaphas_items = []
        for item in items:
            if isinstance(item, Element):
                gaphas_items.append(item)
            else:
                try:
                    gaphas_items.append(item.parent)
                except AttributeError:
                    pass
        super(ExtendedGtkView, self).queue_draw_item(*gaphas_items)
github gaphor / gaphor / gaphor / diagram / general / simpleitem.py View on Github external
self._load_orthogonal = ast.literal_eval(value)

    def postload(self):
        if hasattr(self, "_load_orthogonal"):
            self.orthogonal = self._load_orthogonal
            del self._load_orthogonal

    def draw(self, context):
        cr = context.cairo
        style = self.style
        cr.set_line_width(style("line-width"))
        cr.set_source_rgba(*style("color"))
        super().draw(context)


class Box(Element):
    """
    A Box has 4 handles (for a start)::

    NW +---+ NE
    SW +---+ SE
    """

    def __init__(self, id=None, model=None):
        super().__init__(10, 10)
        self.style = {"line-width": 2, "color": (0, 0, 0, 1)}.__getitem__
        self._id = id

    id = property(lambda self: self._id, doc="Id")

    def save(self, save_func):
        save_func("matrix", tuple(self.matrix))
github gaphor / gaphor / gaphor / diagram / general / simpleitem.py View on Github external
def postload(self):
        pass

    def draw(self, context):
        cr = context.cairo
        nw = self._handles[NW]
        style = self.style
        cr.rectangle(nw.pos.x, nw.pos.y, self.width, self.height)
        # cr.set_source_rgba(*style("color"))
        # cr.fill_preserve()
        cr.set_source_rgba(*style("color"))
        cr.set_line_width(style("line-width"))
        cr.stroke()


class Ellipse(Element):
    """
    """

    def __init__(self, id=None, model=None):
        super().__init__()
        self.style = {"line-width": 2, "color": (0, 0, 0, 1)}.__getitem__
        self._id = id

    id = property(lambda self: self._id, doc="Id")

    def save(self, save_func):
        save_func("matrix", tuple(self.matrix))
        save_func("width", self.width)
        save_func("height", self.height)

    def load(self, name, value):
github DLR-RM / RAFCON / source / rafcon / gui / mygaphas / items / state.py View on Github external
from rafcon.gui.mygaphas.utils import gap_draw_helper
from rafcon.gui.mygaphas.utils.cache.image_cache import ImageCache

from rafcon.gui.models import AbstractStateModel, LibraryStateModel, ContainerStateModel
from rafcon.gui.helpers.meta_data import contains_geometric_info
from rafcon.gui.config import global_gui_config as gui_config
from rafcon.gui.runtime_config import global_runtime_config
from rafcon.gui.utils import constants
from rafcon.utils import log
logger = log.get_logger(__name__)

# Fixed width of the Pango layout. The higher this value, the better is the accuracy, but the more memory is consumed
BASE_WIDTH = 100.


class StateView(Element):
    """ A State has 4 handles (for a start):
     NW +---+ NE
     SW +---+ SE
    """

    _map_handles_port_v = {}

    def __init__(self, state_m, size, hierarchy_level):
        super(StateView, self).__init__(size[0], size[1])
        assert isinstance(state_m, AbstractStateModel)
        # Reapply size, as Gaphas sets default minimum size to 1, which is too large for highly nested states
        self.min_width = self.min_height = 0
        self.width = size[0]
        self.height = size[1]

        self._c_min_w = self._constraints[0]