um mir - gerade für Testzwecke oder Experimente - das Entwickeln von (einfachen) wxPython GUIs ein wenig zu erleichtern, habe ich folgenden Decorator geschrieben.
Angewendet auf eine wx.Frame erbende Klasse welches als quasi "MainFrame/Window" für die GUI-Anwendung dienen soll, lassen sich mit ein paar Konfigurationen, komfortabel und mit wenigen Zeilen Code eine wxAppication starten.

Also ... viel Spass damit

Code: Alles auswählen
!/usr/bin/env python
"""
WxPython convenient application boot strap decorator for wx.Frames classes.
Supports `no` or optional following parameters which will overwrite initialzing attributes of the frame
* name
* size
* pos (supports also wx.CENTER... constants for a litte bit more convenience)
* icon (icon path or wx.Icon instance)
"""
import os
import wx
class wxApp(object):
VALID_FRAME_OPTS = ['name', 'size', 'pos', 'icon']
def __init__(self, *args, **kwargs):
self._args = args
self._kwargs = kwargs
for elem in kwargs:
if not elem in self.VALID_FRAME_OPTS:
raise ValueError("invalid argument '%s'" % elem)
if len(args) == 1 and type(args[0]) == type:
for super_clazz in args[0].__bases__:
if super_clazz == wx.Frame:
self._app_boot_trap(args[0])
def __call__(self, clazz):
self._app_boot_trap(clazz)
def _app_boot_trap(self, frame_clazz):
if frame_clazz.__module__ == '__main__': # avoid running on 'imports'
app = wx.App(False)
frame = frame_clazz()
name = self._kwargs.get('name', None)
if name and name.strip() and isinstance(name, (str, unicode)):
frame.SetTitle(name.strip())
size = self._kwargs.get('size', None)
if size and isinstance(size, (list, tuple, wx.Size)):
frame.SetSize(self._kwargs['size'])
pos = self._kwargs.get('pos', None)
if pos:
if isinstance(pos, (list, tuple, wx.Point)):
frame.SetPosition(pos)
elif pos in [wx.CENTER, wx.CENTER_FRAME, wx.CENTER_ON_SCREEN]:
frame.Center()
icon = self._kwargs.get('icon', None)
if icon:
if isinstance(icon, (str, unicode)) and os.path.isfile(icon):
icon = wx.Icon(icon)
if isinstance(icon, wx.Icon):
frame.SetIcon(icon)
frame.Show()
app.MainLoop()
- ohne call Parameter
- mit call Parameter (name, size, pos, icon)
- und zuletzt ein Beispiel unter Verwendung von super(), welches nicht funktionieren wird ... tja ... vielleicht kennt ja wer noch eine Lösung für das Problem, ansonsten heisst eben auf super zu verzichten

Code: Alles auswählen
@wxApp
class TestFrameSimple(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None)
Code: Alles auswählen
@wxApp(name="TestFrame", size=(800, 600), pos=wx.CENTER, icon='python_icon.gif')
class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "will be overwritten", size=(100, 200))
Code: Alles auswählen
@wxApp
class TestFrameNeverWorkCauseSuper(wx.Frame):
def __init__(self):
super(TestFrameNeverWorkCauseSuper, self).__init__(None, -1, "not works")
# super() is not supported
Traceback (most recent call last):
...
NameError: global name 'TestFrameNeverWorkCauseSuper' is not defined