Hi guys, I am trying to write a simple applet for mate that displays the output of a configurable command. For this purpose I'm trying to create a "hello world" applet which just displays a label. I have run into trouble and can't progress, hopefully someone can tell me what I need to do.
I am having two problems: 1) I don't know how to restart the matecomponent server. This is on Ubuntu 12.04. It's a bit impractical to reboot every time I change something in the .server file 2) The status of the code in itself is that the .server gets recognized - an entry is shown in the "add to panel" dialog - however, if I double-click it then I get a dialog saying "The panel encountered a problem while loading "OAFIID:ExampleApplet". Do you want to delete the applet from your configuration?" - I have no idea how to progress from that. In addition to a C applet I also tried a python applet and it shows the same behaviour. Below I include C source for the program and a .server file. The .server file is placed under /usr/lib/matecomponent/servers/ and the binary file is placed in the path mentioned in the .server file. Things I have tried already are: - going through mate bug reports - reading the original gnome docs and adjusting for the differences in APIs: http://projects.gnome.org/ORBit2/appletstutorial.html - going through the mate-applets source (haven't found anything I wouldn't be doing otherwise). - the "gtk object introspection" approach, in python, used by newer gnome applets. I've found some code that shows an icon, but I have been unable to display a label - the mateapplet module, to no success. I butchered some hindi-learning applet originally written for gnomeapplet. The code style still sucks, but it's correct and apparently it has worked at some point. I include source listings at the very end. - going through this mailing list of course - vigorously googling and asking for advice on IRC for about 20 hours now I did notice that this guy uses an ini style format rather than xml for his applet factory definition; and tha he also registers a d-bus service of some sort. Do I have to do this as well? http://sourceforge.net/mailarchive/message.php?msg_id=29485938 In specific see src/org.mate.* If we can work it out I'll make sure to write a blog post describing the correct way to do this.. it's been a wild ride so far and hopefully it can spare others a lot of trouble in the future. Thanks $ cat compile.sh gcc -o my_applet my_applet.c $(pkg-config --cflags --libs libmatepanelapplet-3.0 glib-2.0 gtk+-2.0 gobject-2.0) $ cat my_applet.c #include <string.h> #include <mate-panel-applet.h> #include <gtk-2.0/gtk/gtklabel.h> static gboolean myexample_applet_fill (MatePanelApplet *applet, const gchar *iid, gpointer data) { GtkWidget *label; //if (strcmp (iid, "OAFIID:ExampleApplet") != 0) // return FALSE; label = gtk_label_new ("Hello World"); gtk_container_add (GTK_CONTAINER (applet), label); //gtk_widget_show_all (GTK_WIDGET (applet)); gtk_widget_show (GTK_WIDGET (applet)); return TRUE; } // MATE_PANEL_APPLET_OUT_PROCESS_FACTORY ("OAFIID:ExampleApplet_Factory", PANEL_TYPE_APPLET, "The Hello World Applet", (MatePanelAppletFactoryCallback) myexample_applet_fill, NULL); MATE_PANEL_APPLET_OUT_PROCESS_FACTORY ("ExampleApplet_Factory", PANEL_TYPE_APPLET, "The Hello World Applet", (MatePanelAppletFactoryCallback) myexample_applet_fill, NULL); $ cat ExampleApplet_Factory.server <oaf_info> <oaf_server iid="OAFIID:ExampleApplet_Factory" type="exe" location="/usr/lib/gnome-panel/my_applet"> <oaf_attribute name="repo_ids" type="stringv"> <item value="IDL:MateComponent/GenericFactory:1.0"/> <item value="IDL:MateComponent/Unknown:1.0"/> </oaf_attribute> <oaf_attribute name="name" type="string" _value="Invest"/> <oaf_attribute name="description" type="string" _value="Track your invested money."/> </oaf_server> <!-- gtik was replaced by invest-applet, transparently upgrade the user --> <oaf_server iid="OAFIID:ExampleApplet" type="factory" location="OAFIID:ExampleApplet_Factory"> <oaf_attribute name="repo_ids" type="stringv"> <item value="IDL:MATE/Vertigo/MatePanelAppletShell:1.0"/> <item value="IDL:MateComponent/Control:1.0"/> <item value="IDL:MateComponent/Unknown:1.0"/> </oaf_attribute> <oaf_attribute name="name" type="string" value="Example Applet"/> <oaf_attribute name="description" type="string" value="Example Description"/> <oaf_attribute name="panel:category" type="string" value="Accessories"/> <oaf_attribute name="panel:icon" type="string" value="mate-invest-applet"/> </oaf_server> </oaf_info> $ cat /etc/issue Ubuntu 12.04.1 LTS \n \l $ uname -a Linux SX20S 3.5.0-18-generic #29~precise1-Ubuntu SMP Mon Oct 22 16:32:29 UTC 2012 i686 i686 i386 GNU/Linux $ cat hindi #!/usr/bin/env python import pygtk pygtk.require('2.0') import gtk import mateapplet import gobject import sys class HindiScroller(mateapplet.Applet): #Reads a utf-8 file, reads all lines and returns them as a list with newlines stripped #Picks a random word from the list. If its empty, it starts with original list again. def getNextWord(self): return "hello applet" #Displays the next word to GUI. Uses set_markup to use HTML def displayNextWord(self): wordToShow = self.getNextWord() self.label.set_markup(wordToShow) return True def __init__(self,applet,iid): self.timeout_interval = 1000 * 10 #Timeout set to 10secs self.applet = applet #File used as source expects each line in english|hindi format self.wordsToShow = [] wordToShow = self.getNextWord() self.label = gtk.Label("") self.label.set_markup(wordToShow) self.applet.add(self.label) self.applet.show_all() gobject.timeout_add(self.timeout_interval, self.displayNextWord) #Register the applet datatype gobject.type_register(HindiScroller) def hindi_scroller_factory(applet,iid): HindiScroller(applet,iid) return gtk.TRUE #Very useful if I want to debug. To run in debug mode python hindiScroller.py -d if len(sys.argv) == 2: if sys.argv[1] == "-d": #Debug mode main_window = gtk.Window(gtk.WINDOW_TOPLEVEL) main_window.set_title("Python Applet") main_window.connect("destroy", gtk.main_quit) app = mateapplet.Applet() hindi_scroller_factory(app,None) app.reparent(main_window) main_window.show_all() gtk.main() sys.exit() #If called via gnome panel, run it in the proper way if __name__ == '__main__': mateapplet.matecomponent_factory("OAFIID:GNOME_HindiScroller_Factory", HindiScroller.__gtype__, "hello", "0", hindi_scroller_factory) $ cat ExampleApplet2_Factory.server <oaf_info> <oaf_server iid="OAFIID:ExampleApplet2_Factory" type="exe" location="/usr/local/bin/hindi"> <oaf_attribute name="repo_ids" type="stringv"> <item value="IDL:MateComponent/GenericFactory:1.0"/> <item value="IDL:MateComponent/Unknown:1.0"/> </oaf_attribute> <oaf_attribute name="name" type="string" _value="Invest"/> <oaf_attribute name="description" type="string" _value="Track your invested money."/> </oaf_server> <!-- gtik was replaced by invest-applet, transparently upgrade the user --> <oaf_server iid="OAFIID:ExampleApplet2" type="factory" location="OAFIID:ExampleApplet2_Factory"> <oaf_attribute name="repo_ids" type="stringv"> <item value="IDL:MATE/Vertigo/MatePanelAppletShell:1.0"/> <item value="IDL:MateComponent/Control:1.0"/> <item value="IDL:MateComponent/Unknown:1.0"/> </oaf_attribute> <oaf_attribute name="name" type="string" value="Example Applet2"/> <oaf_attribute name="description" type="string" value="Example Description2"/> <oaf_attribute name="panel:category" type="string" value="Accessories"/> <oaf_attribute name="panel:icon" type="string" value="mate-invest-applet"/> </oaf_server> </oaf_info> ------------------------------------------------------------------------------ Everyone hates slow websites. So do we. Make your web apps faster with AppDynamics Download AppDynamics Lite for free today: http://p.sf.net/sfu/appdyn_d2d_nov _______________________________________________ Matede-velopment mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/matede-velopment
