[Dextrose] [PATCH sugar 1/2] Two kinds of feedback submits

Aleksey Lim alsroot at member.fsf.org
Mon Jan 17 21:53:44 EST 2011


---
 extensions/deviceicon/feedback.py |  214 +++++++++++++++++++++++--------------
 1 files changed, 132 insertions(+), 82 deletions(-)

diff --git a/extensions/deviceicon/feedback.py b/extensions/deviceicon/feedback.py
index 2a0075e..add633c 100644
--- a/extensions/deviceicon/feedback.py
+++ b/extensions/deviceicon/feedback.py
@@ -16,113 +16,163 @@
 
 import logging
 from gettext import gettext as _
+
 import gconf
 import gtk
+
+from sugar import profile
 from sugar.graphics import style
+from sugar.graphics.icon import Icon
 from sugar.graphics.tray import TrayIcon
 from sugar.graphics.palette import Palette
-from sugar.graphics.xocolor import XoColor
+from sugar.graphics.menuitem import MenuItem
+from sugar.graphics.toolbutton import ToolButton
+
 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)
+        TrayIcon.__init__(self, icon_name=_ICON_NAME,
+                xo_color=profile.get_color())
         self.create_palette()
-            
+
     def create_palette(self):
         logging.debug('palette created')
-        self.palette = BugsPalette(_('Bugs'))
+        self.palette = _Palette(_('Feedback'))
         self.palette.set_group_id('frame')
         return self.palette
 
 
-class BugsPalette(Palette):  
-    
+class _Palette(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()        
-    
+
+        icon = Icon()
+        icon.set_from_icon_name('emblem-favorite', gtk.ICON_SIZE_MENU)
+        icon.props.xo_color = profile.get_color()
+
+        personalized = MenuItem(_('Personalized submit...'))
+        personalized.set_image(icon)
+        personalized.connect('activate', self.__personalized_activate_cb)
+        personalized.show()
+        self.menu.append(personalized)
+
+        self._anonymous = MenuItem(_('Anonymous submit'), 'emblem-favorite')
+        self._anonymous.connect('activate', self.__anonymous_activate_cb)
+        self._anonymous.show()
+        self.menu.append(self._anonymous)
+
     def popup(self, immediate=False, state=None):
+        self._anonymous.set_sensitive(not feedback_collector.is_empty())
         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)
+
+    def __anonymous_activate_cb(self, button):
+        feedback_collector.anonymous_submit()
+
+    def __personalized_activate_cb(self, button):
+        window = _Window()
+        window.show()
+
+
+class _Window(gtk.Window):
+
+    __gtype_name__ = 'FeedbackWindow'
+
+    def __init__(self):
+        gtk.Window.__init__(self)
+
+        self.set_border_width(style.LINE_WIDTH)
+        offset = style.GRID_CELL_SIZE
+        width = gtk.gdk.screen_width() - offset * 2
+        height = gtk.gdk.screen_height() - offset * 2
+        self.set_size_request(width, height)
+        self.set_position(gtk.WIN_POS_CENTER_ALWAYS)
+        self.set_decorated(False)
+        self.set_resizable(False)
+        self.set_modal(True)
+
+        canvas = gtk.VBox()
+        self.add(canvas)
+
+        self._toolbar = gtk.Toolbar()
+        canvas.pack_start(self._toolbar, False)
+
+        icon = Icon()
+        icon.set_from_icon_name('emblem-favorite', gtk.ICON_SIZE_LARGE_TOOLBAR)
+        icon.props.xo_color = profile.get_color()
+        self._add_widget(icon)
+
+        self._add_separator(False)
+
+        title = gtk.Label(_('Submit feedback with contact infromation'))
+        self._add_widget(title)
+
+        self._add_separator(True)
+
+        submit = ToolButton('dialog-ok', tooltip=_('Submit'))
+        submit.connect('clicked', lambda button: self._submit())
+        self._toolbar.insert(submit, -1)
+
+        cancel = ToolButton('dialog-cancel', tooltip=_('Cancel'))
+        cancel.connect('clicked', lambda button: self.destroy())
+        self._toolbar.insert(cancel, -1)
+
+        bg = gtk.EventBox()
+        bg.modify_bg(gtk.STATE_NORMAL, style.COLOR_WHITE.get_gdk_color())
+        canvas.pack_start(bg)
+
+        self._message = gtk.TextView()
+        scrolled = gtk.ScrolledWindow()
+        scrolled.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
+        scrolled.set_border_width(style.DEFAULT_PADDING)
+        scrolled.add(self._message)
+        bg.add(scrolled)
+
+        self.show_all()
+        self.set_focus(self._message)
+
+        self.connect("realize", self.__realize_cb)
+
+    def do_key_press_event(self, event):
+        if event.keyval == gtk.keysyms.Escape:
+            self.destroy()
+        elif event.keyval == gtk.keysyms.Return and \
+                event.state & gtk.gdk.CONTROL_MASK:
+            self._submit()
         else:
-            self._open_log_button.set_sensitive(False)
-        
-                
-        if have_reports:
-            self._send_report_button.set_sensitive(True)
+            gtk.Window.do_key_press_event(self, event)
+
+    def _add_widget(self, widget):
+        tool_item = gtk.ToolItem()
+        tool_item.add(widget)
+        self._toolbar.insert(tool_item, -1)
+
+    def _add_separator(self, expand):
+        separator = gtk.SeparatorToolItem()
+        separator.props.draw = False
+        if expand:
+            separator.set_expand(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))
- 
+            separator.set_size_request(style.DEFAULT_SPACING, -1)
+        self._toolbar.insert(separator, -1)
+
+    def _submit(self):
+        feedback_collector.submit(self._message.props.buffer.props.text)
+        self.destroy()
+
+    def __realize_cb(self, widget):
+        self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
+        self.window.set_accept_focus(True)
+
+
 def setup(tray):
     client = gconf.client_get_default()
     if client.get_bool('/desktop/sugar/feedback/enabled'):
-- 
1.7.3.4



More information about the Dextrose mailing list