Issue #1591 <https://github.com/leo-editor/leo-editor/issues/1591> concerns
disappearing icons in the todo.py plugin, but only for recent versions of
pyqt. This post discusses a discovery I made while studying the code.
The todo.py plugin uses todo.ui. This is an xml file created by Qt
Designer. Qt can create the entire UI with a single call to
uic.loadUiType(<<path to todo.ui>>)
I've known about this capability for 15+ years, but I never really paid
attention to it because I thought that using a .ui file was inflexible. But
that's totally wrong.
This line from todo.py showed me the truth:
self.ui.UI.txtDetails.setText(txt)
Originally I had planned to create an alternate version of todo.ui that
would replace icons in the various buttons with text. So I was pretty
familiar with the structure of todo.ui. From that study, I knew that
txtDetails is a name of an xml element:
<widget class="QFrame" name="frmDetails">...</widget>
I was discussing this issue with Rebecca two night ago when I suddenly
realized that there is no need for an alternate todo.ui. Instead, the
patch_1591 method contains the workaround. I won't show the entire method
here, but the code to patch the "priority" buttons is elegant:
ui = self.ui.UI
# Add text and tooltips to all numeric priority buttons.
for i in range(10):
button = getattr(ui, f"butPri{i}")
button.setText(f"{i}")
button.setToolTip(f"Priority {i}")
Oh my. I immediately saw that I could use the same pattern to patch *any*
attribute of any *python* object created by loadUiType. That includes, for
example, all the layout objects in todo.ui. And really, all the other
properties in todo.ui.
*Summary*
For at least a decade I have mistakenly believed that using a .ui file
would create an inflexible ui. But that's completely wrong. I could have
designed all aspects of Leo's ui with Qt designer, including docks, the
Find Panel, etc., etc, while *still* retaining the ability to set and query
the corresponding python objects.
In other words, *lots* of Leo's gui code is unnecessary.
Edward
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/leo-editor/3bac9b48-5417-45b8-b754-1de8c3d51212n%40googlegroups.com.