]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/demo/wxScrolledWindow.py
2 from wxPython
.wx
import *
4 #---------------------------------------------------------------------------
6 class MyCanvas(wxScrolledWindow
):
7 def __init__(self
, parent
):
8 wxScrolledWindow
.__init
__(self
, parent
, -1, wxPoint(0, 0), wxPyDefaultSize
, wxSUNKEN_BORDER
)
12 self
.SetBackgroundColour(wxNamedColor("WHITE"))
13 self
.Connect(-1, -1, wxEVT_LEFT_DOWN
, self
.OnLeftButtonEvent
)
14 self
.Connect(-1, -1, wxEVT_LEFT_UP
, self
.OnLeftButtonEvent
)
15 self
.Connect(-1, -1, wxEVT_MOTION
, self
.OnLeftButtonEvent
)
17 self
.SetCursor(wxStockCursor(wxCURSOR_PENCIL
))
18 bmp
= wxBitmap('bitmaps/test2.bmp', wxBITMAP_TYPE_BMP
)
21 self
.SetScrollbars(20, 20, 50, 50)
24 def OnPaint(self
, event
):
30 def DoDrawing(self
, dc
):
33 pen1
= wxPen(wxNamedColour('RED'))
35 dc
.DrawRectangle(5, 5, 50, 50)
37 dc
.SetBrush(wxLIGHT_GREY_BRUSH
)
38 dc
.SetPen(wxPen(wxNamedColour('BLUE'), 4))
39 dc
.DrawRectangle(15, 15, 50, 50)
41 font
= wxFont(14, wxSWISS
, wxNORMAL
, wxNORMAL
)
43 dc
.SetTextForeground(wxColour(0xFF, 0x20, 0xFF))
44 te
= dc
.GetTextExtent("Hello World")
45 dc
.DrawText("Hello World", 60, 65)
47 dc
.SetPen(wxPen(wxNamedColour('VIOLET'), 4))
48 dc
.DrawLine(5, 65+te
[1], 60+te
[0], 65+te
[1])
50 lst
= [(100,110), (150,110), (150,160), (100,160)]
51 dc
.DrawLines(lst
, -60)
53 dc
.DrawPolygon(lst
, 75)
54 dc
.SetPen(wxGREEN_PEN
)
55 dc
.DrawSpline(lst
+[(100,100)])
57 dc
.DrawBitmap(self
.bmp
, 200, 20)
58 dc
.SetTextForeground(wxColour(0, 0xFF, 0x80))
59 dc
.DrawText("a bitmap", 200, 80)
61 self
.DrawSavedLines(dc
)
65 def DrawSavedLines(self
, dc
):
66 dc
.SetPen(wxPen(wxNamedColour('MEDIUM FOREST GREEN'), 4))
67 for line
in self
.lines
:
69 apply(dc
.DrawLine
, coords
)
72 def SetXY(self
, event
):
73 self
.x
, self
.y
= self
.ConvertEventCoords(event
)
75 def ConvertEventCoords(self
, event
):
76 xView
, yView
= self
.ViewStart()
77 xDelta
, yDelta
= self
.GetScrollPixelsPerUnit()
78 return (event
.GetX() + (xView
* xDelta
),
79 event
.GetY() + (yView
* yDelta
))
81 def OnLeftButtonEvent(self
, event
):
86 elif event
.Dragging():
90 dc
.SetPen(wxPen(wxNamedColour('MEDIUM FOREST GREEN'), 4))
91 coords
= (self
.x
, self
.y
) + self
.ConvertEventCoords(event
)
92 self
.curLine
.append(coords
)
93 apply(dc
.DrawLine
, coords
)
98 self
.lines
.append(self
.curLine
)
101 #---------------------------------------------------------------------------
103 def runTest(frame
, nb
, log
):
107 #---------------------------------------------------------------------------