tags:

views:

64

answers:

2

Hello,

Noob question...

class msgbox:
    def __init__(self, lbl_msg = '', dlg_title = ''):
            self.wTree = gtk.glade.XML('msgbox.glade')    

            self.wTree.get_widget('dialog1').set_title(dlg_title) 
            self.wTree.get_widget('label1').set_text(lbl_msg)

            self.wTree.signal_autoconnect( {'on_okbutton1_clicked':self.done} )

    def done(self,w):
            self.wTree.get_widget('dialog1').destroy()

class Fun(object):
    wTree = None
    def __init__(self):      
        self.wTree = gtk.glade.XML( "main.glade" )
        self.wTree.signal_autoconnect( {'on_buttonOne' : self.one,} ) 

        gtk.main()

    @yieldsleep
    def one(self, widget, data=None):
        self.msg = msgbox('Please wait...','')
        yield 500
        self.msg = msgbox().done()  # <----------------???
        self.msg = msgbox('Done!','')

With this i get an error: messageBox().done() TypeError: done() takes exactly 2 arguments (1 given)

How can i make the dialog box with "please wait" to close before the second dialog box with "done" appears??

Thank you.

A: 

It looks like you want

self.msg.done()

to close the existing "Please wait..." message box. msgbox().done() creates a new message box, then calls done on this new instance.

As for the extra parameter, you aren't using it, so remove it from the definition of done:

def done(self):
    self.wTree.get_widget('dialog1').destroy()

Off Topic

Class msgbox should inherit from object so you get a new-style class.

Define a destructor on msgbox and you don't need to explicitly call msgbox.done, which you might forget to do.

class Msgbox(object):
    ...
    def __del__(self):
        self.wTree.get_widget('dialog1').destroy()

class Fun(object):
    ...
    @yieldsleep
    def one(self, widget, data=None):
        self.msg = Msgbox('Please wait...','')
        yield 500
        # actually, you probably need to delete the old self.msg
        # so it gets destroyed before the new message box is created
        del self.msg
        self.msg = Msgbox('Done!','')
outis
thanks :) didn't even notice the mysterious "w" ... damn beer is getting on my head.
@wtzolt: trying to reach the Ballmer peak?
outis
:D yea you could say that ...
Python never promises to call your object's `__del__` method or to GC your object at any given time. It certainly does not promise to destroy the object when you `del` an attribute referring to it, and *definitely* isn't more likely to do it for `del` than if you had simple reassigned `self.msg`. Using `__del__` is quite undependable and not recommended.
Mike Graham
If you do wish to have cleanup code called, you need to define a method you make sure gets called (which you cannot do with `__del__`). This can be a normal method like `done` or, if you want to use context managers (the `with` statement) to ensure it *definitely* gets called, it can be `__exit__`.
Mike Graham
@Mike: is that documented? The only caveat that I've read is that reference cycles having objects w/ a `__del__` method can't be garbage collected. (http://docs.python.org/reference/datamodel.html#object.__del__, http://docs.python.org/library/gc.html#gc.garbage)
outis
@outis, your first link also notes that `__del__` is not guaranteed to be called for objects that exist when the interpreter exits. It is also only implementation detail of CPython that objects are typically GCed immediately when they can be; this isn't the case in all implementations and isn't promised to forever be the way CPython works.
Mike Graham
+2  A: 

You've chosen to define the done method like this:

def done(self,w):

so it does need two arguments -- the msgbox instance you're calling it on, and a second mysterious w argument which it then never uses. When you call done, you don't pass that mysterious and totally useless argument. So why not change the def to:

def done(self):

getting rid of the mysterious, useless w which you're currently requiring but not supplying?

Alex Martelli