Strategies for avoiding wx.PyNoAppError?

[snip]

I might be wrong BUT to me that kind of error is directly connected to globals, I've had my share of wx.PyNoAppError but once I joined the "globals are evil" group... they vanished, I cannot remember seeing the error in the last year... :slight_smile:

can we have SVN access to the source code? if yes, what is the link?

if you're still keen on having those constants global I guess you could also push them there using __builtin__.

Peter

路路路

On Tue, 19 Jul 2005 22:33:46 +0300, Brandon DuRette <bdurette@enthought.com> wrote:

At Enthought, we have developed a tool stack that has dependencies on wxPython. We are currently running under wxPython 2.4.1.2, but desperately want to migrate to 2.6.1.0 and are finally getting the opportunity to do the migration. However, the App initialization requirement is giving us some fits -- not in the sense that we can't find a workaround, but in the sense that we have not yet come up with a workaround that we particularly like. Let me give you a brief background of our tool stack and pose the following questions: Has anyone else run into issues with App initialization? If so, have you come up with a solution you think is elegant? Among the various alternative workarounds, are there specific pros/cons which led you to one solution or another?

Martin Chilvers wrote:

class Frobnicator(HasTraits):
    # Background color.
    background_color = Color

...then the undelying code for 'Color' tries to declare a default value that is a 'wx.Color' instance, and this is now at module load time not instance creation time.

I'm confused why you can't enforce a programming style that puts something like:

import wx
if __name__ == "__main__":
  Don't import anything until you do this:
  TheApp = MyWxApp(whatever you need)
  # now do everything else

i.e. it's a requirement of some of your modules that a wx.App be created before they are imported. You have to create a wx.App at some point, why not have it be the first thing done?

When this change was made, a number of folks had problems because they were doing a bunch of configuration, then creating the App with that configuration info. The alternative is to do very little in the MyWxApp.__init__, then have a MyWxApp.Setup() method that gets called after the various configuration is done.

Heck if you wanted to, you could even create your own wrapper around the wx package that enforced that there was always an App after importing it.

# file MyWx.py

import wx
if not wx.GetApp():
     # there has not yet been an app created.
     TheApp = wx.PySimpleApp() # or a custom wx.App object

-Chris