Exemple #1
0
    def _draw_mainlayer(self, gc, view_bounds=None, mode="default"):
        """ Draws the component """

        gc.save_state()
        try:
            # Specify the font
            font = str_to_font(str(self.pen.font))
            gc.set_font(font)

            gc.set_fill_color(self.pen.color_)

            x = self.text_x - ( self.text_w / 2 )
            y = self.text_y - ( font.size / 2 )

            # Show text at the same scale as the graphics context
            ctm = gc.get_ctm()
            if hasattr(ctm, "__len__") and len(ctm) == 6:
                scale = sqrt( (ctm[0] + ctm[1]) * (ctm[0] + ctm[1]) / 2.0 + \
                              (ctm[2] + ctm[3]) * (ctm[2] + ctm[3]) / 2.0 )
            elif hasattr(gc, "get_ctm_scale"):
                scale = gc.get_ctm_scale()
            else:
                raise RuntimeError("Unable to get scale from GC.")
            x *= scale
            y *= scale
            gc.show_text_at_point(self.text, x, y)
        finally:
            gc.restore_state()
Exemple #2
0
    def _draw_mainlayer(self, gc, view_bounds=None, mode="default"):
        """ Draws the component """

        gc.save_state()
        try:
            # Specify the font
            font = str_to_font(str(self.pen.font))
            gc.set_font(font)

            gc.set_fill_color(self.pen.color_)

            x = self.text_x - (self.text_w / 2)
            y = self.text_y - (font.size / 2)

            # Show text at the same scale as the graphics context
            ctm = gc.get_ctm()
            if hasattr(ctm, "__len__") and len(ctm) == 6:
                scale = sqrt( (ctm[0] + ctm[1]) * (ctm[0] + ctm[1]) / 2.0 + \
                              (ctm[2] + ctm[3]) * (ctm[2] + ctm[3]) / 2.0 )
            elif hasattr(gc, "get_ctm_scale"):
                scale = gc.get_ctm_scale()
            else:
                raise RuntimeError("Unable to get scale from GC.")
            x *= scale
            y *= scale
            gc.show_text_at_point(self.text, x, y)
        finally:
            gc.restore_state()
Exemple #3
0
    def _update(self):
        if self.pen is None:
            return

        x = self.text_x - (self.text_w / 2)
        x2 = x + self.text_w

        font = str_to_font( str(self.pen.font) )

        y = self.text_y - (font.size / 2)
        y2 = y + font.size

        self.position = [x, y]
        # If bounds are set to 0, horizontal/vertical lines will not render.
        self.bounds = [max(x2 - x, 1), max(y2 - y, 1)]

        self.request_redraw()
Exemple #4
0
    def _update(self):
        if self.pen is None:
            return

        x = self.text_x - (self.text_w / 2)
        x2 = x + self.text_w

        font = str_to_font(str(self.pen.font))

        y = self.text_y - (font.size / 2)
        y2 = y + font.size

        self.position = [x, y]
        # If bounds are set to 0, horizontal/vertical lines will not render.
        self.bounds = [max(x2 - x, 1), max(y2 - y, 1)]

        self.request_redraw()
Exemple #5
0
    def _draw_mainlayer(self, gc, view_bounds=None, mode="default"):

        gc.save_state()

        font = str_to_font( str(self.font) )
        gc.set_font(font)

        gc.set_fill_color(self.font_color_)
#        gc.set_fill_color(self.font_color)

        x = gc.width() * 0.3
        y = gc.height() * 0.6

        gc.show_text_at_point(self.text, x, y)

        self.position = [x, y]
#            self.bounds = [w, h]

        gc.restore_state()
Exemple #6
0
def move_to_origin(components):
    """ Components are positioned relative to their container. Use this
        method to position the bottom-left corner of the components at
        the origin.
    """
    for component in components:
        if isinstance(component, Ellipse):
            component.x_origin = component.e_width
            component.y_origin = component.e_height

        elif isinstance(component, (Polygon, BSpline)):
            min_x = min( [t[0] for t in component.points] )
            min_y = min( [t[1] for t in component.points] )

            component.points = [
                ( p[0]-min_x, p[1]-min_y ) for p in component.points
            ]

        elif isinstance(component, Text):
            font = str_to_font( str(component.pen.font) )
            component.text_x = 0#-( component.text_w / 2 )
            component.text_y = 0#-( font.size / 2 )