non-modal but modal-like window

Hello,

My application needs to perform a "long" running operation in the
background. It also needs to inform the user what it's doing and not
allow the user to interact with the ScrolledWindow. A simple window
with some informative text would be great. I would like it to act like
a modal dialog. Here's the steps I'm trying to accomplish:

1) Create the infomative window
2) Start a thread to do some work
3) Wait for thread to finish
4) Close informative window

I've tried this with a Window, Frame and a Dialog using the Show()
method.They all give me an informative window, but I can still
interact with the ScrolledWindow behind it.

So, I must be missing something. This seems like it would be a very
common thing to do. Or, there is a better way of doing it. Any
suggestions?

Thanks,
Tom

I think I saw this on the wxPython wiki somewhere but can't remember
where but something like this might work:
def FakeModal(self):
        self.CenterOnParent()
        self.GetParent().Enable(False)
        wx.Dialog.Show(self)
        self.Raise()

then when closing:
def MyClose(self):
        self.GetParent().Enable(True)
        self.Close()

--Mark

···

On Fri, Feb 6, 2009 at 3:44 PM, Tom Brown <nextstate@gmail.com> wrote:

Hello,

My application needs to perform a "long" running operation in the
background. It also needs to inform the user what it's doing and not
allow the user to interact with the ScrolledWindow. A simple window
with some informative text would be great. I would like it to act like
a modal dialog. Here's the steps I'm trying to accomplish:

1) Create the infomative window
2) Start a thread to do some work
3) Wait for thread to finish
4) Close informative window

I've tried this with a Window, Frame and a Dialog using the Show()
method.They all give me an informative window, but I can still
interact with the ScrolledWindow behind it.

So, I must be missing something. This seems like it would be a very
common thing to do. Or, there is a better way of doing it. Any
suggestions?

Thanks,
Tom
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

My application needs to perform a “long” running operation in the

background. It also needs to inform the user what it’s doing and not

allow the user to interact with the ScrolledWindow. A simple window

with some informative text would be great. I would like it to act like

a modal dialog. Here’s the steps I’m trying to accomplish:

I’ve tried this with a Window, Frame and a Dialog using the Show()

method.They all give me an informative window, but I can still

interact with the ScrolledWindow behind it.

How about Window.MakeModal? If I understand it correctly, it can toggle that behavior. I use it to work around modal dialogs in messy multi-window situations where most of the other windows are wx.Frame objects.

-Nat

Tom Brown wrote:

Hello,

My application needs to perform a "long" running operation in the
background. It also needs to inform the user what it's doing and not
allow the user to interact with the ScrolledWindow. A simple window
with some informative text would be great. I would like it to act like
a modal dialog. Here's the steps I'm trying to accomplish:

1) Create the infomative window
2) Start a thread to do some work
3) Wait for thread to finish
4) Close informative window

I've tried this with a Window, Frame and a Dialog using the Show()
method.They all give me an informative window, but I can still
interact with the ScrolledWindow behind it.

So, I must be missing something. This seems like it would be a very
common thing to do. Or, there is a better way of doing it. Any
suggestions?

Thanks,
Tom

If you use a Dialog object, use it's ShowModal() method instead of Show(). Otherwise, see the frame's MakeModal() method as Nat has mentioned.

You might want to use a progress dialog or a busy dialog...

···

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org

Hey guys!

Thanks for all your input. You solved my problem. I used a combination
of the FakeModal() solution and the BusyInfo dialog. I created a
custom window that subclassed Frame and implemented the
FakeModal/MyClose methods as given. Then, I used WindowDisabler class
as described in the BusyInfo documentation along with the Yield()
method. Well, here a code snipped to show what I did:

        disableAll = wx.WindowDisabler()
        pleaseWaitWin = PleaseWaitWin(self, -1,
            text='Updating. Please wait...')
        pleaseWaitWin.FakeModal()
        self.app.Yield()
        for i in range(10):
            sleep(1)
            self.app.Yield()
        pleaseWaitWin.MyClose()

The above is really just an example. I'll may end up using a worker
thread to do the processing. Although, I really don't have to use a
thread. I'll figure that out tomorrow.

Thanks!
Tom