]>
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
, id = -1, size
= wxDefaultSize
):
8 wxScrolledWindow
.__init
__(self
, parent
, id, wxPoint(0, 0), size
, 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
)
21 mask
= wxMaskColour(bmp
, wxBLUE
)
25 self
.SetScrollbars(20, 20, self
.maxWidth
/20, self
.maxHeight
/20)
34 def OnPaint(self
, event
):
40 def DoDrawing(self
, dc
):
42 pen1
= wxPen(wxNamedColour('RED'))
44 dc
.DrawRectangle(5, 5, 50, 50)
46 dc
.SetBrush(wxLIGHT_GREY_BRUSH
)
47 dc
.SetPen(wxPen(wxNamedColour('BLUE'), 4))
48 dc
.DrawRectangle(15, 15, 50, 50)
50 font
= wxFont(14, wxSWISS
, wxNORMAL
, wxNORMAL
)
52 dc
.SetTextForeground(wxColour(0xFF, 0x20, 0xFF))
53 te
= dc
.GetTextExtent("Hello World")
54 dc
.DrawText("Hello World", 60, 65)
56 dc
.SetPen(wxPen(wxNamedColour('VIOLET'), 4))
57 dc
.DrawLine(5, 65+te
[1], 60+te
[0], 65+te
[1])
59 lst
= [(100,110), (150,110), (150,160), (100,160)]
60 dc
.DrawLines(lst
, -60)
62 dc
.DrawPolygon(lst
, 75)
63 dc
.SetPen(wxGREEN_PEN
)
64 dc
.DrawSpline(lst
+[(100,100)])
66 dc
.DrawBitmap(self
.bmp
, 200, 20, true
)
67 dc
.SetTextForeground(wxColour(0, 0xFF, 0x80))
68 dc
.DrawText("a bitmap", 200, 85)
70 self
.DrawSavedLines(dc
)
74 def DrawSavedLines(self
, dc
):
75 dc
.SetPen(wxPen(wxNamedColour('MEDIUM FOREST GREEN'), 4))
76 for line
in self
.lines
:
78 apply(dc
.DrawLine
, coords
)
81 def SetXY(self
, event
):
82 self
.x
, self
.y
= self
.ConvertEventCoords(event
)
84 def ConvertEventCoords(self
, event
):
85 xView
, yView
= self
.ViewStart()
86 xDelta
, yDelta
= self
.GetScrollPixelsPerUnit()
87 return (event
.GetX() + (xView
* xDelta
),
88 event
.GetY() + (yView
* yDelta
))
90 def OnLeftButtonEvent(self
, event
):
95 elif event
.Dragging():
99 dc
.SetPen(wxPen(wxNamedColour('MEDIUM FOREST GREEN'), 4))
100 coords
= (self
.x
, self
.y
) + self
.ConvertEventCoords(event
)
101 self
.curLine
.append(coords
)
102 apply(dc
.DrawLine
, coords
)
107 self
.lines
.append(self
.curLine
)
110 #---------------------------------------------------------------------------
112 def runTest(frame
, nb
, log
):
116 #---------------------------------------------------------------------------