In Python 3.10, a change[1] was implemented where extension functions
that take integer arguments will no longer silently accept non-integer
arguments (e.g., floats) that can only be converted to integers with a
loss of precision. This PR fixes most of these issues in the pure-Python
classes and demos by explicitly converting the parameters to int before
passing them to wxWidgets. There is loss of precision, but this was
happening before (automatically) anyway as most wxWidgets DeviceContext
functions operate using integers.
Additionally, the PR fixes a few sizing issues, mostly with SpinCtrls being
too small on GTK3.
This is an example of the relevant exception:
Traceback (most recent call last):
File "/usr/lib64/python3.10/site-packages/wx/lib/agw/pygauge.py", line 355, in OnPaint
r.width = w
TypeError: 'float' object cannot be interpreted as an integer
Fixes#2038.
[1] https://bugs.python.org/issue37999
ThumbnailCtrl is more of a image browser demo application than a widget,
in that it reads files from a directory, selects which files to display,
deletes files, displays the source directory path in a text ctrl, etc.
This makes it unlikely that it could be used in any other application,
for example, to provide thumbnails of files with different file types
than the ones hard-coded in the class.
ThumbnailCtrl delegates most of its operations to ScrolledThumbnail
which actually implements a scrolled window of thumbnails, a Thumb class,
which contains information about a thumbnail, and an ImageHandler class,
which manipulates images. There was poor isolation of functionality
between these classes, violating object-oriented design, with one class
making changes to the internal data of another class. Additionally, there
was substantial non-functional code, as well as code which did not
function correctly.
This refactoring maintains the functionality and interfaces of
ThumbnailCtrl, except for those which were unused. Existing uses of
the thumbnailctrl package should work without modification. A new package,
scrolledthumbnail, contains the functionality for a scrolled window
containing thumbnails, an extendable Thumb class, and image manipulation
classes. The scrolledthumbnail package can be used in other applications,
independent of the ThumbnailCtrl class, and without the functional
restrictions of that application.
Detailed changes:
ThumbnailCtrl.py (demo program):
- Always import from wx.lib.agw
- Optional code to use PIL instead of native image handling
- Add setting for thumbnail width and height
- Increase size of demo window
thumbnailctrl.py:
- Move Thumb, ScrolledThumbnail, ImageHandler to scrolledthumbnail.py
- Remove EVT_THUMBNAILS_CAPTION_CHANGED (unused)
- Add EVT_THUMBNAILS_CHAR to respond to keystrokes
- Remove image processing code
- Add scrolling dialog for delete files
- Move directory processing from ScrolledThumbnail
- Move file delete processing from ScrolledThumbnail
- List all files to be deleted in scrolling dialog
- Remove unused or unimplemented methods and options
scrolledthumbnail.py:
- Move Thumb, ScrolledThumbnail, ImageHander classes from thumbnailctrl.py
- Add documentation for ScrolledThumbnail widget
- Add example program which does not use ThumbnailCtrl
- New EVT_THUMBNAILS_CHAR event for key press
- Remove unused options and dead code
- Add Rotate() to PILImageHandler and NativeImageHandler
- Throw event EVT_THUMBNAILS_CHAR for keystroke on thumbnail
- Fix failure to rotate images correctly
- Redisplay window when thumb size changed
- Simplify logic
- Remove popup dialog when rotating images