thanvardefs.py :  » Business-Application » ThanCad » thancad-0.0.9 » thandefs » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Business Application » ThanCad 
ThanCad » thancad 0.0.9 » thandefs » thanvardefs.py
##############################################################################
# ThanCad 0.0.9 "DoesSomething": 2dimensional CAD with raster support for engineers.
# 
# Copyright (c) 2001-2009 Thanasis Stamos,  August 23, 2009
# URL:     http://thancad.sourceforge.net
# e-mail:  cyberthanasis@excite.com
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details (www.gnu.org/licenses/gpl.html).
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
##############################################################################

"""\
ThanCad 0.0.9 "DoesSomething": 2dimensional CAD with raster support for engineers.

This module defines the ThanCad TextStyle, and an object used if an image is
not found or if Python Image Library is not installed.
"""
import copy

class ThanTstyle:
    def __init__(self, name, font, height=0.0, widthfactor=1.0, obliqueangle=0.0,
                 upsidedown=False, backwards=False, vertical=False):
        "Initialise textstyle object."
  self.thanName = name
  self.thanFont       = font.thanCopy()
  self.thanHeight     = height
  self.thanWidthfactor= widthfactor
  self.thanOblique    = obliqueangle
        self.thanUpsidedown = upsidedown
  self.thanBackwards  = backwards
  self.thanVertical   = vertical
#  self.thanRecreate()

    def thanCopy(self):
        "Make a distinct copy of self."
  c = copy.copy(self)
  c.thanFont = self.thanFont.thanCopy()
  return c


class ThanImageMissing:
    def __init__(self, size=(100,100)): self.size = size
    def copy    (self): return ThanImageMissing(self.size)
    def __error (self):  raise ValueError, "Image was not found/not supported/corrupted."
    def getpixel(self, *args, **kw): self.__error()
    def resize  (self, *args, **kw): self.__error()
    def crop    (self, *args, **kw): self.__error()
    def paste   (self, *args, **kw): self.__error()


class ThanCoor(list):
    "A list with attribute aliases."
    def __getx(self): return self[0]
    def __gety(self): return self[1]
    def __getz(self): return self[2]
    def __gett(self): return self[3]
    def __setx(self, val): self[0] = val
    def __sety(self, val): self[1] = val
    def __setz(self, val): self[2] = val
    def __sett(self, val): self[3] = val
    x = property(__getx, __setx)
    y = property(__gety, __sety)
    z = property(__getz, __setz)
    t = property(__gett, __sett)


def testThanCoorMemory():
    "Tests the memory consumed by this class."
    import time
    from p_ggen import prg
    a = []
    c = [1.0,2.0,3.0]
    n = 1100000
    cl = ThanCoor
    t1 = time.time()
    for i in xrange(n):
        a.append(cl(c))
    t2 = time.time()
    prg("Time for ThanCoor: %s" % (t2-t1,))
    x=raw_input()


def testThanCoor():
    "Tests the list class."
    from p_ggen import prg
    c = ThanCoor((1.0,2.0,3.0,4.0))
    prg("%s" % c)
    prg("x=%s=%s" % (c[0], c.x))
    prg("y=%s=%s" % (c[0], c.y))
    prg("z=%s=%s" % (c[0], c.z))
    prg("t=%s=%s" % (c[0], c.t))
    c.x = 10
    c.y = 20
    c.z = 30
    c.t = 40
    prg("%s" % c)
    prg("x=%s=%s" % (c[0], c.x))
    prg("y=%s=%s" % (c[0], c.y))
    prg("z=%s=%s" % (c[0], c.z))
    prg("t=%s=%s" % (c[0], c.t))
    c = ThanCoor((1.0,2.0,3.0))
    prg("%s" % c)
    prg("x=%s=%s" % (c[0], c.x))
    prg("y=%s=%s" % (c[0], c.y))
    prg("z=%s=%s" % (c[0], c.z))
    prg("t=%s=%s" % (c[0], c.t))


class ThanMultiSet:
    "Multilevel set."

    def __init__(self):
        "Create level 0 set."
        self.__sets = [set()]
        self.thanLevel = 0

    def add(self, val):
        "Add point to the highest level set."
        self.__sets[-1].add(val)

    def in_(self, val):
        "Check if val is in one of the sets."
        for set1 in self.__sets:
            if val in set1: return True
        return False


    def pushLevel(self):
        "Create a new level of sets."
        self.thanLevel += 1
        self.__sets.append(set())


    def popLevel(self):
        "Delete the highest level of sets."
        assert len(self.__sets) > 0, "There is no level to delete!"
        self.__sets.pop()

    def clear(self):
        "Empties the multiset."
        del self.__sets[1:]
        self.__sets[0].clear()


if __name__ == "__main__":
    print __doc__
    testThanCoorMemory()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.