Wait dialog

Hello,

I have some computation that takes 10-20 seconds and when waiting this to be finished, I'd like to display a very simple window that shows a message 'Wait ... be patient, etc...'. This looks pretty trivial, but for some reason I cannot make it work ok. I would do the code like this:

     def myComputation(self):
         waitWin = wx.theMiracleClassThatIdontFind()
         waitWin.Show()

         ...
         do my computation things

         ...
         waitWin.Close()

I could use a wx.Dialog(), but this stops the process and my computation things are never done.
I could put my computation into a thread ... but what a pain for such a simple thing to do.
I tried to make a class derived from wx.Frame to display my wait window, and although I'm doing the same code than in other places (using a panel, sizers, etc.) it doesn't work well: the controls in that window are never displayed.

Before I spend the time making a small sample, does anybody have an idea of what's wrong, or already has a simple solution ?

Thanks.

Raphael

Hello,

I have some computation that takes 10-20 seconds and when
waiting this
to be finished, I'd like to display a very simple window that shows a
message 'Wait ... be patient, etc...'. This looks pretty trivial, but
for some reason I cannot make it work ok. I would do the code
like this:

     def myComputation(self):
         waitWin = wx.theMiracleClassThatIdontFind()
         waitWin.Show()

         ...
         do my computation things

         ...
         waitWin.Close()

I could use a wx.Dialog(), but this stops the process and my
computation
things are never done.
I could put my computation into a thread ... but what a pain
for such a
simple thing to do.
I tried to make a class derived from wx.Frame to display my
wait window,
and although I'm doing the same code than in other places (using a
panel, sizers, etc.) it doesn't work well: the controls in
that window
are never displayed.

Before I spend the time making a small sample, does anybody
have an idea
of what's wrong, or already has a simple solution ?

Raphael,

I rolled my own:

    # Create a popup telling the user about the load (needed for large
files)
    loadDlg = PopupDialog(None, _("Loading..."), _("Loading your
transcript.\nPlease wait...."))

    ...

    # Destroy the Load Popup Dialog
    loadDlg.Destroy()

class PopupDialog(wx.Dialog):
    """ A popup dialog for temporary user messages """

    def __init__(self, parent, title, msg):
        # Create a dialog
        wx.Dialog.__init__(self, parent, -1, title, size=(350, 150),
style=wx.CAPTION | wx.STAY_ON_TOP)
        # Add sizers
        box = wx.BoxSizer(wx.VERTICAL)
        box2 = wx.BoxSizer(wx.HORIZONTAL)
        # Add an Info graphic
        bitmap = wx.EmptyBitmap(32, 32)
        bitmap = wx.ArtProvider_GetBitmap(wx.ART_INFORMATION,
wx.ART_MESSAGE_BOX, (32, 32))
        graphic = wx.StaticBitmap(self, -1, bitmap)
        box2.Add(graphic, 0, wx.EXPAND | wx.ALIGN_CENTER | wx.ALL, 10)
        # Add the message
        message = wx.StaticText(self, -1, msg)
        box2.Add(message, 0, wx.EXPAND | wx.ALIGN_CENTER |
wx.ALIGN_CENTER_VERTICAL | wx.ALL, 10)
        box.Add(box2, 0, wx.EXPAND)
        # Handle layout
        self.SetAutoLayout(True)
        self.SetSizer(box)
        self.Fit()
        self.Layout()
        self.CentreOnScreen()
        # Display the Dialog
        self.Show()
        # Make sure the screen gets fully drawn before continuing.
        wx.Yield()

David

Thanks a lot. wx.Yield() solves the problem!

Raphael

···

On 2011-10-27 18:12, David wrote:

Hello,

I have some computation that takes 10-20 seconds and when
waiting this
to be finished, I'd like to display a very simple window that shows a
message 'Wait ... be patient, etc...'. This looks pretty trivial, but
for some reason I cannot make it work ok. I would do the code
like this:

      def myComputation(self):
          waitWin = wx.theMiracleClassThatIdontFind()
          waitWin.Show()

          ...
          do my computation things

          ...
          waitWin.Close()

I could use a wx.Dialog(), but this stops the process and my
computation
things are never done.
I could put my computation into a thread ... but what a pain
for such a
simple thing to do.
I tried to make a class derived from wx.Frame to display my
wait window,
and although I'm doing the same code than in other places (using a
panel, sizers, etc.) it doesn't work well: the controls in
that window
are never displayed.

Before I spend the time making a small sample, does anybody
have an idea
of what's wrong, or already has a simple solution ?

Raphael,

I rolled my own:

     # Create a popup telling the user about the load (needed for large
files)
     loadDlg = PopupDialog(None, _("Loading..."), _("Loading your
transcript.\nPlease wait...."))

     ...

     # Destroy the Load Popup Dialog
     loadDlg.Destroy()

class PopupDialog(wx.Dialog):
     """ A popup dialog for temporary user messages """

     def __init__(self, parent, title, msg):
         # Create a dialog
         wx.Dialog.__init__(self, parent, -1, title, size=(350, 150),
style=wx.CAPTION | wx.STAY_ON_TOP)
         # Add sizers
         box = wx.BoxSizer(wx.VERTICAL)
         box2 = wx.BoxSizer(wx.HORIZONTAL)
         # Add an Info graphic
         bitmap = wx.EmptyBitmap(32, 32)
         bitmap = wx.ArtProvider_GetBitmap(wx.ART_INFORMATION,
wx.ART_MESSAGE_BOX, (32, 32))
         graphic = wx.StaticBitmap(self, -1, bitmap)
         box2.Add(graphic, 0, wx.EXPAND | wx.ALIGN_CENTER | wx.ALL, 10)
         # Add the message
         message = wx.StaticText(self, -1, msg)
         box2.Add(message, 0, wx.EXPAND | wx.ALIGN_CENTER |
wx.ALIGN_CENTER_VERTICAL | wx.ALL, 10)
         box.Add(box2, 0, wx.EXPAND)
         # Handle layout
         self.SetAutoLayout(True)
         self.SetSizer(box)
         self.Fit()
         self.Layout()
         self.CentreOnScreen()
         # Display the Dialog
         self.Show()
         # Make sure the screen gets fully drawn before continuing.
         wx.Yield()

David

Also Check SafeYield depending if you want the user to enter sthg while
waiting or not ...
http://www.wxpython.org/docs/api/wx-module.html#SafeYield

Cheers

···

Am 27.10.11 18:20, schrieb Raphael Mayoraz:

On 2011-10-27 18:12, David wrote:

Hello,

I have some computation that takes 10-20 seconds and when
waiting this
to be finished, I'd like to display a very simple window that shows a
message 'Wait ... be patient, etc...'. This looks pretty trivial, but
for some reason I cannot make it work ok. I would do the code
like this:

      def myComputation(self):
          waitWin = wx.theMiracleClassThatIdontFind()
          waitWin.Show()

          ...
          do my computation things

          ...
          waitWin.Close()

I could use a wx.Dialog(), but this stops the process and my
computation
things are never done.
I could put my computation into a thread ... but what a pain
for such a
simple thing to do.
I tried to make a class derived from wx.Frame to display my
wait window,
and although I'm doing the same code than in other places (using a
panel, sizers, etc.) it doesn't work well: the controls in
that window
are never displayed.

Before I spend the time making a small sample, does anybody
have an idea
of what's wrong, or already has a simple solution ?

Raphael,

I rolled my own:

     # Create a popup telling the user about the load (needed for large
files)
     loadDlg = PopupDialog(None, _("Loading..."), _("Loading your
transcript.\nPlease wait...."))

     ...

     # Destroy the Load Popup Dialog
     loadDlg.Destroy()

class PopupDialog(wx.Dialog):
     """ A popup dialog for temporary user messages """

     def __init__(self, parent, title, msg):
         # Create a dialog
         wx.Dialog.__init__(self, parent, -1, title, size=(350, 150),
style=wx.CAPTION | wx.STAY_ON_TOP)
         # Add sizers
         box = wx.BoxSizer(wx.VERTICAL)
         box2 = wx.BoxSizer(wx.HORIZONTAL)
         # Add an Info graphic
         bitmap = wx.EmptyBitmap(32, 32)
         bitmap = wx.ArtProvider_GetBitmap(wx.ART_INFORMATION,
wx.ART_MESSAGE_BOX, (32, 32))
         graphic = wx.StaticBitmap(self, -1, bitmap)
         box2.Add(graphic, 0, wx.EXPAND | wx.ALIGN_CENTER | wx.ALL, 10)
         # Add the message
         message = wx.StaticText(self, -1, msg)
         box2.Add(message, 0, wx.EXPAND | wx.ALIGN_CENTER |
wx.ALIGN_CENTER_VERTICAL | wx.ALL, 10)
         box.Add(box2, 0, wx.EXPAND)
         # Handle layout
         self.SetAutoLayout(True)
         self.SetSizer(box)
         self.Fit()
         self.Layout()
         self.CentreOnScreen()
         # Display the Dialog
         self.Show()
         # Make sure the screen gets fully drawn before continuing.
         wx.Yield()

David

Thanks a lot. wx.Yield() solves the problem!

Raphael

How about either:
BusyInfo = wx.ProgressDialog(Title, BusyMsg, HowMuchToDo)
...
BusyInfo.Update(HowMuchDone)
....
del BusyInfo

OR

The new pyProgress?

Gadget/Steve

···

On 27/10/2011 5:06 PM, Raphael Mayoraz wrote:

Hello,

I have some computation that takes 10-20 seconds and when waiting this
to be finished, I'd like to display a very simple window that shows a
message 'Wait ... be patient, etc...'. This looks pretty trivial, but
for some reason I cannot make it work ok. I would do the code like this:

    def myComputation(self):
        waitWin = wx.theMiracleClassThatIdontFind()
        waitWin.Show()

        ...
        do my computation things

        ...
        waitWin.Close()

I could use a wx.Dialog(), but this stops the process and my
computation things are never done.
I could put my computation into a thread ... but what a pain for such
a simple thing to do.
I tried to make a class derived from wx.Frame to display my wait
window, and although I'm doing the same code than in other places
(using a panel, sizers, etc.) it doesn't work well: the controls in
that window are never displayed.

Before I spend the time making a small sample, does anybody have an
idea of what's wrong, or already has a simple solution ?

Thanks.

Raphael

If you just need something super simple then take a look at wx.BusyInfo.

···

On 10/27/11 9:06 AM, Raphael Mayoraz wrote:

Hello,

I have some computation that takes 10-20 seconds and when waiting this
to be finished, I'd like to display a very simple window that shows a
message 'Wait ... be patient, etc...'. This looks pretty trivial, but
for some reason I cannot make it work ok. I would do the code like this:

def myComputation(self):
waitWin = wx.theMiracleClassThatIdontFind()
waitWin.Show()

...
do my computation things

...
waitWin.Close()

I could use a wx.Dialog(), but this stops the process and my computation
things are never done.
I could put my computation into a thread ... but what a pain for such a
simple thing to do.
I tried to make a class derived from wx.Frame to display my wait window,
and although I'm doing the same code than in other places (using a
panel, sizers, etc.) it doesn't work well: the controls in that window
are never displayed.

Before I spend the time making a small sample, does anybody have an idea
of what's wrong, or already has a simple solution ?

--
Robin Dunn
Software Craftsman

Thanks for all the answers.
I need a bit more than wx.BusyInfo (so, keeping this in mind for another time). My main problem ended up being more of a layout one, now solved by wx.Yield()

Raphael

···

On 2011-10-27 21:52, Robin Dunn wrote:

On 10/27/11 9:06 AM, Raphael Mayoraz wrote:

Hello,

I have some computation that takes 10-20 seconds and when waiting this
to be finished, I'd like to display a very simple window that shows a
message 'Wait ... be patient, etc...'. This looks pretty trivial, but
for some reason I cannot make it work ok. I would do the code like this:

def myComputation(self):
waitWin = wx.theMiracleClassThatIdontFind()
waitWin.Show()

...
do my computation things

...
waitWin.Close()

I could use a wx.Dialog(), but this stops the process and my computation
things are never done.
I could put my computation into a thread ... but what a pain for such a
simple thing to do.
I tried to make a class derived from wx.Frame to display my wait window,
and although I'm doing the same code than in other places (using a
panel, sizers, etc.) it doesn't work well: the controls in that window
are never displayed.

Before I spend the time making a small sample, does anybody have an idea
of what's wrong, or already has a simple solution ?

If you just need something super simple then take a look at wx.BusyInfo.