an0malaus opened this issue on Oct 14, 2019 ยท 9 posts
an0malaus posted Mon, 14 October 2019 at 4:31 AM
I have a problem. There are many ways to build user interfaces with wxPython, but due to the lack of development in this area of Poser to date, we are currently stuck with such old versions that many options are buggy or simply do not work at all on either Windows or MacOS or both.
I am encountering many code examples which simply do not and possibly cannot work within Poser Python, because they rely on the wxApp() initialisation to instantiate functions like wx.BLACK and wx.WHITE that seem to be heavily relied upon by various flavours of UI managers within wxPython.
My particular need was to have ToolTips on wx.Notebook page tabs, but they are not supported. The wx.lib.agw.aui.AuiNotebook is purported to support this, but cannot be accessed, because it relies on wx.App() having initialised. Poser has its own alternative, poser.WxAuiManager(), but does not make the frequently used colour functions available (wx.BLACK & wx.WHITE, etc.), throwing errors whenever these are referenced.
wx.App() cannot be used at all, as it's event loop is in conflict with Poser's own and will immediately crash Poser to the desktop if called.
I have found certain magic incantations that supposedly can perform the necessary initialisation/instantiation, but they are not designed for use in Poser, so do not work.
wxWidgets How to initialze wxApp...
This link also appears specifically relevant wxPython 2.6 Migration Guide in its Module Initialisation section.
Verbosity: Profusely promulgating Graham's number epics of complete and utter verbiage by the metric monkey barrel.
adp001 posted Mon, 14 October 2019 at 6:36 AM
Maybe you can create your own ToolTip handling with (wx.window).SetTooltip(...)
.
https://docs.wxpython.org/wx.ToolTip.html#wx.ToolTip
an0malaus posted Mon, 14 October 2019 at 7:33 AM
Thanks Freddi, I think I may have found the solution by trawling through some of SnarlyGribbly's scripts. It appears that
import wx, wx.aui, wx.lib.agw.aui as aui
wx.StockGDI._initStockObjects()
is the thing which finally initialises what I need, since now:
>>> wx.WHITE
wx.Colour(255, 255, 255, 255)
I get what I expect from that initialised name, rather than just wx.Colour(), which is no use to man or beast.
Off to plug it in and check it out.
Verbosity: Profusely promulgating Graham's number epics of complete and utter verbiage by the metric monkey barrel.
adp001 posted Mon, 14 October 2019 at 11:26 AM
wx.WHITE and wx.BLACK are no functions.
The following in my Linux-Environment:
import wx
print(wx.version())
print(wx.WHITE)
results in:
3.0.2.0 gtk3 (classic)
Traceback (most recent call last):
print(wx.WHITE)
File "/usr/lib/python2.7/dist-packages/wx-3.0-gtk3/wx/_gdi.py", line 278, in __str__
def __str__(self): return str(self.Get(True))
File "/usr/lib/python2.7/dist-packages/wx-3.0-gtk3/wx/_gdi.py", line 266, in Get
return _gdi_.Colour_Get(*args, **kwargs)
TypeError: in method 'Colour_Get', expected argument 1 of type 'wxColour *'
Seems Poser-Python is not guilty here :)
an0malaus posted Mon, 14 October 2019 at 12:07 PM
Gotta compare eggs with eggs. It's a different wx version, and there were substantial changes between wx 2.9.1 and 3.0. Probably even moreso between wxMAC and wxGTK.
Anyway, the kind of error you're seeing is exactly the same as what I had if I tried to instantiate a wx.lib.agw.aui.AuiNotebook, without having a call to wxApp() (Prohibited in Poser as it breaks Poser's own event loop). Fortunately, the call wx.StockGDI._initStockObjects() is exactly the thing that was missing to correctly define wx.WHITE and all the other class objects that normally happens in wxApp().
Here's my working AuiNotebook example.
Verbosity: Profusely promulgating Graham's number epics of complete and utter verbiage by the metric monkey barrel.
adp001 posted Mon, 14 October 2019 at 5:47 PM
Here is what wx.StockGDI._initStockObjects() does: https://github.com/wxWidgets/Phoenix/blob/master/src/stockgdi.sip
Seems a good idea to call it with every wx PoserPython script.
an0malaus posted Tue, 15 October 2019 at 12:15 AM
Yes, exactly, it's the missing magic that Poser scripts need in the absence of being able to instantiate wxApp() which does that very thing we need.
It really ought to be in an example script provided with Poser script samples.
Verbosity: Profusely promulgating Graham's number epics of complete and utter verbiage by the metric monkey barrel.
Snarlygribbly posted Tue, 15 October 2019 at 2:11 PM
adp001 posted at 8:10PM Tue, 15 October 2019 - #4367113
Here is what wx.StockGDI._initStockObjects() does: https://github.com/wxWidgets/Phoenix/blob/master/src/stockgdi.sip
Seems a good idea to call it with every wx PoserPython script.
I have made templates for regular Poser scripts and Poser addon scripts, and this is one of the lines that I consider essential enough to feature in my templates.
Free stuff @ https://poser.cobrablade.net/
an0malaus posted Tue, 15 October 2019 at 6:49 PM
Thanks, Snarly. Was trying to catch you for a question on mat file image conflicts between simple and shader-tree which seems to affect EZDome, but it'll wait.
Verbosity: Profusely promulgating Graham's number epics of complete and utter verbiage by the metric monkey barrel.