]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxScrolledWindow.py
2 from wxPython
.wx
import *
6 #---------------------------------------------------------------------------
8 class MyCanvas(wxScrolledWindow
):
9 def __init__(self
, parent
, id = -1, size
= wxDefaultSize
):
10 wxScrolledWindow
.__init
__(self
, parent
, id, wxPoint(0, 0), size
, wxSUNKEN_BORDER
)
17 self
.SetBackgroundColour(wxNamedColor("WHITE"))
18 EVT_LEFT_DOWN(self
, self
.OnLeftButtonEvent
)
19 EVT_LEFT_UP(self
, self
.OnLeftButtonEvent
)
20 EVT_MOTION(self
, self
.OnLeftButtonEvent
)
21 EVT_PAINT(self
, self
.OnPaint
)
23 self
.SetCursor(wxStockCursor(wxCURSOR_PENCIL
))
24 bmp
= images
.getTest2Bitmap()
25 mask
= wxMaskColour(bmp
, wxBLUE
)
29 self
.SetScrollbars(20, 20, self
.maxWidth
/20, self
.maxHeight
/20)
39 def OnPaint(self
, event
):
41 #print self.count, "begin paint...",
48 def DoDrawing(self
, dc
):
50 dc
.SetPen(wxPen(wxNamedColour('RED')))
51 dc
.DrawRectangle(5, 5, 50, 50)
53 dc
.SetBrush(wxLIGHT_GREY_BRUSH
)
54 dc
.SetPen(wxPen(wxNamedColour('BLUE'), 4))
55 dc
.DrawRectangle(15, 15, 50, 50)
57 dc
.SetFont(wxFont(14, wxSWISS
, wxNORMAL
, wxNORMAL
))
58 dc
.SetTextForeground(wxColour(0xFF, 0x20, 0xFF))
59 te
= dc
.GetTextExtent("Hello World")
60 dc
.DrawText("Hello World", 60, 65)
62 dc
.SetPen(wxPen(wxNamedColour('VIOLET'), 4))
63 dc
.DrawLine(5, 65+te
[1], 60+te
[0], 65+te
[1])
65 lst
= [(100,110), (150,110), (150,160), (100,160)]
66 dc
.DrawLines(lst
, -60)
68 dc
.DrawPolygon(lst
, 75)
69 dc
.SetPen(wxGREEN_PEN
)
70 dc
.DrawSpline(lst
+[(100,100)])
72 dc
.DrawBitmap(self
.bmp
, 200, 20, true
)
73 dc
.SetTextForeground(wxColour(0, 0xFF, 0x80))
74 dc
.DrawText("a bitmap", 200, 85)
76 font
= wxFont(20, wxSWISS
, wxNORMAL
, wxNORMAL
)
78 dc
.SetTextForeground(wxBLACK
)
79 for a
in range(0, 360, 45):
80 dc
.DrawRotatedText("Rotated text...", 300, 300, a
)
82 dc
.SetPen(wxTRANSPARENT_PEN
)
83 dc
.SetBrush(wxBLUE_BRUSH
)
84 dc
.DrawRectangle(50,500,50,50)
85 dc
.DrawRectangle(100,500,50,50)
87 dc
.SetPen(wxPen(wxNamedColour('RED')))
88 dc
.DrawEllipticArc(200, 500, 50, 75, 0, 90)
91 for style
in [wxDOT
, wxLONG_DASH
, wxSHORT_DASH
, wxDOT_DASH
, wxUSER_DASH
]:
92 pen
= wxPen("DARK ORCHID", 1, style
)
93 if style
== wxUSER_DASH
:
94 pen
.SetDashes([1, 2, 3, 4, 5, 6, 7, 8])
97 dc
.DrawLine(300, y
, 400, y
)
100 dc
.SetBrush(wxNullBrush
)
101 dc
.SetPen(wxPen(wxColour(0xFF, 0x20, 0xFF), 1, wxSOLID
))
102 dc
.DrawRectangle(450, 50, 100, 100)
103 old_pen
= dc
.GetPen()
104 new_pen
= wxPen("BLACK", 5)
106 dc
.DrawRectangle(470, 70, 60, 60)
108 dc
.DrawRectangle(490, 90, 20, 20)
111 self
.DrawSavedLines(dc
)
115 def DrawSavedLines(self
, dc
):
116 dc
.SetPen(wxPen(wxNamedColour('MEDIUM FOREST GREEN'), 4))
117 for line
in self
.lines
:
119 apply(dc
.DrawLine
, coords
)
122 def SetXY(self
, event
):
123 self
.x
, self
.y
= self
.ConvertEventCoords(event
)
125 def ConvertEventCoords(self
, event
):
126 xView
, yView
= self
.GetViewStart()
127 xDelta
, yDelta
= self
.GetScrollPixelsPerUnit()
128 return (event
.GetX() + (xView
* xDelta
),
129 event
.GetY() + (yView
* yDelta
))
131 def OnLeftButtonEvent(self
, event
):
137 elif event
.Dragging():
138 dc
= wxClientDC(self
)
141 dc
.SetPen(wxPen(wxNamedColour('MEDIUM FOREST GREEN'), 4))
142 coords
= (self
.x
, self
.y
) + self
.ConvertEventCoords(event
)
143 self
.curLine
.append(coords
)
144 apply(dc
.DrawLine
, coords
)
149 self
.lines
.append(self
.curLine
)
154 ## This is an example of what to do for the EVT_MOUSEWHEEL event,
155 ## but since wxScrolledWindow does this already it's not
156 ## necessary to do it ourselves.
159 ## def OnWheel(self, evt):
160 ## delta = evt.GetWheelDelta()
161 ## rot = evt.GetWheelRotation()
162 ## linesPer = evt.GetLinesPerAction()
163 ## ws = self.wheelScroll
165 ## lines = ws / delta
166 ## ws = ws - lines * delta
167 ## self.wheelScroll = ws
169 ## lines = lines * linesPer
170 ## vsx, vsy = self.GetViewStart()
171 ## scrollTo = vsy - lines
172 ## self.Scroll(-1, scrollTo)
174 #---------------------------------------------------------------------------
176 def runTest(frame
, nb
, log
):
180 #---------------------------------------------------------------------------