]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/wxScrolledWindow.py
527209813077c80b46fb2d3e7643e18b6772747e
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
)
16 self
.SetBackgroundColour(wxNamedColor("WHITE"))
17 EVT_LEFT_DOWN(self
, self
.OnLeftButtonEvent
)
18 EVT_LEFT_UP(self
, self
.OnLeftButtonEvent
)
19 EVT_MOTION(self
, self
.OnLeftButtonEvent
)
20 EVT_PAINT(self
, self
.OnPaint
)
22 self
.SetCursor(wxStockCursor(wxCURSOR_PENCIL
))
23 bmp
= images
.getTest2Bitmap()
24 mask
= wxMaskColour(bmp
, wxBLUE
)
28 self
.SetScrollbars(20, 20, self
.maxWidth
/20, self
.maxHeight
/20)
38 def OnPaint(self
, event
):
44 def DoDrawing(self
, dc
):
46 dc
.SetPen(wxPen(wxNamedColour('RED')))
47 dc
.DrawRectangle(5, 5, 50, 50)
49 dc
.SetBrush(wxLIGHT_GREY_BRUSH
)
50 dc
.SetPen(wxPen(wxNamedColour('BLUE'), 4))
51 dc
.DrawRectangle(15, 15, 50, 50)
53 dc
.SetFont(wxFont(14, wxSWISS
, wxNORMAL
, wxNORMAL
))
54 dc
.SetTextForeground(wxColour(0xFF, 0x20, 0xFF))
55 te
= dc
.GetTextExtent("Hello World")
56 dc
.DrawText("Hello World", 60, 65)
58 dc
.SetPen(wxPen(wxNamedColour('VIOLET'), 4))
59 dc
.DrawLine(5, 65+te
[1], 60+te
[0], 65+te
[1])
61 lst
= [(100,110), (150,110), (150,160), (100,160)]
62 dc
.DrawLines(lst
, -60)
64 dc
.DrawPolygon(lst
, 75)
65 dc
.SetPen(wxGREEN_PEN
)
66 dc
.DrawSpline(lst
+[(100,100)])
68 dc
.DrawBitmap(self
.bmp
, 200, 20, true
)
69 dc
.SetTextForeground(wxColour(0, 0xFF, 0x80))
70 dc
.DrawText("a bitmap", 200, 85)
72 font
= wxFont(20, wxSWISS
, wxNORMAL
, wxNORMAL
)
74 dc
.SetTextForeground(wxBLACK
)
75 for a
in range(0, 360, 45):
76 dc
.DrawRotatedText("Rotated text...", 300, 300, a
)
78 dc
.SetPen(wxTRANSPARENT_PEN
)
79 dc
.SetBrush(wxBLUE_BRUSH
)
80 dc
.DrawRectangle(50,500,50,50)
81 dc
.DrawRectangle(100,500,50,50)
83 dc
.SetPen(wxPen(wxNamedColour('RED')))
84 dc
.DrawEllipticArc(200, 500, 50, 75, 0, 90)
87 for style
in [wxDOT
, wxLONG_DASH
, wxSHORT_DASH
, wxDOT_DASH
, wxUSER_DASH
]:
88 pen
= wxPen("DARK ORCHID", 1, style
)
89 if style
== wxUSER_DASH
:
90 pen
.SetDashes([1, 2, 3, 4, 5, 6, 7, 8])
94 dc
.DrawLine(300, y
, 400, y
)
97 self
.DrawSavedLines(dc
)
102 def DrawSavedLines(self
, dc
):
103 dc
.SetPen(wxPen(wxNamedColour('MEDIUM FOREST GREEN'), 4))
104 for line
in self
.lines
:
106 apply(dc
.DrawLine
, coords
)
109 def SetXY(self
, event
):
110 self
.x
, self
.y
= self
.ConvertEventCoords(event
)
112 def ConvertEventCoords(self
, event
):
113 xView
, yView
= self
.GetViewStart()
114 xDelta
, yDelta
= self
.GetScrollPixelsPerUnit()
115 return (event
.GetX() + (xView
* xDelta
),
116 event
.GetY() + (yView
* yDelta
))
118 def OnLeftButtonEvent(self
, event
):
124 elif event
.Dragging():
125 dc
= wxClientDC(self
)
128 dc
.SetPen(wxPen(wxNamedColour('MEDIUM FOREST GREEN'), 4))
129 coords
= (self
.x
, self
.y
) + self
.ConvertEventCoords(event
)
130 self
.curLine
.append(coords
)
131 apply(dc
.DrawLine
, coords
)
136 self
.lines
.append(self
.curLine
)
141 ## This is an example of what to do for the EVT_MOUSEWHEEL event,
142 ## but since wxScrolledWindow does this already it's not
143 ## necessary to do it ourselves.
146 ## def OnWheel(self, evt):
147 ## delta = evt.GetWheelDelta()
148 ## rot = evt.GetWheelRotation()
149 ## linesPer = evt.GetLinesPerAction()
150 ## ws = self.wheelScroll
152 ## lines = ws / delta
153 ## ws = ws - lines * delta
154 ## self.wheelScroll = ws
156 ## lines = lines * linesPer
157 ## vsx, vsy = self.GetViewStart()
158 ## scrollTo = vsy - lines
159 ## self.Scroll(-1, scrollTo)
161 #---------------------------------------------------------------------------
163 def runTest(frame
, nb
, log
):
167 #---------------------------------------------------------------------------