Hi, is there a program that can scan your program’s source code or python compiled files and create a list of used widgets, then make a minimal wxPython library file that only has the widgets your program needs?
Hi Misbah,
All modules imported in the program are stored in sys.modules
dictionary.
import sys
import re
for k, v in sys.modules.items():
# if re.match(r"wx[.]*", k):
if k == 'wx' or k.startswith('wx.'):
print(v)
So if you try this, you will get the following results:
<module 'wx.__version__' from 'C:\\Python39\\lib\\site-packages\\wx\\__version__.py'>
<module 'wx.siplib' from 'C:\\Python39\\lib\\site-packages\\wx\\siplib.cp39-win_amd64.pyd'>
<module 'wx._core' from 'C:\\Python39\\lib\\site-packages\\wx\\_core.cp39-win_amd64.pyd'>
<module 'wx.core' from 'C:\\Python39\\lib\\site-packages\\wx\\core.py'>
<module 'wx' from 'C:\\Python39\\lib\\site-packages\\wx\\__init__.py'>
...
Thank you for the help. Your code does print the .py and .so files used by a program but it doesn’t tell you which widgets your program is currently using.
I understand. How about this?
from pprint import pprint
def dump():
def _dump(widget):
for obj in widget.GetChildren():
yield obj.__class__
for x in _dump(obj): # dump as flatiter
yield x
for w in wx.GetTopLevelWindows():
pprint(w.__class__)
pprint(list(_dump(w)))
Nice code!
I tried it in this program:
import wx
from pprint import pprint
def dump():
def _dump(widget):
for obj in widget.GetChildren():
yield obj.__class__
for x in _dump(obj): # dump as flatiter
yield x
for w in wx.GetTopLevelWindows():
pprint(w.__class__)
pprint(list(_dump(w)))
def main():
app = wx.App()
frame = wx.Frame(None, title="Hi")
panel = wx.Panel(frame)
st = wx.StaticText(panel, -1, "Hello world", pos=(50,50))
button = wx.Button(panel, -1, "Push", pos=(140, 50))
button.Bind(wx.EVT_BUTTON, doit)
frame.Show()
app.MainLoop()
def doit(evt):
wx.Bell()
dump()
if __name__ == "__main__":
main()
The result was this:
<class ‘wx._core.Frame’>
[<class ‘wx._core.Panel’>,
<class ‘wx._core.StaticText’>,
<class ‘wx._core.Button’>]
Now I have to figure out how to make wxPython. So far I have made progress with building wxwidgets. Using the following command I was able to shrink wxwidgets down from over 50 files to only three and from a 15 MB file for libwx_osx_cocoau-3.1.5.0.0.dylib down to 11.7 MB.
./configure --with-libtiff=no --with-libjpeg=no --with-libpng=no --disable-sys-libs --enable-monolithic --enable-joystick=no --with-zlib=no --with-regex=no --with-expat --enable-svg=no --disable-compat30 --enable-webview=no --enable-filehistory=no --enable-filesystem=no --enable-fontenum --enable-fontmap=no --enable-fs_archive=no --enable-fs_inet=no --enable-fs_zip=no --enable-fsvolume=no --enable-fswatcher=no --enable-geometry --enable-html=no --enable-graphics_ctx=no --enable-docview=no --enable-dctransform=no --enable-mdi=no --enable-richtext=no