Exemplo n.º 1
0
    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:
            self.is_visible = visible

        if pattern:
            self._pattern = pattern
        else:
            self._pattern = "%s"

        self.editable = editable
Exemplo n.º 2
0
    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:
            self.is_visible = visible

        if pattern:
            self._pattern = pattern
        else:
            self._pattern = "%s"

        self.editable = editable
Exemplo n.º 3
0
 def __init__(self, id=None):
     super(Line, self).__init__()
     self.style = Style(Line.__style__)
     self._id = id
     self.fuzziness = 2
     self._handles[0].connectable = False
     self._handles[-1].connectable = False
Exemplo n.º 4
0
    def set_style(self, data):
        """
        Set item style information by merging provided information with
        style information from base classes.

        @param cls:   new instance of diagram item class
        @param bases: base classes of an item
        @param data:  metaclass data with style information
        """
        style = Style()
        for c in self.__bases__:
            if hasattr(c, "style"):
                for (name, value) in list(c.style.items()):
                    style.add(name, value)

        if "__style__" in data:
            for (name, value) in data["__style__"].items():
                style.add(name, value)

        self.style = style
Exemplo n.º 5
0
    def set_style(self, data):
        """
        Set item style information by merging provided information with
        style information from base classes.

        @param cls:   new instance of diagram item class
        @param bases: base classes of an item
        @param data:  metaclass data with style information
        """
        style = Style()
        for c in self.__bases__:
            if hasattr(c, 'style'):
                for (name, value) in c.style.items():
                    style.add(name, value)

        if '__style__' in data:
            for (name, value) in six.iteritems(data['__style__']):
                style.add(name, value)

        self.style = style
Exemplo n.º 6
0
class TextElement:
    """
    Representation of an editable text, which is part of a diagram item.

    Text element is aligned according to style information.

    It also displays and allows to edit value of an attribute of UML
    class (DiagramItem.subject). Attribute name can be recursive, all
    below attribute names are valid:
     - name (named item name)
     - guard.value (flow item guard)

    Attributes and properties:
     - attr:     name of displayed and edited UML class attribute
     - bounds:   text bounds
     - _style:   text style (i.e. align information, padding)
     - text:     rendered string to be displayed
     - pattern:  print pattern of text
     - editable: True if text should be editable

    See also EditableTextSupport.add_text.
    """

    bounds = property(lambda self: self._bounds)

    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:
            self.is_visible = visible

        if pattern:
            self._pattern = pattern
        else:
            self._pattern = "%s"

        self.editable = editable

    def _set_text(self, value):
        """
        Render text value using pattern.
        """
        self._text = value and self._pattern % value or ""

    text = property(lambda s: s._text, _set_text)

    style = property(lambda s: s._style)

    def is_visible(self):
        """
        Display text by default.
        """
        return True

    def draw(self, context):
        bounds = self.bounds
        x, y = bounds.x, bounds.y
        width, height = bounds.width, bounds.height

        cr = context.cairo
        cr.save()
        try:
            if isinstance(cr, FreeHandCairoContext):
                cr = cr.cr
            if isinstance(cr, cairo.Context) and self.text:
                cr.move_to(x, y)
                layout = PangoCairo.create_layout(cr)
                layout.set_font_description(Pango.FontDescription(self._style.font))
                layout.set_text(text=self.text, length=-1)
                PangoCairo.show_layout(cr, layout)
            if self.editable and (context.hovered or context.focused):
                cr.set_source_rgb(0.6, 0.6, 0.6)
                cr.set_line_width(0.5)
                cr.rectangle(x - 5, y - 1, width + 10, height + 2)
                cr.stroke()
        finally:
            cr.restore()
Exemplo n.º 7
0
class TextElement(object):
    """
    Representation of an editable text, which is part of a diagram item.

    Text element is aligned according to style information.

    It also displays and allows to edit value of an attribute of UML
    class (DiagramItem.subject). Attribute name can be recursive, all
    below attribute names are valid:
     - name (named item name)
     - guard.value (flow item guard)

    Attributes and properties:
     - attr:     name of displayed and edited UML class attribute
     - bounds:   text bounds
     - _style:   text style (i.e. align information, padding)
     - text:     rendered string to be displayed
     - pattern:  print pattern of text
     - editable: True if text should be editable

    See also EditableTextSupport.add_text.
    """

    bounds = property(lambda self: self._bounds)

    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:
            self.is_visible = visible

        if pattern:
            self._pattern = pattern
        else:
            self._pattern = "%s"

        self.editable = editable

    def _set_text(self, value):
        """
        Render text value using pattern.
        """
        self._text = value and self._pattern % value or ""

    text = property(lambda s: s._text, _set_text)

    style = property(lambda s: s._style)

    def is_visible(self):
        """
        Display text by default.
        """
        return True

    def draw(self, context):
        bounds = self.bounds
        x, y = bounds.x, bounds.y
        width, height = bounds.width, bounds.height

        cr = context.cairo
        cr.save()
        try:
            if isinstance(cr, FreeHandCairoContext):
                cr = cr.cr
            if isinstance(cr, cairo.Context) and self.text:
                cr.move_to(x, y)
                layout = PangoCairo.create_layout(cr)
                layout.set_font_description(
                    Pango.FontDescription(self._style.font))
                layout.set_text(text=self.text, length=-1)
                PangoCairo.show_layout(cr, layout)
            if self.editable and (context.hovered or context.focused):
                cr.set_source_rgb(0.6, 0.6, 0.6)
                cr.set_line_width(0.5)
                cr.rectangle(x - 5, y - 1, width + 10, height + 2)
                cr.stroke()
        finally:
            cr.restore()
Exemplo n.º 8
0
 def __init__(self, id=None):
     super(Box, self).__init__(10, 10)
     self.style = Style(Box.__style__)
     self._id = id
Exemplo n.º 9
0
 def __init__(self, id=None):
     super(Ellipse, self).__init__()
     self.style = Style(Ellipse.__style__)
     self._id = id