Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 10th, 2004, 02:28 PM
Tkinter_Bell Tkinter_Bell is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Location: Isle of dogs
Posts: 68 Tkinter_Bell User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
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()

Reply With Quote
  #2  
Old November 10th, 2004, 03:34 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is online now
Banned ;)
Click here for more information.
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,717 Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 3 Days 12 h 29 m 35 sec
Reputation Power: 1179
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

Reply With Quote
  #3  
Old November 10th, 2004, 07:06 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is online now
Banned ;)
Click here for more information.
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,717 Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level)Scorpions4ever User rank is General 3rd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 3 Days 12 h 29 m 35 sec
Reputation Power: 1179
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()

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > Need to turn a SubClass into a Function.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT