Unhandled exception

This error is sometimes shown when I try to redraw a screen with many
sizers after changing many of the controls (mostly wx.panels):

Unhandled exception
An unhandled exception occurred. Press 'Abort' to terminate the
program, 'Retry' to Exit the program normally and 'Ignore' to try to
continue.

No python line numbers or error details are shown. If I click Ignore,
the program continues, apparently none the worse. The screen is drawn
with correct results. If I click Abort, everything ends. I have
encased the offending method in try/except block, but it doesn't catch
anything. The error seems to be outside python. My python print
statements appear right to the last line of expected execution.

The error is intermittent.. maybe occurs once out of 4 tries.. No
apparent reason.. The same exact same sequence, starting the program
from fresh, can be fine or can crash.

How do I get started with troubleshooting this?

Sam,

···

On Jul 29, 10:00 am, Sam23 <qm0...@gmail.com> wrote:

This error is sometimes shown when I try to redraw a screen with many
sizers after changing many of the controls (mostly wx.panels):

Unhandled exception
An unhandled exception occurred. Press 'Abort' to terminate the
program, 'Retry' to Exit the program normally and 'Ignore' to try to
continue.

No python line numbers or error details are shown. If I click Ignore,
the program continues, apparently none the worse. The screen is drawn
with correct results. If I click Abort, everything ends. I have
encased the offending method in try/except block, but it doesn't catch
anything. The error seems to be outside python. My python print
statements appear right to the last line of expected execution.

The error is intermittent.. maybe occurs once out of 4 tries.. No
apparent reason.. The same exact same sequence, starting the program
from fresh, can be fine or can crash.

How do I get started with troubleshooting this?

Many people recommend the builtin Python debugger, pdb. I've never
used it, but I have Wingware's IDE which has its own debugger. Here
are some docs though:

Others on this list will have other hints.

Mike

Sam,

Sam23 wrote:

This error is sometimes shown when I try to redraw a screen with many
sizers after changing many of the controls (mostly wx.panels):

Unhandled exception
An unhandled exception occurred. Press 'Abort' to terminate the
program, 'Retry' to Exit the program normally and 'Ignore' to try to
continue.

No python line numbers or error details are shown. If I click Ignore,
the program continues, apparently none the worse. The screen is drawn
with correct results. If I click Abort, everything ends. I have
encased the offending method in try/except block, but it doesn't catch
anything. The error seems to be outside python. My python print
statements appear right to the last line of expected execution.

The error is intermittent.. maybe occurs once out of 4 tries.. No
apparent reason.. The same exact same sequence, starting the program
from fresh, can be fine or can crash.

How do I get started with troubleshooting this?
  

As Mike suggested a debugger can definitely help (I use the one built in
with Boa).

What kind of changes are you making to your controls/sizers? If you
add/destroy are you maybe in some situation a control twice to a sizer
or use an incorrect sizer? I found that making errors with sizers can
cause crashes which don't tell you much (I think this is due to what
Robin calls the C++/Python sandwich -
C++ & Python Sandwich - wxPyWiki).

It might also help to comment out sections of code and see when the
problem goes away.

Werner

···

>

Sam23 wrote:

This error is sometimes shown when I try to redraw a screen with many
sizers after changing many of the controls (mostly wx.panels):

Unhandled exception
An unhandled exception occurred. Press 'Abort' to terminate the
program, 'Retry' to Exit the program normally and 'Ignore' to try to
continue.

No python line numbers or error details are shown.

It's a C++ error, not a Python exception.

If I click Ignore,
the program continues, apparently none the worse. The screen is drawn
with correct results. If I click Abort, everything ends. I have
encased the offending method in try/except block, but it doesn't catch
anything. The error seems to be outside python. My python print
statements appear right to the last line of expected execution.

The error is intermittent.. maybe occurs once out of 4 tries.. No
apparent reason.. The same exact same sequence, starting the program
from fresh, can be fine or can crash.

How do I get started with troubleshooting this?

If you are not able to track it down from the Python side (see the excellent suggestions from others) and if you are not able to build a debug version of wxWidgets and wxPython so you can run it under the C++ debugger then try to make a small sample application that has the same problem and send it here. Please read: MakingSampleApps - wxPyWiki

···

--
Robin Dunn
Software Craftsman

Thanks for the replies and suggestions. I will have a go at narrowing
down the problem.

One question: For a crashes in the C++ code, is there any easy way to
get a error report? Something along the line of ‘redirect=false/true’
for wxPython?

Some details regarding the screen that is having the problem:

A panel called OuterFrame containing: (a) A panel containing
wx.lib.button buttons and static text (b) A panel of wx.lib.button
buttons (c) a wx.aui notebook with 2 tabs. These are arranged using a
vertical sizer.

Each tab in wx aui notebook contains a wx.Panel: Panel A and Panel B.
Panels A and B each contains many wx.panels that are arranged using
GridBagSizer. The crash happens during the redraw of Panels A and B;
in which all the wxpanels in Panel A and Panel B are destroyed and
then redrawn based on changed user data. Layout(), Freeze() and Thaw()
are called during the redraw. The crash seems to be after all the
Python and wxPython code has completed executing and control handed
over to wxWidgets.

The problem may be related to the wx aui notebook. Panel A and Panel B
should probably have the wx aui notebook as the parent, but when I do
this, they became very small in size, and cannot be resized to fill
the whole tab, even when I try to force this by issuing SetSize() via
the InspectionTool. They only show up correctly (fill up whole tab)
if I create them with OuterFrame as their parent. I also tried using
wxNotebook instead of wx aui notebook, but the same tiny size problem
also shows up.

Panels A and B depict appointments for different groups of people.
These are positioned using GridBagSizer. The redraw schedule was
working fine for adding new appointments and deleting appointments
(even with the odd behaviour regarding the parent), but the crash
started showing up when I added the change appointment function. This
is even though the same redraw function is called for add, delete and
change. The difference is in the update of the appointment data, which
is in python-only code and not wxpython.

I have to confess that the code suffers from an embarassing confusion
in organisation because I started off by by trying to partition the
code based on MVC design, but gave up towards the end as it I found it
increasingly difficult to separate the display code from the logic.

I will probably start by reorganising the code first. This will at
least make it easier to extract out the minimal set of code required
to duplicate the problem.

Cheers
Sam

···

On Jul 30, 7:51 am, Robin Dunn <ro...@alldunn.com> wrote:

Sam23 wrote:
> This error is sometimes shown when I try to redraw a screen with many
> sizers after changing many of the controls (mostly wx.panels):

> Unhandled exception
> An unhandled exception occurred. Press 'Abort' to terminate the
> program, 'Retry' to Exit the program normally and 'Ignore' to try to
> continue.

> No python line numbers or error details are shown.

It's a C++ error, not a Python exception.

> If I click Ignore,
> the program continues, apparently none the worse. The screen is drawn
> with correct results. If I click Abort, everything ends. I have
> encased the offending method in try/except block, but it doesn't catch
> anything. The error seems to be outside python. My python print
> statements appear right to the last line of expected execution.

> The error is intermittent.. maybe occurs once out of 4 tries.. No
> apparent reason.. The same exact same sequence, starting the program
> from fresh, can be fine or can crash.

> How do I get started with troubleshooting this?

If you are not able to track it down from the Python side (see the
excellent suggestions from others) and if you are not able to build a
debug version of wxWidgets and wxPython so you can run it under the C++
debugger then try to make a small sample application that has the same
problem and send it here. Please read:MakingSampleApps - wxPyWiki

--
Robin Dunn
Software Craftsmanhttp://wxPython.org

Hi,

2009/7/30 Sam23:

The problem may be related to the wx aui notebook. Panel A and Panel B
should probably have the wx aui notebook as the parent, but when I do
this, they became very small in size, and cannot be resized to fill
the whole tab, even when I try to force this by issuing SetSize() via
the InspectionTool. They only show up correctly (fill up whole tab)
if I create them with OuterFrame as their parent.

You can not do that. If panelA and panelB are in the AUI notebook,
they need to be children of the notebook or children of a panel you
put in the notebook page. Try to do something like this:

mainPanel = wx.Panel(AUINotebook)
panelA = wx.Panel(mainPanel)
panelB = wx.Panel(mainPanel)

sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(panelA, 1, wx.EXPAND)
sizer.Add(panelB, 1, wx.EXPAND)
mainPanel.SetSizer(sizer)

sizer.Layout()

AUINotebook.AddPage(mainPanel, "Main")

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/

I have tested further. I have not solved the problem but have some
findings to report. I think I will rewrite most of the code – will
probably stop using sizers for the appointment table. My testing so
far:

I tried adding the vertical sizers as suggested, and created Panels A
and B with the notebook as the parent, but the drawn size is still
tiny, 100*80 pixels instead of occupying most of the screen as
expected. The AUI notebook itself is small in size, not just its
contents (Panels A and B). This is even though it was placed in a
vertical sizer as follows:
sizer.Add(self.nb, 1, wx.EXPAND)

where:
sizer = wx.BoxSizer(wx.VERTICAL)
  and
self.nb = wx.aui.AuiNotebook(self.op)

Panel A and Panel B each occupy different pages on the auiNotebook,
and therefore shouldn’t put into 1 vertical sizer i.e. each is to fill
up the entire notebook when its tab is selected, and not occupy top
and bottom halves of the notebook. I have previously tried creating
a putting Panel A into a frame (call this X) and used VERTICAL sizer
to expand it within this frame, and then adding X to the notebook,
(and ditto for Panel B), but the notebook size was still tiny.
Anyway, I now see that the problem is the size of the auiNotebook and
not Panels A and B. This is by looking at it using the
InspectionTool.

I then changed the aui notebook to plain wx.Notebook - problem was
still the same, except that the notebook wasn’t so tiny – 307 by 325
pixels. I hunted around, and found a SetMinSize command in a
AdjustScrollBar method in Panels A and B (both are created from the
same custom class). I commented this out, added a SetSizeHints
command, and voila the notebook filled its available space - but the
scrollbars in Panels A and B were missing – just empty space where
they were supposed to be. I then tested the change appointment – it
still crashes with the python exception. So I was wrong; the exception
has nothing to do with aui notebook.

I then switched back to auiNotebook, and the notebook became tiny
again – couldn’t get it to expand. By the way if I take out Panels A
and B, and just add a simply text control to the auiNotebook, the
notebook fills the screen properly, so it appears that something in
Panels A and B is causing the auiNotebook to choke on sizing.

Anyway, I think I probably have to rewrite most of the code – there
probably a lot wrong in it – it was my first wxPython coding and
probably full of errors. The fact that “unhandled exception” doesn’t
show any error details is worrying.

···

On Jul 30, 9:02 pm, Andrea Gavana <andrea.gav...@gmail.com> wrote:

Hi,

2009/7/30 Sam23:

> The problem may be related to the wx aui notebook. Panel A and Panel B
> should probably have the wx aui notebook as the parent, but when I do
> this, they became very small in size, and cannot be resized to fill
> the whole tab, even when I try to force this by issuing SetSize() via
> the InspectionTool. They only show up correctly (fill up whole tab)
> if I create them with OuterFrame as their parent.

You can not do that. If panelA and panelB are in the AUI notebook,
they need to be children of the notebook or children of a panel you
put in the notebook page. Try to do something like this:

mainPanel = wx.Panel(AUINotebook)
panelA = wx.Panel(mainPanel)
panelB = wx.Panel(mainPanel)

sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(panelA, 1, wx.EXPAND)
sizer.Add(panelB, 1, wx.EXPAND)
mainPanel.SetSizer(sizer)

sizer.Layout()

AUINotebook.AddPage(mainPanel, "Main")

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."http://xoomer.alice.it/infinity77/http://thedoomedcity.blogspot.com/

Sam,

What about creating a small runnable example of your problem and attach it here.

http://wiki.wxpython.org/MakingSampleApps

Sam23 wrote:

I have tested further. I have not solved the problem but have some
findings to report. I think I will rewrite most of the code – will
probably stop using sizers for the appointment table.

I think this will sooner or later just cause you other problems.

I am just starting with AUI, i.e. convert my application to using AUI and AUINotebooks and have run into similar problems but with the help of Andrea and others have been able to resolve them all or it was found that it was a bug in AUI in which case they get pretty quickly solved by Andrea if you use pyAUI (wx.lib.agw.aui).

Werner

I will try to see if I can create the sample app that can show the
problem. It may take some time because there is code spread out over 7
or 8 python programs - mostly due to my less than successful attempt
at MVC. I am little apprehensive of my handiwork right now :stuck_out_tongue:

Thanks & cheers
Sam

···

On Jul 31, 3:28 pm, "Werner F. Bruhin" <wbru...@gmail.com> wrote:

Sam,

What about creating a small runnable example of your problem and attach
it here.

MakingSampleApps - wxPyWiki

Sam23 wrote:
> I have tested further. I have not solved the problem but have some
> findings to report. I think I will rewrite most of the code – will
> probably stop using sizers for the appointment table.

I think this will sooner or later just cause you other problems.

I am just starting with AUI, i.e. convert my application to using AUI
and AUINotebooks and have run into similar problems but with the help of
Andrea and others have been able to resolve them all or it was found
that it was a bug in AUI in which case they get pretty quickly solved by
Andrea if you use pyAUI (wx.lib.agw.aui).

Werner

Sam23 wrote:

I will try to see if I can create the sample app that can show the
problem. It may take some time because there is code spread out over 7
or 8 python programs - mostly due to my less than successful attempt
at MVC. I am little apprehensive of my handiwork right now :stuck_out_tongue:
  

Everyone here is very nice about these things - otherwise I wouldn't dare posting some of my stuff :wink:

I don't think it is a problem of attaching/requiring multiple files, just make sure that there are no dependencies others might not have.

Werner

I attach a zip file containing the code that with these
problems: (a) unhandled exception (b) incorrect size aui.notebook with VERTICAL sizer.

Run the cAps.py file. This is the ‘controller’ that runs
other necessary files. A window with a
notebook containing 2 pages will appear.
First page of the notebook is titled ‘Group 1’ and second page, ‘Group
2’.

---------- Error (a) Unhandled Exception:

This is an intermittent but fairly frequent error. To see the error, try this:

Click on ‘Group 2’
page of the notebook. Click on
appointment labeled ‘Giant Step’ in column ‘2 Decibel’, in the row (from 9:00 to 10:00). The appointment will be highlighted with
yellow border. Click on ‘Shift’ button at the top of the window (just above the
Group 2 page title). Then click on any
empty timeslot e.g. column ‘2 Decibel’, for time from 8:00 to 9:00. The empty destination timeslot will be
highlighted with red border. Click on the destination timeslot again to confirm shift. The appointment time will then be changed
from [9 to 10] to [8 to 9]. The change is successful and the screen will update
correctly.

Most of the time, after this shift is completed successfully, this error will be shown:

‘Unhandled Exception’.
If you click on ‘Ignore’, the program will usually continue normally, apparently
none the worse.

Sometimes, but rarely, when this shift is done, the entire
wx program just shuts down without any message at all. At other times, the shift will be executed
successfully without any errors, but for the shift of this particular appointment,
it will fail 4 in 5 times.

If there is no error, simply try shifting this appointment
again, or shifting other appointments. It is almost guaranteed to fail within 5
attempts. But the failure rate is also intermittent – I have experienced times
when it doesn’t fail at all; sometimes after a seemingly unrelated and minor
change to the code. Shift for Group 2 appointments seems to be more likely to
fail then Group 1’s. Group 1 and Group
2 windows are created from the same Class: CalendarPanel.

I have tried changing the code so that the shift requires
only 1 step (i.e. the second confirmation click is not required) and this
seems to prevent the ‘unhandled exception’. However, it it not clear
why. I have gone through the difference
in the code, and there doesn’t seem to be any difference that could account
for the crash when the shift is
executed in the second click compared to when done in the first.

Currently, the code only allows for shifts of appointments
that are of 1 hour duration, i.e. same as the empty slots.

---------- Error (b) incorrect size of panel in
aui.notebook.

The code as it is, shows aui notebook as correctly sized
i.e. fills expands to fill most of its containing panel (self.op) based on the
add to a VERTICAL sizer with proportion 1 and wx.EXPAND flag. However, this is
only when the panels of the appointment windows are incorrectly created with
the outer panel as the parent instead of the AuiNotebook. The ‘outer panel’, self.op, contains the auiNotebook. If
the appointment windows are created with the AuiNotebook as the parent, the
AuiNotebook becomes tiny – occupying only 100*80 pixels. A similar size problem is seen when
wx.Notebook is used – one difference is that, in the first place, wx.Notebook
does not allow the 2 pages to be added if their parents are not wx.Notebook.

The relevant lines of codes are in vAps.py:

Line 263:

self.nb =
wx.aui.AuiNotebook(self.op)

Lines 429 to 435:

self.calG1Panel =
CalendarPanel(self.op)

self.calG1Panel.name = ‘G1’

self.nb.AddPage(self.calG1Panel,
“Group 1”)

self.calG2Panel =
CalendarPanel(self.op)

self.calG2Panel.name = ‘G2’

self.nb.AddPage(self.calG2Panel, “Group 2”)

(*** Changing the parents for the 2 CalendarPanels to self.nb
in Lines 429 and 433 will cause the size of the notebook will become tiny)

Lines 441 to 445:

sizer = wx.BoxSizer(wx.VERTICAL)

self.sizer=sizer

sizer.Add(spSizer, 0, wx.EXPAND)

sizer.Add(wx.StaticLine(self.op), 0, wx.EXPAND | wx.LEFT |
wx.TOP | wx.BOTTOM, 8)

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

------ Apologies for large number of files and amount of
code —

I tried to start of by creating a single minimalist file
that can demonstrate the error, but had a hard time, and after spending hours,
gave up. I then decided to work backward by starting with the code I had and
cutting it down. I didn’t cut down the
number of files by much, but I have deleted most of the code that has no
bearing on the error e.g. functions for adding and deleting appointments; and
cleaned it up as best as I could.
There is still a lot of code, but having spent another few hours on this
second effort, I hope it is sufficient to provide some ideas on the cause of
the problems. If you look at the code, and also, consider the intermittent nature of the problem,
you will probably know why both efforts was so time consuming and
difficult. Not my finest moment.

One major suspect is the way I created the ‘scrolling’
appointment schedule with ‘frozen’ row and column titles. This was by manually controlling the
scrollbars and shuffling appointment windows in a GridBagSizer. Not the most elegant way and required a ton
of coding - and may be the cause of both problems; but currently is the only
way I have to solve the problem. I
suspect I have to abandon this awkward design or have to radically relook at
the entire approach to meeting this requirement.

Well, any feedback and suggestions is welcome.

Thanks.

Sam

cAps.zip (12.9 KB)

···

2009/7/29 Sam23 qm0023@gmail.com

This error is sometimes shown when I try to redraw a screen with many

sizers after changing many of the controls (mostly wx.panels):

Unhandled exception

An unhandled exception occurred. Press ‘Abort’ to terminate the

program, ‘Retry’ to Exit the program normally and ‘Ignore’ to try to

continue.

No python line numbers or error details are shown. If I click Ignore,

the program continues, apparently none the worse. The screen is drawn

with correct results. If I click Abort, everything ends. I have

encased the offending method in try/except block, but it doesn’t catch

anything. The error seems to be outside python. My python print

statements appear right to the last line of expected execution.

The error is intermittent… maybe occurs once out of 4 tries… No

apparent reason… The same exact same sequence, starting the program

from fresh, can be fine or can crash.

How do I get started with troubleshooting this?

Hi Sam,

I did not solve your problem, at least not the exception, but I think I narrowed down were your problem is.

Made following changes:
cAps.py - moved inspection tool so one can load it when one wants using ctrl-alt-i and it shows the control which currently has the focus.
vAps.py:
- parent the notebook pages to the notebook
- added a sizer to the frame and defined col/row as growable
- in drawOutPanel method replaced your CalendarPanel with empty wx.Panel
mAps.py - added "return" to drawSchedule so above hack "works"

At this point the notebook sizes correctly. However if I put the CalendarPanel back then it shrinks again. Haven't figured out why this is happening, as I haven't figured out how this class works. I suspect that the sizer in it is not expanding.

I'll attach the changed files, maybe they will give you an idea what is wrong in CalendarPanel.

Werner

mAps.py (11.5 KB)

vAps.py (30.5 KB)

cAps.py (936 Bytes)

Werner,
Thanks for taking time to look at this. I have looked at the code
samples you attached.

(a) What does self.Init() do in the App class? i.e.
class App(wx.App, InspectionMixin):
    def __init__(self, redirect=False, filename=None):
        wx.App.__init__(self, redirect, filename)
        self.controller = Controller(self)
----> self.Init()

Is this different from the wx.App.__init__ method called?

I haven't seen this before, and looking at the wx reference or
googling didn't throw up any clues.

(b) The InspectionMixin tool is great. Previously, I had resorted to
commenting and uncommenting the "wx.lib.inspection.InspectionTool
().Show()" lines to get the Widget Inspector to show or not to show.
Figuring out which control was which object in the Widget Inspector
also required some work then.

(c) Yes, the notebook sizes correctly until the CalendarPanel objects
are added as pages. I have tested this with TextControl before, as
per the AuiNotebook wx examples. This is with the original VERTICAL
SIZER used. AuiNotebook sizes fine until CalendarPanel is introduced.
CalendarPanel also sizes fine in normal panels, i.e. only messes up
Notebooks... So notebook sizes fine without CalendarPanel and
CalendarPanel sizes fine without Notebook. But, I would like the 2 of
them to work together, if possible. Don't know how to do this yet,
except may to rewrite the entire CalendarPanel class to be simpler -
in some way.

(d) The 'unhandled exception' problem is a big concern. Maybe it has
to do with my lack of understanding of what to do and what not to do
in wxpython...

···

On Aug 5, 4:29 pm, "Werner F. Bruhin" <wbru...@gmail.com> wrote:

Hi Sam,

I did not solve your problem, at least not the exception, but I think I
narrowed down were your problem is.

Made following changes:
cAps.py - moved inspection tool so one can load it when one wants using
ctrl-alt-i and it shows the control which currently has the focus.
vAps.py:
- parent the notebook pages to the notebook
- added a sizer to the frame and defined col/row as growable
- in drawOutPanel method replaced your CalendarPanel with empty wx.Panel
mAps.py - added "return" to drawSchedule so above hack "works"

At this point the notebook sizes correctly. However if I put the
CalendarPanel back then it shrinks again. Haven't figured out why this
is happening, as I haven't figured out how this class works. I suspect
that the sizer in it is not expanding.

I'll attach the changed files, maybe they will give you an idea what is
wrong in CalendarPanel.

Werner

mAps.py
11KViewDownload

vAps.py
30KViewDownload

cAps.py
< 1KViewDownload

Sam23 wrote:

Werner,
Thanks for taking time to look at this. I have looked at the code
samples you attached.

(a) What does self.Init() do in the App class? i.e.
class App(wx.App, InspectionMixin):
    def __init__(self, redirect=False, filename=None):
        wx.App.__init__(self, redirect, filename)
        self.controller = Controller(self)
----> self.Init()
  

That is for the InspectionMixin.

Is this different from the wx.App.__init__ method called?

I haven't seen this before, and looking at the wx reference or
googling didn't throw up any clues.

(b) The InspectionMixin tool is great. Previously, I had resorted to
commenting and uncommenting the "wx.lib.inspection.InspectionTool
().Show()" lines to get the Widget Inspector to show or not to show.
Figuring out which control was which object in the Widget Inspector
also required some work then.
  

Yes, this is really cool and very very helpful - especially when I look at sizer issues.

(c) Yes, the notebook sizes correctly until the CalendarPanel objects
are added as pages. I have tested this with TextControl before, as
per the AuiNotebook wx examples. This is with the original VERTICAL
SIZER used. AuiNotebook sizes fine until CalendarPanel is introduced.
CalendarPanel also sizes fine in normal panels, i.e. only messes up
Notebooks... So notebook sizes fine without CalendarPanel and
CalendarPanel sizes fine without Notebook. But, I would like the 2 of
them to work together, if possible. Don't know how to do this yet,
except may to rewrite the entire CalendarPanel class to be simpler -
in some way.
  

I'll try and have another look at this. What I would do is to "down size" CalendarPanel to try to isolate what is causing the problem. I.e. comment out code that CalendarPanel is a simple panel and then start activating code you have in it and see when it starts to go wrong. I am pretty sure (just a gut feel) it has to do with sizers and either flags not being set or somewhere in the sizer chain something which is not allowed/defined to expand.

(d) The 'unhandled exception' problem is a big concern. Maybe it has
to do with my lack of understanding of what to do and what not to do
in wxpython...
  

I understand, but I would try to resolve the sizing issue, and make sure that you parent things correctly. I.e. the notebook page parent (i.e. pages have to be children of a notebook) issue is a potential cause of this, or having a parent/sizer which you tell to manage something which is higher up in the hierarchy.

Werner

<<That is for the InspectionMixin.>>
Understand. Now it makes sense. I was looking for the Init() in the
wrong parent - App.

<< What I would do is to "downsize" CalendarPanel to try to isolate
what is causing
the problem. I.e. comment out code that CalendarPanel is a simple
panel and then start
activating code you have in it and see when it starts to go wrong.>>

Sounds like a plan to me. Commenting/uncommenting the monster
CalendarPanel code until the AuiNotebook sizing is correct looks like
something I can do. If there is any example code showing a better way
to build the CalendarPanel, it would really be good too.

<< I am pretty sure (just a gut feel) it has to do with sizers and
either flags
not being set or somewhere in the sizer chain something which is not
allowed/defined to expand. >>

OK, I will pay attention to sizers and flags. Is this the wx.EXPAND|
wx.TOP, etc type flags you are talking about? I won't be surprised if
there was a problem with a sizer somewhere inside CalendarPanel. I
had a really tough time getting it to layout properly in the first
place - recall having to slap on commands like SetSize, SetClientSize,
SetBestSize(GetBestSize), etc to get it to work.

<< I understand, but I would try to resolve the sizing issue, and make
sure
that you parent things correctly. I.e. the notebook page parent (i.e.
pages have to be children of a notebook) issue is a potential cause of
this, or having a parent/sizer which you tell to manage something
which
is higher up in the hierarchy. >>

If the unhandled exception is caused by the notebook sizing issue, and
solving the sizing issue solves the unhandled exception, that would be
a really great bonus. The intermittent/inconsistent unhandled
exception is quite difficult to hunt down (for me). At least the
parenting/sizing problem is consistent.

Thanks again. I will update if I find anything. Let me know if there
are further clues/hints you can find/see.

Cheers
Sam

···

On Aug 5, 10:33 pm, wbruhin - free <wbru...@free.fr> wrote:

Sam23 wrote:
> Werner,
> Thanks for taking time to look at this. I have looked at the code
> samples you attached.

> (a) What does self.Init() do in the App class? i.e.
> class App(wx.App, InspectionMixin):
> def __init__(self, redirect=False, filename=None):
> wx.App.__init__(self, redirect, filename)
> self.controller = Controller(self)
> ----> self.Init()

That is for the InspectionMixin.> Is this different from the wx.App.__init__ method called?

> I haven't seen this before, and looking at the wx reference or
> googling didn't throw up any clues.

> (b) The InspectionMixin tool is great. Previously, I had resorted to
> commenting and uncommenting the "wx.lib.inspection.InspectionTool
> ().Show()" lines to get the Widget Inspector to show or not to show.
> Figuring out which control was which object in the Widget Inspector
> also required some work then.

Yes, this is really cool and very very helpful - especially when I look
at sizer issues.> (c) Yes, the notebook sizes correctly until the CalendarPanel objects
> are added as pages. I have tested this with TextControl before, as
> per the AuiNotebook wx examples. This is with the original VERTICAL
> SIZER used. AuiNotebook sizes fine until CalendarPanel is introduced.
> CalendarPanel also sizes fine in normal panels, i.e. only messes up
> Notebooks... So notebook sizes fine without CalendarPanel and
> CalendarPanel sizes fine without Notebook. But, I would like the 2 of
> them to work together, if possible. Don't know how to do this yet,
> except may to rewrite the entire CalendarPanel class to be simpler -
> in some way.

I'll try and have another look at this. What I would do is to "down
size" CalendarPanel to try to isolate what is causing the problem. I.e.
comment out code that CalendarPanel is a simple panel and then start
activating code you have in it and see when it starts to go wrong. I am
pretty sure (just a gut feel) it has to do with sizers and either flags
not being set or somewhere in the sizer chain something which is not
allowed/defined to expand.> (d) The 'unhandled exception' problem is a big concern. Maybe it has
> to do with my lack of understanding of what to do and what not to do
> in wxpython...

I understand, but I would try to resolve the sizing issue, and make sure
that you parent things correctly. I.e. the notebook page parent (i.e.
pages have to be children of a notebook) issue is a potential cause of
this, or having a parent/sizer which you tell to manage something which
is higher up in the hierarchy.

Werner

Sam23 wrote:

(c) Yes, the notebook sizes correctly until the CalendarPanel objects
are added as pages.

I've only taken a very quick look so far... Is the problem that the ApptGrid window is not filling the notebook page? If so then it's just because it's given a specific size of (300,300) and that the parent CalendarPanel does not have a sizer to manage the position and size of its child so it stays at (0,0) (300,300). The blue that you are seeing is inherited from the OuterPanel further up the containment hierarchy, it's *not* a manifestation of the notebook being laid out incorrectly. (Set the CalendarPanel's bg color to something else to verify that, or use the WIT's Highlight tool.)

(d) The 'unhandled exception' problem is a big concern. Maybe it has
to do with my lack of understanding of what to do and what not to do
in wxpython...

The problems may be related. For example, if you have a loop in the sizer containment then something may be being destroyed twice, which would cause a crash like you're seeing.

···

--
Robin Dunn
Software Craftsman

Sam23 wrote:

(b) The InspectionMixin tool is great. Previously, I had resorted to
commenting and uncommenting the "wx.lib.inspection.InspectionTool
().Show()" lines to get the Widget Inspector to show or not to show.
Figuring out which control was which object in the Widget Inspector
also required some work then.

Using the Find and the Highlight tools in the WIT can help you do that.

···

--
Robin Dunn
Software Craftsman

<<Is the problem that the ApptGrid window is not filling the notebook
page? >>
The ApptGrid actually seems to be overflowing the notebook page!
(further details below). The problem seems to be that the AuiNotebook
is not expanding to fill available space in the panel that contains it
(OuterPanel aka self.op). The AuiNotebook expands fine, if it doesn't
contain a CalendarPanel object. Once CalendarPanel is added to its
pages, AuiNotebook collapses to a tiny size of (96, 76).

<< If so then it's just because it's given a specific size of
(300,300) and that the parent
CalendarPanel does not have a sizer to manage the position and size of
its child so it stays at (0,0) (300,300).>>

The (300,300) is a size assigned to ApptGrid during in its __init__
method. ApptGrid is added to 'mainSizer' as follows:
        self.mainSizer = wx.GridBagSizer(hgap=0, vgap=0) (where self
        self.mainSizer.Add(self.apptGrid, pos=(0, 0), span=(1, 1),
flag=wx.ALL)

This seems to expand it correctly when there is no AuiNotebook
involved; i.e. it is directly added to OuterPanel (wx.Panel) without
AuiNotebook as its parent. I tried changing the default size setting
to (-1, -1) instead of (300, 300), but it didn't seem to make any
difference.

<< (Set the CalendarPanel's bg color to something else to verify that,
or use the WIT's Highlight tool.)>>

I set CalendarPanel bg colour to Yellow, and yellow fills the
AuiNotebook, which is tiny. The blue still fills most of the
containing panel.

The containment hierachy is as follows:
View (frame) >> OuterPanel (wx.Panel) >> self.nb (AuiNotebook) >>
CalendarPanel (wx.Panel) >> ApptGrid (wx.Panel)

I also tried the Highlight tool with interesting results:

When I highlight AuiNotebook, a small area is higlighted: (96, 76).
Ditto for CalendarPanel: (94, 49) - this fills available visible space
in AuiNotebook. But when I highlight ApptGrid, most of the available
windows is highlighted (i.e. fills available space in OuterPanel).
Widget inspector reports its size as (760, 385) i.e. its size is
bigger than its parent and grandparent.

Looking at the code and the hierarchy I just described, I suspect that
I may have messed up the sizers/parenting of these windows within
CalendarPanel. Ouch. I will take a closer look again.

<< The problems may be related. For example, if you have a loop in
the
sizer containment then something may be being destroyed twice, which
would cause a crash like you're seeing. >>

Is this sizer containment Destroy() loop something inside my python
code or is this c++ code? Should I be looking for Destroy() in my
python code?

If a loop always incorrectly destroys an item twice, should this
always cause a crash, or could it be intermittent? The exception is
intermittent even with the exact same sequence and data.

Thanks & cheers
Sam

···

On Aug 6, 12:54 am, Robin Dunn <ro...@alldunn.com> wrote:

Sam23 wrote:
> (b) The InspectionMixin tool is great. Previously, I had resorted to
> commenting and uncommenting the "wx.lib.inspection.InspectionTool
> ().Show()" lines to get the Widget Inspector to show or not to show.
> Figuring out which control was which object in the Widget Inspector
> also required some work then.

Using the Find and the Highlight tools in the WIT can help you do that.

--
Robin Dunn
Software Craftsmanhttp://wxPython.org

Figuring out which control was which object in the Widget Inspector
also required some work then.

<<<< Using the Find and the Highlight tools in the WIT can help you do
that. >>>>
Thanks heaps. That's a really useful tip. I was doing stupid things
like adding a property called name with some text value and then
looking for the text in the name property in objects of the same
class.

···

On Aug 6, 1:43 am, Sam23 <qm0...@gmail.com> wrote:

<<Is the problem that the ApptGrid window is not filling the notebook
page? >>
The ApptGrid actually seems to be overflowing the notebook page!
(further details below). The problem seems to be that the AuiNotebook
is not expanding to fill available space in the panel that contains it
(OuterPanel aka self.op). The AuiNotebook expands fine, if it doesn't
contain a CalendarPanel object. Once CalendarPanel is added to its
pages, AuiNotebook collapses to a tiny size of (96, 76).

<< If so then it's just because it's given a specific size of
(300,300) and that the parent
CalendarPanel does not have a sizer to manage the position and size of
its child so it stays at (0,0) (300,300).>>

The (300,300) is a size assigned to ApptGrid during in its __init__
method. ApptGrid is added to 'mainSizer' as follows:
self.mainSizer = wx.GridBagSizer(hgap=0, vgap=0) (where self
self.mainSizer.Add(self.apptGrid, pos=(0, 0), span=(1, 1),
flag=wx.ALL)

This seems to expand it correctly when there is no AuiNotebook
involved; i.e. it is directly added to OuterPanel (wx.Panel) without
AuiNotebook as its parent. I tried changing the default size setting
to (-1, -1) instead of (300, 300), but it didn't seem to make any
difference.

<< (Set the CalendarPanel's bg color to something else to verify that,
or use the WIT's Highlight tool.)>>

I set CalendarPanel bg colour to Yellow, and yellow fills the
AuiNotebook, which is tiny. The blue still fills most of the
containing panel.

The containment hierachy is as follows:
View (frame) >> OuterPanel (wx.Panel) >> self.nb (AuiNotebook) >>
CalendarPanel (wx.Panel) >> ApptGrid (wx.Panel)

I also tried the Highlight tool with interesting results:

When I highlight AuiNotebook, a small area is higlighted: (96, 76).
Ditto for CalendarPanel: (94, 49) - this fills available visible space
in AuiNotebook. But when I highlight ApptGrid, most of the available
windows is highlighted (i.e. fills available space in OuterPanel).
Widget inspector reports its size as (760, 385) i.e. its size is
bigger than its parent and grandparent.

Looking at the code and the hierarchy I just described, I suspect that
I may have messed up the sizers/parenting of these windows within
CalendarPanel. Ouch. I will take a closer look again.

<< The problems may be related. For example, if you have a loop in
the
sizer containment then something may be being destroyed twice, which
would cause a crash like you're seeing. >>

Is this sizer containment Destroy() loop something inside my python
code or is this c++ code? Should I be looking for Destroy() in my
python code?

If a loop always incorrectly destroys an item twice, should this
always cause a crash, or could it be intermittent? The exception is
intermittent even with the exact same sequence and data.

Thanks & cheers
Sam

On Aug 6, 12:54 am, Robin Dunn <ro...@alldunn.com> wrote:

> Sam23 wrote:
> > (b) The InspectionMixin tool is great. Previously, I had resorted to
> > commenting and uncommenting the "wx.lib.inspection.InspectionTool
> > ().Show()" lines to get the Widget Inspector to show or not to show.
> > Figuring out which control was which object in the Widget Inspector
> > also required some work then.

> Using the Find and the Highlight tools in the WIT can help you do that.

> --
> Robin Dunn
> Software Craftsmanhttp://wxPython.org

Sam,

Attached is a version of vAps.py which sizes fine for me.

Robin's tip on fixed sizes helped - basically got rid of all the hard coded sizing stuff I came across.

Now the crash is pretty predictable, it happens about every second or third move of the item "Giant Step" in the group 2.

I think it is in "ResetCalPanel" but I can't figure it out and I can't catch it with an try/except either.

Maybe instead of destroying/rebuilding all these things when you shift an entry it would be better to figure out a way to just move the existing item, i.e. remove it from the grid and reinsert it.

By the way the id's of ApptWindow instances are all "-n" - could it be a problem that they are not positive numbers?

Werner

vAps.py (30.8 KB)