On Tue, 2008-02-05 at 01:36 +0100, Andreas Sliwka wrote:
> Greetings,
> I'm looking for an example on how to create a PanelApplet with vala.
> Any help would be greatly appreciated.
[snip]
Hi Andreas,
I've done some panel applets with vala, so here are my experiences.
The code it's not so clean because libpanelapplet vapi miss some
function call and for other reasons.
Instructions:
1) Save all attached files to some directory in your home
2) compile the applet with vala:
valac -o vala-applet vala-applet.vala --vapidir ./ --pkg gtk+-2.0 --pkg
libpanelapplet-2.0-custom --pkg libbonoboui-2.0 --Xcc="-export-dynamic
`pkg-config --cflags --libs libpanelapplet-2.0`"
Note the -export-dynamic arguments, the ` around the pkg-config command
and the " and (finally) that I've used some private vapis.
3) Adjust the path at the beginning of vala-applet.server to the folder
where you just compile the applet
4) Copy the vala-applet.server to /usr/lib/bonobo/servers/
5) execute the applet from within the folder you just
compiled: ./vala-applet
6) Then add the applet to the panel as usual: right click etc etc...
The applet is called ValaApplet and should have a green apple pixmap
Hope this help. Bye,
Andrea
P.S.
I've tested all with a Debian Sid.
[CCode (cheader_filename = "libbonoboui.h")]
namespace BonoboUI {
public struct Verb {
public string cname;
public VerbFn cb;
public pointer user_data;
public pointer dummy;
}
public class Component
{
}
public static delegate void VerbFn (Component component, pointer
user_data, string cname);
}
gtk+-2.0
libgnomeui-2.0
/* libpanelapplet-2.0.vala
*
* Copyright (C) 2007 Jürg Billeter
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author:
* Jürg Billeter <[EMAIL PROTECTED]>
*/
[CCode (cheader_filename = "panel-applet.h")]
namespace Panel {
public class Applet : Gtk.EventBox {
public Applet ();
public string get_preferences_key ();
public void set_flags (AppletFlags flags);
public static int factory_main (string iid, GLib.Type applet_type, AppletFactoryCallback callback, pointer data);
public void set_background_widget (Gtk.Widget widget);
public signal void change_background (AppletBackgroundType type, ref Gdk.Color color, Gdk.Pixmap pixmap);
[NoArrayLength]
public void setup_menu (string xml, BonoboUI.Verb[] verb_list, pointer data);
}
[CCode (cprefix = "PANEL_")]
public enum AppletBackgroundType {
NO_BACKGROUND,
COLOR_BACKGROUND,
PIXMAP_BACKGROUND
}
[CCode (cprefix = "PANEL_APPLET_")]
public enum AppletFlags {
FLAGS_NONE,
EXPAND_MAJOR,
EXPAND_MINOR,
HAS_HANDLE
}
public static delegate bool AppletFactoryCallback (Applet applet, string iid, pointer user_data);
}
<oaf_info>
<oaf_server iid="OAFIID:GNOME_ValaApplet_Factory" type="exe"
location="/home/andrea/Documenti/src/vala/tests/applet/vala-applet">
<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="ValaApplet"/>
<oaf_attribute name="description" type="string" value="A Gnome panel
applet written in Vala"/>
</oaf_server>
<oaf_server iid="OAFIID:GNOME_ValaApplet" type="factory"
location="OAFIID:GNOME_ValaApplet_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="ValaApplet"/>
<oaf_attribute name="description" type="string" value="A Gnome panel
applet written in Vala"/>
<oaf_attribute name="panel:category" type="string" value="Generic"/>
<oaf_attribute name="panel:icon" type="string" value="apple-green.png"/>
</oaf_server>
</oaf_info>
using Panel;
using GLib;
using Gtk;
public class Test.ValaApplet : Panel.Applet {
private string right_click_menu_xml =
"<popup name=\"button3\">\n <menuitem name=\"Properties Item\" verb=\"Properties\" _label=\"_Preferences...\"\n pixtype=\"stock\" pixname=\"gtk-properties\"/>\n <menuitem name=\"About Item\" verb=\"About\" _label=\"_About...\"\n pixtype=\"stock\" pixname=\"gnome-stock-about\"/>\n </popup>\n";
private BonoboUI.Verb[] verbs = null;
construct {
}
public ValaApplet() {
}
private void create() {
verbs = new BonoboUI.Verb[3];
var image = new Gtk.Image.from_icon_name ("gtk-about", Gtk.IconSize.SMALL_TOOLBAR);
var verb = new BonoboUI.Verb();
verb.cname = "Properties";
verb.cb = this.on_context_menu_item_clicked;
verb.user_data = null;
verbs[0] = verb;
verb = new BonoboUI.Verb();
verb.cname = "About";
verb.cb = this.on_context_menu_item_clicked;
verb.user_data = null;
verbs[1] = verb;
verb = new BonoboUI.Verb();
verb.cname = null;
verb.cb = null;
verb.user_data = null;
verbs[2] = verb;
this.add (image);
this.setup_menu (right_click_menu_xml, verbs, this);
this.delete_event += this.on_applet_deleted;
this.button_press_event += this.on_button_press;
this.show_all ();
}
static bool factory (ValaApplet applet, string iid, pointer data) {
debug ("applet factory called. iid=%s", iid);
applet.create ();
return true;
}
private bool on_button_press (Widget sender, Gdk.EventButton eventButton) {
if (eventButton.type == Gdk.EventType.BUTTON_PRESS &&
eventButton.button == 1) {
debug ("applet icon click");
return true;
}
return false;
}
private static void on_context_menu_item_clicked (BonoboUI.Component component, pointer user_data, string cname) {
debug ("context menu item selected: %s", cname);
}
private void on_applet_deleted () {
debug ("applet deleted");
}
public static int main(string[] args) {
var program = Gnome.Program.init ("GNOME_ValaApplet", "0", Gnome.libgnomeui_module, args.length, args, "sm-connect", false);
var ret = Panel.Applet.factory_main ("OAFIID:GNOME_ValaApplet_Factory", typeof(Test.ValaApplet), factory, null);
return ret;
}
}
_______________________________________________
Vala-list mailing list
Vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list