Dynamic Panel

Hello,

I am developping a wxPython interface.
In my program, I need to display dynamically a panel in an other panel :
The choice in a ComboBox of my interface implies the type of panel I will display dynamically.

This a part of my source :

···

class PanelDynamiqueAvecCombo(usi5_xrc.xrc_PanelDynamiqueAvecCombo):
def OnCombobox_ComboChoix (self, evt):

    cb = evt.GetEventObject()
    print('EvtComboBox: %s\n' % (evt.GetString(), ))

    choix_txt = evt.GetString()
   

    grille =self.ComboChoix.GetContainingSizer()
    gbitem = wx.GridBagSizer.FindItemAtPosition(grille, (0,1))

   
    if (gbitem != None):

        print "!!! ATTENTION !!! "
        # Faire une sauvegarde ici des choix dans la base xml avant de detruire

        # le panel
       
        Destroy(self.panelChoix)

       
    else:

        exec "self.panelChoix = usi5_xrc.xrc%sPanel(self)"%(choix_txt,)
       

        wx.GridBagSizer.Add(grille, self.panelChoix, (0,1))
   

        self.ComboChoix.GetParent().Layout()

        self.panelChoix.Refresh()
   

        self.panelChoix.Update()

self.panelChoix.UpdateWindowUI()


The problem is that the panel panelChoix is not displayed immediatelly.
It is only displayed when I resize the main window of my application.
Thanks in advance for your help.
Christophe

Christophe Gengembre wrote:

Hello,

I am developping a wxPython interface.
In my program, I need to display dynamically a panel in an other panel :
The choice in a ComboBox of my interface implies the type of panel I will display dynamically.

This a part of my source :
----
class PanelDynamiqueAvecCombo(usi5_xrc.xrc_PanelDynamiqueAvecCombo):
    def OnCombobox_ComboChoix (self, evt):
        cb = evt.GetEventObject()
        print('EvtComboBox: %s\n' % (evt.GetString(), ))
        choix_txt = evt.GetString()
               grille =self.ComboChoix.GetContainingSizer()
        gbitem = wx.GridBagSizer.FindItemAtPosition(grille, (0,1))
               if (gbitem != None):
            print "!!! ATTENTION !!! "
            # Faire une sauvegarde ici des choix dans la base xml avant de detruire
            # le panel
                       Destroy(self.panelChoix)
                   else:
            exec "self.panelChoix = usi5_xrc.xrc%sPanel(self)"%(choix_txt,)
                       wx.GridBagSizer.Add(grille, self.panelChoix, (0,1))
                   self.ComboChoix.GetParent().Layout()

            self.panelChoix.Refresh()
                   self.panelChoix.Update()
# self.panelChoix.UpdateWindowUI()
---

The problem is that the panel panelChoix is not displayed immediatelly.
It is only displayed when I resize the main window of my application.
Thanks in advance for your help.
Christophe

It sounds like it's not refreshing after the layout to me. Try adding this after the Layout():

self.ComboChoix.GetParent().Refresh()

Oddly enough, I thought Refresh() was called automagically after Layout, but I have probably gotten something mixed up. Looking at some of my code where I add or destroy widgets in a panel, I just need to call Layout() on the panel that has changed.

So, if you have a panel in a panel, call the outer panel's Layout(). I think you may be getting the wrong parent...

Mike

Christophe,

Christophe Gengembre wrote:

Hello,

I am developping a wxPython interface.
In my program, I need to display dynamically a panel in an other panel :
The choice in a ComboBox of my interface implies the type of panel I will display dynamically.

This a part of my source :
----
class PanelDynamiqueAvecCombo(usi5_xrc.xrc_PanelDynamiqueAvecCombo):
    def OnCombobox_ComboChoix (self, evt):
        cb = evt.GetEventObject()
        print('EvtComboBox: %s\n' % (evt.GetString(), ))
        choix_txt = evt.GetString()
               grille =self.ComboChoix.GetContainingSizer()
        gbitem = wx.GridBagSizer.FindItemAtPosition(grille, (0,1))
               if (gbitem != None):
            print "!!! ATTENTION !!! "
            # Faire une sauvegarde ici des choix dans la base xml avant de detruire
            # le panel
                       Destroy(self.panelChoix)
                   else:
            exec "self.panelChoix = usi5_xrc.xrc%sPanel(self)"%(choix_txt,)
                       wx.GridBagSizer.Add(grille, self.panelChoix, (0,1))
                   self.ComboChoix.GetParent().Layout()

            self.panelChoix.Refresh()
                   self.panelChoix.Update()
# self.panelChoix.UpdateWindowUI()
---

The problem is that the panel panelChoix is not displayed immediatelly.
It is only displayed when I resize the main window of my application.
Thanks in advance for your help.
Christophe

You can try the Layout method and then the Refresh+Update ones.
Mathias

Thanks Mike and Mathias :slight_smile:

By the outer panel’s Layout(), you nean the older parent panel (The farest from the leaf) . My error was calling the trio Layout, Refresh, Update of the children panels instances :slight_smile:

Thanks a lot.
Christophe

···

2008/10/16 Mike Driscoll mike@pythonlibrary.org

Christophe Gengembre wrote:

Hello,

I am developping a wxPython interface.

In my program, I need to display dynamically a panel in an other panel :

The choice in a ComboBox of my interface implies the type of panel I will display dynamically.

This a part of my source :


class PanelDynamiqueAvecCombo(usi5_xrc.xrc_PanelDynamiqueAvecCombo):

def OnCombobox_ComboChoix (self, evt):

    cb = evt.GetEventObject()

    print('EvtComboBox: %s\n' % (evt.GetString(), ))

    choix_txt = evt.GetString()

          grille =self.ComboChoix.GetContainingSizer()

    gbitem = wx.GridBagSizer.FindItemAtPosition(grille, (0,1))

          if (gbitem != None):

        print "!!! ATTENTION !!! "

        # Faire une sauvegarde ici des choix dans la base xml avant de detruire

        # le panel

                  Destroy(self.panelChoix)

              else:

        exec "self.panelChoix = usi5_xrc.xrc%sPanel(self)"%(choix_txt,)

                  wx.GridBagSizer.Add(grille, self.panelChoix, (0,1))

              self.ComboChoix.GetParent().Layout()



        self.panelChoix.Refresh()

              self.panelChoix.Update()

self.panelChoix.UpdateWindowUI()


The problem is that the panel panelChoix is not displayed immediatelly.

It is only displayed when I resize the main window of my application.

Thanks in advance for your help.

Christophe

It sounds like it’s not refreshing after the layout to me. Try adding this after the Layout():

self.ComboChoix.GetParent().Refresh()

Oddly enough, I thought Refresh() was called automagically after Layout, but I have probably gotten something mixed up. Looking at some of my code where I add or destroy widgets in a panel, I just need to call Layout() on the panel that has changed.

So, if you have a panel in a panel, call the outer panel’s Layout(). I think you may be getting the wrong parent…

Mike


wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Mike Driscoll wrote:

Oddly enough, I thought Refresh() was called automagically after Layout, but I have probably gotten something mixed up.

Paint events are sent either when the system sees that some portion of some widget has been damaged or exposed, or when explicitly told to do so by calling Refresh. Automatically calling Refresh from Layout would be a waste of time at best, or cause extra flicker at worst, because if the layout causes some portion of a widget to be exposed the system will already send a paint event for just that portion of the widget, and a plain Refresh() will invalidate (mark as damaged) the whole widget and it and all of its children will be repainted for no reason.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin,

Mike Driscoll wrote:

Oddly enough, I thought Refresh() was called automagically after Layout, but I have probably gotten something mixed up.

Paint events are sent either when the system sees that some portion of some widget has been damaged or exposed, or when explicitly told to do so by calling Refresh. Automatically calling Refresh from Layout would be a waste of time at best, or cause extra flicker at worst, because if the layout causes some portion of a widget to be exposed the system will already send a paint event for just that portion of the widget, and a plain Refresh() will invalidate (mark as damaged) the whole widget and it and all of its children will be repainted for no reason.

Thanks for straightening that out. I'll try to remember this in future.

···

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

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

Thank you for that clarification Mike.

···

2008/10/20 Mike Driscoll mike@pythonlibrary.org

Robin,

Mike Driscoll wrote:

Oddly enough, I thought Refresh() was called automagically after Layout, but I have probably gotten something mixed up.

Paint events are sent either when the system sees that some portion of some widget has been damaged or exposed, or when explicitly told to do so by calling Refresh. Automatically calling Refresh from Layout would be a waste of time at best, or cause extra flicker at worst, because if the layout causes some portion of a widget to be exposed the system will already send a paint event for just that portion of the widget, and a plain Refresh() will invalidate (mark as damaged) the whole widget and it and all of its children will be repainted for no reason.

Thanks for straightening that out. I’ll try to remember this in future.


Mike Driscoll

Blog: http://blog.pythonlibrary.org

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


wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Christophe Gengembre wrote:

Thank you for that clarification Mike.

That was Robin's prose...for some reason, Thunderbird cut his signature off...

Mike

···

2008/10/20 Mike Driscoll <mike@pythonlibrary.org <mailto:mike@pythonlibrary.org>>

    Robin,

        Mike Driscoll wrote:

            Oddly enough, I thought Refresh() was called automagically
            after Layout, but I have probably gotten something mixed up.

        Paint events are sent either when the system sees that some
        portion of some widget has been damaged or exposed, or when
        explicitly told to do so by calling Refresh. Automatically
        calling Refresh from Layout would be a waste of time at best,
        or cause extra flicker at worst, because if the layout causes
        some portion of a widget to be exposed the system will already
        send a paint event for just that portion of the widget, and a
        plain Refresh() will invalidate (mark as damaged) the whole
        widget and it and all of its children will be repainted for no
        reason.

    Thanks for straightening that out. I'll try to remember this in
    future.

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

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

Yes, I am sorry for this mistake.
Thank you Robin.
Some times I am in the moon or in the clouds …
Christophe

···

2008/10/20 Mike Driscoll mike@pythonlibrary.org

Christophe Gengembre wrote:

Thank you for that clarification Mike.

That was Robin’s prose…for some reason, Thunderbird cut his signature off…

Mike

2008/10/20 Mike Driscoll <mike@pythonlibrary.org mailto:mike@pythonlibrary.org>

Robin,





    Mike Driscoll wrote:





        Oddly enough, I thought Refresh() was called automagically

        after Layout, but I have probably gotten something mixed up.





    Paint events are sent either when the system sees that some

    portion of some widget has been damaged or exposed, or when

    explicitly told to do so by calling Refresh.  Automatically

    calling Refresh from Layout would be a waste of time at best,

    or cause extra flicker at worst, because if the layout causes

    some portion of a widget to be exposed the system will already

    send a paint event for just that portion of the widget, and a

    plain Refresh() will invalidate (mark as damaged) the whole

    widget and it and all of its children will be repainted for no

    reason.







Thanks for straightening that out. I'll try to remember this in

future.



-------------------

Mike Driscoll



Blog:   [http://blog.pythonlibrary.org](http://blog.pythonlibrary.org)

Python Extension Building Network:     [http://www.pythonlibrary.org](http://www.pythonlibrary.org)

wxpython-users mailing list

wxpython-users@lists.wxwidgets.org

http://lists.wxwidgets.org/mailman/listinfo/wxpython-users