]>
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
)
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
)
21 EVT_PAINT(self
, self
.OnPaint
)
24 self
.SetCursor(wxStockCursor(wxCURSOR_PENCIL
))
25 bmp
= images
.getTest2Bitmap()
26 mask
= wxMaskColour(bmp
, wxBLUE
)
30 self
.SetScrollbars(20, 20, self
.maxWidth
/20, self
.maxHeight
/20)
39 def OnPaint(self
, event
):
45 def DoDrawing(self
, dc
):
47 dc
.SetPen(wxPen(wxNamedColour('RED')))
48 dc
.DrawRectangle(5, 5, 50, 50)
50 dc
.SetBrush(wxLIGHT_GREY_BRUSH
)
51 dc
.SetPen(wxPen(wxNamedColour('BLUE'), 4))
52 dc
.DrawRectangle(15, 15, 50, 50)
54 dc
.SetFont(wxFont(14, wxSWISS
, wxNORMAL
, wxNORMAL
))
55 dc
.SetTextForeground(wxColour(0xFF, 0x20, 0xFF))
56 te
= dc
.GetTextExtent("Hello World")
57 dc
.DrawText("Hello World", 60, 65)
59 dc
.SetPen(wxPen(wxNamedColour('VIOLET'), 4))
60 dc
.DrawLine(5, 65+te
[1], 60+te
[0], 65+te
[1])
62 lst
= [(100,110), (150,110), (150,160), (100,160)]
63 dc
.DrawLines(lst
, -60)
65 dc
.DrawPolygon(lst
, 75)
66 dc
.SetPen(wxGREEN_PEN
)
67 dc
.DrawSpline(lst
+[(100,100)])
69 dc
.DrawBitmap(self
.bmp
, 200, 20, true
)
70 dc
.SetTextForeground(wxColour(0, 0xFF, 0x80))
71 dc
.DrawText("a bitmap", 200, 85)
73 font
= wxFont(20, wxSWISS
, wxNORMAL
, wxNORMAL
)
75 dc
.SetTextForeground(wxBLACK
)
76 for a
in range(0, 360, 45):
77 dc
.DrawRotatedText("Rotated text...", 300, 300, a
)
79 dc
.SetPen(wxTRANSPARENT_PEN
)
80 dc
.SetBrush(wxBLUE_BRUSH
)
81 dc
.DrawRectangle(50,500,50,50)
82 dc
.DrawRectangle(100,500,50,50)
84 dc
.SetPen(wxPen(wxNamedColour('RED')))
85 dc
.DrawEllipticArc(200, 500, 50, 75, 0, 90)
87 self
.DrawSavedLines(dc
)
92 def DrawSavedLines(self
, dc
):
93 dc
.SetPen(wxPen(wxNamedColour('MEDIUM FOREST GREEN'), 4))
94 for line
in self
.lines
:
96 apply(dc
.DrawLine
, coords
)
99 def SetXY(self
, event
):
100 self
.x
, self
.y
= self
.ConvertEventCoords(event
)
102 def ConvertEventCoords(self
, event
):
103 xView
, yView
= self
.GetViewStart()
104 xDelta
, yDelta
= self
.GetScrollPixelsPerUnit()
105 return (event
.GetX() + (xView
* xDelta
),
106 event
.GetY() + (yView
* yDelta
))
108 def OnLeftButtonEvent(self
, event
):
114 elif event
.Dragging():
115 dc
= wxClientDC(self
)
118 dc
.SetPen(wxPen(wxNamedColour('MEDIUM FOREST GREEN'), 4))
119 coords
= (self
.x
, self
.y
) + self
.ConvertEventCoords(event
)
120 self
.curLine
.append(coords
)
121 apply(dc
.DrawLine
, coords
)
126 self
.lines
.append(self
.curLine
)
130 #---------------------------------------------------------------------------
132 def runTest(frame
, nb
, log
):
136 #---------------------------------------------------------------------------