[Dextrose] [PATCH sugar] Patch to add feedback icon to frame

Aleksey Lim alsroot at member.fsf.org
Mon Jan 17 21:54:15 EST 2011


From: Mukesh Gupta <mukeshgupta.2006 at gmail.com>

Signed-off-by: Mukesh Gupta <mukeshgupta.2006 at gmail.com>
---
 extensions/deviceicon/Makefile.am |    4 +-
 extensions/deviceicon/feedback.py |  129 +++++++++++++++++++++++++++++++++++++
 2 files changed, 132 insertions(+), 1 deletions(-)
 create mode 100644 extensions/deviceicon/feedback.py

diff --git a/extensions/deviceicon/Makefile.am b/extensions/deviceicon/Makefile.am
index 3a74053..b38cbb3 100644
--- a/extensions/deviceicon/Makefile.am
+++ b/extensions/deviceicon/Makefile.am
@@ -8,4 +8,6 @@ sugar_PYTHON = 		\
 	speaker.py	\
 	touchpad.py	\
 	virtualkeyboard.py	\
-	volume.py
+	volume.py	\
+	feedback.py
+	
diff --git a/extensions/deviceicon/feedback.py b/extensions/deviceicon/feedback.py
new file mode 100644
index 0000000..2a0075e
--- /dev/null
+++ b/extensions/deviceicon/feedback.py
@@ -0,0 +1,129 @@
+# Copyright (C) Mukesh Gupta <mukeshgupta.2006 at gmail.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+import logging
+from gettext import gettext as _
+import gconf
+import gtk
+from sugar.graphics import style
+from sugar.graphics.tray import TrayIcon
+from sugar.graphics.palette import Palette
+from sugar.graphics.xocolor import XoColor
+from jarabe.model import feedback_collector
+from jarabe.view import launcher
+from sugar.activity import activityfactory
+from jarabe.model import bundleregistry
+from sugar.activity.activityhandle import ActivityHandle
+
+_ICON_NAME = 'feedback-icon'
+
+class DeviceView(TrayIcon):
+    FRAME_POSITION_RELATIVE = 100
+    def __init__(self):
+        client = gconf.client_get_default()
+        self._color = XoColor(client.get_string('/desktop/sugar/user/color'))
+        TrayIcon.__init__(self, icon_name=_ICON_NAME, xo_color=self._color)
+        self.create_palette()
+            
+    def create_palette(self):
+        logging.debug('palette created')
+        self.palette = BugsPalette(_('Bugs'))
+        self.palette.set_group_id('frame')
+        return self.palette
+
+
+class BugsPalette(Palette):  
+    
+    def __init__(self, primary_text):
+        Palette.__init__(self, primary_text)
+        self._level = 0        
+        self._status_label = gtk.Label()
+        self._status_label.show()
+        self.vbox = gtk.VBox()        
+        self.hbox = gtk.HBox()              
+        self.set_content(self.vbox)
+        self._bugs_count_text = gtk.Label()
+        self.vbox.pack_start(self._bugs_count_text,
+         padding = style.DEFAULT_PADDING)                      
+        self.vbox.pack_start(self.hbox, padding = style.DEFAULT_PADDING)
+        self.vbox.show()        
+        self.hbox.pack_start(self._status_label,
+         padding = style.DEFAULT_PADDING)
+        self.hbox.show()        
+        self._open_log_button = gtk.Button("Open Log")
+        self._open_log_button.connect("clicked",
+         self.__open_log_activity)
+        self.hbox.pack_start(self._open_log_button,
+         padding = style.DEFAULT_PADDING)        
+        self._send_report_button = gtk.Button("Send Report")
+        self._send_report_button.connect("clicked", self.__send_bug_report)
+        self.hbox.pack_start(self._send_report_button,
+         padding = style.DEFAULT_PADDING)       
+        self.__get_bug_count()
+        self._bugs_count_text.show()
+        self._open_log_button.show()
+        self._send_report_button.show()        
+    
+    def popup(self, immediate=False, state=None):
+        Palette.popup(self, immediate=immediate, state=state)
+        self.__update_bug_palette()
+        
+        
+    def __send_bug_report(self, button):
+        feedback_collector.submit()
+        
+    def __open_log_activity(self, path):
+        
+        registry = bundleregistry.get_registry()
+        bundle = registry.get_bundle('org.laptop.Log')
+        activity_id = activityfactory.create_activity_id()
+        client = gconf.client_get_default()
+        xo_color = XoColor(client.get_string('/desktop/sugar/user/color'))
+        launcher.add_launcher(activity_id, bundle.get_icon(), xo_color)
+        activityfactory.create(bundle, ActivityHandle(activity_id))
+            
+    def __get_bug_count(self):
+        """This method returns the total error count"""
+        bugs_count = 0
+        
+        
+        return bugs_count
+    
+    def __update_bug_palette(self):        
+        bugs_count = self.__get_bug_count()    
+        self._open_log_button.set_sensitive(False)
+        have_reports, have_errors = feedback_collector.stat()
+        #have_reports, have_errors=[True,False]
+        if have_errors:
+            self._open_log_button.set_sensitive(True)
+        else:
+            self._open_log_button.set_sensitive(False)
+        
+                
+        if have_reports:
+            self._send_report_button.set_sensitive(True)
+        else:
+            self._send_report_button.set_sensitive(False)
+                    
+        if bugs_count == 0:        
+            self._bugs_count_text.set_label('No Errors')
+        else :            
+            self._bugs_count_text.set_label(_('Total Errors: %d' %  bugs_count))
+ 
+def setup(tray):
+    client = gconf.client_get_default()
+    if client.get_bool('/desktop/sugar/feedback/enabled'):
+        tray.add_device(DeviceView())
-- 
1.7.3.4



More information about the Dextrose mailing list