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
class ThumbDemoConfig contains the user interface and controls used
by both ScrolledThumbnail and ThumbnailCtrl.
Functions which are different between the two demos are overwridden
by each demo.
demo/agw/ScrolledThumbnail.py:
Set frame size to (850, 800).
Decrease left side of splitter.
Use default font.
Remove SetAutoLayout()
Fix THUMB_OUTLINE_NONE, etc. not found.
demo/agw/Thumbnailctrl.py:
Set frame size to (850, 800).
Make scroll instance variable, not local.
Replace self.TC with self.scroll.
Decrease left side of splitter.
Use default font.
Remove SetAutoLayout().
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
Feature addition
Add SetDragFullScreen and GetDragFullScreen methods which changes the
way the simplified drag/drop works in the tree. This flag is passed
to the wx.DragImage.BeginDrag() method when it is called.
Also add this option to HyperTreeList.
Modify the CustomTreeCtrl and HyperTreeList demos so it can be tested.
Feature addition.
Add SetColumnSortIcon() method to HyperTreeList so that a native sort
arrow can be easily shown in the header columns. For some reason does
not work on GTK (won't draw arrow) but works great on Windows/MacOS.
Modify the demo with LIST_COL_CLICK event options so it can be tested.
CustomTreeCtrl and HyperTreeList use wx.SYS_COLOUR_LISTBOX for their
default background colors. This defaults to dank Grey on MSW/GTK/MacOS
even though the TreeCtrl and ListCtrl on all three platforms default
to a white background. Use a trick from UltimateListCtrl to take
default colors from wx.ListCtrl.
This can be seen in the demos, except that the CustomTreeCtrl demo
forces its background to wx.WHITE. With these changes forcing the
background color is no longer necessary and allows the controls to
take on the native background color for themes that change it.
In CustomTreeCtrl and HyperTreeList the SetItemText method recalculates
the size of the item row in which the text was changed. If the number
of lines in the text changes the entire tree must be recalculated
as all items below must be shifted to compensate. This change attempts
to recalculate the entire tree only when necessary (when number of
lines change) in order not to slow down existing code that performs a
lot of SetItemText() operations on an unfrozen tree.
Add a "Change Item Text" option to the CustomTreeCtrl and HyperTreeList
demos so that this can be tested. Before this fix, changing the number
of lines of text in an item would leave gaps or create overlaps
between items in the tree.
The HyperTreeList demo receives events from an embedded TreeCtrl
window which reports a different item type (TreeItemId) than the
HyperTreeList events (TreeListItem). This throws an exception:
AttributeError: 'TreeItemId' object has no attribute 'GetText'.
Guard against this by only processing events with TreeListItem items.
To reproduce, start the HyperTreeList demo and expand "item 0-a" then
enable it by clicking the radio button. Selecting any item in the
ListCtrl, or expanding/collapsing a tree node will generate exceptions.
Move item hiding from HyperTreeList to CustomTreeCtrl so that both
trees can have the feature.
Add a HideItemWindows() method to hide windows only for a specific item
and its children. This is much faster than calling HideWindows().
Add context menu options to the CustomTreeCtrl demo so that Hiding
can be tested.
Hiding items was only partially implemented and very buggy.
This feature does not exist in CustomTreeCtrl but I see no reason why
it couldn't be added in the future. This fix requires the arrow key fixes
in order for arrow keys to work reliably in a tree with hidden items.
Hidden items always report they are disabled and not expanded.
Also updates the demo of HyperTreeList to add hide options to context
menu so the feature can be tested.
Since I had to fix a image issue and optimize it. I decided to rerun FileOptimizer 13.30.2393 over all pngs. Small bytes for some that had been optimized before, but this comit covers all pngs that may have been missed in the past. Maybe revisit running them all again in 2 years. Total time to process all pngs: approx 8 hours.
As technology improves this will only get better/faster when downloading, loading in browser, embedded, etc...