473,772 Members | 2,965 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inheritance problem. Creating an instance.

.nu
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Name: Sleepy Hollow
# Author: .nu

import wx
import os
import sys
NEW_ID = 1; OPEN_ID = 2; SAVE_ID = 3; SAVE_AS_ID = 4;
QUIT_ID = 5; UNDO_ID = 6; REDO_ID = 7; HELPME_ID = 8;
ABOUT_ID = 9; OPTIONS_ID = 10

APP_NAME = 'Sleepy Hollow'

class SleepyHollow(wx .Frame):
def __init__(self, parent, id, title):
wx.Frame.__init __(self, parent, id, title, size=(600, 400))
self.SetTitle(A PP_NAME)
# create sizers
self.vbox = wx.BoxSizer(wx. VERTICAL)

# create instance of the NoteBook class, then put a tab on it
self.notebook = NoteBook(self)
self.notebook.c reateTab()

# Create items(statusbar , number panel, etc)
self.statusbar = self.CreateStat usBar()
#self.statusbar .Hide()

#wx.EVT_KEY_UP( self.textarea, self.key_press)
# Call methods that can be turned on/off through options
self.statusbar_ toggle(self, 0)
#self.hbox.Add( self.textarea, 1, wx.EXPAND|wx.AD JUST_MINSIZE, 0)
#self.vbox.Add( self.hbox, 1, wx.EXPAND, 0)

#self.SetAutoLa yout(True)

self.Layout()

## Menu
self.menubar = wx.MenuBar()
self.SetMenuBar (self.menubar)

self.file = wx.Menu()
self.new = wx.MenuItem(sel f.file, NEW_ID, 'new')
self.file.Appen dItem(self.new)
self.open = wx.MenuItem(sel f.file, OPEN_ID, '&Open\tCtrl+O' )
self.file.Appen dItem(self.open )
self.file.Appen dSeparator()
self.save = wx.MenuItem(sel f.file, SAVE_ID, '&Save\tCtrl+S' )
self.file.Appen dItem(self.save )
self.saveas = wx.MenuItem(sel f.file, SAVE_AS_ID, '&Save
as\tCtrl+Shift+ s')
self.file.Appen dItem(self.save as)
self.file.Appen dSeparator()
self.quit = wx.MenuItem(sel f.file, QUIT_ID, '&Quit')
self.file.Appen dItem(self.quit )

self.edit = wx.Menu()
self.undo = wx.MenuItem(sel f.edit, UNDO_ID, '&Undo\tCtrl+z' )
self.edit.Appen dItem(self.undo )
self.redo = wx.MenuItem(sel f.edit, REDO_ID, '&Redo\tCtrl+Sh ift+z')
self.edit.Appen dItem(self.redo )
self.edit.Appen dSeparator()
self.options = wx.MenuItem(sel f.edit, OPTIONS_ID, '&Options\tCtrl +p')
self.edit.Appen dItem(self.opti ons)

self.help = wx.Menu()
self.helpme = wx.MenuItem(sel f.help, HELPME_ID, '&Help\tF1')
self.help.Appen dItem(self.help me)
self.about = wx.MenuItem(sel f.help, ABOUT_ID, '&About\tF2')
self.help.Appen dItem(self.abou t)

self.menubar.Ap pend(self.file, '&File')
self.menubar.Ap pend(self.edit, '&Edit')
self.menubar.Ap pend(self.help, '&Help')

# bind items to functions
self.Bind(wx.EV T_MENU, self.New, id=NEW_ID)
self.Bind(wx.EV T_MENU, self.Open, id=OPEN_ID)
self.Bind(wx.EV T_MENU, self.Save, id=SAVE_ID)
self.Bind(wx.EV T_MENU, self.Saveas, id=SAVE_AS_ID)
self.Bind(wx.EV T_MENU, self.Undo, id=UNDO_ID)
self.Bind(wx.EV T_MENU, self.Redo, id=REDO_ID)
self.Bind(wx.EV T_MENU, self.Helpme, id=HELPME_ID)
self.Bind(wx.EV T_MENU, self.About, id=ABOUT_ID)
self.Bind(wx.EV T_MENU, self.Quit, id=QUIT_ID)
self.Bind(wx.EV T_MENU, self.Options, id=OPTIONS_ID)
## Random variables
self.fileName = ''
self.dirName = ''

self.tempFileNa me = ''
self.tempDirNam e = ''

self.oldPos = -1
self.show_posit ion(self)
## Menu Methods
def New(self, event):
self.popup(self , "Would you like to save this file before starting a
new one?", "Save?", wx.YES | wx.NO | wx.ICON_QUESTIO N)
#self.textarea. SetValue('')
self.notebook.c reateTab()

def Open(self, event):
open_dialog = wx.FileDialog(s elf, "Open", self.dirName,
self.fileName, "Text Files (*.txt)|*.txt|A ll Files|*.*", wx.OPEN)
# If open_dialog opens, try to get dirName and fileName, and open it
in the textarea
if (open_dialog.Sh owModal() == wx.ID_OK):
try:
self.tempDirNam e = open_dialog.Get Directory()
self.tempFileNa me = open_dialog.Get Filename()
self.file = file(os.path.jo in(self.tempDir Name, self.tempFileNa me),
'r')
self.fileConten ts = self.file.read( )
self.textarea.S etValue(self.fi leContents.deco de('utf-8'))
self.SetTitle(A PP_NAME + " | " + self.tempFileNa me + "")
self.fileName = self.tempFileNa me
print '--------- Open succeeded. Showing temporary and current
filenames (testing purposes) -------';
print '--------- Open succeeded. Showing temporary and current
filenames (testing purposes) -------';
print 'fileName :',self.fileNam e
self.dirName = self.tempDirNam e
self.file.close ()
except:
self.tempDirNam e = self.dirName
self.tempFilena me = self.fileName
print '--------- open failed. showing file names again (testing
purposes) ----------'
print 'temp file :',self.tempFil eName
print 'fileName :', self.fileName
self.popup(self ,'Could Not open file.', 'Error', wx.OK
|wx.ICON_ERROR)
open_dialog.Des troy()
def Save(self, event):
if (self.fileName != "") and (self.dirName != ""):
self.file = file(os.path.jo in(self.dirName , self.fileName), 'w') #
<-- Same as: self.file = file(self.dirNa me + '/' + self.fileName, 'w')
self.fileConten ts = self.textarea.G etValue()
self.file.write (self.fileConte nts.encode('utf-8'))
self.SetTitle(A PP_NAME + " | " + self.fileName + "")
self.file.close ()
print '*saved*'

else:
self.Saveas(sel f)
def Saveas(self, event):
# Ask for filename
saveDialogue = wx.FileDialog(s elf, "Save As", self.dirName,
self.fileName, "Text Files (*.txt)|*.txt|A ll Files|*.*", wx.SAVE |
wx.OVERWRITE_PR OMPT)
if (saveDialogue.S howModal() == wx.ID_OK):
self.fileName = saveDialogue.Ge tFilename()
self.dirName = saveDialogue.Ge tDirectory()
if self.Save(self) :
self.SetTitle(A PP_NAME + " | " + self.fileName + "")
saveDialogue.De stroy()
def Quit(self, event):
self.Destroy()

def Undo(self, event):
pass

def Redo(self, event):
pass

def Helpme(self, event):
self.popup(self , "No help file has been created yet.", "Help", wx.OK
| wx.ICON_INFORMA TION)

def About(self, event):
self.popup(self , "Milkpad Lite 1.0\nby .nu\nwww.ficti0 n.com",
"About", wx.OK | wx.ICON_INFORMA TION)

def Options(self, event):
pass

## Option Methods
def statusbar_toggl e(self, event, switch):
#if 1, then show. if 0, hide.
if (switch == True):
self.statusbar. Show()
self.Refresh()
elif (switch == False):
self.statusbar. Hide()

## Random Methods
def popup(self, event, message, title, button_type_and _icon):
# Show a pop-up message
popup_dialog = wx.MessageDialo g(self, message, title,
button_type_and _icon)
popup_dialog.Sh owModal()
popup_dialog.De stroy()

def key_press(self, event):
self.show_posit ion(self)
event.Skip()

def show_position(s elf, event):
#(bPos,ePos) = self.textarea.G etSelection()
#if (self.oldPos != ePos):
#(c,r) = self.textarea.P ositionToXY(ePo s)
#self.SetStatus Text(" " + str((r+1,c+1)))
#self.oldPos = ePos
pass
## This is the Notebook class. It is called in SleepyHollow's __init__
method to
## Create the notebook and createTab() creates/add a new tab(file->new)
class NoteBook(wx.Not ebook):
def __init__(self, parent):
wx.Notebook.__i nit__(self, parent, -1, style=wx.NB_TOP )
#print parent
#self.notebook = wx.Notebook(par ent, -1, style=wx.NB_TOP )
self.number_of_ tabs = 0

""" #*_*_*__*_*_*_* _*_*_*_*__*_*_* _*_*_*_*_*__*__ _ERROR__*__*_*_ *_*_*_*_*_*__*_ *_*_*_*_*_*_*__ *_*_*_*_*_*_*_* __*_*_*_*_*_
# This is where I am having problems. I am trying to create an
instance of SleepyHollow
# So i can call its 'popup' method. But i keep getting errors when
trying to create this instance
sh = SleepyHollow(pa rent, -1, '')
#*_*_*__*_*_*_* _*_*_*_*__*_*_* _*_*_*_*_*__*__ _ERROR__*__*_*_ *_*_*_*_*_*__*_ *_*_*_*_*_*_*__ *_*_*_*_*_*_*_* __*_*_*_*_*_
"""

def tabCounter(self , action):
""" action is either 'add' or 'subtract' """
if(action == 'add'):
self.number_of_ tabs += 1
print self.number_of_ tabs
elif(action == 'subtract'):
self.number_of_ tabs -= 1
#SleepyHollow.p opup(SleepyHoll ow,'Could Not open file.', 'Error',
wx.OK |wx.ICON_ERROR)

def createTab(self) :
#self.notebook_ pane1 = wx.Panel(self.n otebook)
#wx.Panel.__ini t__(self)
#t = wx.StaticText(s elf, -1, "This is a PageOne object", (20,20))
self.textarea = wx.TextCtrl(sel f, -1, ' hehe', style=wx.TE_MUL TILINE)
self.AddPage(se lf.textarea, 'tab')
self.tabCounter ('add')

def deleteTab(self) :
pass

if __name__ == "__main__":
app = wx.App(0)
MainFrame = SleepyHollow(No ne, -1, '')
MainFrame.Show( )
app.MainLoop()


So there i have two classes.
The main class, SleepyHollow, creates the main frame and the menu.
Inside the SleepyHollow class, i create an instance to NoteBook class
and call on it.
The NoteBook class creates a notebook and adds tabs to the notebook.

However, inside the NoteBook class, i try to call a SleepyHollow method
(the 'popup' method, for displaying dialogues), but i keep getting this
error:

/usr/bin/python -u "path/to/file/file.py"
Traceback (most recent call last):

File "path/to/file/file.py", line 256, in ?
MainFrame = SleepyHollow(No ne, -1, '')

File "path/to/file/file.py", line 26, in __init__
self.notebook = NoteBook(self)

File "path/to/file/file.py", line 222, in __init__
wx.Notebook.__i nit__(self, parent, -1, style=wx.NB_TOP )

File "path/to/file/file.py", line 3117, in __init__
self.this = newobj.this
AttributeError: 'PySwigObject' object has no attribute 'this'

Dec 6 '06 #1
0 1333

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1842
by: Alex Vinokur | last post by:
Hi, I need something like "function inheritance". typedef void (*func_type1) (int); typedef int (*func_type2) (double); typedef char (*func_type3) (short, int); .... I need a vector contains pointers to functions of types above.
12
1725
by: Taylor | last post by:
I'm trying to understand inheritance. I'd like to make my own type of IPAddress lets call it myIp. The following gives me CS0029 error: Cannot implicitly convert type 'System.Net.IPAddress' to 'Inheritance_Testing.myIp' Could you steer me in the right direction? class myIp : System.Net.IPAddress
45
6368
by: Ben Blank | last post by:
I'm writing a family of classes which all inherit most of their methods and code (including constructors) from a single base class. When attempting to instance one of the derived classes using parameters, I get CS1501 (no method with X arguments). Here's a simplified example which mimics the circumstances: namespace InheritError { // Random base class. public class A { protected int i;
9
14148
by: Marcel Hug | last post by:
Hallo NG ! I Have a little question about inheritance of a singleton class. In my application i have a Database-Connection Lib, in which I would ¨like to connect different databases of the same project (thats why it is in a lib). For the database A I created a singleton class AProxy and for the database B the same as BProxy. Initializing and connetcing to the Database is the same in both classes (except of the database-path, which is a...
2
6348
by: Kevin Newman | last post by:
I have been playing around with a couple of ways to add inheritance to a JavaScript singleton pattern. As far as I'm aware, using an anonymous constructor to create a singleton does not allow any kind of inheritance: singletonObj = new function() { this.prop = true; } Here are two ways to create a singleton with inheritance:
36
2729
by: Pacific Fox | last post by:
Hi all, haven't posted to this group before, but got an issue I can't work out... and hoping to get some help here ;-) I've got a base object that works fine with named arguments when called on it's own. However when I call the child object I get an error " has no properties (in firefox)." I simple test:
6
1885
by: burningodzilla | last post by:
Hi all - I'm preparing to dive in to more complex application development using javascript, and among other things, I'm having a hard time wrapping my head around an issues regarding "inheritance" using the prototype property. I realize there are no classes in JS, that code therefore lives in objects instead of class definitions, and that "inheritance" must be achieved prototypically and not classically. That said, on with the code. Say I...
26
5375
by: nyathancha | last post by:
Hi, How Do I create an instance of a derived class from an instance of a base class, essentially wrapping up an existing base class with some additional functionality. The reason I need this is because I am not always able to control/create all the different constructors the base class has. My problem can be described in code as follows ... /* This is the base class with a whole heap of constructors/functionality*/ public class Animal
9
1224
by: glomde | last post by:
Hi I wonder if you can set what subclass a class should have at instance creation. The problem is that I have something like: class CoreLang(): def AssignVar(self, var, value): pass class Lang1(CoreLang):
5
1327
by: Michael Thompson | last post by:
I am new to .Net and OOP techniques; I am not even certain that I using the correct terminology here. I believe that I want to know how to do inheritance. I want to create a custom "string" class, "TSTString". TSTString should behave exactly like a string except that I want to add a couple methods like "public string ProperCase()", but still have the TSTString object behave like string, and be able to pass them through as string-type...
0
10261
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10104
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9912
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7460
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.