sketch-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

re:warmreader


From: Christof Ecker
Subject: re:warmreader
Date: Fri, 3 Jan 2003 14:33:05 +0100

Romain Bossart wrote:

>Hello Sketch dev,
>
>       I'd like an add-on to be developped for Sketch.
>
>       Short story
>       -----------
>       When creating a figure with Sketch, would it be possible to
create
>       a file which gives coordinates of some points (here 3) and
>associated
>       arbitrary labels ? Those points should have their own layer,
>       and be called 'Marked Objects'. Normally, they should not appear
>in the
>       exported figures, but only in this file.
[...]
Hi Romain,

this can be solved with a simple plugin object, like the code below. The only 
unusual part is that the inherited "DrawShape" method is overidden. This way 
the TeXMark objects don't appear in the printout. 

Reading out the coordinates from .sk-files is easy as:

from sys import stdin
from string import split

for l in stdin.readlines():
    if l[:12] == "PC('TeXMark'":
        values = split(l[3:-3], ',') 
        name = values[1]
        x,y = values[-2:]
        print x,y,name

Hope this is what you wanted, 
Christof


###Sketch Config
#type = PluginCompound
#class_name = 'TeXMark'
#menu_text = 'TeX Mark'
#standard_messages = 1
#parameters = (('label', 'text', '', None, 'Label'),)
###End

import Sketch
from Sketch import Rectangle, Trafo, TrafoPlugin, _, SolidPattern, \
     SimpleText, Translation
from Sketch.Graphics import handle
from Sketch.Graphics.color import StandardColors


class TeXMark(TrafoPlugin):
    class_name = 'TeXMark'    
    def __init__(self, label = "", trafo = None, duplicate = None, \
                 loading = 0):
        TrafoPlugin.__init__(self, trafo = trafo, duplicate = duplicate)
        if duplicate:
            self.label = duplicate.label
        else:
            self.label = label
        if not (loading or duplicate):
            self.recompute()

    def GetObjectHandle(self, *args):
        return []

    def Info(self):
        return _("TeX Mark '%s'") % self.Label()
    
    def Label(self):
        return self.label
    
    def recompute(self):
        bg = SolidPattern(StandardColors.white)
        fg = SolidPattern(StandardColors.black)
        objects = []
        text = SimpleText(text = self.label)
        x0, y0, x1, y1 = text.bounding_rect
        w = max(x1-x0, 2)
        h = 15 

        rect0 = Rectangle(Trafo(w+8, 0, 0, h+1, -7, -3))
        rect0.SetProperties(line_pattern = fg, \
                            fill_pattern = fg)
        objects.append(rect0)

        rect1 = Rectangle(Trafo(w+4, 0, 0, h, -3, -3))
        rect1.SetProperties(line_pattern = fg, \
                            fill_pattern = bg)
        objects.append(rect1)
        objects.append(text)

        # make (0,0) the upper left corner:
        move = Translation(7, 2-h)
        
        for obj in objects:
            obj.Transform(move)
            obj.Transform(self.trafo)
        self.set_objects(objects)
            
    def DrawShape(self, device, rect = None):
        if device.draw_visible:
            TrafoPlugin.DrawShape(self, device, rect)
        
    def SaveToFile(self, file):
        TrafoPlugin.SaveToFile(self, file, self.label, self.trafo.coeff())

______________________________________________________________________________
Ent- oder weder? Nein! Wer den nicht kauft, der platzt vor Neid: 
M E D I O N - PC P4 2.4 kompl. nur 969,- http://www.mempag.de/xmas3.php




reply via email to

[Prev in Thread] Current Thread [Next in Thread]