Skip to content

Commit 2b27f3c

Browse files
authored
Update image_viewer_working.py
Fixes for wxPython 4.1.1+
1 parent c097c26 commit 2b27f3c

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

chapter2_image_viewer/image_viewer_working.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def __init__(self, parent, image_size):
99
self.max_size = 240
1010

1111
img = wx.Image(*image_size)
12-
self.image_ctrl = wx.StaticBitmap(self,
12+
self.image_ctrl = wx.StaticBitmap(self,
1313
bitmap=wx.Bitmap(img))
1414

1515
browse_btn = wx.Button(self, label='Browse')
@@ -37,29 +37,29 @@ def on_browse(self, event):
3737
wildcard = "JPEG files (*.jpg)|*.jpg"
3838
with wx.FileDialog(None, "Choose a file",
3939
wildcard=wildcard,
40-
style=wx.ID_OPEN) as dialog:
40+
style=wx.FD_OPEN) as dialog:
4141
if dialog.ShowModal() == wx.ID_OK:
4242
self.photo_txt.SetValue(dialog.GetPath())
4343
self.load_image()
44-
44+
4545
def load_image(self):
4646
"""
4747
Load the image and display it to the user
4848
"""
4949
filepath = self.photo_txt.GetValue()
5050
img = wx.Image(filepath, wx.BITMAP_TYPE_ANY)
51-
51+
5252
# scale the image, preserving the aspect ratio
5353
W = img.GetWidth()
5454
H = img.GetHeight()
5555
if W > H:
5656
NewW = self.max_size
57-
NewH = self.max_size * H / W
57+
NewH = int(self.max_size * H / W)
5858
else:
5959
NewH = self.max_size
60-
NewW = self.max_size * W / H
60+
NewW = int(self.max_size * W / H)
6161
img = img.Scale(NewW,NewH)
62-
62+
6363
self.image_ctrl.SetBitmap(wx.Bitmap(img))
6464
self.Refresh()
6565

@@ -75,4 +75,4 @@ def __init__(self):
7575
if __name__ == '__main__':
7676
app = wx.App(redirect=False)
7777
frame = MainFrame()
78-
app.MainLoop()
78+
app.MainLoop()

0 commit comments

Comments
 (0)