Ticket #144: xomenu_patch

File xomenu_patch, 3.7 KB (added by rkabir, 15 years ago)

patch to create xomenu.py, deviceicon

Line 
1diff --git a/extensions/deviceicon/xomenu.py b/extensions/deviceicon/xomenu.py
2new file mode 100644
3index 0000000..a36992e
4--- /dev/null
5+++ b/extensions/deviceicon/xomenu.py
6@@ -0,0 +1,110 @@
7+# Copyright (C) 2008 Ryan Kabir
8+#
9+# This program is free software; you can redistribute it and/or modify
10+# it under the terms of the GNU General Public License as published by
11+# the Free Software Foundation; either version 2 of the License, or
12+# (at your option) any later version.
13+#
14+# This program is distributed in the hope that it will be useful,
15+# but WITHOUT ANY WARRANTY; without even the implied warranty of
16+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17+# GNU General Public License for more details.
18+#
19+# You should have received a copy of the GNU General Public License
20+# along with this program; if not, write to the Free Software
21+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22+
23+from gettext import gettext as _
24+import gconf
25+
26+import gobject
27+import gtk
28+import hippo
29+
30+from sugar.graphics import style
31+from sugar.graphics.menuitem import MenuItem
32+from sugar.graphics.tray import TrayIcon
33+from sugar.graphics.palette import Palette
34+from sugar.graphics.xocolor import XoColor
35+
36+from jarabe.frame.frameinvoker import FrameWidgetInvoker
37+from jarabe.controlpanel.gui import ControlPanel
38+from jarabe.model.session import get_session_manager
39+
40+_ICON_NAME = 'computer-xo'
41+
42+class SystemView(TrayIcon):
43+
44+    FRAME_POSITION_RELATIVE = 800
45+
46+    def __init__(self):
47+        client = gconf.client_get_default()       
48+        self._color = XoColor(client.get_string('/desktop/sugar/user/color'))
49+
50+        TrayIcon.__init__(self, icon_name=_ICON_NAME, xo_color=self._color)
51+
52+        self._model = SystemModel()
53+        self.palette = SystemPalette(_('System functions'), self._model)
54+        self.palette.props.invoker = FrameWidgetInvoker(self)
55+        self.palette.set_group_id('frame')
56+
57+        name = _ICON_NAME
58+        self.icon.props.icon_name = _ICON_NAME
59+
60+    def controlpanel_activate_cb(self, *args):
61+        panel = ControlPanel()
62+        panel.set_transient_for(self.get_toplevel())
63+        panel.show()
64+
65+
66+class SystemModel(gobject.GObject):
67+    def __init__(self):
68+        gobject.GObject.__init__(self)
69+
70+    def get_type(self):
71+        return 'Settings'
72+
73+class SystemPalette(Palette):
74+    def __init__(self, primary_text, model):
75+        Palette.__init__(self, label=primary_text)
76+        self._model = model
77+        self.set_size_request(style.zoom(style.GRID_CELL_SIZE * 2), -1)
78+        vbox = gtk.VBox()
79+        self.set_content(vbox)
80+        vbox.show()
81+
82+        item = MenuItem(_('Settings'), 'preferences-system')
83+        item.connect('activate', self.__controlpanel_activate_cb)
84+        self.menu.append(item)
85+        item.show()
86+
87+        item = MenuItem(_('Restart'), 'system-restart')
88+        item.connect('activate', self._reboot_activate_cb)
89+        self.menu.append(item)
90+        item.show()
91+
92+        item = MenuItem(_('Shutdown'), 'system-shutdown')
93+        item.connect('activate', self._shutdown_activate_cb)
94+        self.menu.append(item)
95+        item.show()
96+
97+        self.connect('popup', self.__popup_cb)
98+
99+    def _reboot_activate_cb(self, menuitem):
100+        session_manager = get_session_manager()
101+        session_manager.reboot()
102+
103+    def _shutdown_activate_cb(self, menuitem):
104+        session_manager = get_session_manager()
105+        session_manager.shutdown()
106+       
107+    def __controlpanel_activate_cb(self, menuitem):
108+        panel = ControlPanel()
109+        panel.set_transient_for(self.get_toplevel())
110+        panel.show()
111+
112+    def __popup_cb(self, palette_):
113+        pass
114+
115+def setup(tray):
116+    tray.add_device(SystemView())