|
1 | | -#!/usr/bin/env python2.4 |
| 1 | +#!/usr/bin/env |
2 | 2 |
|
3 | | -from wxPython.wx import * |
| 3 | +import wx |
4 | 4 |
|
| 5 | +# set an image file here |
| 6 | +img_filename = 'Images/white_tank.jpg' |
5 | 7 |
|
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) |
9 | | - ##wxScrolledWindow.__init__(self, parent) |
10 | | - ## read the image in (this is not a good place to do this in a real app) |
11 | 8 |
|
12 | | - print "about to Init" |
| 9 | +class MyCanvas(wx.ScrolledWindow): |
| 10 | + def __init__(self, *args, **kwargs): |
| 11 | + wx.ScrolledWindow.__init__(self, *args, **kwargs) |
13 | 12 |
|
14 | | - wxInitAllImageHandlers() |
| 13 | + self.bmp = wx.Image(img_filename).ConvertToBitmap() |
15 | 14 |
|
16 | | - print "done initing" |
| 15 | + self.maxWidth, self.maxHeight = self.bmp.GetWidth(), self.bmp.GetHeight() |
17 | 16 |
|
18 | | - #img = wxImage("white_tank.jpg",wxBITMAP_TYPE_JPEG ) |
19 | | - #img = wxImage("white_tank.jpg") |
20 | | - #bmp = img.ConvertToBitmap() |
21 | | - #jpg = wxImage(opj('bitmaps/image.jpg'), wxBITMAP_TYPE_JPEG).ConvertToBitmap() |
| 17 | + self.SetScrollbars(20, 20, self.maxWidth / 20, self.maxHeight / 20) |
22 | 18 |
|
23 | | - self.bmp = wxImage('Images/white_tank.jpg', wxBITMAP_TYPE_JPEG ).ConvertToBitmap() |
| 19 | + self.Bind(wx.EVT_PAINT, self.OnPaint) |
24 | 20 |
|
25 | | - print "done loading image" |
26 | | - |
27 | | - self.maxWidth, self.maxHeight = self.bmp.GetWidth(), self.bmp.GetHeight() |
28 | | - |
29 | | - self.SetScrollbars(20, 20, self.maxWidth/20, self.maxHeight/20) |
30 | | - |
31 | | - EVT_PAINT(self, self.OnPaint) |
| 21 | + # an arbitrary rect to draw -- in pixel coords |
| 22 | + self.rect = (200, 200, 300, 200) # x, y, width, height |
32 | 23 |
|
33 | 24 | def OnPaint(self, event): |
34 | | - dc = wxPaintDC(self) |
| 25 | + dc = wx.PaintDC(self) |
35 | 26 | self.PrepareDC(dc) |
36 | | - dc.DrawBitmap(self.bmp, 0, 0) |
37 | 27 |
|
| 28 | + dc.SetPen(wx.Pen(wx.RED, 2)) |
| 29 | + dc.SetBrush(wx.Brush((255, 255, 255, 85))) |
38 | 30 |
|
39 | | -class TestFrame(wxFrame): |
40 | | - def __init__(self,parent, id,title,position,size): |
41 | | - wxFrame.__init__(self,parent, id,title,position, size) |
| 31 | + dc.DrawBitmap(self.bmp, 0, 0) |
| 32 | + dc.DrawRectangle(*self.rect) |
42 | 33 |
|
43 | 34 |
|
44 | | - EVT_CLOSE(self, self.OnCloseWindow) |
| 35 | +class TestFrame(wx.Frame): |
| 36 | + def __init__(self, *args, **kwargs): |
| 37 | + wx.Frame.__init__(self, *args, **kwargs) |
45 | 38 |
|
| 39 | + wx.EVT_CLOSE(self, self.OnCloseWindow) |
46 | 40 |
|
47 | | - self.Canvas1 = MyCanvas(self, wxNewId() ) |
| 41 | + self.Canvas1 = MyCanvas(self, wx.NewId()) |
48 | 42 |
|
49 | 43 | def OnCloseWindow(self, event): |
50 | 44 | self.Destroy() |
51 | 45 |
|
52 | | -class App(wxApp): |
| 46 | + |
| 47 | +class App(wx.App): |
53 | 48 | def OnInit(self): |
54 | | - frame = TestFrame(NULL, -1, "Scroll Test", wxDefaultPosition,(550,200)) |
| 49 | + frame = TestFrame(None, title="Scroll Test", size=(800, 700)) |
55 | 50 | self.SetTopWindow(frame) |
56 | 51 | frame.Show(True) |
57 | | - return true |
| 52 | + return True |
58 | 53 |
|
59 | 54 | if __name__ == "__main__": |
60 | 55 |
|
61 | | - app = App(0) |
62 | | - print "about to start Mainloop" |
| 56 | + app = App(False) |
63 | 57 |
|
64 | 58 | app.MainLoop() |
65 | | - |
| 59 | + |
66 | 60 |
|
67 | 61 |
|
68 | 62 |
|
|
0 commit comments