Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/jkz88/amsn2 into jkz88/master
Browse files Browse the repository at this point in the history
  • Loading branch information
drf committed Feb 28, 2009
2 parents ded759b + 3be51b9 commit 06465d5
Showing 1 changed file with 24 additions and 52 deletions.
76 changes: 24 additions & 52 deletions amsn2.py 100755 → 100644
Expand Up @@ -11,56 +11,29 @@
passwd = None passwd = None
default_front_end = "console" default_front_end = "console"


if os.name == "posix": # Detect graphical toolkit available.
system = os.uname()[0] # Format - 'default_front_end : module name'
if system == "Linux": # cocoa > efl > qt4 > gtk > console

toolkits = {'cocoa' : '????',
""" Here we are trying to import some base modules for the GUI 'elf' : 'ecore',
interfaces to get a working default frontend. EFL is the first one, 'qt4' : 'PyQt4.QtGui',
then come the others. 'gtk' : 'gtk',
'console' : None}
Suggestion/TODO: we can avoid OS detection through this method. for toolkit in toolkits:
I think it makes more sense creating a priority list, something like try:
that one: default_front_end = toolkit
module_name = toolkits[toolkit]
cocoa > efl > qt4 > gtk > console module = __import__(module_name)
vars()[module_name] = module
As you can imagine, the OS you're using no longer matters: IMHO # Debug
this list (except for qt & gtk, didn't know what to put first) is # print 'Imported toolkit "%s" with module "%s"' % (toolkit, module)
the right way to do it, since it tries to be as native as possible. break
There are some even better ways to do it, especially on gtk/qt side. except ImportError:
For example, we can use DBus to know what DE is running. # Debug
# print 'Couldn\'t import %s - doesn\'t exist!' % module_name
So, my thoughts on how to do it: pass
Try cocoa, try Efl. If both went bad, try to see if DBus is running. except TypeError:
If not, we're probably not on Linux, so give priority to Qt. If it is, pass
check for kded service or for a GNOME service and choose that toolkit.
When all else fails, console will be our friend.
This way we'll have the best default possible, and as you can see
from the first implementation, it's really easy to do.
"""

try:
import ecore
default_front_end = "efl"
except ImportError: # Efl not available
try:
import PyQt4.QtGui
default_front_end = "qt4"
except ImportError: # Qt not available
try:
import gtk
default_front_end = "gtk"
except ImportError: # GTK not available
print "No graphical toolkits detected, falling back to console..."
default_front_end = "console"

elif system == "Darwin":
default_front_end = "cocoa"
elif os.name == "nt":
default_front_end = "qt4"



parser = optparse.OptionParser() parser = optparse.OptionParser()
parser.add_option("-a", "--account", dest="account", parser.add_option("-a", "--account", dest="account",
Expand All @@ -75,5 +48,4 @@


amsn = aMSNCore(options) amsn = aMSNCore(options)


amsn.run() amsn.run()

0 comments on commit 06465d5

Please sign in to comment.