Page 1 of 1

Applet programming

Posted: Sun Dec 05, 2010 3:34 pm
by hanoii
Is there any docs or pointers into lxde applet programming?

I searched but couldn't find anything.

Also, what I am interested in doing is something rather simple. I liked the kde clock where I can choose other timezones to display on mouseover on the clock (I work with other countries and I find useful to quickly check the time on other places) and I was tempted on either writing a new clock applet myself or even contributing to the ones that's currently there.

Any suggestions on this will be as appreciated as well.

Thanks,
a.=

Re: Applet programming

Posted: Sat Dec 18, 2010 6:51 pm
by percival
LXDE uses the gtk applet framework, the same that gnome uses. This is why many gnome applets work in LXDE. There are some tutorials for this out there.

The clock applet is one of the core lxpanel applets, so it can be found in the lxpanel source. I believe the gnome clock has a similar feature to this, there's a location choice bar under the calendar that pops up when you click on it. You might want to check out the gnome-panel source for some inspiration.

Re: Applet programming

Posted: Sat Dec 18, 2010 7:38 pm
by Marty Jack
percival wrote:LXDE uses the gtk applet framework, the same that gnome uses. This is why many gnome applets work in LXDE. There are some tutorials for this out there.

The clock applet is one of the core lxpanel applets, so it can be found in the lxpanel source. I believe the gnome clock has a similar feature to this, there's a location choice bar under the calendar that pops up when you click on it. You might want to check out the gnome-panel source for some inspiration.
So no one is confused, this answer is completely incorrect (beyond the fact that LXDE and GNOME are both built on the GTK toolkit). GNOME applets do not work in LXDE. LXDE has its own implementation of the applets that it offers.

Re: Applet programming

Posted: Mon Dec 20, 2010 8:45 pm
by percival
mm, sorry about that. I was thinking of systray icons.

Re: Applet programming

Posted: Sat Dec 25, 2010 6:17 am
by jgillich
systray icons: http://standards.freedesktop.org/system ... ec/latest/
lxpanel plugins: http://wiki.lxde.org/en/How_to_write_pl ... or_LXPanel

Hmm, seems to be not very helpful 8-)
But maybe should take a look at the lxpanel sources and then write this tutorial? ;)

Re: Applet programming

Posted: Fri Jan 28, 2011 7:33 am
by nelsonlombardo
systray icons: http://standards.freedesktop.org/system ... ec/latest/
lxpanel plugins: http://wiki.lxde.org/en/How_to_write_pl ... or_LXPanel

Hmm, seems to be not very helpful 8-)
But maybe should take a look at the lxpanel sources and then write this tutorial? ;)
He is right. Maybe you think this is wasting time, but the better way to help to developers newbies is create documentation based in this type of situations. In my case I don't have experience making applets but if I read something about this...
Regards.

Re: Applet programming

Posted: Fri Apr 13, 2012 5:30 am
by technosaurus
I recently developed the simplest (but still full featured) tray applet program I could and released it to the public domain (or any license approved by the open source initiative for locales that do not recognize releasing copyright to the public domain)

The whole thing is designed for tray applet development and really simple - it simply displays whatever icon(s) you tell and you can specify the refresh interval, tooltip (mouse-over text) and output for right and left mouse clicks for each icon (this can be used to pull up a controlling program like Xdialog, gtkdialog, zenity, yad, etc ... ).

Feel free to fork it for LXDE if you want, it does everything I wanted it to already (allow me to run all my tray applets with a single shell daemon) so I won't exactly be "maintaining" it except to make it build on later versions of gtk if it breaks.

HTH
http://www.murga-linux.com/puppy/viewtopic.php?t=76431

Re: Applet programming

Posted: Sat Apr 28, 2012 7:25 pm
by rockdoctor
For those who perfer Python over C, I offer the code below:

Code: Select all

#!/bin/env python

"""
sit.py - a translation of technosaurus's sit.c
translator: RockDoctor
"""

import sys
from gi.repository import Gtk


class SitApp:

  def __init__(self):
    if sys.argv[1][0]=='-' or len(sys.argv)!=6:
      self.write1("Usage:\n"
      "sit interval /pathto/image tooltip left-click-action right-click-action\n");
      sys.exit(1)
    this_prgm,t,si,tooltip,lca,rca = sys.argv
    si = Gtk.StatusIcon.new_from_file(si)
    t = int(t)
    si.set_tooltip_text(tooltip)
    si.connect("activate",self.leftClick,lca)
    si.connect("popup-menu",self.rightClick,rca)

    Gtk.main()

  def write1(self,s):
    print s

  def leftClick(self, status_icon, s):
    self.write1 (s)

  def rightClick(self, status_icon, button, activate_time, s):
    self.write1 (s)
    sys.exit() # temporary way to exit the program

  def refresh (self, si):
    Gtk.StatusIcon.get_from_file(si,Gtk.StatusIcon.get_title(si))

def main(data=None):
    app = SitApp()

if __name__ == '__main__':
    main()

Re: Applet programming

Posted: Wed Jun 13, 2012 9:24 pm
by technosaurus
It now uses inotify (via a gdk_input) so that no refresh rate is needed and also executes the left and right click commands directly.
Just start her up and use any external program to modify the icons (SVG is the easiest). Your limit is your imagination

Code: Select all

#include <sys/inotify.h>
#include <gtk/gtk.h>
void leftclick(GtkStatusIcon *si, gpointer s){popen(s,"r");} /* exec s */
void rightclick(GtkStatusIcon *si, guint b,guint a_t, gpointer s){popen(s,"r");}
void refresh(gpointer si, gint fd, GdkInputCondition c){	char buffer[sizeof (struct inotify_event)];
	read( fd, buffer, sizeof(buffer) ); /* we are just clearing it & don't care what event type */
	gtk_status_icon_set_from_file(si,gtk_status_icon_get_title(si));} /* redraws */
int main(int argc, char *argv[]){	GtkStatusIcon *si; int i=1, watch, fd;
gtk_init (&argc, &argv); /* loop through icon, tooltip, click messages */
while (i<argc) {	fd = inotify_init(); /* get file descriptor to write on if image changes */
	si = gtk_status_icon_new_from_file(argv[i]); /* get a status icon widget */
	gtk_status_icon_set_title(si,argv[i]); /* hack to store the image path */
	watch = inotify_add_watch( fd, argv[i++], IN_MODIFY );
	gdk_input_add( fd, GDK_INPUT_READ, refresh, si ); /* inotify fd is ready for reading, refresh */
	gtk_status_icon_set_tooltip_text(si,argv[i++]);
	g_signal_connect(G_OBJECT(si), "activate", G_CALLBACK(leftclick),(gpointer) argv[i++]);
	g_signal_connect(G_OBJECT(si), "popup-menu", G_CALLBACK(rightclick), (gpointer) argv[i++]);}
gtk_main ();}