More on: How to dispose of a GUI

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

More on: How to dispose of a GUI

sylvain roy
Dear all,

I posted a request yesterday and was able to partially solve the problem.
Let me explain what the problem is.

A main GUI (GUI #1) is displayed with a single button. When the user
pushes the button, another GUI (GUI #2) appears with a Save button on it. When the user
presses the Save button, a dialog box appears and prompts the user to select a file to be saved.
When the user presses Save on the dialog box, the dialog box disappears of the screen as it should. Is
there a way that GUI #2 disappears as well?

I include below an example. Notice that I partially solve the problem by adding "info.ui.dispose()"
in the handler. Unfortunately, this is not satisfactory for me. The problem is that once GUI #2 is gone,
there is no trace of its attributes. To see that, I include in the example two print statements:
(1) print 'a', filename #(inside GUI #2)
(2) print 'b', filename #(inside GUI #1, after disposing of GUI #2)

Have a look at the example:

from enthought.traits.api import HasTraits, Button, Str
from enthought.pyface.api import FileDialog, OK
from enthought.traits.ui.api import View, Item, Handler
from import Action

class UI_Handler(Handler):
    def save(self, info):
        """ Save location info to location file and load the location info """

class MainClass(HasTraits):
    myButton = Button(label = 'My Button',
        height_padding = 30,
        orientation = 'horizontal')  
    traits_view = View(Item('myButton', show_label=False, style='custom'))
    def __init__(self, **traits):
        super(MainClass, self).__init__(**traits)
    def _myButton_fired(self):
        sc = SubClass()
        print 'b', sc.filename
class SubClass(HasTraits):
    saveButton = Action(name='Save',action='save')
    filename = Str
    traits_view = View(
                       handler = UI_Handler(),
                       resizable = True,
                       kind = 'modal')
    def __init__(self, **traits):
        super(SubClass, self).__init__(**traits)
    def save(self):
        dialog = FileDialog(title='Save File',
                action='save as')
        if == OK:
            self.filename = dialog.path
            print 'a', self.filename

if __name__ == "__main__":
    main_object = MainClass()


Enthought-Dev mailing list
[hidden email]