File: floatCanvasTest.py

package info (click to toggle)
pythoncard 0.8.2-2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 8,452 kB
  • sloc: python: 56,787; makefile: 56; sh: 22
file content (140 lines) | stat: -rw-r--r-- 5,054 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/python

"""
__version__ = "$Revision: 1.1 $"
__date__ = "$Date: 2004/09/14 23:41:14 $"
"""

"""
try:
    import Numeric
    import random
    import RandomArray
    haveNumeric = True
except ImportError:
    haveNumeric = False
"""

import os
import wx
from PythonCard import model

class Doodle(model.Background):

    def on_initialize(self, event):
        self.singleItemExpandingSizerLayout()
        
        ## getting all the colors and linestyles  for random objects
        # don't need this since PythonCard has already called it
        #wx.lib.colourdb.updateColourDB()
        self.colors = wx.lib.colourdb.getColourList()
        self.DrawTest()

    def DrawTest(self,event=None):
        wx.GetApp().Yield()
        import random
        import RandomArray
        Range = (-10,10)
        colors = self.colors

        #self.BindAllMouseEvents()
        Canvas = self.components.float

        Canvas.ClearAll()
        Canvas.SetProjectionFun(None)

        ## Random tests of everything:
        
        # Rectangles
        for i in range(3):
            x,y = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
            lw = random.randint(1,5)
            cf = random.randint(0,len(colors)-1)
            h = random.randint(1,5)
            w = random.randint(1,5)
            Canvas.AddRectangle(x,y,h,w,LineWidth = lw,FillColor = colors[cf])
          
        # Ellipses
        for i in range(3):
            x,y = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
            lw = random.randint(1,5)
            cf = random.randint(0,len(colors)-1)
            h = random.randint(1,5)
            w = random.randint(1,5)
            Canvas.AddEllipse(x,y,h,w,LineWidth = lw,FillColor = colors[cf])
          
##            # Dots -- Does anyone need this?
##            for i in range(5):
##                x,y = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
##                D = random.randint(1,50)
##                lw = random.randint(1,5)
##                cf = random.randint(0,len(colors)-1)
##                cl = random.randint(0,len(colors)-1)
##                Canvas.AddDot(x,y,D,LineWidth = lw,LineColor = colors[cl],FillColor = colors[cf])
          
            # Circles
        for i in range(5):
            x,y = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
            D = random.randint(1,5)
            lw = random.randint(1,5)
            cf = random.randint(0,len(colors)-1)
            cl = random.randint(0,len(colors)-1)
            Canvas.AddCircle(x,y,D,LineWidth = lw,LineColor = colors[cl],FillColor = colors[cf])
            Canvas.AddText("Circle # %i"%(i),x,y,Size = 12,BackgroundColor = None,Position = "cc")
          
            # Lines
        for i in range(5):
            points = []
            for j in range(random.randint(2,10)):
                point = (random.randint(Range[0],Range[1]),random.randint(Range[0],Range[1]))
                points.append(point)
            lw = random.randint(1,10)
            cf = random.randint(0,len(colors)-1)
            cl = random.randint(0,len(colors)-1)
            Canvas.AddLine(points, LineWidth = lw, LineColor = colors[cl])
          
            # Polygons
        for i in range(3):
            points = []
            for j in range(random.randint(2,6)):
                point = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
                points.append(point)
            lw = random.randint(1,6)
            cf = random.randint(0,len(colors)-1)
            cl = random.randint(0,len(colors)-1)
            Canvas.AddPolygon(points,
                                   LineWidth = lw,
                                   LineColor = colors[cl],
                                   FillColor = colors[cf],
                                   FillStyle = 'Solid')
                            
        ## Pointset
        for i in range(4):
            points = []
            points = RandomArray.uniform(Range[0],Range[1],(100,2))
            cf = random.randint(0,len(colors)-1)
            D = random.randint(1,4)
            Canvas.AddPointSet(points, Color = colors[cf], Diameter = D)
        
        # Text
        String = "Unscaled text"
        for i in range(3):
            ts = random.randint(10,40)
            cf = random.randint(0,len(colors)-1)
            x,y = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
            Canvas.AddText(String, x, y, Size = ts, Color = colors[cf], Position = "cc")

        # Scaled Text
        String = "Scaled text"
        for i in range(3):
            ts = random.random()*3 + 0.2
            cf = random.randint(0,len(colors)-1)
            x,y = (random.uniform(Range[0],Range[1]),random.uniform(Range[0],Range[1]))
            Canvas.AddScaledText(String, x, y, Size = ts, Color = colors[cf], Position = "cc")

        Canvas.ZoomToBB()


if __name__ == '__main__':
    app = model.Application(Doodle)
    app.MainLoop()