Copy Source | Copy HTML<br/> #!/usr/bin/env python <br/> <br/> import pygtk<br/> import sys<br/>pygtk.require( '2.0' )<br/> <br/> import gnomeapplet<br/> import gtk<br/> <br/> def factory (applet, iid):<br/> button = gtk.Button()<br/> button.set_relief(gtk.RELIEF_NONE)<br/> button.set_label( "Simple Button" )<br/> button.connect( "button_press_event" , showMenu , applet)<br/> applet.add(button)<br/> applet.show_all()<br/> return True<br/> <br/> def showMenu (widget, event, applet):<br/> if event.type == gtk.gdk.BUTTON_PRESS and event.button == 3 :<br/> widget.emit_stop_by_name( "button_press_event" )<br/> create_menu (applet)<br/> <br/> def create_menu (applet):<br/> propxml= """ <br/> <popup name="button3"> <br/> <menuitem name="Item 3" verb="About" label="_About" pixtype="stock" pixname="gtk-about"/> <br/> </popup>""" <br/> verbs = [( "About" , showAboutDialog )]<br/> applet.setup_menu(propxml, verbs, None)<br/> <br/> def showAboutDialog (*arguments, **keywords):<br/> pass <br/> <br/> if len ( sys .argv) == 2 :<br/> if sys .argv[ 1 ] == "run-in-window" :<br/> mainWindow = gtk.Window(gtk.WINDOW_TOPLEVEL)<br/> mainWindow.set_title( "Ubuntu System Panel" )<br/> mainWindow.connect( "destroy" , gtk.main_quit)<br/> applet = gnomeapplet.Applet()<br/> factory (applet, None)<br/> applet.reparent(mainWindow)<br/> mainWindow.show_all()<br/> gtk.main()<br/> sys .exit()<br/> <br/> if __name__ == '__main__' :<br/> print "Starting factory" <br/> gnomeapplet.bonobo_factory( "OAFIID:Gnome_Panel_Example_Factory" , gnomeapplet.Applet.__gtype__, "Simple gnome applet example" , "1.0" , factory )<br/> <br/>
Now for the meta-information of our applet. Create a file with the .server extension and name it SimpleApplet.server. This file will contain in XML format the description of the meta-information of our applet (the displayed icon, the path to the executable .py file, etc.) For different applets, the main framework .server remains unchanged. SimpleApplet.server:Copy Source | Copy HTML<br/> < oaf_info > <br/> < oaf_server iid ="OAFIID:Gnome_Panel_Example_Factory" type ="exe" location ="/home/SimpleApplet.py"> <br/> < oaf_attribute name ="repo_ids" type ="stringv"> <br/> < item value ="IDL:Bonobo/GenericFactory:1.0"/> <br/> < item value ="IDL:Bonobo/Unknown:1.0"/> <br/> </ oaf_attribute > <br/> < oaf_attribute name ="name" type ="string" value ="Gnome Applet Example"/> <br/> < oaf_attribute name ="description" type ="string" value ="Simple gnome applet example"/> <br/> </ oaf_server > <br/> < oaf_server iid ="OAFIID:Gnome_Panel_Example" type ="factory" location ="OAFIID:Gnome_Panel_Example_Factory"> <br/> < oaf_attribute name ="repo_ids" type ="stringv"> <br/> < item value ="IDL:GNOME/Vertigo/PanelAppletShell:1.0"/> <br/> < item value ="IDL:Bonobo/Control:1.0"/> <br/> < item value ="IDL:Bonobo/Unknown:1.0"/> <br/> </ oaf_attribute > <br/> < oaf_attribute name ="name" type ="string" value ="Example"/> <br/> < oaf_attribute name ="description" type ="string" value ="Simple gnome applet example"/> <br/> < oaf_attribute name ="panel:category" type ="string" value ="Utility"/> <br/> < oaf_attribute name ="panel:icon" type ="string" value ="computer.png"/> <br/> </ oaf_server > <br/> </ oaf_info > <br/>
Here in princep and all. Our applet is ready, it does not know how to do anything, but its development gives a general idea of applets. To add our applet to the panel, do the following: - Move the SimpleApplet.server file to the / usr / lib / bonobo / servers / directory - Make the SimpleApplet.py file executable: chmod + x SimpleApplet.py - Add the applet to the panel using The standard context menu of the panel. The result should be an applet in the Gnome panel that looks like this: Source: https://habr.com/ru/post/73973/
All Articles