What is the current recommendation for import syntax?

I've been looking at lots of examples, and writing lots of code,
to get my head around wxPython, wxWindows, and Python in
general.

Now I'm wondering, what is the preferred way to import
wxPython?:

import wx
from wxPython.wx import *

Are there benefits/disadvantages to either? Is one of these ways
deprecated? I've noticed most examples use the second method,
but I've taken a liking to the first method myself, as it
doesn't fill up my global namespace.

Thanks

···

--
Paul

I have a bit of a problem. I think it all has to do how i'm creating the
frame itself, but here it goes.

I have this function

  def updateStatus(self, fractionDone=None, timeEst=None, downRate=None,
upRate=None, activity=None, statistics=None, spew=None, sizeDone=None,
**kws):
    if upRate is not None:
      self.upSpeedTextCh.SetLabel('%.0f kB/s' % (float(upRate) / 1000))
      #self.upSpeedTextCh.Refresh()
    if downRate is not None:
      self.downSpeedTextCh.SetLabel('%.0f kB/s' % (float(downRate) / 1000))
      self.downSpeedTextCh.Refresh()

When it calls self.downSpeedTextCh.Refresh() which is a text table I get this

Traceback (most recent call last):
  File "main.py", line 134, in Notify
    self.SetStatusText(st, 1)
  File "/usr/lib/python2.3/site-packages/wxPython/frames.py", line 114, in
SetStatusText
    val = framesc.wxFrame_SetStatusText(self, *_args, **_kwargs)
wxPython.wxc.wxPyAssertionError: C++ assertion "wxTheApp->m_idleTag == 0"
failed in ../src/gtk/app.cpp(374): attempt to install idle handler twice

If you want to look at the class its at

http://homer.meso.com/crap/torrentFrame.py

Thanks
Mike

Paul McNett wrote:

I've been looking at lots of examples, and writing lots of code, to get my head around wxPython, wxWindows, and Python in general.

Now I'm wondering, what is the preferred way to import wxPython?:

import wx
from wxPython.wx import *

Are there benefits/disadvantages to either? Is one of these ways deprecated? I've noticed most examples use the second method, but I've taken a liking to the first method myself, as it doesn't fill up my global namespace.

We are in the process of transitioning from the second to the first. In 2.4 the real classes are in the wxPython package and the wx package has a set of dynamic renamer modules that imports from wxPython and fixes the names. So there is a tiny bit of additional startup overhead.

In 2.5 the real classes are in the wx package with their names already renamed and the wxPython package has the (reverse) renamers.

···

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

mike@zcentric.com wrote:

I have a bit of a problem. I think it all has to do how i'm creating the
frame itself, but here it goes.

I have this function

  def updateStatus(self, fractionDone=None, timeEst=None, downRate=None,
upRate=None, activity=None, statistics=None, spew=None, sizeDone=None,
**kws):
    if upRate is not None:
      self.upSpeedTextCh.SetLabel('%.0f kB/s' % (float(upRate) / 1000))
      #self.upSpeedTextCh.Refresh()
    if downRate is not None:
      self.downSpeedTextCh.SetLabel('%.0f kB/s' % (float(downRate) / 1000))
      self.downSpeedTextCh.Refresh()

When it calls self.downSpeedTextCh.Refresh() which is a text table I get this

Traceback (most recent call last):
  File "main.py", line 134, in Notify
    self.SetStatusText(st, 1)
  File "/usr/lib/python2.3/site-packages/wxPython/frames.py", line 114, in
SetStatusText
    val = framesc.wxFrame_SetStatusText(self, *_args, **_kwargs)
wxPython.wxc.wxPyAssertionError: C++ assertion "wxTheApp->m_idleTag == 0"
failed in ../src/gtk/app.cpp(374): attempt to install idle handler twice

Could it be called from another thread? If so, don't.

···

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

I've tried to refresh the main frame too and it doesn't work either. i
don't understand why i can't refresh a label inside a class that's not the
main class

···

mike@zcentric.com wrote:

I have a bit of a problem. I think it all has to do how i'm creating
the frame itself, but here it goes.

I have this function

  def updateStatus(self, fractionDone=None, timeEst=None,
downRate=None,
upRate=None, activity=None, statistics=None, spew=None, sizeDone=None,
**kws):
    if upRate is not None:
      self.upSpeedTextCh.SetLabel('%.0f kB/s' % (float(upRate) / 1000))
#self.upSpeedTextCh.Refresh()
    if downRate is not None:
      self.downSpeedTextCh.SetLabel('%.0f kB/s' % (float(downRate) /
1000)) self.downSpeedTextCh.Refresh()

When it calls self.downSpeedTextCh.Refresh() which is a text table I
get this

Traceback (most recent call last):
  File "main.py", line 134, in Notify
    self.SetStatusText(st, 1)
  File "/usr/lib/python2.3/site-packages/wxPython/frames.py", line
114, in
SetStatusText
    val = framesc.wxFrame_SetStatusText(self, *_args, **_kwargs)
wxPython.wxc.wxPyAssertionError: C++ assertion "wxTheApp->m_idleTag ==
0" failed in ../src/gtk/app.cpp(374): attempt to install idle handler
twice

Could it be called from another thread? If so, don't.

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

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

mike@zcentric.com wrote:

I've tried to refresh the main frame too and it doesn't work either. i
don't understand why i can't refresh a label inside a class that's not the
main class

I don't think that the classes are the problem, but that you are trying to do GUI stuff from the non-gui thread.

···

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