[wxPython-users] Re: xrc and wxStatusBar probs

Josiah Carlson jcarlson at uci.edu
Sun Jun 18 12:02:10 PDT 2006


Marc Risney <marc.stuart.risney at gmail.com> wrote:
> I tried to create the status Bar in my code, but the layout is all 
> wrong, from my experience it is hard to work, using xrc, and then do 
> something in traditional python. I understand the value of working in a 
> MVC type pattern with .xrc, but this somewhat frustrating.

I find that not using MVC is easier to get right, though layout with XRC
seems quite convenient, though I've never used it in any kind of
production code.


> On a tangent, I work predominately in J2EE, and every once in a while I 
> wander back to doing something in python, and now my experience with 
> wxPython leads me to think that the community around python, and 
> wxPython, is not the same as the J2EE community.

Why is that?  About one hour after you posted your initial question,
someone who I don't believe posted before today attempted to answer your
question in quite a reasonable manner, and was able to offer some
potential insight as to why you were running into your particular
problem. Robin hasn't jumped at answering, but maybe he's out for the
day.


> Java server Faces, 
> Jakarta Commons, the myriad of J2EE containers (Jetty, Orion, Tomcat, 
> etc.) when there is an issue about an incomplete library, there is a 
> rush to make it available, Python users and maybe wxPython seems a 
> little more leisure in their approach, ok rant over.

There are 3 separate groups of modules here:
1. the Python standard library
2. arbitrary 3rd party Python modules
3. wxPython

The Python standard library generally has a somewhat high barrier of
entry because they don't want to start including large numbers of
modules, as such could get both unmaintainable and bloat the < 10 meg
default binary distribution.  If a feature is shown to be a nontrivial
advancement in a pre-existing module, which also fits the future
direction that the module is going, then it is generally added.

How arbitrary 3rd party module/package developers handle the
incompleteness of their library is beyond the scope of this conversation. 
If you have complaints about some other bit of free Python software, you
should address your concerns to them.

And now wxPython.  Any time I have found wxPython to be lacking in any
particular feature (it has happened once in my memory), I posted to this
list, and Robin made it available literally in the next release.

Now, in regards to your current problem using a status bar, real code
isn't that terribly difficult.  If you want two text fields:

    self.frame.statusbar = wx.StatusBar(self.frame)
    self.frame.statusbar.SetFieldsCount(2)
    #use -x for auto-sized with proportion,
    #positive values for absolute sizes
    self.frame.statusbar.SetFieldsWidth([-1, 100])

If you want to use arbitrary controls in the status bar, you need to do
a bit more work, but it isn't that terribly bad (the below borrowed from
the wxPython demo and made generic)...

class ResizeInStatusBar:
    def __init__(self, statusbar, control, position):
        self.sb = statusbar
        self.ctrl = control
        self.posn = position
        self.sb.Bind(wx.EVT_SIZE, self.OnSize)
        self.sb.Bind(wx.EVT_IDLE, self.OnIdle)
        self.sizeChanged = False
        self.Reposition()

    def OnSize(self, evt):
        self.Reposition()
        self.sizeChanged = True
        evt.Skip()

    def OnIdle(self, evt):
        if self.sizeChanged:
            self.Reposition()

    def Reposition(self):
        rect = self.sb.GetFieldRect(self.posn)
        self.ctrl.SetPosition((rect.x+2, rect.y+2))
        self.ctrl.SetSize((rect.width-4, rect.height-4))
        self.sizeChanged = False

And is used by...

    statusbar = wx.StatusBar(...)
    statusbar.SetFieldsCount(...)
    ctrl = ...
    ResizeInStatusBar(statusbar, ctrl, POSN)


> where is the Link to the current wxPython that can fix this, I 
> downloaded the wxPython package from sourceforge (2.6.3), I assumed that 
> this was the latest build, where are the (newer) binaries that will 
> resolve this issue?

All of the latest wxPython binaries are linked from wxpython.org .  To
help us further attempt to diagnose your problem, what platform and
version of Python are you using?

 - Josiah





More information about the wxpython-users mailing list