]>
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
)
14 self
.SetBackgroundColour(wxNamedColor("WHITE"))
15 self
.Connect(-1, -1, wxEVT_LEFT_DOWN
, self
.OnLeftButtonEvent
)
16 self
.Connect(-1, -1, wxEVT_LEFT_UP
, self
.OnLeftButtonEvent
)
17 self
.Connect(-1, -1, wxEVT_MOTION
, self
.OnLeftButtonEvent
)
19 self
.SetCursor(wxStockCursor(wxCURSOR_PENCIL
))
20 bmp
= wxBitmap('bitmaps/test2.bmp', wxBITMAP_TYPE_BMP
)
23 self
.SetScrollbars(20, 20, self
.maxWidth
/20, self
.maxHeight
/20)
32 def OnPaint(self
, event
):
38 def DoDrawing(self
, dc
):
40 pen1
= wxPen(wxNamedColour('RED'))
42 dc
.DrawRectangle(5, 5, 50, 50)
44 dc
.SetBrush(wxLIGHT_GREY_BRUSH
)
45 dc
.SetPen(wxPen(wxNamedColour('BLUE'), 4))
46 dc
.DrawRectangle(15, 15, 50, 50)
48 font
= wxFont(14, wxSWISS
, wxNORMAL
, wxNORMAL
)
50 dc
.SetTextForeground(wxColour(0xFF, 0x20, 0xFF))
51 te
= dc
.GetTextExtent("Hello World")
52 dc
.DrawText("Hello World", 60, 65)
54 dc
.SetPen(wxPen(wxNamedColour('VIOLET'), 4))
55 dc
.DrawLine(5, 65+te
[1], 60+te
[0], 65+te
[1])
57 lst
= [(100,110), (150,110), (150,160), (100,160)]
58 dc
.DrawLines(lst
, -60)
60 dc
.DrawPolygon(lst
, 75)
61 dc
.SetPen(wxGREEN_PEN
)
62 dc
.DrawSpline(lst
+[(100,100)])
64 dc
.DrawBitmap(self
.bmp
, 200, 20)
65 dc
.SetTextForeground(wxColour(0, 0xFF, 0x80))
66 dc
.DrawText("a bitmap", 200, 85)
68 self
.DrawSavedLines(dc
)
72 def DrawSavedLines(self
, dc
):
73 dc
.SetPen(wxPen(wxNamedColour('MEDIUM FOREST GREEN'), 4))
74 for line
in self
.lines
:
76 apply(dc
.DrawLine
, coords
)
79 def SetXY(self
, event
):
80 self
.x
, self
.y
= self
.ConvertEventCoords(event
)
82 def ConvertEventCoords(self
, event
):
83 xView
, yView
= self
.ViewStart()
84 xDelta
, yDelta
= self
.GetScrollPixelsPerUnit()
85 return (event
.GetX() + (xView
* xDelta
),
86 event
.GetY() + (yView
* yDelta
))
88 def OnLeftButtonEvent(self
, event
):
93 elif event
.Dragging():
97 dc
.SetPen(wxPen(wxNamedColour('MEDIUM FOREST GREEN'), 4))
98 coords
= (self
.x
, self
.y
) + self
.ConvertEventCoords(event
)
99 self
.curLine
.append(coords
)
100 apply(dc
.DrawLine
, coords
)
105 self
.lines
.append(self
.curLine
)
108 #---------------------------------------------------------------------------
110 def runTest(frame
, nb
, log
):
114 #---------------------------------------------------------------------------