From: Alec B. <wry...@gm...> - 2008-12-30 07:22:59
|
I'm trying to subclass the Minimal example so I can make the window always on top. I'm having trouble doing it though. Can someone possibly point out what I'm doing wrong? Here's my stripped down example, called test.py. Note the 3rd parameter currently called "dummy" in the init statement, which might be a source of troubule. Also I was wondering if I need to define a panel? And if so, does it need to have a specific name? from PythonCard import model import wx class Minimal(model.Background): def __init__(self, parent, dummy): wx.Frame.__init__(self, parent, -1, "Test", style = wx.STAY_ON_TOP) #panel = wx.Panel(self, -1) self.Show() if __name__ == '__main__': app = model.Application(Minimal) app.MainLoop() Here's the resource file, called test.rsrc.py: {'application':{'type':'Application', 'name':'Minimal', 'backgrounds': [ {'type':'Background', 'name':'bgMin', 'title':u'Tester', 'size':(403, 371), 'backgroundColor':(0, 0, 0), 'style':['resizeable'], 'components': [ {'type':'StaticText', 'name':'Testing', 'position':(151, 131), 'font':{'faceName': u'Tahoma', 'family': 'sansSerif', 'size': 12}, 'foregroundColor':(255, 255, 0, 255), 'text':u'Testing', }, ] # end components } # end background ] # end backgrounds } } |
From: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - 2008-12-30 19:28:39
|
On Mon, 29 Dec 2008 23:22:55 -0800 "Alec Bennett" <wry...@gm...> wrote: > I'm trying to subclass the Minimal example so I can make the window > always on top. I'm having trouble doing it though. Can someone > possibly point out what I'm doing wrong? If I understand the PythonCard model.py source correctly, the Application object initializes the Background object but you have created an __init__ method in Minimal so that gets called instead. You don't then call the Background __init__ which does various other start-up tasks and I'm guessing that is why the application does not work. (You don't say what is wrong when you run it, but trying it here I just get a blank window). If you just want to add the STAY_ON_TOP style then try the following...it seems to work here: from PythonCard import model class Minimal(model.Background): def __init__(self, aParent, aBgRsrc): aBgRsrc.style = ['wx.DEFAULT_FRAME_STYLE','wx.STAY_ON_TOP'] model.Background.__init__(self, aParent, aBgRsrc) if __name__ == '__main__': app = model.Application(Minimal) app.MainLoop() aBgRsrc is the application bacground resource properties from the resource file. Adding an extra style is a bit tricky, but since you have set it to 'resizeable' and the Background object translates that into wx.DEFAULT_FRAME_STYLE you can replace that with the two item list. The Background object has been coded to eval() each item in the list (hence I've made them strings) and bitwise OR them. -- XXXXXXXXXXX |
From: Alec B. <wry...@gm...> - 2008-12-30 20:06:30
|
Thank you! Works like a proverbial charm. To anyone else coming down this road, here's how to make a PythonCard app always on top: test.py: from PythonCard import model import wx class Minimal(model.Background): def __init__(self, aParent, aBgRsrc): aBgRsrc.style = ['wx.DEFAULT_FRAME_STYLE','wx.STAY_ON_TOP'] model.Background.__init__(self, aParent, aBgRsrc) if __name__ == '__main__': app = model.Application(Minimal) app.MainLoop() test.rsrc.py {'application':{'type':'Application', 'name':'Minimal', 'backgrounds': [ {'type':'Background', 'name':'bgMin', 'title':u'Tester', 'size':(403, 371), 'backgroundColor':(0, 0, 0), 'style':['resizeable'], 'components': [ {'type':'StaticText', 'name':'Testing', 'position':(151, 131), 'font':{'faceName': u'Tahoma', 'family': 'sansSerif', 'size': 12}, 'foregroundColor':(255, 255, 0, 255), 'text':u'Testing', }, ] # end components } # end background ] # end backgrounds } } |
From: Alec B. <wry...@gm...> - 2008-12-30 20:24:24
|
The final thing I need to be able to do is pass the app a parameter. Can you see an easy way to do that? Something like this... Note the "test" and "dummy" below. This fails with "No such file or directory: 'test'". from PythonCard import model import wx class Minimal(model.Background): def __init__(self, aParent, dummy, aBgRsrc): aBgRsrc.style = ['wx.DEFAULT_FRAME_STYLE','wx.STAY_ON_TOP'] model.Background.__init__(self, aParent, dummy, aBgRsrc) if __name__ == '__main__': app = model.Application(Minimal, "test") app.MainLoop() |
From: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX - 2008-12-31 16:27:55
|
On Tue, 30 Dec 2008 12:24:20 -0800 "Alec Bennett" <wry...@gm...> wrote: > The final thing I need to be able to do is pass the app a parameter. > Can you see an easy way to do that? Something like this... Note the > "test" and "dummy" below. This fails with "No such file or directory: > 'test'". That'll be because the Application object expects the second parameter passed to it to be a resource filename that already exists. You can then specify something other than minimal.rsrc.py. You could subclass again... from PythonCard import model class Minimal(model.Background): def __init__(self, aParent, aBgRsrc): aBgRsrc.style = ['wx.DEFAULT_FRAME_STYLE','wx.STAY_ON_TOP'] model.Background.__init__(self, aParent, aBgRsrc) class MyApplication(model.Application): def __init__(self, frameClass, param1): print "This should go to console: %s" % (param1,) model.Application.__init__(self, frameClass) if __name__ == '__main__': app = MyApplication(Minimal, "test") app.MainLoop() The problem is, if you want to pass "test" into Minimal through the __init__ methods you're probably going to have to hack model.py. You could be lazy and set up a global variable. Pythoncard doesn't really expect you to be passing in parameters from the command line, for example, and really expects stuff to arrive either via the resource file or via the on_initialize() method in the Minimal object. Again though, whenever I've done that, it's tended to be via a configuration file, e.g. to switch on debugging via a .INI file. -- XXXXXXXXXXX |