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 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
"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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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?...
|
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
|
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,
|
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
|
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...
| |
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.
|
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
#----------------------------------------------------------------
|
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...
|
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....
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |