Hi all, because I was asking for it several times and didn't find anything here is a small applet for whatever WM, written in python/GTk.
It is *very*much* work in progress, mind that I have never before: - programed in python - programed an applet - used dbus/hal - programed pygtk But well, one afternoon, several examples from the web, and the plasma applet of Eva did help to get even the HAL interface-beast more or less tamed. Problems: - it does not work as applet at the moment, no idea why, maybe someone can help here - no configuration can be done - sometimes strange error messages because the hso device disappears slowly after disabling sony-wwan, and then HAL ships some errors Howto: Put the rfkill-applet.py somewhere, and call it python rfkill-applet.py -d do NOT forget the -d or it will not start. If you want to work on the applet thingy, you have to put the attached files as follows: /usr/bin/rfkill-applet.py /usr/lib/bonobo/servers/rfkill-applet.server and then restart your gnome session (kde?) and it should be possible to select the applet, but loading doesn't work If someone wants to help a bit that would be great!!! Best wishes Norbert ------------------------------------------------------------------------------- Dr. Norbert Preining <prein...@logic.at> Vienna University of Technology Debian Developer <prein...@debian.org> Debian TeX Group gpg DSA: 0x09C5B094 fp: 14DF 2E6C 0307 BE6D AD76 A9C0 D2BF 4AA3 09C5 B094 ------------------------------------------------------------------------------- Aaaargggh...' These two words are usually coupled together in the Old Pink Dog Bar. --- Ford in a spot of bother. --- Douglas Adams, The Hitchhikers Guide to the Galaxy
#!/usr/bin/env python # # rfkill-applet # (C) 2009 Norbert Preining # Licensed under GPLv3 or any version higher # import sys import os import dbus import pygtk pygtk.require('2.0') import gtk import gnomeapplet bus = dbus.SystemBus() hal_obj = bus.get_object("org.freedesktop.Hal", "/org/freedesktop/Hal/Manager") hal = dbus.Interface(hal_obj, "org.freedesktop.Hal.Manager") class Rfkill: def __init__(self, applet, iid): self.rfkill_devs = {} self.rfkill_devobjs = {} self.rfkill_names = {} self.rfkill_states = {} self.get_rfkills() self.get_rfstates() self.applet = applet self.tooltops = gtk.Tooltips() self.ebmain = gtk.EventBox() self.icon = gtk.Image() self.image = 'rfkill-applet.png' self.icon.set_from_file(self.image) self.ebmain.add(self.icon) self.applet.add(self.ebmain) self.ebmain.connect("button-press-event", self.click_menu) applet.connect("destroy", self.cleanup) self.menuxml=""" <popup name="button3"> <menuitem name="Item 1" verb="About" label="_About" pixtype="stock" pixname="gnome-stock-about"/> <menuitem name="Item 2" verb="Preferences" label="_Preferences" pixtype="stock" pixname="gtk-preferences"/> </popup> """ self.applet.setup_menu(self.menuxml, [ ("About",self.about_box), ("Preferences",self.prefs) ], None) applet.show_all() # self.load_prefs() def about_box(self, event, data=None): authors = ["Norbert Preining <preining at logic.at>"] about = gtk.AboutDialog() about.set_name("Rfkill Applet") about.set_version("0.1") about.set_copyright("(C) 2009 Norbert Preining") about.set_authors(authors) #about.set_website("http://gfreqlet.sf.net") #about.set_website_label("http://gfreqlet.sf.net") about.run() about.destroy() def prefs(self, event, data=None): print ("Not implemented") def click_menu(self, widget, event): if event.button == 1: popmenu = gtk.Menu() for uri in self.rfkill_names.keys(): menu_item = gtk.CheckMenuItem(label= self.rfkill_names[uri]) menu_item.set_active(self.rfkill_states[uri]) menu_item.show() menu_item.connect("toggled", self.toggle_rfkill, uri) popmenu.append(menu_item) popmenu.show() popmenu.popup(None, None, None, event.button, event.time) def toggle_rfkill (self, widget, uri): print "Toggling " + self.rfkill_names[uri] dev = dbus.Interface(self.rfkill_devobjs[uri], 'org.freedesktop.Hal.Device.KillSwitch') newval = not(self.rfkill_states[uri]) dev.SetPower(newval) self.get_rfkills() self.get_rfstates() def get_rfkills(self): self.rfkill_devobjs = {} self.rfkill_devs = {} self.rfkill_names = {} for udi in hal.FindDeviceByCapability ("killswitch"): dev_obj = bus.get_object('org.freedesktop.Hal', udi) dev = dbus.Interface(dev_obj, 'org.freedesktop.Hal.Device') if (dev.GetProperty('killswitch.type') != "unknown"): self.rfkill_devobjs[udi] = dev_obj self.rfkill_devs[udi] = dev self.rfkill_names[udi] = dev.GetProperty ('killswitch.name') def get_rfstates(self): for udi in self.rfkill_devs.keys(): if (int(self.rfkill_devs[udi].GetProperty('killswitch.state')) > 0): self.rfkill_states[udi] = True else: self.rfkill_states[udi] = False def cleanup(self, data): gtk.main_quit() sys.exit() def rfkill_factory(applet, iid): Rfkill(applet, iid) return True # if __name__ == '__main__': print('Starting factory') if len(sys.argv) > 1 and sys.argv[1] == '-d': main_window = gtk.Window(gtk.WINDOW_TOPLEVEL) main_window.set_title("Rfkill Applet") main_window.connect("destroy", gtk.main_quit) app = gnomeapplet.Applet() rfkill_factory(app, None) app.reparent(main_window) main_window.show_all() gtk.main() sys.exit() else: gnomeapplet.bonobo_factory("OAFIID:RkfillApplet_Factory", gnomeapplet.Applet.__gtype__, "RFKill Switch Applet", "0.1", rfkill_factory)
<oaf_info> <oaf_server iid="OAFIID:RfkillApplet_Factory" type="exe" location="/usr/bin/rfkill-applet.py"> <oaf_attribute name="repo_ids" type="stringv"> <item value="IDL:Bonobo/GenericFactory:1.0"/> <item value="IDL:Bonobo/Unknown:1.0"/> </oaf_attribute> <oaf_attribute name="name" type="string" value="rfkill switch applet"/> <oaf_attribute name="description" type="string" value="Controlling hardware via rfkill switches"/> </oaf_server> <oaf_server iid="OAFIID:RfkillApplet" type="factory" location="OAFIID:RfkillApplet_Factory"> <oaf_attribute name="repo_ids" type="stringv"> <item value="IDL:GNOME/Vertigo/PanelAppletShell:1.0"/> <item value="IDL:Bonobo/Control:1.0"/> <item value="IDL:Bonobo/Unknown:1.0"/> </oaf_attribute> <oaf_attribute name="name" type="string" value="rfkill switch applet"/> <oaf_attribute name="description" type="string" value="Controlling hardware via rfkill switches"/> <oaf_attribute name="panel:category" type="string" value="Utility"/> <oaf_attribute name="panel:icon" type="string" value="rfkill-applet.png"/> </oaf_server> </oaf_info>
_______________________________________________ Mailing list: https://launchpad.net/~sony-vaio-z-series Post to : sony-vaio-z-series@lists.launchpad.net Unsubscribe : https://launchpad.net/~sony-vaio-z-series More help : https://help.launchpad.net/ListHelp