Snippets
From Woofgui
(Difference between revisions)
Line 48: | Line 48: | ||
- | ==test | + | ==test for desktop-environment== |
#!/usr/bin/env python | #!/usr/bin/env python | ||
- | + | import os | |
- | import | + | |
- | + | # Returns 'gnome' or 'kde' or ... | |
- | + | desktoptype = os.environ.get('DESKTOP_SESSION') | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
- | + | ||
Line 74: | Line 68: | ||
dlg.Destroy() | dlg.Destroy() | ||
print "you have entered %s" % val | print "you have entered %s" % val | ||
+ | |||
+ | ==OLD: test if kde or gnome== | ||
+ | |||
+ | #!/usr/bin/env python | ||
+ | |||
+ | import subprocess as data | ||
+ | |||
+ | p1 = data.Popen(["ps", "-e"], stdout = data.PIPE) | ||
+ | p2 = data.Popen(["grep", "kdesktop"], stdin = p1.stdout, stdout = data.PIPE) | ||
+ | |||
+ | if p2.stdout.read() != '': | ||
+ | print 'kde' | ||
+ | else: | ||
+ | print 'gnome' |
Revision as of 12:58, 15 March 2009
Contents |
create notify-bubble using dbus
#!/usr/bin/env python import dbus import sys # Use session bus session_bus = dbus.SessionBus() # Use notifications object notifications_object = session_bus.get_object('org.freedesktop.Notifications', '/org/freedesktop/Notifications') notifications_interface = dbus.Interface(notifications_object, 'org.freedesktop.Notifications') # Sample notification notification_id = notifications_interface.Notify(sys.argv[0], 0, , 'Sample summary', 'Sample body', dbus.Array([], signature='s'), dbus.Array([], signature='(sv)'), -1) # Sample notification with actions and hints notification_id = notifications_interface.Notify(sys.argv[0], 0, , 'Sample summary', 'Sample body', ['sample', 'Sample action'], {'x': 100, 'y': 100}, -1)
create icon in systray with notification-bubble using pynotify
#!/usr/bin/env python import gtk import pygtk import pynotify def callback(icon): notification.show() pynotify.init("Woofgui") notification = pynotify.Notification("Title", "Text in body", "dialog-warning") # the dialog-warning specifies icon type notification.set_urgency(pynotify.URGENCY_NORMAL) notification.set_timeout(pynotify.EXPIRES_DEFAULT) # _NEVER sets timeout to never, user has to click icon = gtk.status_icon_new_from_stock(gtk.STOCK_ABOUT) icon.connect('activate', callback) notification.attach_to_status_icon(icon) gtk.main()
test for desktop-environment
#!/usr/bin/env python import os
# Returns 'gnome' or 'kde' or ... desktoptype = os.environ.get('DESKTOP_SESSION')
example wxpython textentry
#!/usr/bin/env python import wx app = wx.PySimpleApp() dlg = wx.TextEntryDialog(None, 'Enter value', 'Title', ) if dlg.ShowModal() == wx.ID_OK: val = dlg.GetValue() # this line should be indented dlg.Destroy() print "you have entered %s" % val
OLD: test if kde or gnome
#!/usr/bin/env python import subprocess as data p1 = data.Popen(["ps", "-e"], stdout = data.PIPE) p2 = data.Popen(["grep", "kdesktop"], stdin = p1.stdout, stdout = data.PIPE) if p2.stdout.read() != : print 'kde' else: print 'gnome'