Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I deal with multiple common user interfaces?

I'm working on a python application that runs on 2 different platforms, namely regular desktop linux and Maemo 4. We use PyGTK on both platforms but on Maemo there are a bunch of little tweaks to make it look nice which are implemented as follows:

if util.platform.MAEMO:
    # do something fancy for maemo
else:
    # regular pygtk

There are roughly 15 of these if statements needed to get the UI looking and working nice on Maemo 4.

This has been very manageable for all this time. The problem is that a while ago there was a new version of Maemo released (5, aka fremantle) and it has some big differences compared to Maemo 4. I don't want to add a bunch of checks throughout the GUI code in order to get all 3 platforms working nicely with the same codebase because that would get messy. I also don't want to create a copy of the original GUI code for each platform and simply modify it for the specific platform (I'd like to re-use as much code as possible).

So, what are ways to have slightly different UIs for different platforms which are based on the same core UI code? I don't think this is a python or Maemo-specific question, I'd just like to know how this is done.

like image 275
nikosapi Avatar asked Jan 07 '10 18:01

nikosapi


1 Answers

You could wind up much of this in a factory:

def createSpec():
  if util.platform.MAEMO: return Maemo4Spec()
  elif util.platform.MAEMO5: return Maemo5Spec()
  return StandardPyGTKSpec()

Then, somewhere early in your code, you just call that factory:

 spec = createSpec()

Now, everywhere else you had conditions, you just call the necessary function:

 spec.drawComboBox()

As long as drawComboBox(), handles anything specific to the platform, you should be in good shape.

like image 126
Kaleb Pederson Avatar answered Sep 27 '22 22:09

Kaleb Pederson