File: TestSpline.py

package info (click to toggle)
wxpython4.0 4.2.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 221,752 kB
  • sloc: cpp: 962,555; python: 230,573; ansic: 170,731; makefile: 51,756; sh: 9,342; perl: 1,564; javascript: 584; php: 326; xml: 200
file content (185 lines) | stat: -rw-r--r-- 4,596 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/usr/bin/env python


"""
This is a very small app using the FloatCanvas

It tests the Spline object, including how you can put points together to
create an object with curves and square corners.


"""
import wx

#### import local version:
#import sys
#sys.path.append("../")
#from floatcanvas import NavCanvas
#from floatcanvas import FloatCanvas as FC

from wx.lib.floatcanvas import FloatCanvas as FC
from wx.lib.floatcanvas import NavCanvas

class Spline(FC.Line):
    def __init__(self, *args, **kwargs):
            FC.Line.__init__(self, *args, **kwargs)

    def _Draw(self, dc , WorldToPixel, ScaleWorldToPixel, HTdc=None):
        Points = WorldToPixel(self.Points)
        dc.SetPen(self.Pen)
        dc.DrawSpline(Points)
        if HTdc and self.HitAble:
            HTdc.SetPen(self.HitPen)
            HTdc.DrawSpline(Points)

class DrawFrame(wx.Frame):

    """
    A frame used for the FloatCanvas

    """
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)

        ## Set up the MenuBar
        MenuBar = wx.MenuBar()

        file_menu = wx.Menu()
        item = file_menu.Append(-1, "&Close","Close this frame")
        self.Bind(wx.EVT_MENU, self.OnQuit, item)
        MenuBar.Append(file_menu, "&File")

        help_menu = wx.Menu()
        item = help_menu.Append(-1, "&About",
                                "More information About this program")
        self.Bind(wx.EVT_MENU, self.OnAbout, item)
        MenuBar.Append(help_menu, "&Help")

        self.SetMenuBar(MenuBar)
        self.CreateStatusBar()

        # Add the Canvas
        self.Canvas = NavCanvas.NavCanvas(self,
                                          BackgroundColor = "White",
                                          ).Canvas

        self.Canvas.Bind(FC.EVT_MOTION, self.OnMove)

        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)

        self.DrawTest()
        self.Show()
        self.Canvas.ZoomToBB()

    def OnAbout(self, event):
        print("OnAbout called")

        dlg = wx.MessageDialog(self, "This is a small program to demonstrate\n"
                                                  "the use of the FloatCanvas\n",
                                                  "About Me", wx.OK | wx.ICON_INFORMATION)
        dlg.ShowModal()
        dlg.Destroy()

    def OnMove(self, event):
        """
        Updates the status bar with the world coordinates
        """
        self.SetStatusText("%.2f, %.2f"%tuple(event.Coords))

    def OnQuit(self,event):
        self.Close(True)

    def OnCloseWindow(self, event):
        self.Destroy()

    def DrawTest(self,event=None):
        wx.GetApp().Yield()

        Canvas = self.Canvas

        Points = [(0, 0),
                  (200,0),
                  (200,0),
                  (200,0),
                  (200,15),
                  (185,15),
                  (119,15),
                  (104,15),
                  (104,30),
                  (104,265),
                  (104,280),
                  (119,280),
                  (185,280),
                  (200,280),
                  (200,295),
                  (200,295),
                  (200,295),
                  (0, 295),
                  (0, 295),
                  (0, 295),
                  (0, 280),
                  (15, 280),
                  (81, 280),
                  (96, 280),
                  (96, 265),
                  (96, 30),
                  (96, 15),
                  (81, 15),
                  (15, 15),
                  (0, 15),
                  (0, 0),
                  ]

        Canvas.ClearAll()

        MyLine = FC.Spline(Points,
                      LineWidth = 3,
                      LineColor = "Blue")

        Canvas.AddObject(MyLine)
        Canvas.AddPointSet(Points,
                           Color = "Red",
                           Diameter = 4,
                           )

        ## A regular old spline:
        Points = [(-30, 260),
                  (-10, 130),
                  (70, 185),
                  (160,60),
                  ]

        Canvas.AddSpline(Points,
                             LineWidth = 5,
                             LineColor = "Purple")

class DemoApp(wx.App):

    def __init__(self, *args, **kwargs):
        wx.App.__init__(self, *args, **kwargs)

    def OnInit(self):
        frame = DrawFrame(None, title="FloatCanvas Spline Demo", size = (700,700))

        self.SetTopWindow(frame)
        return True

app = DemoApp(False)# put in True if you want output to go to it's own window.
app.MainLoop()