driscollis / applications_with_wxpython

Code examples for the book, Creating GUI Application with wxPython
https://www.blog.pythonlibrary.org
116 stars 26 forks source link

wxWidgets version?? #52

Open tester0077 opened 2 years ago

tester0077 commented 2 years ago

Just purchased the book and am working my way through the examples. In chapter 2, with the image viewer, I have run into one problem and one warning. FWIW, I am new to wxPython & Python, but not wxWidgets and my goal - partially achieved already - is to use wxFormBuilder as a front-end for designing the GUI itself.

In order to sort out the problems I am running into, I am now running the file image_viewer_working.py from the github repo in the current Visual Stdio Code 1.64.0 (user setup) - running Win 10-64-bit The problem message when running the code: __PS D:\pkg\python\wxFB\wxPython\ImageViewer> d:; cd 'd:\pkg\python\wxFB\wxPython\ImageViewer'; & 'C:\Users\arnold\AppData\Local\Programs\PythonCodingPack\python.exe' 'c:\Users\arnold.vscode\extensions\ms-python.python-2022.0.1786462952\pythonFiles\lib\python\debugpy\launcher' '59120' '--' 'd:\pkg\python\wxPython\applications_with_wxpython-master\chapter2_image_viewer\image_viewer_working.py'
Traceback (most recent call last): File "d:\pkg\python\wxPython\applications_with_wxpython-master\chapter2_image_viewer\image_viewer_working.py", line 43, in on_browse self.photo_txt.SetValue(dialog.GetPath()) wx._core.wxAssertionError: C++ assertion ""!HasFlag(wxFD_MULTIPLE)"" failed at C:\PROJECTS\bb2\dist-win64-py38\build\ext\wxWidgets\include\wx/filedlg.h(109) in wxFileDialogBase::GetPath(): When using wxFD_MULTIPLE, must call GetPaths() instead__

and the image is never displayed because of this exception. replacing line 40 : style=wx.ID_OPEN) as dialog: with : style=wx.FD_OPEN) as dialog:

gives me the warning _d:; cd 'd:\pkg\python\wxFB\wxPython\ImageViewer'; & 'C:\Users\arnold\AppData\Local\Programs\PythonCodingPack\python.exe' 'c:\Users\arnold.vscode\extensions\ms-python.python-2022.0.1786462952\pythonFiles\lib\python\debugpy\launcher' '59190' '--' 'd:\pkg\python\wxPython\applications_with_wxpython-master\chapter2_image_viewer\image_viewer_working.py'
d:\pkg\python\wxPython\applications_with_wxpython-master\chapter2_image_viewer\image_viewerworking.py:62: DeprecationWarning: an integer is required (got type float). Implicit conversion to integers using int is deprecated, and may be removed in a future version of Python. img = img.Scale(NewW,NewH)

though the image is displayed as I would expect, though, at this stage I am unsure about what to expect.

Questions: 1) is there a way to easily tell which version of wxPython is being used, version which version(s) might be installed? 2) is there a way to easily tell which version of wxWidgets wxPython is using? Again, as opposed to which version(s) of wsWidgets might be installed on the PC

The first problem is seemingly caused by a mismatch of the wxWidgets versions expected by your code and what is installed on my system - the PC I am running this one has ONLY wxWidgets 3.1.4

driscollis commented 2 years ago

I installed the latest wxPython version when I wrote that book, which was wxPython 4. I think 4.1.1 is out now, but that version should work the same way with this book's code.

But yes, the example you mentioned should definitely be style=wx.FD_OPEN. I think I had tried that example using an earlier version of wxPython on accident and left that in there.

You can get the version info by doing this:

import wx

print(wx.version())
tester0077 commented 2 years ago

Thank you. Being new to Python etc, I am still learning many 'new' things.

There is line missing in the code for the first image viewer code ( p. 24) in the book: self.max_size = 240

Still, your book has gotten me "off the ground" and I will be referring to its content on a regular basis as I am getting used to Python and its way of doing things. Arnold

On Tue, Feb 8, 2022 at 8:32 AM Mike Driscoll @.***> wrote:

I installed the latest wxPython version when I wrote that book, which was wxPython 4. I think 4.1.1 is out now, but that version should work the same way with this book's code.

But yes, the example you mentioned should definitely be style=wx.FD_OPEN. I think I had tried that example using an earlier version of wxPython on accident and left that in there.

You can get the version info by doing this:

import wx

print(wx.version())

— Reply to this email directly, view it on GitHub https://github.com/driscollis/applications_with_wxpython/issues/52#issuecomment-1032817303, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACFCLPAKSABA5NPXQBEKMH3U2FASNANCNFSM5NYIKJWQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you authored the thread.Message ID: @.***>

abcdenis commented 1 year ago
When using wxFD_MULTIPLE, must call GetPaths() instead

Can be fixed by using dialog.GetPaths()[0] instead of dialog.GetPath()