BoxSizer : problem with replace item sizer

In my application I want to provide for the change of an element of my

form on the fly and make this you change an element of the sizer.
When you press the button the textctrl item sizer is replaced with datepickerctrl but

this does not work. In fact, the calendar just show, but when I position mouse over there disappears.

I duplicate the problem in sample runnable code

gestgrid.py (9.99 KB)

···


Fabio Spadaro
www.fabiospadaro.com

In my application I want to provide for the change of an element of my
form on the fly and make this you change an element of the sizer.
When you press the button the textctrl item sizer is replaced with
datepickerctrl but
this does not work. In fact, the calendar just show, but when I position
mouse over there disappears.
I duplicate the problem in sample runnable code

I'm not sure this is the right approach, but I think you have to
.Hide() the textCtrl in addition to using .Replace() on the sizer. I
also think you might want to check if the datepickerctrl is already
there before you create a new one. So, you could rewrite your
function as something like:

def OnTest(self,evt):
        date_picker_exists = False
        #test if already there
        for child in self.container.GetChildren():
            if isinstance(child, wx.DatePickerCtrl):
                date_picker_exists = True

        if date_picker_exists == False:
            self.dpc = wx.DatePickerCtrl(self.container, size=(140,-1),
                                style = wx.DP_DROPDOWN
                                      > wx.DP_SHOWCENTURY)
            print 'result',self.sizertot.Replace(self.t1,self.dpc)
            self.t1.Hide()
            self.container.Layout()
            self.container.Refresh()

And do something similar with going back to the textCtrl.

Che

···

On Mon, Aug 23, 2010 at 4:50 PM, Fabio Spadaro <fabiolinospad@gmail.com> wrote:

Hi C M

···

2010/8/23 C M cmpython@gmail.com

On Mon, Aug 23, 2010 at 4:50 PM, Fabio Spadaro fabiolinospad@gmail.com wrote:

In my application I want to provide for the change of an element of my

form on the fly and make this you change an element of the sizer.

When you press the button the textctrl item sizer is replaced with

datepickerctrl but

this does not work. In fact, the calendar just show, but when I position

mouse over there disappears.

I duplicate the problem in sample runnable code

I’m not sure this is the right approach, but I think you have to

.Hide() the textCtrl in addition to using .Replace() on the sizer. I

also think you might want to check if the datepickerctrl is already

there before you create a new one. So, you could rewrite your

function as something like:

def OnTest(self,evt):

    date_picker_exists = False

    #test if already there

    for child in self.container.GetChildren():

        if isinstance(child, wx.DatePickerCtrl):

            date_picker_exists = True



    if date_picker_exists == False:

        self.dpc = wx.DatePickerCtrl(self.container, size=(140,-1),

                            style = wx.DP_DROPDOWN

                                  > wx.DP_SHOWCENTURY)

        print 'result',self.sizertot.Replace(self.t1,self.dpc)

        self.t1.Hide()

        self.container.Layout()

        self.container.Refresh()

And do something similar with going back to the textCtrl.

Che

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

It’s just right ! :slight_smile:
Thanks.


Fabio Spadaro
www.fabiospadaro.com

Sure. By the way, it occurs to me that if you want to do a switching
back-and-forth from one control to the other, you will want to create
everything in the beginning and then just .Hide() and .Show() them as
needed (this way you are never trying to create a second instance of a
control).

···

On Mon, Aug 23, 2010 at 5:26 PM, Fabio Spadaro <fabiolinospad@gmail.com> wrote:

Hi C M

2010/8/23 C M <cmpython@gmail.com>

On Mon, Aug 23, 2010 at 4:50 PM, Fabio Spadaro <fabiolinospad@gmail.com> >> wrote:
> In my application I want to provide for the change of an element of my
> form on the fly and make this you change an element of the sizer.
> When you press the button the textctrl item sizer is replaced with
> datepickerctrl but
> this does not work. In fact, the calendar just show, but when I position
> mouse over there disappears.
> I duplicate the problem in sample runnable code

I'm not sure this is the right approach, but I think you have to
.Hide() the textCtrl in addition to using .Replace() on the sizer. I
also think you might want to check if the datepickerctrl is already
there before you create a new one. So, you could rewrite your
function as something like:

def OnTest(self,evt):
date_picker_exists = False
#test if already there
for child in self.container.GetChildren():
if isinstance(child, wx.DatePickerCtrl):
date_picker_exists = True

   if date\_picker\_exists == False:
       self\.dpc = wx\.DatePickerCtrl\(self\.container, size=\(140,\-1\),
                           style = wx\.DP\_DROPDOWN
                                 &gt; wx\.DP\_SHOWCENTURY\)
       print &#39;result&#39;,self\.sizertot\.Replace\(self\.t1,self\.dpc\)
       self\.t1\.Hide\(\)
       self\.container\.Layout\(\)
       self\.container\.Refresh\(\)

And do something similar with going back to the textCtrl.

Che

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

It's just right ! :slight_smile:
Thanks.

Hi,

Hi C M

In my application I want to provide for the change of an element of my

form on the fly and make this you change an element of the sizer.

When you press the button the textctrl item sizer is replaced with

datepickerctrl but

this does not work. In fact, the calendar just show, but when I position

mouse over there disappears.

I duplicate the problem in sample runnable code

I’m not sure this is the right approach, but I think you have to

.Hide() the textCtrl in addition to using .Replace() on the sizer. I

also think you might want to check if the datepickerctrl is already

there before you create a new one. So, you could rewrite your

function as something like:

def OnTest(self,evt):

   date_picker_exists = False
   #test if already there
   for child in self.container.GetChildren():
       if isinstance(child, wx.DatePickerCtrl):
           date_picker_exists = True
   if date_picker_exists == False:
       self.dpc = wx.DatePickerCtrl(self.container, size=(140,-1),
                           style = wx.DP_DROPDOWN
                                 > wx.DP_SHOWCENTURY)
       print 'result',self.sizertot.Replace(self.t1,self.dpc)
       self.t1.Hide()
       self.container.Layout()
       self.container.Refresh()

And do something similar with going back to the textCtrl.

Che

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

It’s just right ! :slight_smile:

Thanks.

Sure. By the way, it occurs to me that if you want to do a switching

back-and-forth from one control to the other, you will want to create

everything in the beginning and then just .Hide() and .Show() them as

needed (this way you are never trying to create a second instance of a

control).

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

I integrated the code with other bit(else …) so that each time you press the button the widgets alternate in sizer and it works:

def OnTest(self,evt):

date_picker_exists = False

for child in self.container.GetChildren():

if isinstance(child, wx.DatePickerCtrl):

date_picker_exists = True

if date_picker_exists == False:

self.dpc = wx.DatePickerCtrl(self.container,

#dt=None,

size=(140,-1),

style = wx.DP_DROPDOWN

wx.DP_SHOWCENTURY)

print ‘result’,self.sizertot.Replace(self.t1,self.dpc)

self.t1.Hide()

self.container.Layout()

self.container.Refresh()

else:

if self.dpc.IsShown():

self.dpc.Hide()

self.t1.Show()

else:

self.dpc.Show()

self.t1.Hide()

self.container.Layout()

self.container.Refresh()

···

2010/8/24 C M cmpython@gmail.com

On Mon, Aug 23, 2010 at 5:26 PM, Fabio Spadaro fabiolinospad@gmail.com wrote:

2010/8/23 C M cmpython@gmail.com

On Mon, Aug 23, 2010 at 4:50 PM, Fabio Spadaro fabiolinospad@gmail.com > > >> wrote:


Fabio Spadaro
www.fabiospadaro.com

hi all,

Hi,

Hi C M

In my application I want to provide for the change of an element of my

form on the fly and make this you change an element of the sizer.

When you press the button the textctrl item sizer is replaced with

datepickerctrl but

this does not work. In fact, the calendar just show, but when I position

mouse over there disappears.

I duplicate the problem in sample runnable code

I’m not sure this is the right approach, but I think you have to

.Hide() the textCtrl in addition to using .Replace() on the sizer. I

also think you might want to check if the datepickerctrl is already

there before you create a new one. So, you could rewrite your

function as something like:

def OnTest(self,evt):

   date_picker_exists = False
   #test if already there
   for child in self.container.GetChildren():
       if isinstance(child, wx.DatePickerCtrl):
           date_picker_exists = True
   if date_picker_exists == False:
       self.dpc = wx.DatePickerCtrl(self.container, size=(140,-1),
                           style = wx.DP_DROPDOWN
                                 > wx.DP_SHOWCENTURY)
       print 'result',self.sizertot.Replace(self.t1,self.dpc)
       self.t1.Hide()
       self.container.Layout()
       self.container.Refresh()

And do something similar with going back to the textCtrl.

Che

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

It’s just right ! :slight_smile:

Thanks.

Sure. By the way, it occurs to me that if you want to do a switching

back-and-forth from one control to the other, you will want to create

everything in the beginning and then just .Hide() and .Show() them as

needed (this way you are never trying to create a second instance of a

control).

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

I integrated the code with other bit(else …) so that each time you press the button the widgets alternate in sizer and it works:

def OnTest(self,evt):

date_picker_exists = False

for child in self.container.GetChildren():

if isinstance(child, wx.DatePickerCtrl):

date_picker_exists = True

if date_picker_exists == False:

self.dpc = wx.DatePickerCtrl(self.container,

#dt=None,

size=(140,-1),

style = wx.DP_DROPDOWN

wx.DP_SHOWCENTURY)

print ‘result’,self.sizertot.Replace(self.t1,self.dpc)

self.t1.Hide()

self.container.Layout()

self.container.Refresh()

else:

if self.dpc.IsShown():

self.dpc.Hide()

self.t1.Show()

else:

self.dpc.Show()

self.t1.Hide()

self.container.Layout()

self.container.Refresh()


Fabio Spadaro
www.fabiospadaro.com

Still not working. I modified the code changing

sizer.Add (self.grid, 1, wx.EXPAND).
If you press button datepickerctrl appears, if you press

again reappears textctrl but if you resize the window the
textctrl remains anchored in its position.

Any idea?

Re-attached new script.

gestgrid.py (12 KB)

···

2010/8/24 Fabio Spadaro fabiolinospad@gmail.com

2010/8/24 C M cmpython@gmail.com

On Mon, Aug 23, 2010 at 5:26 PM, Fabio Spadaro fabiolinospad@gmail.com wrote:

2010/8/23 C M cmpython@gmail.com

On Mon, Aug 23, 2010 at 4:50 PM, Fabio Spadaro fabiolinospad@gmail.com > > > > >> wrote:

Fabio Spadaro
www.fabiospadaro.com

You used Replace() so the textctrl is no longer in the sizer, so it's position is not managed by the sizer when the window changes size. Create and add both widgets to the sizer at the beginning and Hide() one of them. Then when you want to switch just Hide() one, Show() the other and do a Layout(). There's no need for the first half of what you have in OnTest.

···

On 8/25/10 5:18 AM, Fabio Spadaro wrote:

Still not working. I modified the code changing
sizer.Add (self.grid, 1, wx.EXPAND).
If you press button datepickerctrl appears, if you press
again reappears textctrl but if you resize the window the
textctrl remains anchored in its position.
Any idea?

--
Robin Dunn
Software Craftsman

Hi,

···

2010/8/25 Robin Dunn robin@alldunn.com

On 8/25/10 5:18 AM, Fabio Spadaro wrote:

Still not working. I modified the code changing

sizer.Add (self.grid, 1, wx.EXPAND).

If you press button datepickerctrl appears, if you press

again reappears textctrl but if you resize the window the

textctrl remains anchored in its position.

Any idea?

You used Replace() so the textctrl is no longer in the sizer, so it’s position is not managed by the sizer when the window changes size. Create and add both widgets to the sizer at the beginning and Hide() one of them. Then when you want to switch just Hide() one, Show() the other and do a Layout(). There’s no need for the first half of what you have in OnTest.

Robin Dunn

Software Craftsman

http://wxPython.org

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

Work.
Thanks a lot.


Fabio Spadaro
www.fabiospadaro.com

Hi,

···

2010/8/26 Fabio Spadaro fabiolinospad@gmail.com

Hi,

2010/8/25 Robin Dunn robin@alldunn.com

On 8/25/10 5:18 AM, Fabio Spadaro wrote:

Still not working. I modified the code changing

sizer.Add (self.grid, 1, wx.EXPAND).

If you press button datepickerctrl appears, if you press

again reappears textctrl but if you resize the window the

textctrl remains anchored in its position.

Any idea?

You used Replace() so the textctrl is no longer in the sizer, so it’s position is not managed by the sizer when the window changes size. Create and add both widgets to the sizer at the beginning and Hide() one of them. Then when you want to switch just Hide() one, Show() the other and do a Layout(). There’s no need for the first half of what you have in OnTest.

Robin Dunn

Software Craftsman

http://wxPython.org

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

Work.
Thanks a lot.


Fabio Spadaro
www.fabiospadaro.com

I followed your suggestion and it works. As the two widgets that alternate in sizer

are textctrl and genericdatepicker, I want based on an X event is changed
Local and consequently the layout of the calendar. The simplest solution would be

to create so many genericdatepicker 's widgets into sizer as there are languages

managed (English, Italian, etc.) and use hide or show as appropriate. But I do not
I want this, there is a better solution that you suggest?


Fabio Spadaro
www.fabiospadaro.com

If you've got many possible widgets that could be displayed then I would probably go back to creating them on-demand. Just be sure to always put the new widget in the sizer and take the old one out. You should probably also Destroy() the old one so you don't have to worry about keeping track of it.

···

On 8/26/10 3:53 AM, Fabio Spadaro wrote:

I followed your suggestion and it works. As the two widgets that
alternate in sizer
are textctrl and genericdatepicker, I want based on an X event is changed
Local and consequently the layout of the calendar. The simplest solution
would be
to create so many genericdatepicker 's widgets into sizer as there are
languages
managed (English, Italian, etc.) and use hide or show as appropriate.
But I do not
I want this, there is a better solution that you suggest?

--
Robin Dunn
Software Craftsman