Add ctrl over a dc

I'm painting bmp from internet on a dc, and I need to put over the dc
an animate ctrl while it download the image,
the only I don't know how to do is to put the animate ctrl over de dc.

class Panel_Fotos(wx.Panel):
    def __init__(self,parent,fotos = []):
        wx.Panel.__init__(self,parent,-1)
        self.fotos = fotos
        self.foto = Panel_DC(self,images.Xphoto.getBitmap())
        ani =
wx.animate.Animation(os.path.join(c.sys_path,"recursos","images","loading.gif"))
        self.ctrl = wx.animate.AnimationCtrl(self, -1, ani,size=
self.GetClientSize())

        Tsizer = wx.BoxSizer(wx.VERTICAL)
        Tsizer.Add(self.foto,1,wx.wx.EXPAND| wx.CENTER)

        self.SetSizer(Tsizer)
        Tsizer.Fit(self)

    def Loading(self):
        self.ctrl.Play()

    def Load_Fotos(self,fotos):
        self.fotos = fotos
        if fotos :
            if not fotos[0] == None:
                bmp = wx.Bitmap(fotos[0],wx.BITMAP_TYPE_ANY)
            else:
                bmp = images.Xphoto.getBitmap()
            self.foto.pic = bmp
            self.Refresh()
        self.ctrl.Stop()

class Panel_DC (wx.Panel):
    def __init__(self, parent, pic = None, thumb = True, Size =
(50,50)):
        wx.Panel.__init__(self, parent, -1)
        self.pic = pic
        self.thumb = thumb
        self.Bind(wx.EVT_PAINT, self.OnPaint)
        self.Bind(wx.EVT_MOVE, self.OnResize)
        self.Bind(wx.EVT_SIZE, self.OnResize)
        self.SetMinSize(Size)

    def OnPaint(self, evt):
        dc = wx.PaintDC(self)
        dc.Clear()
        imsize = size = self.GetClientSize()
        if self.thumb == True: imsize = size -[10,10]
        img = images.thumbnail(self.pic, imsize)
        w = ((size[0])- img.Size[0] )/ 2
        h = ((size[1]) - img.Size[1] )/ 2
        dc.DrawBitmap(img,w,h, True)

    def OnResize(self,event):
        self.Refresh()

Thanks

The AnimationCtrl is just another kind of window, and you can put it on another window by specifying the other as its parent, just like you would for a button or a text field. However, reading between the lines of your question and your code it seems you are wanting to possibly display the animation and the image in the same space, so the fact that the AnimationCtrl is a separate window/widget will likely cause problems because it won't be transparent like you are probably expecting. There are a couple ways to deal with that:

1. Don't try to paint the downloaded image until you have the whole thing. While downloading Show() the animation ctrl and Play() it, and when it is done Stop() and Hide(). Be sure to not block the main event loop with your downloading task otherwise the animation ctrl won't get the timer and paint events where it implements the animation.

2. You can draw the individual images of the animation yourself. The animation object can give you the time to delay between images and also each image. Using a timer you can delay the proper amount of time, then fetch the next image and do a Refresh to cause your paint event to be called. The advantage here is that you can blend your animation and the downloaded image (previous or perhaps a partial of the currently downloading one) and the animation in the same window. The same warning about not blocking the event loop applies here.

3. Of course instead of putting the animation in the same window as the image you could choose to use a wx.ProgressDialog instead, or something similar that shows your animation instead of a wx.Gauge.

···

On 4/12/11 4:14 PM, podio wrote:

I'm painting bmp from internet on a dc, and I need to put over the dc
an animate ctrl while it download the image,
the only I don't know how to do is to put the animate ctrl over de dc.

--
Robin Dunn
Software Craftsman

The AnimationCtrl is just another kind of window, and you can put it on
another window by specifying the other as its parent, just like you
would for a button or a text field. However, reading between the lines
of your question and your code it seems you are wanting to possibly
display the animation and the image in the same space, so the fact that
the AnimationCtrl is a separate window/widget will likely cause problems
because it won't be transparent like you are probably expecting. There
are a couple ways to deal with that:

1. Don't try to paint the downloaded image until you have the whole
thing. While downloading Show() the animation ctrl and Play() it, and
when it is done Stop() and Hide(). Be sure to not block the main event
loop with your downloading task otherwise the animation ctrl won't get
the timer and paint events where it implements the animation.

Thanks I was trying to hide the control with Show(False) didn't notice
Hide(), it's now doing what I wanted but the only I need now is to
center the ctrl in the panel. Try wx.ALIGN_CENTER, CenterOnParent()

class Panel_Fotos(wx.Panel):
    def __init__(self,parent,fotos = ):
        wx.Panel.__init__(self,parent,-1)
        self.fotos = fotos
        self.foto = Panel_DC(self,images.Xphoto.getBitmap())
        ani =
wx.animate.Animation(os.path.join(c.sys_path,"recursos","images","loading.gif"))
        self.ctrl = wx.animate.AnimationCtrl(self, -1, ani,size=
self.GetClientSize())

        Tsizer = wx.BoxSizer(wx.VERTICAL)
        Tsizer.Add(self.ctrl,1,wx.CENTER )
        Tsizer.Add(self.foto,1,wx.EXPAND| wx.CENTER)

        self.SetSizer(Tsizer)
        Tsizer.Fit(self)
        self.ctrl.Hide()

    def Loading(self):
        self.foto.Hide()
        self.ctrl.SetSize(self.GetClientSize())
        self.ctrl.Play()
        self.ctrl.Show()
        self.Refresh()

    def Load_Fotos(self,fotos):
        self.fotos = fotos
        if fotos :
            if not fotos[0] == None:
                bmp = wx.Bitmap(fotos[0],wx.BITMAP_TYPE_ANY)
            else:
                bmp = images.Xphoto.getBitmap()
            self.foto.pic = bmp

        self.ctrl.Stop()
        self.ctrl.Hide()
        self.foto.Show()
        self.Refresh()

Try using a proportion of zero here ^^^, and change the flags to wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER_HORIZONTAL. You should also be calling self.Layout when you show/hide self.foto and self.ctrl.

···

On 4/13/11 5:47 AM, podio wrote:

The AnimationCtrl is just another kind of window, and you can put it on
another window by specifying the other as its parent, just like you
would for a button or a text field. However, reading between the lines
of your question and your code it seems you are wanting to possibly
display the animation and the image in the same space, so the fact that
the AnimationCtrl is a separate window/widget will likely cause problems
because it won't be transparent like you are probably expecting. There
are a couple ways to deal with that:

1. Don't try to paint the downloaded image until you have the whole
thing. While downloading Show() the animation ctrl and Play() it, and
when it is done Stop() and Hide(). Be sure to not block the main event
loop with your downloading task otherwise the animation ctrl won't get
the timer and paint events where it implements the animation.

Thanks I was trying to hide the control with Show(False) didn't notice
Hide(), it's now doing what I wanted but the only I need now is to
center the ctrl in the panel. Try wx.ALIGN_CENTER, CenterOnParent()

class Panel_Fotos(wx.Panel):
     def __init__(self,parent,fotos = ):
         wx.Panel.__init__(self,parent,-1)
         self.fotos = fotos
         self.foto = Panel_DC(self,images.Xphoto.getBitmap())
         ani =
wx.animate.Animation(os.path.join(c.sys_path,"recursos","images","loading.gif"))
         self.ctrl = wx.animate.AnimationCtrl(self, -1, ani,size=
self.GetClientSize())

         Tsizer = wx.BoxSizer(wx.VERTICAL)
         Tsizer.Add(self.ctrl,1,wx.CENTER )

--
Robin Dunn
Software Craftsman

I delete the size when creating the ctrl and now it align horizontaly
but not verticaly, I tryed all

The code:

class Panel_Fotos(wx.Panel):
    def __init__(self,parent,fotos = ):
        wx.Panel.__init__(self,parent,-1)
        self.fotos = fotos
        self.foto = Panel_DC(self,images.Xphoto.getBitmap())

        ani =
wx.animate.Animation(os.path.join(c.sys_path,"recursos","images","loading.gif"))
        self.ctrl = wx.animate.AnimationCtrl(self, -1, ani)

        Tsizer = wx.BoxSizer(wx.VERTICAL)
        Tsizer.Add(self.ctrl,0, wx.ALIGN_CENTER_VERTICAL|
wx.ALIGN_CENTER_HORIZONTAL,)
        Tsizer.Add(self.foto,1,wx.EXPAND)

        self.SetSizer(Tsizer)
        Tsizer.Fit(self)
        self.ctrl.Hide()
        self.Layout()

    def Loading(self):
        self.foto.Hide()
        self.ctrl.Show()
        self.ctrl.Play()
        self.Refresh()
        self.Layout()

    def Load_Fotos(self,fotos):
        self.fotos = fotos
        if fotos :
            if not fotos[0] == None:
                bmp = wx.Bitmap(fotos[0],wx.BITMAP_TYPE_ANY)
            else:
                bmp = images.Xphoto.getBitmap()
            self.foto.pic = bmp

        self.ctrl.Stop()
        self.ctrl.Hide()
        self.foto.Show()
        self.Refresh()
        self.Layout()

···

On 13 abr, 13:14, Robin Dunn <ro...@alldunn.com> wrote:

On 4/13/11 5:47 AM, podio wrote:

>> The AnimationCtrl is just another kind of window, and you can put it on
>> another window by specifying the other as its parent, just like you
>> would for a button or a text field. However, reading between the lines
>> of your question and your code it seems you are wanting to possibly
>> display the animation and the image in the same space, so the fact that
>> the AnimationCtrl is a separate window/widget will likely cause problems
>> because it won't be transparent like you are probably expecting. There
>> are a couple ways to deal with that:

>> 1. Don't try to paint the downloaded image until you have the whole
>> thing. While downloading Show() the animation ctrl and Play() it, and
>> when it is done Stop() and Hide(). Be sure to not block the main event
>> loop with your downloading task otherwise the animation ctrl won't get
>> the timer and paint events where it implements the animation.

> Thanks I was trying to hide the control with Show(False) didn't notice
> Hide(), it's now doing what I wanted but the only I need now is to
> center the ctrl in the panel. Try wx.ALIGN_CENTER, CenterOnParent()

> class Panel_Fotos(wx.Panel):
> def __init__(self,parent,fotos = ):
> wx.Panel.__init__(self,parent,-1)
> self.fotos = fotos
> self.foto = Panel_DC(self,images.Xphoto.getBitmap())
> ani =
> wx.animate.Animation(os.path.join(c.sys_path,"recursos","images","loading.g if"))
> self.ctrl = wx.animate.AnimationCtrl(self, -1, ani,size=
> self.GetClientSize())

> Tsizer = wx.BoxSizer(wx.VERTICAL)
> Tsizer.Add(self.ctrl,1,wx.CENTER )

Try using a proportion of zero here ^^^, and change the flags to
wx.ALIGN_CENTER_VERTICAL|wx.ALIGN_CENTER_HORIZONTAL. You should also be
calling self.Layout when you show/hide self.foto and self.ctrl.

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

Sorry, that little issue slipped my mind. An easy way to center an item in a box sizer is to add a spacer before and after the item, each with a proportion=1 so they will expand to take an equal measure of all the free space. See attached.

centered.py (518 Bytes)

···

On 4/14/11 8:09 AM, podio wrote:

I delete the size when creating the ctrl and now it align horizontaly
but not verticaly, I tryed all

--
Robin Dunn
Software Craftsman

Yes that works but I can't hide spacers, so when the animation is
hide, the spacers remains.
I will tried to another controls which I can hide.

Thanks robin

···

On 14 abr, 20:55, Robin Dunn <ro...@alldunn.com> wrote:

On 4/14/11 8:09 AM, podio wrote:

> I delete the size when creating the ctrl and now it align horizontaly
> but not verticaly, I tryed all

Sorry, that little issue slipped my mind. An easy way to center an item
in a box sizer is to add a spacer before and after the item, each with a
proportion=1 so they will expand to take an equal measure of all the
free space. See attached.

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

centered.py
< 1 KBVerDescargar

Yes, but when you do the Layout() after hiding the animation widget and showing the bitmap widget then the spacers will shrink to make room for the bitmap widget. They only take the left-over space.

···

On 4/14/11 7:52 PM, podio wrote:

Yes that works but I can't hide spacers, so when the animation is
hide, the spacers remains.
I will tried to another controls which I can hide.

--
Robin Dunn
Software Craftsman