question about ProgressDialog

Hi, all:
     recently, I would like to create a Costumed Progressdialog or
kind of waiting dialog. Because I don't need the progress bar, but a
animated gif.
     So I use wx.Dialog as the parent class, and the code is as
follows:

import wx
import wx.animate
from threading import *
class Progress_Dialog(wx.Dialog):

    def __init__(self, parent, Title, Lable):
        wx.Dialog.__init__(self, parent, -1, Title)
        ag_fname = "..\\menuicon\\progress.gif"
        ag = wx.animate.GIFAnimationCtrl(self, -1, ag_fname)
        # clears the background
        ag.GetPlayer().UseBackgroundColour(True)
        # continuously loop through the frames of the gif file
(default)
        ag.Play()
        text = wx.StaticText(self, -1, Lable)
        size1 = wx.BoxSizer(wx.VERTICAL)
        size1.Add(ag, -1, wx.EXPAND)
        size1.Add(text,-1, wx.ALIGN_CENTER)
        self.SetSizer(size1)
        self.Layout()
        self.ShowModal()

# Thread class that executes processing
class WorkerThread(Thread):
    """Worker Thread Class."""
    def __init__(self, notify_window):
        """Init Worker Thread Class."""
        Thread.__init__(self)
        self._notify_window = notify_window
        # This starts the thread running on creation, but you could
        # also make the GUI thread responsible for calling this
        self.start()

    def run(self):
        self._notify_window.progressdialog =
Progress_Dialog(self._notify_window, "progressbox","Time remaining")

So in my opinion, the WorkerThread should generate a Dialog window
which show the animated gif. But in fact, there is an error happened
"PyAssertionError: C++ assertion "wxThread::IsMain()" failed at ..\..
\src\common\timercmn.cpp(66) in wxTimerBase::Start(): timer can only
be started from the main thread"

Does that mean the animated gif only can used in main thread? I am not
sure?!

So the basic question is that how can I develop a Waiting dialog or
progress dialog with an animated gif?

So in my opinion, the WorkerThread should generate a Dialog window
which show the animated gif. But in fact, there is an error happened
"PyAssertionError: C++ assertion "wxThread::IsMain()" failed at ..\..
\src\common\timercmn.cpp(66) in wxTimerBase::Start(): timer can only
be started from the main thread"

Does that mean the animated gif only can used in main thread? I am not
sure?!

That is correct. In addition, you can not create or manipulate any GUI element from other than the GUI thread.

So the basic question is that how can I develop a Waiting dialog or
progress dialog with an animated gif?

There are several examples of allowing worker threads to interact with the gui in the wiki, demo and archives of this list. Here is a good starting point:

http://wiki.wxpython.org/LongRunningTasks
http://wiki.wxpython.org/Non-Blocking_Gui

···

On 1/8/11 9:05 PM, zhengqing wrote:

--
Robin Dunn
Software Craftsman

Hi, Robin:
     Thanks for the answer.
     So now I know that animate gif can't be used in a work thread.
     And now I find another way to simulate the progress
dialog---------the PopupWindow. Which can include a animated gif.
     Now a question is that is it possible to make the popupwindow
transparent?
     the SetTransparent doesn't work! and if I set the style wx.
TRANSPARENT_WINDOW doesn't work either.
     Is there any way to do that?
    Thank you very much!

···

On Jan 10, 11:07 am, Robin Dunn <ro...@alldunn.com> wrote:

On 1/8/11 9:05 PM, zhengqing wrote:

> So in my opinion, the WorkerThread should generate a Dialog window
> which show the animated gif. But in fact, there is an error happened
> "PyAssertionError: C++ assertion "wxThread::IsMain()" failed at ..\..
> \src\common\timercmn.cpp(66) in wxTimerBase::Start(): timer can only
> be started from the main thread"

> Does that mean the animated gif only can used in main thread? I am not
> sure?!

That is correct. In addition, you can not create or manipulate any GUI
element from other than the GUI thread.

> So the basic question is that how can I develop a Waiting dialog or
> progress dialog with an animated gif?

There are several examples of allowing worker threads to interact with
the gui in the wiki, demo and archives of this list. Here is a good
starting point:

http://wiki.wxpython.org/LongRunningTaskshttp://wiki.wxpython.org/Non-Blocking_Gui

--
Robin Dunn
Software Craftsmanhttp://wxPython.org

Use a class derived from wx.Dialog or wx.Frame.

···

On 1/10/11 4:26 PM, zhengqing wrote:

Hi, Robin:
      Thanks for the answer.
      So now I know that animate gif can't be used in a work thread.
      And now I find another way to simulate the progress
dialog---------the PopupWindow. Which can include a animated gif.
      Now a question is that is it possible to make the popupwindow
transparent?
      the SetTransparent doesn't work! and if I set the style wx.
TRANSPARENT_WINDOW doesn't work either.
      Is there any way to do that?

--
Robin Dunn
Software Craftsman

Here are some demos that you can look at to gather ideas. To get a transparent window or dialog you will need to start with an frame (or wx.window ?) and then get it to act like a dialog.

Ray Pasco

FRAME-SEMI-TRANSPARENT.PY (700 Bytes)

FRAME-BORDERLESS-SHAPED.PY (3.39 KB)

CUSTOM_DIALOG_WITH_NO_FRAME_CONTROLS.PY (5.95 KB)

FULL_CUSTOM_DIALOG_INTERACTIVE_WITH_TIMEOUT.PY (4.38 KB)

FULL_CUSTOM_MESSAGE_POPUP_WITH_TIMEOUT.PY (2.43 KB)

···

On Jan 10, 7:26 pm, zhengqing zhengqing...@gmail.com wrote:

 Is there any way to do that?
Thank you very much!

Hi, Ray:
    Thank you very much for these examples.
    one more questions is that is popupwindow inherited from window,
and thus popupwindow should have the method SetTransparent, but why it
is not?
    Thanks!

···

On Jan 12, 9:40 am, Ray Pasco <pascor22...@gmail.com> wrote:

On Jan 10, 7:26 pm, zhengqing <zhengqing...@gmail.com> wrote:

> Is there any way to do that?
> Thank you very much!

Here are some demos that you can look at to gather ideas. To get a
transparent window or dialog you will need to start with an frame (or
wx.window ?) and then get it to act like a dialog.

Ray Pasco

FRAME-SEMI-TRANSPARENT.PY
< 1KViewDownload

FRAME-BORDERLESS-SHAPED.PY
4KViewDownload

CUSTOM_DIALOG_WITH_NO_FRAME_CONTROLS.PY
8KViewDownload

FULL_CUSTOM_DIALOG_INTERACTIVE_WITH_TIMEOUT.PY
5KViewDownload

FULL_CUSTOM_MESSAGE_POPUP_WITH_TIMEOUT.PY
3KViewDownload

Only a wx.Frame can have transparency and all dialogs must have
parents, so it it isn't possible to create a dialog with transparency
that is derived from wx.Dialog. You must start with a wx.Frame to get
transparency.

The word "dialog" implies that there needs to be some kind of user
interaction with the control. If you simply want to display, say, a
progress bar or any other status indicators, then there is no need for
a dialog at all.

Ray Pasco

···

On Jan 12, 7:50 pm, zhengqing <zhengqing...@gmail.com> wrote:

Hi, Ray:
Thank you very much for these examples.
one more questions is that is popupwindow inherited from window,
and thus popupwindow should have the method SetTransparent, but why it
is not?
Thanks!

A little redraw of a shape(with a colour, or maybe rounded with a
colour), to a portion of the frame/panel, through threads, maybe.

Not true. SetTransparent is implemented in wx.TopLevelWindow, which is the class that both wx.Dialog and wx.Frame derive from.

···

On 1/13/11 9:15 AM, Ray Pasco wrote:

On Jan 12, 7:50 pm, zhengqing<zhengqing...@gmail.com> wrote:

Hi, Ray:
     Thank you very much for these examples.
     one more questions is that is popupwindow inherited from window,
and thus popupwindow should have the method SetTransparent, but why it
is not?
     Thanks!

Only a wx.Frame can have transparency and all dialogs must have
parents, so it it isn't possible to create a dialog with transparency
that is derived from wx.Dialog. You must start with a wx.Frame to get
transparency.

--
Robin Dunn
Software Craftsman

Robin, are you saying that a wx.Dialog can have transparency ?

Ray

···

On Jan 13, 1:05 pm, Robin Dunn <ro...@alldunn.com> wrote:

On 1/13/11 9:15 AM, Ray Pasco wrote:

Not true. SetTransparent is implemented in wx.TopLevelWindow, which is
the class that both wx.Dialog and wx.Frame derive from.

--
Robin Dunn
Software Craftsmanhttp://wxPython.org

Yes.

···

On 1/14/11 2:18 PM, Ray Pasco wrote:

On Jan 13, 1:05 pm, Robin Dunn<ro...@alldunn.com> wrote:

On 1/13/11 9:15 AM, Ray Pasco wrote:

Not true. SetTransparent is implemented in wx.TopLevelWindow, which is
the class that both wx.Dialog and wx.Frame derive from.

--
Robin Dunn
Software Craftsmanhttp://wxPython.org

Robin, are you saying that a wx.Dialog can have transparency ?

--
Robin Dunn
Software Craftsman

I stand corrected!

Ray

···

On Jan 15, 5:45 pm, Robin Dunn <ro...@alldunn.com> wrote:

On 1/14/11 2:18 PM, Ray Pasco wrote:

> Robin, are you saying that a wx.Dialog can have transparency ?

Yes.

--
Robin Dunn
Software Craftsmanhttp://wxPython.org