ListCtrl + TBIcon issues

Hi,

I am currently working on a little reminder program that works kind of
like Outlook's. I am using a ListCtrl in Report View and it works great
most of the time. I have the ListCtrl and a few other elements in a nested
set of sizers. There's a top level BoxSizer and then 3 others that go
inside of it that hold the various elements.

Most of the time, it loads fine. But every now and again, it'll load and
the widgets don't seem to go into their sizers. They all get scrunched up
in the upper left corner of the screen instead. I can't get it to do this
consistently.

The other problem I am having is with the taskbar/system tray icon. I am
using a slightly modified version from the demo. Anyway, when I
right-click it and tell it to close the program, it closes but I get an
error (see attached screenshot). The main app is using wx.App, but I pass
a frame object to the TBIcon. Should I be using wx.Frame instead of wx.App
and just run the program using wx.PySimpleApp instead of basing it on
wx.App?

Any ideas would be appreciated.

I am using wxPython 2.8, Python 2.4 on Windows XP SP2.

Mike Driscoll
Applications Specialist
MCIS - Technology Center

pyError.jpg

Mike Driscoll wrote:

Hi,

I am currently working on a little reminder program that works kind of
like Outlook's. I am using a ListCtrl in Report View and it works great
most of the time. I have the ListCtrl and a few other elements in a nested
set of sizers. There's a top level BoxSizer and then 3 others that go
inside of it that hold the various elements.

Most of the time, it loads fine. But every now and again, it'll load and
the widgets don't seem to go into their sizers. They all get scrunched up
in the upper left corner of the screen instead. I can't get it to do this
consistently.

It probably just needs an extra call to Layout() somewhere.

The other problem I am having is with the taskbar/system tray icon. I am
using a slightly modified version from the demo. Anyway, when I
right-click it and tell it to close the program, it closes but I get an
error (see attached screenshot).

What are you using to close the program? You may want to delay it using wx.CallAfter to make sure that there are no more pending events for the window or the tbicon. Otherwise the system can end up trying to send events to an object that has already been destroyed. If all else fails make a small runnable sample that shows the problem and send it here.

···

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

From: Robin Dunn [mailto:robin@alldunn.com]
Sent: Tuesday, June 19, 2007 1:01 PM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] ListCtrl + TBIcon issues

Mike Driscoll wrote:
> Hi,
>
> I am currently working on a little reminder program that
works kind of
> like Outlook's. I am using a ListCtrl in Report View and it works
> great most of the time. I have the ListCtrl and a few other
elements
> in a nested set of sizers. There's a top level BoxSizer and then 3
> others that go inside of it that hold the various elements.
>
> Most of the time, it loads fine. But every now and again,
it'll load
> and the widgets don't seem to go into their sizers. They all get
> scrunched up in the upper left corner of the screen
instead. I can't
> get it to do this consistently.

It probably just needs an extra call to Layout() somewhere.

I'll try this. I just wish it did it consistently so I could troubleshoot
it more easily.

> The other problem I am having is with the taskbar/system
tray icon. I
> am using a slightly modified version from the demo. Anyway, when I
> right-click it and tell it to close the program, it closes
but I get
> an error (see attached screenshot).

What are you using to close the program? You may want to
delay it using wx.CallAfter to make sure that there are no
more pending events for the window or the tbicon. Otherwise
the system can end up trying to send events to an object that
has already been destroyed. If all else fails make a small
runnable sample that shows the problem and send it here.

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

Currently, the command in the TBIcon file is just like the demo's (I
think) in that it tells the frame object to close:

self.frame.Close()

I've tried that, but while it closes the frame, it doesn't get rid of the
TBIcon or stop the program itself from running and I get the following
traceback:

Traceback (most recent call last):
  File
"\\someServer\\Scripts\PythonPackages\Development\zimbra\reminder.py",
line 328, in updateAlerts
    self.list_ctrl.DeleteAllItems()
  File "C:\Python24\lib\site-packages\wx-2.8-msw-ansi\wx\_core.py", line
13750, in __getattr__
    raise PyDeadObjectError(self.attrStr % self._name)
wx._core.PyDeadObjectError: The C++ part of the TestListCtrl object has
been deleted, attribute access no longer allowed.

I've tried catching the close event like this:

self.frame.Bind(wx.EVT_CLOSE, self.onClose)

def onClose(self, event):
        '''
        Closes the program and deletes the icon from the system tray.
        '''
        print 'in onClose'
        try:
            self.tbicon.Destroy()
            wx.GetApp().ProcessIdle()
        except:
            pass
        self.frame.Destroy()

This works if I close with the little "x" in the upper right hand corner
of my app. I tried sticking a wx.CallAfter() at the top and bottom of the
try as well as before and after the self.frame.Destroy(). I also tried
self.frame.Close() in all those circumstances. Interestingly, if
wx.CallAfter() is the beginning line in the try statement and I use
self.frame.Close(), it goes into an infinite loop.

Any other ideas?

Thanks,

Mike

···

-----Original Message-----

Mike Driscoll wrote:

Currently, the command in the TBIcon file is just like the demo's (I
think) in that it tells the frame object to close:

self.frame.Close()

I've tried that, but while it closes the frame, it doesn't get rid of the
TBIcon or stop the program itself from running and I get the following
traceback:

Traceback (most recent call last):
  File
"\\someServer\\Scripts\PythonPackages\Development\zimbra\reminder.py",
line 328, in updateAlerts
    self.list_ctrl.DeleteAllItems()
  File "C:\Python24\lib\site-packages\wx-2.8-msw-ansi\wx\_core.py", line
13750, in __getattr__
    raise PyDeadObjectError(self.attrStr % self._name)
wx._core.PyDeadObjectError: The C++ part of the TestListCtrl object has
been deleted, attribute access no longer allowed.

I've tried catching the close event like this:

self.frame.Bind(wx.EVT_CLOSE, self.onClose)

Please make a runnable sample so we can see what is going on.

···

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

Mike Driscoll wrote:

> Currently, the command in the TBIcon file is just like the demo's (I
> think) in that it tells the frame object to close:
>
> self.frame.Close()
>
> I've tried that, but while it closes the frame, it doesn't
get rid of
> the TBIcon or stop the program itself from running and I get the
> following
> traceback:
>
> Traceback (most recent call last):
> File
>
"\\someServer\\Scripts\PythonPackages\Development\zimbra\reminder.py",
> line 328, in updateAlerts
> self.list_ctrl.DeleteAllItems()
> File "C:\Python24\lib\site-packages\wx-2.8-msw-ansi\wx\_core.py",
> line 13750, in __getattr__
> raise PyDeadObjectError(self.attrStr % self._name)
> wx._core.PyDeadObjectError: The C++ part of the TestListCtrl object
> has been deleted, attribute access no longer allowed.
>
>
> I've tried catching the close event like this:
>
> self.frame.Bind(wx.EVT_CLOSE, self.onClose)

Please make a runnable sample so we can see what is going on.

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

Robin et al,

I've included a runnable example of the code. It closes fine using the
"Close" button and the little "x". It just behaves poorly when trying to
close by right-clicking the TBIcon and choosing "Exit Program". Thanks for
all the help!

Mike

Mike,

you forgot to attach the script

Werner

Mike Driscoll wrote:

···

  

Mike Driscoll wrote:

Currently, the command in the TBIcon file is just like the demo's (I
think) in that it tells the frame object to close:

self.frame.Close()

I've tried that, but while it closes the frame, it doesn't
      

get rid of
    

the TBIcon or stop the program itself from running and I get the following
traceback:

Traceback (most recent call last):
  File

"\\someServer\\Scripts\PythonPackages\Development\zimbra\reminder.py",
    

line 328, in updateAlerts
    self.list_ctrl.DeleteAllItems()
  File "C:\Python24\lib\site-packages\wx-2.8-msw-ansi\wx\_core.py", line 13750, in __getattr__
    raise PyDeadObjectError(self.attrStr % self._name)
wx._core.PyDeadObjectError: The C++ part of the TestListCtrl object has been deleted, attribute access no longer allowed.

I've tried catching the close event like this:

self.frame.Bind(wx.EVT_CLOSE, self.onClose)
      

Please make a runnable sample so we can see what is going on.

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

Robin et al,

I've included a runnable example of the code. It closes fine using the
"Close" button and the little "x". It just behaves poorly when trying to
close by right-clicking the TBIcon and choosing "Exit Program". Thanks for
all the help!

Mike

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Werner F. Bruhin wrote:

Mike,

you forgot to attach the script

He sent it directly to me.

Robin et al,

I've included a runnable example of the code. It closes fine using the
"Close" button and the little "x". It just behaves poorly when trying to
close by right-clicking the TBIcon and choosing "Exit Program". Thanks for
all the help!

Your sample works fine for me. Maybe you have some 3rd party software running that is interfering with it in some way...

···

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

Yup, I sure did. Sorry about that.

TBIcon.py (2.46 KB)

rem_sample.py (3.45 KB)

···

-----Original Message-----
From: Werner F. Bruhin [mailto:werner.bruhin@free.fr]
Sent: Thursday, June 21, 2007 10:16 AM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] ListCtrl + TBIcon issues

Mike,

you forgot to attach the script

Werner

Mike Driscoll wrote:
>
>
>> Mike Driscoll wrote:
>>
>>
>>> Currently, the command in the TBIcon file is just like
the demo's (I
>>> think) in that it tells the frame object to close:
>>>
>>> self.frame.Close()
>>>
>>> I've tried that, but while it closes the frame, it doesn't
>>>
>> get rid of
>>
>>> the TBIcon or stop the program itself from running and I get the
>>> following
>>> traceback:
>>>
>>> Traceback (most recent call last):
>>> File
>>>
>>>
>>
"\\someServer\\Scripts\PythonPackages\Development\zimbra\reminder.py"
>> ,
>>
>>> line 328, in updateAlerts
>>> self.list_ctrl.DeleteAllItems()
>>> File
"C:\Python24\lib\site-packages\wx-2.8-msw-ansi\wx\_core.py",
>>> line 13750, in __getattr__
>>> raise PyDeadObjectError(self.attrStr % self._name)
>>> wx._core.PyDeadObjectError: The C++ part of the
TestListCtrl object
>>> has been deleted, attribute access no longer allowed.
>>>
>>>
>>> I've tried catching the close event like this:
>>>
>>> self.frame.Bind(wx.EVT_CLOSE, self.onClose)
>>>
>> Please make a runnable sample so we can see what is going on.
>>
>>
>>
>> --
>> Robin Dunn
>> Software Craftsman
>> http://wxPython.org Java give you jitters? Relax with wxPython!
>>
>>
>
> Robin et al,
>
> I've included a runnable example of the code. It closes
fine using the
> "Close" button and the little "x". It just behaves poorly
when trying
> to close by right-clicking the TBIcon and choosing "Exit Program".
> Thanks for all the help!
>
> Mike
>
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
wxPython-users-unsubscribe@lists.wxwidgets.org
> For additional commands, e-mail:
> wxPython-users-help@lists.wxwidgets.org
>
>
>
>

Werner F. Bruhin wrote:
> Mike,
>
> you forgot to attach the script
>

He sent it directly to me.

>> Robin et al,
>>
>> I've included a runnable example of the code. It closes fine using
>> the "Close" button and the little "x". It just behaves poorly when
>> trying to close by right-clicking the TBIcon and choosing "Exit
>> Program". Thanks for all the help!

Your sample works fine for me. Maybe you have some 3rd party
software running that is interfering with it in some way...

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

Hmmm...I closed all my applications that weren't running in the background
except for Python and tried running it and I still get the pop-up dialog
that an error occurred when I close my application from the TBIcon
right-click menu. I'm not seeing much in the Tast Manager that's not
supposed to be there. I do have some VMWare cruft that's running. Does
wxPython have any known issues with VMWare?

Maybe I'll just disable the closing ability of the icon and create a way
to do it from a menu instead.

Thanks for the help. Let me know if anything new occurs to you.

Mike

I can recreate the error. It's because you're calling ProcessIdle
within the shutdown and it's causing events to be dispatched to your
already destroyed tray icon instance. Why are you calling this? It's
not required to get the application to shut down.

Depending on your application needs, I'd either call
app.ExitMainLoop() directly from the tray menu handler (that will exit
the app regardless of how many windows you might have around) or I'd
simply get rid of the try/except block and the ProcessIdle call.

···

On 6/22/07, Mike Driscoll <mdriscoll@co.marshall.ia.us> wrote:

> Werner F. Bruhin wrote:
> > Mike,
> >
> > you forgot to attach the script
> >
>
> He sent it directly to me.
>
> >> Robin et al,
> >>
> >> I've included a runnable example of the code. It closes fine using
> >> the "Close" button and the little "x". It just behaves poorly when
> >> trying to close by right-clicking the TBIcon and choosing "Exit
> >> Program". Thanks for all the help!
>
> Your sample works fine for me. Maybe you have some 3rd party
> software running that is interfering with it in some way...
>
> --
> Robin Dunn
> Software Craftsman
> http://wxPython.org Java give you jitters? Relax with wxPython!
>

Hmmm...I closed all my applications that weren't running in the background
except for Python and tried running it and I still get the pop-up dialog
that an error occurred when I close my application from the TBIcon
right-click menu. I'm not seeing much in the Tast Manager that's not
supposed to be there. I do have some VMWare cruft that's running. Does
wxPython have any known issues with VMWare?

Maybe I'll just disable the closing ability of the icon and create a way
to do it from a menu instead.

Thanks for the help. Let me know if anything new occurs to you.

>
> > Werner F. Bruhin wrote:
> > > Mike,
> > >
> > > you forgot to attach the script
> > >
> >
> > He sent it directly to me.
> >
> >
> > >> Robin et al,
> > >>
> > >> I've included a runnable example of the code. It closes fine
> > >> using the "Close" button and the little "x". It just behaves
> > >> poorly when trying to close by right-clicking the TBIcon and
> > >> choosing "Exit Program". Thanks for all the help!
> >
> > Your sample works fine for me. Maybe you have some 3rd party
> > software running that is interfering with it in some way...
> >
> >
> > --
> > Robin Dunn
> > Software Craftsman
> > http://wxPython.org Java give you jitters? Relax with wxPython!
> >
>
> Hmmm...I closed all my applications that weren't running in the
> background except for Python and tried running it and I
still get the
> pop-up dialog that an error occurred when I close my
application from
> the TBIcon right-click menu. I'm not seeing much in the
Tast Manager
> that's not supposed to be there. I do have some VMWare cruft that's
> running. Does wxPython have any known issues with VMWare?
>
> Maybe I'll just disable the closing ability of the icon and
create a
> way to do it from a menu instead.
>
> Thanks for the help. Let me know if anything new occurs to you.
>

I can recreate the error. It's because you're calling
ProcessIdle within the shutdown and it's causing events to be
dispatched to your already destroyed tray icon instance. Why
are you calling this? It's not required to get the
application to shut down.

Depending on your application needs, I'd either call
app.ExitMainLoop() directly from the tray menu handler (that
will exit the app regardless of how many windows you might
have around) or I'd simply get rid of the try/except block
and the ProcessIdle call.

Chris,

Originally I didn't do the ProcessIdle call, but when I didn't, the icon
wouldn't get destroyed. However, now when I try it without the try/except
or the ProcessIdle, it works perfectly. I don't know what was wrong with
it before, but it doesn't matter. Thanks a lot!

Mike