Esempio n. 1
0
#-------------------------------------
import os
from Utils import GeomUtils
from Utils.Template import TemplateDict
from Utils import Logger

from SketchFramework import Point
from SketchFramework import Stroke
from SketchFramework import SketchGUI

from SketchFramework.Annotation import Annotation
from SketchFramework.Board import BoardObserver, BoardSingleton


logger = Logger.getLogger('TemplateObserver', Logger.DEBUG )

#-------------------------------------

class TemplateAnnotation(Annotation):
    "Annotation for strokes matching templates. Fields: name - the template's tag/name, template - the list of points making up the template"
    def __init__(self, tag, template):
        Annotation.__init__(self)
        self.template = template
        self.name = tag
        
#-------------------------------------

class TemplateMarker( BoardObserver ):
    "Compares all strokes with templates and annotates strokes with any template within some threshold."
    def __init__(self):
Esempio n. 2
0
#from SketchFramework.strokeout import imageBufferToStrokes, imageToStrokes
#from SketchFramework.NetworkReceiver import ServerThread
from Utils.StrokeStorage import StrokeStorage
from Utils.GeomUtils import getStrokesIntersection
from Utils import Logger

from Observers.ObserverBase import Animator

# Constants
WIDTH = 1000
HEIGHT = 800
MID_W = WIDTH/2
MID_H = HEIGHT/2

   
logger = Logger.getLogger("TkSketchGUI", Logger.DEBUG)

class TkSketchGUI(_SketchGUI):

    Singleton = None
    def __init__(self):
       "Set up members for this GUI"
       global HEIGHT, WIDTH
       self.sketchFrame = None

       TkSketchGUI.Singleton = self
       self.run()
    def run(self):
       root = Tk()
       root.title("Sketchy/Scratch")
       self.sketchFrame = TkSketchFrame(master = root)
Esempio n. 3
0
import time
import math
import sys
import pdb

from Utils import Logger
from Utils import GeomUtils
from SketchFramework.Point import Point
from SketchFramework.Stroke import Stroke
from SketchFramework.Board import BoardObserver
from SketchFramework.Annotation import Annotation, AnimateAnnotation
from Observers import ObserverBase


logger = Logger.getLogger('TestObserver', Logger.DEBUG)

#-------------------------------------

class TestAnnotation(AnimateAnnotation):
    def __init__(self):
        Annotation.__init__(self)
        self.dt = 0
        self.pattern = [1,1,1,1,1,0,0,0,0,0,2,0,0,0,0,0]
        self.idx = 0

    def step(self,dt):
        "Test animator, tracks the time since this was last called"
        self.idx = (self.idx + 1) % len(self.pattern)
        self.dt += dt
Esempio n. 4
0
from sketchvision.ImageStrokeConverter import imageBufferToStrokes, GETNORMWIDTH
from Utils.StrokeStorage import StrokeStorage
from Utils import Logger

from Observers.ObserverBase import Animator

# Constants
WIDTH = 1024
HEIGHT = int(4.8 * WIDTH / 8)

MID_W = WIDTH/2
MID_H = HEIGHT/2

   
logger = Logger.getLogger("NetSketchGUI", Logger.DEBUG)


class DrawAction(object):
    "Base class for a draw action"
    def __init__(self, action_type):
        self.action_type = action_type
    def xml(self):
        raise NotImplemented

class DrawCircle(DrawAction):
    "An object that defines parameters for drawing a circle"
    def __init__(self, x, y, radius, color, fill, width):
        DrawAction.__init__(self, "Circle")
        self.x = x
        self.y = y
Esempio n. 5
0
>>> m = MyCollector([Annotation],Annotation2)


"""

#-------------------------------------

import math
from Utils import Logger
from Utils import GeomUtils
from SketchFramework.Point import Point
from SketchFramework.Stroke import Stroke
from SketchFramework.Board import BoardObserver, BoardSingleton
from SketchFramework.Annotation import Annotation, AnnotatableObject

logger = Logger.getLogger('ObserverBase', Logger.WARN )

#-------------------------------------

class Visualizer( BoardObserver ):
    "Watches for annotations, draws them"
    def __init__(self, anno_type):
        BoardSingleton().AddBoardObserver( self )
        BoardSingleton().RegisterForAnnotation( anno_type, self )
        self.annotation_list = []

    def onAnnotationAdded( self, strokes, annotation ):
        logger.debug("anno added   %s", annotation )
        self.annotation_list.append(annotation)
  
 
Esempio n. 6
0
# import sys
from SketchFramework.Annotation import AnnotatableObject
from Utils import Logger

logger = Logger.getLogger("Point", Logger.WARN)


class Point(AnnotatableObject):
    "Point defined by X, Y, T.  X,Y Cartesian Coords, T as Time"

    def __init__(self, xLoc, yLoc, drawTime=0):
        AnnotatableObject.__init__(self)
        # self.X = int(xLoc)
        # self.Y = int(yLoc)
        # self.T = int(drawTime)
        self.X = float(xLoc)
        self.Y = float(yLoc)
        self.T = float(drawTime)

    def distance(self, point2):
        "Returns the distance from this point to the point in argument 1"
        logger.error("Point.distance deprecated, use GeomUtils.pointDist")
        return 0.0

    def copy(self):
        return Point(self.X, self.Y, self.T)

    def __str__(self):
        return "(" + ("%.1f" % self.X) + "," + ("%.1f" % self.Y) + ")"
        # return "(" + str(self.X) + "," + str(self.Y) + ")"
        # return "(" + str(self.X) + "," + str(self.Y) + "," + str(self.T) + ")"
Esempio n. 7
0
from Utils import GeomUtils

from Observers import CircleObserver
from Observers import LineObserver
from Observers import ObserverBase

from SketchFramework.Point import Point
from SketchFramework.Stroke import Stroke
from SketchFramework.Board import BoardObserver
from SketchFramework.Annotation import Annotation, AnnotatableObject

from xml.etree import ElementTree as ET

from Bin import DirectedLine

logger = Logger.getLogger('TextObserver', Logger.WARN )

#-------------------------------------

class MultAnnotation(Annotation):
    def __init__(self, scale):
        "Create a Text annotation. text is the string, and scale is an appropriate size"
        Annotation.__init__(self)
        self.scale = scale # an approximate "size" for the text
    def xml(self):
        root = Annotation.xml(self)
        root.attrib['scale'] = str(self.scale)
        return root

#-------------------------------------
Esempio n. 8
0
import sys
import traceback
from Utils import Logger
from SketchFramework.Point import Point
from SketchFramework.Annotation import Annotation, AnnotatableObject
from xml.etree import ElementTree as ET

logger = Logger.getLogger('Stroke', Logger.WARN )


#FIXME: this module is in dire need of some documentation

class Stroke(AnnotatableObject):
    "Stroke defined as a List of Points: Points"

    # counter shared with all strokes, incremented on each new stroke
    Number = 0
    DefaultStrokeColor = "#000000"

    def __repr__(self):
        return "<Stroke %s>" % (str(self.ident))
    
    def __len__(self):
        """Returns the length of this stroke in number of points"""
        return len(self.Points)

    def __init__(self, points=None, id = None, board=None):#, smoothing=False): DEPRECATED
        # call parent constructor
        AnnotatableObject.__init__(self) 
        # give each stroke a unique ident
        if id != None:
Esempio n. 9
0
from Utils import Logger
from Utils.GeomUtils import ellipseAxisRatio, pointDist
from Utils.LaTexCalculation import solveLaTex
from xml.etree import ElementTree as ET
import math
import pdb
from Utils.GeomUtils import strokelistBoundingBox

from SketchFramework.Point import Point
from SketchFramework.Stroke import Stroke
from SketchFramework.Board import BoardObserver
from SketchFramework.Annotation import Annotation, AnnotatableObject



logger = Logger.getLogger('ChartObserver', Logger.DEBUG)

#-------------------------------------
class ChartAreaAnnotation(Annotation):
    def __init__(self, horizArrow, vertArrow):
        Annotation.__init__(self)
        self.horizontalArrow = horizArrow
        self.verticalArrow = vertArrow
        self.equations = []


    def __repr__(self):
        return "CA: H {}, V {}".format(self.horizontalArrow, self.verticalArrow)

#-------------------------------------
Esempio n. 10
0
from Utils import Logger
from Utils import GeomUtils

from SketchFramework.Point import Point
from SketchFramework.Stroke import Stroke
from SketchFramework.Board import BoardObserver
from SketchFramework.Annotation import Annotation, AnnotatableObject

from Observers import CircleObserver
from Observers import ArrowObserver
from Observers import ObserverBase

from xml.etree import ElementTree as ET


logger = Logger.getLogger('DiGraphObserver', Logger.WARN)
node_log = Logger.getLogger('DiGraphNode', Logger.WARN)

#-------------------------------------
class DiGraphNodeAnnotation(CircleObserver.CircleAnnotation):
    
    def __init__(self, circularity, center, radius):
        #Reminder, CircleAnno has fields:
        #   center
        CircleObserver.CircleAnnotation.__init__(self, circularity, center, radius)
        node_log.debug("Creating new Node")

#-------------------------------------

class NodeMarker( BoardObserver ):
    "Watches for Circle, and annotates them with the circularity, center and the radius"
Esempio n. 11
0
import datetime 

from SketchFramework.Stroke import Stroke

from Utils import Logger
from Utils import GeomUtils
from Utils.Hacks import type

logger = Logger.getLogger('Board', Logger.DEBUG )

#--------------------------------------------
class BoardObserver(object):
    "The Board Observer Class from which all other Board Observers should be derived"
    def __init__(self):
        self.AnnoFuncs={}
        
    def onStrokeAdded( self, stroke ):
        pass
    
    def onStrokeRemoved( self, stroke ):
        pass
    
    def onStrokeEdited( self, oldStroke, newStroke ):
        pass
    
    def onAnnotationAdded( self, obj, annotation ):
        pass

    def onAnnotationUpdated( self, annotation ):
        pass
Esempio n. 12
0
                self.drawLine(prev_p.X, prev_p.Y, next_p.X, next_p.Y, width=width, color=color)
            prev_p = next_p

    def drawCurve(self, curve, width=2, color="#000000"):
        "Draw a curve on the board with width and color as specified"
        self.drawStroke(curve.toStroke(), width=width, color=color)
        colorwheel = ["#FF0000", "#00FF00", "#0000FF", "#FF00FF"]
        for i, pt in enumerate(curve.getControlPoints()):
            color = colorwheel[i]
            self.drawCircle(pt.X, pt.Y, radius=1, width=width, color=color)

        pt = curve.getControlPoints()[0]
        self.drawCircle(pt.X, pt.Y, radius=2, width=width, color="#0000FF")


dummylog = Logger.getLogger("DummyGUI", Logger.DEBUG)


class DummyGUI(_SketchGUI):
    """A Dummy GUI subclass that is only used as a black hole for method calls"""

    def getDimensions(self):
        return (0, 0)

    def __init__(self):
        dummylog.info("GUI Object created")

    def drawCircle(self, x, y, radius=1, color="#000000", fill="", width=1.0):
        dummylog.warn("Circle to be drawn")

    def drawLine(self, x1, y1, x2, y2, width=2, color="#000000"):
Esempio n. 13
0
from Utils import Logger
from multiprocessing.queues import Queue
import Image
import commands
import cv
import multiprocessing
import numpy
import os
import threading
import time

log = Logger.getLogger("ImUtil", Logger.DEBUG)
######################################
# Image Manipulation
######################################
def getFillPoints(image):
    """Generate points from which iterative flood fill would cover all non-zero pixels
    in image."""
    image = cv.CloneMat(image)
    retList = []
    _, maxVal, _ , maxLoc = cv.MinMaxLoc(image)
    while maxVal > 0:
        retList.append(maxLoc)
        cv.FloodFill(image, maxLoc, 0)
        _, maxVal, _, maxLoc = cv.MinMaxLoc(image)
    return retList


def resizeImage(img, scale=None, dims=None):
    """Return a resized copy of the image for either relative
    scale, or that matches the dimensions given"""
Esempio n. 14
0
from sketchvision.ImageStrokeConverter import imageBufferToStrokes, GETNORMWIDTH
from Utils.StrokeStorage import StrokeStorage
from Utils import Logger

from Observers.ObserverBase import Animator

# Constants
WIDTH = 1024
HEIGHT = 3 * WIDTH / 4

MID_W = WIDTH/2
MID_H = HEIGHT/2

   
logger = Logger.getLogger("DebugSketchGUI", Logger.DEBUG)



class FileResponseThread(threading.Thread):
    def __init__(self, inQ, outQ, filename = "xmlout.xml"):
        threading.Thread.__init__(self)
        self.daemon = True
        self.fname = filename
        self.inQ = inQ
        self.outQ = outQ


    def run(self):
       while True:
            image = self.inQ.get()
Esempio n. 15
0
from Utils import Rubine

from Observers import CircleObserver
from Observers import LineObserver
from Observers import ObserverBase

from SketchFramework.Point import Point
from SketchFramework.Stroke import Stroke
from SketchFramework.Board import BoardObserver
from SketchFramework.Annotation import Annotation, AnnotatableObject

from xml.etree import ElementTree as ET

from numpy  import *

logger = Logger.getLogger('RubineObserver', Logger.DEBUG )

#-------------------------------------

class RubineAnnotation(Annotation):
    def __init__(self, scores):
        "Create a Rubin annotation."
        Annotation.__init__(self)
        #self.type = type # Deprecated
        #self.accuracy = accuracy Deprecated
        #self.scale = scale # Deprecated
        self.scores = scores
        self.name = ""
        if len(self.scores) > 0:
            self.name = scores[0]['symbol']
    
Esempio n. 16
0
>>> d.trackAnnotation(myAnnotation)

FIXME: need some way to actually trigger the proper events to 
       actually test that the visualizer is called correctly

"""

import time
import pdb
from Utils import Logger
from Utils import GeomUtils
from SketchFramework.Point import Point
from SketchFramework.Board import BoardObserver
from SketchFramework.Annotation import Annotation, AnnotatableObject

logger = Logger.getLogger('DiGraphObserver', Logger.WARN )

#-------------------------------------
class DebugObserver( BoardObserver ):
    "Watches for all annotations, and draws them"

    def __init__(self, board):
        BoardObserver.__init__(self, board)
        self.getBoard().AddBoardObserver( self, [] )
	self.watchSet = set([]) # set of annotation types to track
	self.seenBefore = {} # set of particular annotation that we have already drawn

    def trackAnnotation(self,annoType):
        logger.debug("debugObserver adding %s", annoType.__name__ );
        # add this annotation type to the list to track
        self.watchSet.add(annoType)
Esempio n. 17
0
from Observers import LineObserver
from Observers import ObserverBase

from SketchFramework.Point import Point
from SketchFramework.Stroke import Stroke
from SketchFramework.Board import BoardObserver
from SketchFramework.Annotation import Annotation, AnnotatableObject

from xml.etree import ElementTree as ET


from Bin.BinObserver import BinAnnotation
from Bin.EqualsObserver import EqualsAnnotation
from types import *

logger = Logger.getLogger('TextObserver', Logger.WARN )

#-------------------------------------

class EquationAnnotation(Annotation):
    def __init__(self, scale, type, number = 0):
        "Create a Text annotation. text is the string, and scale is an appropriate size"
        Annotation.__init__(self)
        self.scale = scale # an approximate "size" for the text
        self.type = type
        self.number = number
    def xml(self):
        root = Annotation.xml(self)
        root.attrib['scale'] = str(self.scale)
        return root
Esempio n. 18
0
from SketchFramework.SketchGUI import DummyGUI
from SketchFramework.Stroke import Stroke
from Utils import GeomUtils
from Utils import Logger
from xml.etree import ElementTree as ET
import datetime 
import pdb 
import sys 
import threading
from Utils.GeomUtils import pointDistance



logger = Logger.getLogger('Board', Logger.WARN )

#--------------------------------------------
class BoardException (Exception):
    """A custom exception class to handle errors within the framework"""
    def __init__(self, message):
        """input: message for the error"""
        self.message = message
    def __str__(self):
        return repr(self.message)

#--------------------------------------------
class BoardObserver(object):
    "The Board Observer Class from which all other Board Observers should be derived"
    def __init__(self, board):
        self._parentBoard = board
        self.AnnoFuncs={}
        self._targetAnnotations = None #Set by the Board with a call to "RegisterBoardObserver"
Esempio n. 19
0
from Utils.ImageUtils import findCalibrationChessboard

from multiprocessing.queues import Queue
from sketchvision import ImageStrokeConverter as ISC
import cv
import gobject
import gtk
import multiprocessing
import pdb
import pygtk
import threading


pygtk.require('2.0')

log = Logger.getLogger("CamArea", Logger.DEBUG)
    
MAXCAPSIZE = (2592, 1944)
HD1080 = (1920, 1080)
HD720 = (1280, 720)
DEFAULT_CORNERS = [
                    (777.6, 239.76000000000002),
                    (2080, 533),
                    (2235.6, 1506.6000000000001),
                    (625.32, 1441.8000000000002),
                  ]
if __name__ == "__main__":
    DEBUG = True
else:
    DEBUG = False
class CamArea (ImageArea):
Esempio n. 20
0
from Observers.ObserverBase import Animator

import Config

from functools import partial

# Constants
WIDTH = 950
HEIGHT = 640
#WIDTH = 1680 
#HEIGHT =  1050
MID_W = WIDTH/2
MID_H = HEIGHT/2

logger = Logger.getLogger("TkSketchFrame", Logger.DEBUG)

class ImgProcThread (threading.Thread):
    """A Thread that continually pulls image data from imgQ and puts the
    resulting strokes in strokeQ"""
    def __init__(self, imgQ, strokeQ):
        threading.Thread.__init__(self)
        self.daemon = True

        self.img_queue = imgQ
        self.stk_queue = strokeQ
    def run(self):
        while True:
            image = StringIO.StringIO(self.img_queue.get())
            logger.debug("Processing net image")
            stks = imageBufferToStrokes(image)
Esempio n. 21
0
#-------------------------------------

import math
import pdb
from Utils import Logger
from Utils import GeomUtils
from Utils import Template

from SketchFramework.Point import Point
from SketchFramework.Stroke import Stroke
from SketchFramework.Board import BoardObserver
from SketchFramework.Annotation import Annotation, AnnotatableObject
from xml.etree import ElementTree as ET
from Observers.Semantics_Class1 import Class1Annotation

logger = Logger.getLogger('ArrowObserver', Logger.WARN)

arrowHeadMatcher = Template.TemplateDict(filename = "Utils/arrowheads.templ")

class ArrowHeadAnnotation( Class1Annotation ):
    def __init__(self, end1, cusp, end2):
        Class1Annotation.__init__(self)
        self.addKeyPoint("end1", end1)
        self.addKeyPoint("cusp", cusp)
        self.addKeyPoint("end2", end2)

def classifyArrowhead(board, stroke):
    """Following the class 1 semantics, this classifies arrowheads"""
    if _isArrowHead(stroke, arrowHeadMatcher):
        #                * (tip-point)
        #              o   o
import random
import pdb
from SketchFramework import SketchGUI

from Utils import Logger
from Utils import GeomUtils
from SketchFramework.Point import Point
from SketchFramework.Stroke import Stroke
from SketchFramework.Board import BoardObserver, BoardSingleton
from SketchFramework.Annotation import Annotation, AnnotatableObject
from Observers import ObserverBase


#-------------------------------------

ssv_logger = Logger.getLogger("SplitStrokekVisualizer", Logger.DEBUG)
class SplitStrokeVisualizer( ObserverBase.Visualizer ):
    COLORMAP = {"#00AAAA": None,
                 "#AA00AA": None,
                 "#AAAA00": None,
                 "#AAAAAA": None,
                 "#AAFFFF": None,
                 "#FFAAFF": None,
                 "#FFAAFF": None,
                 "#22AAAA": None,
                 "#AA22AA": None,
                 "#AA22AA": None,
                }
    def __init__(self):
        ObserverBase.Visualizer.__init__( self, SplitStrokeAnnotation )
Esempio n. 23
0
#-------------------------------------

import math
import sys
from SketchFramework import SketchGUI

from Utils import Logger
from Utils import GeomUtils
from SketchFramework.Point import Point
from SketchFramework.Stroke import Stroke
from SketchFramework.Board import BoardObserver, BoardSingleton
from SketchFramework.Annotation import Annotation, AnnotatableObject

from xml.etree import ElementTree as ET

logger = Logger.getLogger('CircleObserver', Logger.WARN )

#-------------------------------------

class CircleAnnotation(Annotation):
    def __init__(self, circ, cen, avgDist):
        Annotation.__init__(self)
        self.circularity = circ # float
        self.center = cen # Point
        self.radius = avgDist # float

    def xml( self ):
        "Returns an element tree object for the XML serialization of this annotation"
        root = Annotation.xml(self)

        root.attrib['circularity'] = str(self.circularity)
Esempio n. 24
0
import datetime
from Utils.Hacks import type
from Utils import Logger

logger = Logger.getLogger("Annotation/AnnoObject", Logger.DEBUG)

#--------------------------------------------
class Annotation(object):
    "Base Annotation Class, it is a container for data placed on sets of strokes."

    def __init__(self):
        self.Strokes = [] # list of strokes that this annotates
        self.Time = datetime.datetime.utcnow() # time used for debuging replay

    def isType( self, arg):
        "Input: either a classobj, or a list of classobjs.  Return true if this class is one of the classobjs listed"
        if type(arg) == "list":
            clist = arg
        else:
            clist = [arg]

        if self.__class__ in clist:
            return True
        else:
            return False

    def classname( self ):
        "Returns a string with the name of this type of annotation"
        return self.__class__.__name__ 

#--------------------------------------------
Esempio n. 25
0
>>> c.onStrokeAdded(Stroke(circlepoints))

"""

#-------------------------------------

import math
from Utils import Logger
from Utils import GeomUtils

from SketchFramework.Point import Point
from SketchFramework.Stroke import Stroke
from SketchFramework.Board import BoardObserver
from SketchFramework.Annotation import Annotation, AnnotatableObject

logger = Logger.getLogger('LineObserver', Logger.WARN )

#-------------------------------------

class LineAnnotation(Annotation):
    def __init__(self, linearity, angle, start_point, end_point ):
        Annotation.__init__(self) 
        self.linearity = linearity
        self.angle = angle
        self.start_point = start_point
        self.end_point = end_point

#-------------------------------------

class LineMarker( BoardObserver ):
    "Watches for lines, and annotates them with the linearity and angle"
Esempio n. 26
0
import string
import sys

from Utils import Logger
from Utils import GeomUtils

from Observers import ObserverBase

from xml.etree import ElementTree as ET

import pdb

from SketchFramework.Annotation import Annotation, AnnotatableObject


logger = Logger.getLogger('Rubine', Logger.WARN )

#------------------------------------------------------------
class Stroke:
    COUNT = 0
    def __init__(self, points = [], id = None):
        if id is None:
            self.id = Stroke.COUNT
        else:
            self.id = id
        Stroke.COUNT = self.id + 1 #Try to avoid conflicts

        self.points = points

class Dataset():
    # top class of the data set. Containes each participant
Esempio n. 27
0
from  SketchFramework.Stroke import Stroke
from  SketchFramework.Point import Point
from Utils import Logger

logger = Logger.getLogger('StrokeStorage', Logger.DEBUG)


class StrokeStorage(object):
   def __init__(self, filename = "strokes.dat"):
      self._fname = filename
   def saveStrokes(self, strokelist):
      fd = open(self._fname, "w")
      for strk in strokelist:
         print >> fd, "#STROKE"
         for p in strk.Points:
            print >> fd, "  %s %s %s" % ( p.X, p.Y, p.T)
         print >> fd, "#ENDSTROKE"
         logger.debug("Saved Stroke with %s points" % (len(strk.Points)) )
      fd.close()
   def loadStrokes(self):
      fd = open(self._fname, "r")
      curStroke = None
      for line in fd.readlines():
         if line.startswith("#STROKE"):
            curStroke = Stroke()
         elif line.startswith("#ENDSTROKE"):
            logger.debug("Loaded Stroke with %s points" % (len(curStroke.Points)) )
            yield curStroke
            curStroke = None
         else:
            fields = line.split()
Esempio n. 28
0
from Utils.Hacks import type
from pyjamas.Canvas2D import Canvas
from pyjamas.ui.RootPanel import RootPanel
from pyjamas.ui import Event
from pyjamas.ui.MouseListener import MouseHandler
from pyjamas import DOM 
from pyjamas import Window

import math

from __pyjamas__ import jsinclude
jsinclude("javascript/processing.js")
from __javascript__ import Processing


logger = Logger.getLogger('PyjSketchGUI', Logger.DEBUG)

WIDTH = 1024
HEIGHT = 768 

_Singleton = None

def SketchGUISingleton():
   global _Singleton
   if _Singleton is None:
      _Singleton = _PyjSketchGUI()
   return _Singleton


class _PyjSketchGUI(_SketchGUI):
   def __init__(self, *args, **kargs):
Esempio n. 29
0
--- lists of strokes ---
- computes the bounding box of a list of strokes, and returns a tuple of
- point as (topleft,bottomright)
>>> (tl,br) = strokelistBoundingBox( [instroke, instroke] )
>>> str(tl),str(br)
('(1.0,343.0)', '(343.0,1.0)')

"""

import math
import sys
from Utils import Logger
from SketchFramework.Point import Point
from SketchFramework.Stroke import Stroke

logger = Logger.getLogger('GeomUtils', Logger.WARN )

#--------------------------------------------------------------
# Functions on Points

# FIXME: maybe these should be functions on "cordinates" rather than points


def pointDistanceSquared(X1, Y1, X2, Y2):
    "Input: two points. Returns the squared distance between the points"
    distance = (X2 - X1) ** 2 + (Y2 - Y1) ** 2
    return distance

def pointDistance(X1, Y1, X2, Y2):
    "Input: two points. Returns the euclidian distance between the points"
    return math.sqrt(float(pointDistanceSquared(X1,Y1,X2,Y2)));
Esempio n. 30
0
from Utils import Logger
from Utils import GeomUtils

from Observers import CircleObserver
from Observers import LineObserver
from Observers import ObserverBase

from SketchFramework.Point import Point
from SketchFramework.Stroke import Stroke
from SketchFramework.Board import BoardObserver
from SketchFramework.Annotation import Annotation, AnnotatableObject

from xml.etree import ElementTree as ET


logger = Logger.getLogger('TextObserver', Logger.WARN )

#-------------------------------------

class BinAnnotation(Annotation):
    def __init__(self, text, scale):
        "Create a Bin annotation. text is the string, and scale is an appropriate size"
        Annotation.__init__(self)
        self.text = text # a string for the text
        self.scale = scale # an approximate "size" for the text
        self.alternates = [text]
    def xml(self):
        root = Annotation.xml(self)
        root.attrib["text"] = self.text
        root.attrib['scale'] = str(self.scale)
        for i, a in enumerate(self.alternates):