开发者

How to add a transition screen to a program?

开发者 https://www.devze.com 2023-04-02 19:47 出处:网络
I have use traits ui to create a program. I am trying to make the program close its window, so it may be like a transition screen but it doesn\'t 开发者_开发百科work.

I have use traits ui to create a program. I am trying to make the program close its window, so it may be like a transition screen but it doesn't 开发者_开发百科work.

from enthought.traits.api import HasTraits, Str, Int ,Instance, Any
from enthought.traits.ui.api import View, Item,Group, Handler,Controller, UIInfo
from enthought.pyface.timer.api import Timer
class aa(HasTraits):
    name = Str
    age = Int
    view1 = View('name','age',)
class closeHandler(Handler):
    timer = Instance(Timer)
    c = Any#
    def init(self, info):
        super(closeHandler, self).init(info)
        self.c = info
        self.timer = Timer(1000, self.exit_app())
    def close(self,info,is_ok):
        super(closeHandler, self).close(info, is_ok)
    def exit_app(self):
        print self.c
        self.close(self.c)
a = aa()
a.configure_traits(handler=closeHandler())


The close() handler method is called AFTER the OK button or [x] window close buttons are clicked. You can put there things you want to be done the moment the windows is closed, but you cannot make it close itself from there.

To close the window from within a Handler method, call UIInfo.ui.dispose().

So, in your sample code, you should use "self.c.ui.dispose()" rather than "self.close(self.c)", and the close() method should be unnecessary.

That's not enough to make this code work, anyway, because info is not yet initialized when init is called -- I would have to look more into the issue.

0

精彩评论

暂无评论...
验证码 换一张
取 消