473,769 Members | 2,246 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

wxPython: accessing wxFrame methods in __del__ fails

I am attempting to save my window's size and position when it closes. So I
figured I'd put some code in the __del__() method:

from wxPython import *
class MyWindow(wxFram e):
def __init__(self, parent, id=wxID_ANY, title=None, style=None):
# Some stuff here.
def __del__(self):
x, y = self.GetPositio nTuple()
width, height = self.GetSizeTup le()
# Store the values in a file or something.
wxFrame.__del__ (self)

However, when I run this code I end up with an unhandled exception on the
first line in __del__(). Apparently you can't call GetPositionTupl e() (or
GetSizeTuple() for that matter) in __del__(). I'm confused by this, because
I thought that __del__() was called before the object was actually
destroyed. I can still do a dir(self), so obviously not everything
associated with my instance is gone. Or does that work because it's part of
the class, not just my instance? Any insight into this would be greatly
appreciated.

- Alex

Jul 18 '05 #1
2 1908
On Thu, 24 Mar 2005 06:21:36 GMT, Alex VanderWoude <no****@biteme. com> wrote:
I am attempting to save my window's size and position when it closes. So I
figured I'd put some code in the __del__() method:

from wxPython import *
class MyWindow(wxFram e):
def __init__(self, parent, id=wxID_ANY, title=None, style=None):
# Some stuff here.
def __del__(self):
x, y = self.GetPositio nTuple()
width, height = self.GetSizeTup le()
# Store the values in a file or something.
wxFrame.__del__ (self)

However, when I run this code I end up with an unhandled exception on the
first line in __del__(). Apparently you can't call GetPositionTupl e() (or
GetSizeTuple() for that matter) in __del__(). I'm confused by this, because
I thought that __del__() was called before the object was actually
destroyed. I can still do a dir(self), so obviously not everything
associated with my instance is gone. Or does that work because it's part of
the class, not just my instance? Any insight into this would be greatly
appreciated.


Don't use __del__, use EVT_CLOSE

i.e.
self.Bind(wx.EV T_CLOSE, self.OnClose)

and

def OnClose(self, evt):
x, y = self.GetPositio nTuple()

--
Stephen Thorne
Development Engineer
Jul 18 '05 #2
"Stephen Thorne" <st************ @gmail.com> wrote in message
news:ma******** *************** **************@ python.org...
On Thu, 24 Mar 2005 06:21:36 GMT, Alex VanderWoude <no****@biteme. com>

wrote:
I am attempting to save my window's size and position when it closes. So I figured I'd put some code in the __del__() method:

from wxPython import *
class MyWindow(wxFram e):
def __init__(self, parent, id=wxID_ANY, title=None, style=None):
# Some stuff here.
def __del__(self):
x, y = self.GetPositio nTuple()
width, height = self.GetSizeTup le()
# Store the values in a file or something.
wxFrame.__del__ (self)

However, when I run this code I end up with an unhandled exception on the first line in __del__(). Apparently you can't call GetPositionTupl e() (or GetSizeTuple() for that matter) in __del__(). I'm confused by this, because I thought that __del__() was called before the object was actually
destroyed. I can still do a dir(self), so obviously not everything
associated with my instance is gone. Or does that work because it's part of the class, not just my instance? Any insight into this would be greatly
appreciated.


Don't use __del__, use EVT_CLOSE

i.e.
self.Bind(wx.EV T_CLOSE, self.OnClose)

and

def OnClose(self, evt):
x, y = self.GetPositio nTuple()

--
Stephen Thorne
Development Engineer


Thanks for the tip. There doesn't seem to be an equivalent EVT_OPEN, so I
guess I'll continue to use __init__. That works fine.

One thing I noticed in my OnClose() event handler is that I must add a
Skip() command to pass the event futher up the chain, otherwise the app
doesn't actually close! Furthermore, if an exception occurs during my
processing then the close is cancelled, so I also had to wrap my command in
a try block:

def OnClose(self, event):
try:
self.SaveFrameS ettings()
finally:
event.Skip()

- Alex

Jul 18 '05 #3

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

Similar topics

5
4197
by: Daniel Ehrenberg | last post by:
I'm trying to learn wxPython, but I can't seem to find much documentation. The wxPython website says that all advanced (and even some basic) documentation for wxPython is only available in C++ syntax in the main wxWindows documentation. It also says that the samples will help, but I can't seem to make sense of them. Should I just use a not-as-good GUI like Tkinter or a not-as-common one like Anygui or PyUI if I want to have documentation?...
16
2420
by: mike420 | last post by:
Tayss wrote: > > app = wxPySimpleApp() > frame = MainWindow(None, -1, "A window") > frame.Show(True) > app.MainLoop() > Why do you need a macro for that? Why don't you just write
1
5998
by: wang xiaoyu | last post by:
Hello: i want use activex in wxpython program,but when i use MakeActiveXClass an exception occurs. this is my source code dealing the DICOM ocx.I must note that in this program "hwtxcontrol" is a ocx developed my me use vc6,this ocx works fine in wxpython. but you can see i only change this ocx with a new DICOM ocx and set up eventClass,
6
4557
by: Jive Dadson | last post by:
I'm trying (without conspicuous success) to start learning wxPython. Sooo... I opened the doc page wxPythonManual.html#wxpython-overview. The very first example does not work. Try it. I find much of what follows to be incomprehensible. Is there a good tutorial for novices? Here's the example that does not work. ("No module named frame") import wx
0
2178
by: Piet | last post by:
Hello wxPythoneers. I have a problem with a dialog box derived from wxFrame which has a wxComboBox as main element. Depending on the entry selected from the ComboBox, the dialog box will be populated with a number of controls. This works fine for the first selection of a combobox item, but subsequent selections from the combobox cause problems. This is because the event function for the combobox populates the sizer for the window with...
2
2312
by: Emiliano Molina | last post by:
This has been driving me crazy for a couple of days and I have finally narrowed it down to the following code. If the commented section is uncommented the drag and drop handler is never called. I have included the .xrc file for reference. Any help is greatly appreciated. An explanation would be great, but at the moment I would be eternally grateful for a workaround! Thanks in advance for those of you that spend some time helping out.
1
2506
by: marchew | last post by:
hi, i have a problem integrating wxPython and Twisted under Win32. my application consumes 40-50% of CPU resources when wxFrame is visible and reactor (twisted) is running. i looked at integration example which comes with twisted package and figured that it also has that problem. here comes listing: PYTHON_HOME\Lib\site-packages\TwistedDocs\examples\wxdemo.py #----------------------------------------------------------------
3
3498
by: Young H. Rhiu | last post by:
See: http://hilug.org/img/app_layout.GIF I'm implementing an album-like application with wxpython but I'm new to wxPython though I know how to program with python. The problem is that it's not easy for me to deal with drawing layout stuff with wxpython. What layout I'm thinking of looks like the gif image above. The application is about saving some comments for each pictures on the filesystem. There are two windows. The above one is a...
1
3519
by: Marcin Kalicinski | last post by:
I have an application written in C++ that uses wxWidgets for GUI. I use embedded Python for scripting inside of this application. I want to use wxPython to add GUI to my scripts - because my C++ App uses wxWidgets I thought it to be easy. The problem is that wxPython knows nothing about wxApp/wxFrame objects created in my C++ application, and insists (by giving me asserts) that I create another wxApp object for wxPython inside my scripts....
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10206
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
9851
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...
0
8863
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7403
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
5293
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
5441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3949
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
2
3556
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.