1 """To create a panel applet for ROX-Filer, you should add a file called
2 AppletRun to your application. This is run when your applet it dragged onto
3 a panel. It works like the usual AppRun, except that it is passed the XID of
4 the GtkSocket widget that ROX-Filer creates for you on the panel.
6 A sample AppletRun might look like this:
9 import findrox; findrox.version(1, 9, 12)
12 from rox import applet, g
14 plug = applet.Applet(sys.argv[1])
16 label = g.Label('Hello\\nWorld!')
26 _root_window
= g
.gdk
.get_default_root_window()
29 """When your AppletRun file is used, create an Applet widget with
30 the argument passed to AppletRun. Show the widget to make it appear
31 in the panel. toplevel_* functions are called automatically."""
32 def __init__(self
, xid
):
33 """xid is the sys.argv[1] passed to AppletRun."""
35 g
.Plug
.__init
__(self
, xid
)
36 self
.socket
= g
.gdk
.window_foreign_new(xid
)
38 self
.connect('destroy', rox
.toplevel_unref
)
40 def is_vertical_panel(self
):
41 """Returns True if the panel this applet is on is a left
43 pos
= self
.socket
.property_get('_ROX_PANEL_MENU_POS',
47 side
, margin
= pos
.split(',')
50 side
, margin
= None, 2
52 if side
== 'Left' or side
== 'Right':
54 elif side
== 'Top' or side
== 'Bottom':
57 # Couldn't work out the side, return None which will
58 # probably be interpreted as False.
61 def position_menu(self
, menu
):
62 """Use this as the third argument to Menu.popup()."""
63 x
, y
, mods
= _root_window
.get_pointer()
64 pos
= self
.socket
.property_get('_ROX_PANEL_MENU_POS',
68 side
, margin
= pos
.split(',')
71 side
, margin
= None, 2
73 width
, height
= g
.gdk
.screen_width(), g
.gdk
.screen_height()
75 req
= menu
.size_request()
80 elif side
== 'Bottom':
81 y
= height
- margin
- req
[1]
87 x
= width
- margin
- req
[0]
93 def limit(v
, min, max):
94 if v
< min: return min
95 if v
> max: return max
98 x
= limit(x
, 4, width
- 4 - req
[0])
99 y
= limit(y
, 4, height
- 4 - req
[1])