tests/status_icon.js
[app.Builder.js] / tests / status_icon.js
1 #!/usr/bin/env seed
2
3 // Import and initialize GTK+
4 Gtk = imports.gi.Gtk;
5 Gtk.init(null, null);
6
7 // Create the window
8 var window = new Gtk.Window({title: "Hello World"});
9 window.set_default_size(600, 500);
10 window.signal.hide.connect(Gtk.main_quit);
11
12 // Create the GtkStatusIcon from a file
13 var icon = new Gtk.StatusIcon({stock : Gtk.STOCK_MEDIA_PLAY});
14
15 // Create the menu
16 var menu = new Gtk.Menu();
17
18 // Create an item
19 var item = new Gtk.MenuItem({label: "Hello"});
20 menu.append(item);
21
22 // Signal connecting the popup_menu event of the icon to the "activate" function
23 icon.signal.popup_menu.connect(active, menu);
24
25 function active(status_icon, button, time, data)
26 {
27     // GtkMenu.popup, calling the Gtk.StatusIcon.position_menu function
28     // 
29     var area = new Gdk.Rectangle();
30     var orient = new Gtk.Orientation();
31     var ret = {}; 
32     status_icon.get_geometry(ret, area, orient);
33     console.log(JSON.stringify(area));
34     console.log(JSON.stringify(orient));
35     
36     menu.popup(null, null, Gtk.StatusIcon.position_menu, status_icon, button, time);
37 }
38
39 window.show_all();
40
41 Gtk.main();