seeking advice in writing portable wx code

Hi,

   I am finding it pretty tough to adapt wxPython code to be platform
independent -- particularly in contrast to some of the other packages
I have used in the past. I am interested in advice on how to generate
simple and platform independent code. As an example of one current
frustration, the following code snippet works fine on Windows and Mac,
but is not pretty on Linux:

(Version A)
   def ElButton(self, name, pos, tip, color):
        El = wscs.ColourSelect(label=name, parent=self,
            pos=pos, size=wx.Size(24, 23),
            style=wx.RAISED_BORDER,colour=color)
        El.SetLabel(name)
        El.SetToolTipString(tip)
        El.Bind(wx.EVT_BUTTON, self.OnElButton)
(for screen dumps, see http://ftp.xor.aps.anl.gov/11bm/toby/A.fc10.png
http://ftp.xor.aps.anl.gov/11bm/toby/A.osx.png

While this version of code works fine on Windows and Linux, but is
useless on Mac:
(Version B)
    def ElButton(self, name, pos, tip, color):
        El = wx.Button(id=wx.ID_ANY, label=name, name=name,
parent=self,
            pos=pos, size=wx.Size(24, 23), style=0)
        El.SetBackgroundColour(color)
        El.SetFont(wx.Font(8, wx.SWISS, wx.NORMAL, wx.BOLD, False,
                           'Tahoma'))
        El.SetLabel(name)
        El.SetToolTipString(tip)
        El.Bind(wx.EVT_BUTTON, self.OnElButton)
(for screen dumps, see http://ftp.xor.aps.anl.gov/11bm/toby/B.fc10.png,
http://ftp.xor.aps.anl.gov/11bm/toby/B.osx.png
& http://ftp.xor.aps.anl.gov/11bm/toby/B.xp.png)

Are there better approaches to developing portable wxPython apps
without having to write code conditional by sys.platform?

Brian

Hi Brian,

It looks like you’re getting frustrated by the way OS X draws it’s standard buttons (more like a pill shape than the other platforms). I suggest you check out the wxPython demo on Mac OS X, it shows lots of different kinds of buttons you can use, including some that are square-shaped on all three platforms.

You may also want to consider not using wx.Button (or friends) and drawing the periodic table yourself.

-Mike

···

On Tue, Jun 16, 2009 at 12:33 PM, bht toby@anl.gov wrote:

Hi,

I am finding it pretty tough to adapt wxPython code to be platform

independent – particularly in contrast to some of the other packages

I have used in the past. I am interested in advice on how to generate

simple and platform independent code. As an example of one current

frustration, the following code snippet works fine on Windows and Mac,

but is not pretty on Linux:

(Version A)

def ElButton(self, name, pos, tip, color):

    El = wscs.ColourSelect(label=name, parent=self,

        pos=pos, size=wx.Size(24, 23),

        style=wx.RAISED_BORDER,colour=color)

    El.SetLabel(name)

    El.SetToolTipString(tip)

    El.Bind(wx.EVT_BUTTON, self.OnElButton)

(for screen dumps, see http://ftp.xor.aps.anl.gov/11bm/toby/A.fc10.png

http://ftp.xor.aps.anl.gov/11bm/toby/A.osx.png http://ftp.xor.aps.anl.gov/11bm/toby/A.osx.png)

While this version of code works fine on Windows and Linux, but is

useless on Mac:

(Version B)

def ElButton(self, name, pos, tip, color):

    El = wx.Button(id=wx.ID_ANY, label=name, name=name,

parent=self,

        pos=pos, size=wx.Size(24, 23), style=0)

    El.SetBackgroundColour(color)

    El.SetFont(wx.Font(8, wx.SWISS, wx.NORMAL, wx.BOLD, False,

                       'Tahoma'))

    El.SetLabel(name)

    El.SetToolTipString(tip)

    El.Bind(wx.EVT_BUTTON, self.OnElButton)

(for screen dumps, see http://ftp.xor.aps.anl.gov/11bm/toby/B.fc10.png,

http://ftp.xor.aps.anl.gov/11bm/toby/B.osx.png

& http://ftp.xor.aps.anl.gov/11bm/toby/B.xp.png)

Are there better approaches to developing portable wxPython apps

without having to write code conditional by sys.platform?

Brian

For what you’re doing, you need to use custom-drawn controls rather than the native widgets. I also looked into making a periodic table widget last year and concluded that wx.lib.buttons.GenButton was probably going to be the most compatible choice for this.

-Nat

···

On Tue, Jun 16, 2009 at 12:33 PM, bht toby@anl.gov wrote:

Hi,

I am finding it pretty tough to adapt wxPython code to be platform

independent – particularly in contrast to some of the other packages

I have used in the past. I am interested in advice on how to generate

simple and platform independent code. As an example of one current

frustration, the following code snippet works fine on Windows and Mac,

but is not pretty on Linux:

Are there better approaches to developing portable wxPython apps

without having to write code conditional by sys.platform?

bht wrote:


   Hi,
I am finding it pretty tough to adapt wxPython code to be platform
independent

don’t get me started!

-- particularly in contrast to some of the other packages
I have used in the past. I am interested in advice on how to generate
simple and platform independent code. As an example of one current
frustration, the following code snippet works fine on Windows and Mac,
but is not pretty on Linux:

I have also found the reverse to be true, things that look great on
Linux look like sh*t on windows.

Are there better approaches to developing portable wxPython apps
without having to write code conditional by sys.platform?

my code unfortunately is full of them. I have resorted to writing an
abstraction layer hiding the platform weirdness from the rest of my
code. :frowning:

In this case you seem to be having an issue with the native shapes of
buttons and the relative sizes of fonts. What you can try letting the
system size the stuff (version A) to match the size of the fonts. Let
your sizer do the hard work.

Paul

perzonae logo-tiny.JPG

···

wxPython-users@googlegroups.comwxPython-users+unsubscribe@googlegroups.comhttp://groups.google.com/group/wxPython-users?hl=en

perzonae sig



Paul
Sijben
tel:
+31 33 7114626

Perzonae
Unified Communications BV

mobile:
+31 646272086

Amersfoort,
the Netherlands

www.perzonae.com

bht wrote:
> Hi,

> I am finding it pretty tough to adapt wxPython code to be platform
> independent

don't get me started!> -- particularly in contrast to some of the other packages

I wrote a timesheet application a couple of years ago for Windows
users in our organization. It took me about half an hour to port it to
Linux. Unless you are doing a lot of low-level OS stuff, you shouldn't
need a lot of sys.platform conditionals...

You must be doing something complicated!

> I have used in the past. I am interested in advice on how to generate
> simple and platform independent code. As an example of one current
> frustration, the following code snippet works fine on Windows and Mac,
> but is not pretty on Linux:

I have also found the reverse to be true, things that look great on
Linux look like sh*t on windows.

Are you including the manifest? My applications look native on XP and
Vista. Admittedly, wx doesn't have the ribbon bar or certain
components of Windows Forms or WPF, but what it does have has worked
for my projects. What looks bad on yours?

I agree that conditionals can be annoying. I think Chris B. has
mentioned that too. I haven't used the other toolkits enough to know
if they work better in this regard, although I'm pretty sure Tkinter &
pyGTK will look as bland on Linux as it does on Windows.

- Mike

···

On Jun 17, 3:24 am, Paul Sijben <sij...@perzonae.com> wrote:

Mike Driscoll wrote:

don't get me started!>  -- particularly in contrast to some of the other packages

I wrote a timesheet application a couple of years ago for Windows
users in our organization. It took me about half an hour to port it to
Linux. Unless you are doing a lot of low-level OS stuff, you shouldn't
need a lot of sys.platform conditionals...
You must be doing something complicated!

well I found that resizing and redrawing behaves differently between
the platforms, so I had to kick that more for windows than for linux

windows statictext is not transparent, for linux it is, same with
bitmaps (and hence bitmapbuttons), so I ended up making replacements
for that

screen sizes are reported differently across the patforms

events on standard controls are slightly but significantly different
(e.g. listbox)

etc…

Are you including the manifest? My applications look native on XP and
Vista. Admittedly, wx doesn't have the ribbon bar or certain
components of Windows Forms or WPF, but what it does have has worked
for my projects. What looks bad on yours?

it has to do with layouting of things. Also in some cases linux.gtk is
more lenient in accepting things so they only break when I try the app
on windows

perzonae logo-tiny.JPG

···

sij...@perzonae.comwxPython-users@googlegroups.comwxPython-users+unsubscribe@googlegroups.comhttp://groups.google.com/group/wxPython-users?hl=en

perzonae sig



Paul
Sijben
tel:
+31 33 7114626

Perzonae
Unified Communications BV

mobile:
+31 646272086

Amersfoort,
the Netherlands

www.perzonae.com

Paul,

Mike Driscoll wrote:

>> don't get me started!> -- particularly in contrast to some of the other packages

> I wrote a timesheet application a couple of years ago for Windows
> users in our organization. It took me about half an hour to port it to
> Linux. Unless you are doing a lot of low-level OS stuff, you shouldn't
> need a lot of sys.platform conditionals...

> You must be doing something complicated!

well I found that resizing and redrawing behaves differently between the
platforms, so I had to kick that more for windows than for linux
windows statictext is not transparent, for linux it is, same with
bitmaps (and hence bitmapbuttons), so I ended up making replacements for
that
screen sizes are reported differently across the patforms
events on standard controls are slightly but significantly different
(e.g. listbox)

etc...

I see. I haven't created enough applications on Linux to see these
issues yet. I have heard that some native widgets on certain OSes have
more (or better) features than others.

I haven't read anything about events differing on platforms. That's
weird.

> Are you including the manifest? My applications look native on XP and
> Vista. Admittedly, wx doesn't have the ribbon bar or certain
> components of Windows Forms or WPF, but what it does have has worked
> for my projects. What looks bad on yours?

it has to do with layouting of things. Also in some cases linux.gtk is
more lenient in accepting things so they only break when I try the app
on windows

Thanks for sharing those tidbits. It's almost always good to know
something before you do it yourself.

- Mike

···

On Jun 17, 8:49 am, Paul Sijben <sij...@perzonae.com> wrote:

> On Jun 17, 3:24 am, Paul Sijben <sij...@perzonae.com> wrote:

Paul Sijben wrote:

well I found that resizing and redrawing behaves differently between the platforms, so I had to kick that more for windows than for linux
windows statictext is not transparent, for linux it is, same with bitmaps (and hence bitmapbuttons), so I ended up making replacements for that
screen sizes are reported differently across the patforms
events on standard controls are slightly but significantly different (e.g. listbox)

etc...

Differences like that are the cost of using native widgets on each platform. We will never be able to iron out all the platform differences while using native widgets, unless we cripple the toolkit and only offer a small subset of functionality. We can however iron out most of the bumps and differences, and make most things work most of the time.

it has to do with layouting of things. Also in some cases linux.gtk is more lenient in accepting things so they only break when I try the app on windows

One of the core developers once said something that I like to pull out for statements like this, it was something like, "It is much easier to ensure that properly written code behaves consistently and correctly on all platforms than is is to ensure that improperly written code misbehaves consistently and badly (if at all) on all platforms." In other words, just because it works on one platform does not mean it is correct.

···

--
Robin Dunn
Software Craftsman

Mike Driscoll wrote:

I haven't read anything about events differing on platforms. That's
weird.

Sometimes the sequence of events will be different, (sometimes even between different versions of Windows,) so if you have code that depends on a certain sequence then it can be a problem. Most of the time it doesn't matter.

···

--
Robin Dunn
Software Craftsman

There is this page on the wxPyWiki:
http://wiki.wxpython.org/wxPython%20Platform%20Inconsistencies

But I suspect it could use a nice update. Riffing off what Mike D
said above, and from my experience trying to get my stuff to work
well on Win and Linux, I think that as one tries something a little
out of the ordinary, that is when things can get difficult. I was doing

stuff with drawing on text over gradients, etc., and ran into problems
with Ubuntu’s font sizes (which also bit me in things like some
drop-downs).

Che

···

On Tue, Jun 16, 2009 at 3:33 PM, bht toby@anl.gov wrote:

Hi,

I am finding it pretty tough to adapt wxPython code to be platform

independent – particularly in contrast to some of the other packages

I have used in the past. I am interested in advice on how to generate

simple and platform independent code.