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
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()
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...
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()
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
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
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…
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!
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.
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.
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.
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)