views:

368

answers:

4

I'm learning wxPython so most of the libraries and classes are new to me.

I'm creating a Preferences dialog class but don't know the best way to make sure the OK/Cancel (or Save/Close) buttons are in the correct order for the platform. This program is intended to run both on GNOME and Windows, so I want to make sure that the buttons are in the correct order for each platform.

Does wxPython provide functionality that prevents me from doing a if platform.system() == 'Linux' kind of hack?

+4  A: 

The appearance of a dialog can change only if you use stock dialogs (like wx.FileDialog), if you make your own the layout will stay the same on every platform.

wx.Dialog has a CreateStdDialogButtonSizer method that creates a wx.StdDialogButtonSizer with standard buttons where you might see differences in layout on different platforms but you don't have to use that.

Toni Ruža
A: 

If you're going to use wx (or any other x-platform toolkit) you'd better trust that it does the right thing, mon!-)

Alex Martelli
A: 

There's the GenericMessageDialog widget that should do the right thing depending on the platform (but I've never used it so I'm not sure it does). See the wxPython demo.

You can also use the SizedControls addon library (it's part of wxPython). The SizedDialog class helps to create dialogs that conform to the Human Interface Guidelines of each platform. See the wxPython demo.

Frank Niessink
+1  A: 

You can use a StdDialogButtonSizer

http://www.wxpython.org/docs/api/wx.StdDialogButtonSizer-class.html

So long as your buttons have the standard IDs they will be put in the correct order.

Just to add a wrinkle though, on a Mac for instance, a preferences dialog would not have OK / Cancel buttons. It would automatically apply the preferences as they were entered (or at least on dialog close). So you'd still have to do some platform sniffing in that case.

Gareth Simpson