Change ListCtrl

Hola,

I need to change a listCtrl, I tried with listCtrl.destroy() to remove and create it again but it closes the app, I Attach a sample code, any suggestions?

list.py (2.08 KB)

···


SIN ETIQUETAS.[ PUNTO ]
http://hi.im/jyr
http://www.opentumblr.com

Hi,

···

On Nov 16, 11:05 pm, Jair Gaxiola <jyr.gaxi...@gmail.com> wrote:

Hola,

I need to change a listCtrl, I tried with listCtrl.destroy() to remove and
create it again but it closes the app, I Attach a sample code, any
suggestions?

What do you mean by "change" it? Are you wanting to refresh the rows
with new information? Change the number of columns? Or something else?

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

Blog: http://blog.pythonlibrary.org

Yes, I want change all the listCtrl for other with new columns and rows. Look the sample code, please.

···

On Tue, Nov 17, 2009 at 9:17 AM, Mike Driscoll kyosohma@gmail.com wrote:

Hi,

On Nov 16, 11:05 pm, Jair Gaxiola jyr.gaxi...@gmail.com wrote:

Hola,

I need to change a listCtrl, I tried with listCtrl.destroy() to remove and

create it again but it closes the app, I Attach a sample code, any

suggestions?

What do you mean by “change” it? Are you wanting to refresh the rows

with new information? Change the number of columns? Or something else?


SIN ETIQUETAS.[ PUNTO ]
http://hi.im/jyr
http://www.opentumblr.com

Hi,

> Hola,
>
> I need to change a listCtrl, I tried with listCtrl.destroy() to remove
> and
> create it again but it closes the app, I Attach a sample code, any
> suggestions?

Your destroying the control while your inside an event handler that
you bound to it.

You could either

1) Just update the values in the control without destroying it.
Destroying and re-creating the control will likely lead to lots of
flickering and other display issues.

or

2) mark a flag and do the destroy/recreate it in OnIdle (highly
suggest #1 over this option)

Cody

···

On Nov 16, 11:05 pm, Jair Gaxiola <jyr.gaxi...@gmail.com> wrote:

You are destroying the list ctrl from within one of that list ctrl's event handlers. That's like saying, "I'm going to shoot myself in the head and after I'm finished I'll clean the gun and put it away in the gun safe." In other words, there is still some code that will be running that assumes that the list ctrl still exists and crashes when it tries to access it.

If you really need to destroy and recreate the list ctrl then what you could do instead is simply Hide() the old listctrl, create and populate the new one as you do now, and then call the Destroy method of the old one using wx.CallAfter so it will happen after all pending events have been processed.

···

On 11/16/09 9:05 PM, Jair Gaxiola wrote:

Hola,

I need to change a listCtrl, I tried with listCtrl.destroy() to remove
and create it again but it closes the app, I Attach a sample code, any
suggestions?

--
Robin Dunn
Software Craftsman

But by destroyed the widget the app closes, please look the sample code attaching.

···

On Tue, Nov 17, 2009 at 11:15 AM, Cody Precord codyprecord@gmail.com wrote:

Hi,

On Nov 16, 11:05 pm, Jair Gaxiola jyr.gaxi...@gmail.com wrote:

Hola,

I need to change a listCtrl, I tried with listCtrl.destroy() to remove

and

create it again but it closes the app, I Attach a sample code, any

suggestions?

Your destroying the control while your inside an event handler that

you bound to it.


SIN ETIQUETAS.[ PUNTO ]
http://hi.im/jyr

http://www.opentumblr.com

Jair Gaxiola wrote:

···

On Tue, Nov 17, 2009 at 11:15 AM, Cody Precord <codyprecord@gmail.com > <mailto:codyprecord@gmail.com>> wrote:

    Hi,

    >> On Nov 16, 11:05 pm, Jair Gaxiola <jyr.gaxi...@gmail.com > <mailto:jyr.gaxi…@gmail.com>> wrote:
    >> > Hola,
    >> >
    >> > I need to change a listCtrl, I tried with listCtrl.destroy()
    to remove
    >> > and
    >> > create it again but it closes the app, I Attach a sample
    code, any
    >> > suggestions?

    Your destroying the control while your inside an event handler that
    you bound to it.

But by destroyed the widget the app closes, please look the sample
code attaching.

--
SIN ETIQUETAS.[ PUNTO ]
http://hi.im/jyr
http://www.opentumblr.com

>

You mean the application crashes? It seems fine here - you click the
first list item and it changes to the second one.
Windows XP SP3, python 2.6.4 wx 2.8.10.1

You may also just wish to use ClearAll() instead of destroy, then you
can just recreate the list's items, as opposed having to re-construct
the list widgets itself.

--
Steven Sproat, BSc
http://www.basicrpg.com/

Already replacing the old listCtrl with new one, but only shows the new listCtrl when I resize the window. I attach my sample code.

list.py (2.12 KB)

···

On Tue, Nov 17, 2009 at 11:19 AM, Robin Dunn robin@alldunn.com wrote:

You are destroying the list ctrl from within one of that list ctrl’s

event handlers. That’s like saying, "I’m going to shoot myself in the

head and after I’m finished I’ll clean the gun and put it away in the

gun safe." In other words, there is still some code that will be

running that assumes that the list ctrl still exists and crashes when it

tries to access it.

If you really need to destroy and recreate the list ctrl then what you

could do instead is simply Hide() the old listctrl, create and populate

the new one as you do now, and then call the Destroy method of the old

one using wx.CallAfter so it will happen after all pending events have

been processed.


SIN ETIQUETAS.[ PUNTO ]

http://hi.im/jyr
http://www.opentumblr.com

Thank you very much to all, is work with wx.CallAfter

···


SIN ETIQUETAS.[ PUNTO ]
http://hi.im/jyr
http://www.opentumblr.com

try this:

     def click(self, evt):
         self.lc.Hide()
         lc = wx.ListCtrl(self.panel_1, -1,
                  style=wx.LC_REPORT|wx.SUNKEN_BORDER)
         lc.InsertColumn(0, 'A')
         lc.InsertColumn(1, 'B')
         lc.InsertColumn(1, 'C')
         lc.SetColumnWidth(0, 140)
         lc.SetColumnWidth(1, 153)
         lc.SetColumnWidth(1, 133)
         index = lc.InsertStringItem(0, 'none')
         lc.SetStringItem(index,1, 'none')
         lc.SetStringItem(index,2, 'none')
         self.sizer_2.Replace(self.lc, lc)
         wx.CallAfter(self.lc.Destroy)
         self.lc = lc
         self.panel_1.Layout()

···

On 11/17/09 10:01 AM, Jair Gaxiola wrote:

On Tue, Nov 17, 2009 at 11:19 AM, Robin Dunn <robin@alldunn.com > <mailto:robin@alldunn.com>> wrote:

    You are destroying the list ctrl from within one of that list ctrl's
    event handlers. That's like saying, "I'm going to shoot myself in the
    head and after I'm finished I'll clean the gun and put it away in the
    gun safe." In other words, there is still some code that will be
    running that assumes that the list ctrl still exists and crashes when it
    tries to access it.

    If you really need to destroy and recreate the list ctrl then what you
    could do instead is simply Hide() the old listctrl, create and populate
    the new one as you do now, and then call the Destroy method of the old
    one using wx.CallAfter so it will happen after all pending events have
    been processed.

Already replacing the old listCtrl with new one, but only shows the new
listCtrl when I resize the window. I attach my sample code.

--
Robin Dunn
Software Craftsman