diff --git a/sugar/graphics/color.py b/sugar/graphics/color.py index 9798e913..60c2ce6f 100644 --- a/sugar/graphics/color.py +++ b/sugar/graphics/color.py @@ -4,7 +4,9 @@ _system_colors = { 'toolbar-background' : '#414141', 'frame-border' : '#D1D1D2', 'entry-background-focused' : '#FFFFFF', - 'entry-background-unfocused' : '#D1D1D2' + 'entry-background-unfocused' : '#D1D1D2', + 'entry-selection-focused' : '#D1D1D2', + 'entry-selection-unfocused' : '#00FF00' } def _html_to_rgb(html_color): @@ -53,8 +55,12 @@ class Color(object): RED = RGBColor(1.0, 0.0, 0.0) GREEN = RGBColor(0.0, 1.0, 0.0) BLUE = RGBColor(0.0, 0.0, 1.0) + WHITE = RGBColor(1.0, 1.0, 1.0) + BLACK = RGBColor(0.0, 0.0, 0.0) TOOLBAR_BACKGROUND = SystemColor('toolbar-background') FRAME_BORDER = SystemColor('frame-border') ENTRY_BACKGROUND_FOCUSED = SystemColor('entry-background-focused') ENTRY_BACKGROUND_UNFOCUSED = SystemColor('entry-background-unfocused') + ENTRY_SELECTION_FOCUSED = SystemColor('entry-selection-focused') + ENTRY_SELECTION_UNFOCUSED = SystemColor('entry-selection-unfocused') diff --git a/sugar/graphics/entry.py b/sugar/graphics/entry.py index 68970b78..06cf4514 100644 --- a/sugar/graphics/entry.py +++ b/sugar/graphics/entry.py @@ -17,52 +17,64 @@ import math import logging -import hippo +import gobject import gtk +import hippo from sugar.graphics.frame import Frame from sugar.graphics.color import Color class Entry(hippo.CanvasBox, hippo.CanvasItem): __gtype_name__ = 'SugarEntry' + + __gproperties__ = { + 'text' : (str, None, None, None, + gobject.PARAM_READWRITE) + } def __init__(self): hippo.CanvasBox.__init__(self) self._radius = -1 - self._background_color = Color.ENTRY_BACKGROUND_UNFOCUSED self._entry = gtk.Entry() self._entry.props.has_frame = False - self._entry.modify_base(gtk.STATE_NORMAL, - self._background_color.get_gdk_color()) + self._update_colors(focused=False) + self._entry.modify_text(gtk.STATE_SELECTED, + Color.BLACK.get_gdk_color()) self._entry.connect('focus-in-event', self._entry_focus_in_event_cb) self._entry.connect('focus-out-event', self._entry_focus_out_event_cb) - + self._canvas_widget = hippo.CanvasWidget() self._canvas_widget.props.widget = self._entry self.append(self._canvas_widget, hippo.PACK_EXPAND) - def do_paint_below_children(self, cr, damaged_box): - logging.debug('do_paint_below_children: %s', str(self._background_color)) + def do_set_property(self, pspec, value): + if pspec.name == 'text': + self._entry.set_text(value) + def do_get_property(self, pspec, value): + if pspec.name == 'text': + return self._entry.get_text() + + def do_paint_below_children(self, cr, damaged_box): [width, height] = self._canvas_widget.get_allocation() x = 0 y = 0 - cr.move_to(x + self._radius, y); - cr.arc(x + width - self._radius, y + self._radius, + cr.move_to(self._radius, 0); + cr.arc(width - self._radius, self._radius, self._radius, math.pi * 1.5, math.pi * 2); - cr.arc(x + width - self._radius, x + height - self._radius, + cr.arc(width - self._radius, height - self._radius, self._radius, 0, math.pi * 0.5); - cr.arc(x + self._radius, y + height - self._radius, + cr.arc(self._radius, height - self._radius, self._radius, math.pi * 0.5, math.pi); - cr.arc(x + self._radius, y + self._radius, self._radius, + cr.arc(self._radius, self._radius, self._radius, math.pi, math.pi * 1.5); cr.set_source_rgba(*self._background_color.get_rgba()) - cr.fill_preserve(); + cr.fill(); def do_allocate(self, width, height, origin_changed): hippo.CanvasBox.do_allocate(self, width, height, origin_changed) @@ -71,22 +83,32 @@ class Entry(hippo.CanvasBox, hippo.CanvasItem): radius = min(width, height) / 2 if radius != self._radius: self._radius = radius - self._canvas_widget.props.padding_left = self._radius - self._canvas_widget.props.padding_right = self._radius + self._canvas_widget.props.padding_left = self._radius - 2 + self._canvas_widget.props.padding_right = self._radius - 2 self._canvas_widget.do_allocate(self._canvas_widget, width, height, origin_changed) def _entry_focus_in_event_cb(self, widget, event): - self._background_color = Color.ENTRY_BACKGROUND_FOCUSED - self._entry.modify_base(gtk.STATE_NORMAL, - self._background_color.get_gdk_color()) + self._update_colors(focused=True) self.emit_paint_needed(0, 0, -1, -1) - logging.debug('_entry_focus_in_event_cb') def _entry_focus_out_event_cb(self, widget, event): - self._background_color = Color.ENTRY_BACKGROUND_UNFOCUSED - self._entry.modify_base(gtk.STATE_NORMAL, - self._background_color.get_gdk_color()) + self._update_colors(focused=False) self.emit_paint_needed(0, 0, -1, -1) - logging.debug('_entry_focus_out_event_cb') + + def _update_colors(self, focused): + if focused: + self._background_color = Color.ENTRY_BACKGROUND_FOCUSED + + self._entry.modify_base(gtk.STATE_NORMAL, + Color.ENTRY_BACKGROUND_FOCUSED.get_gdk_color()) + self._entry.modify_base(gtk.STATE_SELECTED, + Color.ENTRY_SELECTION_FOCUSED.get_gdk_color()) + else: + self._background_color = Color.ENTRY_BACKGROUND_UNFOCUSED + + self._entry.modify_base(gtk.STATE_NORMAL, + Color.ENTRY_BACKGROUND_UNFOCUSED.get_gdk_color()) + self._entry.modify_base(gtk.STATE_SELECTED, + Color.ENTRY_SELECTION_UNFOCUSED.get_gdk_color()) diff --git a/tests/test-entry.py b/tests/test-entry.py index dd65dc8c..9603d9cd 100755 --- a/tests/test-entry.py +++ b/tests/test-entry.py @@ -44,9 +44,11 @@ button = Button('theme:stock-close') frame.append(button) entry = Entry() +entry.props.text = 'mec mac' toolbar.append(entry, hippo.PACK_EXPAND) entry2 = Entry() +entry2.props.text = 'moc muc' toolbar.append(entry2, hippo.PACK_EXPAND) gtk.main()