|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Need to turn a SubClass into a Function.
I am creating a HTML editor; it uses the worlds best toolkit of course. This project will be purely functional so I will have no user defined classes in it, unless there is good justification for doing so.
But the hart of my applications is that, a user defined class called App. Not only that but one that subclasses another toolkit. Is there a way to cleanly turn this into a function(s)? ....................... ......... class App(wx.App): def OnInit(self): global text global frame frame, text = MainFrame(None, -1, "Small editor") print text tb = build_wx_toolbar(frame) build_wx_menus(frame) wx.EVT_TOOL(frame,ID_FIND, FindReplaceData) wx.EVT_TOOL(frame,ID_LOAD, load) wx.EVT_TOOL(frame,ID_SAVE, save) bind(frame) frame.Show(true) self.SetTopWindow(frame) return True ............................. ...................... if __name__ == "__main__": app = App(0) app.MainLoop() |
|
#2
|
||||
|
||||
|
You can't, because wx.App() calls OnInit() as part of its constructor code. OnInit() is not defined by the wx.App() class, so your derived class needs to define it. If you try something like this:
Code:
import wx app = wx.App() this will fail since the app object doesn't have an OnInit() function defined. On a side note, please post your code within [code] and [/code] tags. This is very important in the python forum .
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by Keath and KevinADC, superior perl programmers of the month |
|
#3
|
||||
|
||||
|
Duh, I think I should have slept some more this week
. The key is to declare wx.App.OnInit and point it at a function. That way it will get called by the constructor and won't complain about a missing function. Something like this ought to do the trick.Code:
import wx
def setupapp(app):
global text
global frame
frame, text = app.MainFrame(None, -1, "Small editor")
print text
tb = app.build_wx_toolbar(frame)
app.build_wx_menus(frame)
wx.EVT_TOOL(frame,ID_FIND, FindReplaceData)
wx.EVT_TOOL(frame,ID_LOAD, load)
wx.EVT_TOOL(frame,ID_SAVE, save)
bind(frame)
frame.Show(true)
return true
def mysuperdupereditor():
wx.App.OnInit = setupapp
app = wx.App()
app.SetTopWindow(frame)
app.Init()
app.MainLoop()
return true
if __name__ == "__main__":
mysuperdupereditor()
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Need to turn a SubClass into a Function. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|