Added text entry control.
This commit is contained in:
parent
39678b8bb8
commit
6115b8af10
@ -6,6 +6,7 @@ sugar_PYTHON = \
|
||||
canvasicon.py \
|
||||
color.py \
|
||||
ClipboardBubble.py \
|
||||
entry.py \
|
||||
frame.py \
|
||||
grid.py \
|
||||
iconcolor.py \
|
||||
|
@ -1,6 +1,10 @@
|
||||
import gtk
|
||||
|
||||
_system_colors = {
|
||||
'toolbar-background' : '#414141',
|
||||
'frame-border' : '#D1D1D2'
|
||||
'toolbar-background' : '#414141',
|
||||
'frame-border' : '#D1D1D2',
|
||||
'entry-background-focused' : '#FFFFFF',
|
||||
'entry-background-unfocused' : '#D1D1D2'
|
||||
}
|
||||
|
||||
def _html_to_rgb(html_color):
|
||||
@ -36,6 +40,10 @@ class RGBColor(object):
|
||||
def get_int(self):
|
||||
return _rgba_to_int(self._r, self._g, self._b, self._a)
|
||||
|
||||
def get_gdk_color(self):
|
||||
return gtk.gdk.Color(int(self._r * 65535), int(self._g * 65535),
|
||||
int(self._b * 65535))
|
||||
|
||||
class SystemColor(RGBColor):
|
||||
def __init__(self, color_id):
|
||||
rgb = _html_to_rgb(_system_colors[color_id])
|
||||
@ -46,5 +54,7 @@ class Color(object):
|
||||
GREEN = RGBColor(0.0, 1.0, 0.0)
|
||||
BLUE = RGBColor(0.0, 0.0, 1.0)
|
||||
|
||||
TOOLBAR_BACKGROUND = SystemColor('toolbar-background')
|
||||
FRAME_BORDER = SystemColor('frame-border')
|
||||
TOOLBAR_BACKGROUND = SystemColor('toolbar-background')
|
||||
FRAME_BORDER = SystemColor('frame-border')
|
||||
ENTRY_BACKGROUND_FOCUSED = SystemColor('entry-background-focused')
|
||||
ENTRY_BACKGROUND_UNFOCUSED = SystemColor('entry-background-unfocused')
|
||||
|
92
sugar/graphics/entry.py
Normal file
92
sugar/graphics/entry.py
Normal file
@ -0,0 +1,92 @@
|
||||
# Copyright (C) 2007, One Laptop Per Child
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This library 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
|
||||
# Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the
|
||||
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
# Boston, MA 02111-1307, USA.
|
||||
import math
|
||||
import logging
|
||||
|
||||
import hippo
|
||||
import gtk
|
||||
|
||||
from sugar.graphics.frame import Frame
|
||||
from sugar.graphics.color import Color
|
||||
|
||||
class Entry(hippo.CanvasBox, hippo.CanvasItem):
|
||||
__gtype_name__ = 'SugarEntry'
|
||||
|
||||
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._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))
|
||||
|
||||
[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,
|
||||
self._radius, math.pi * 1.5, math.pi * 2);
|
||||
cr.arc(x + width - self._radius, x + height - self._radius,
|
||||
self._radius, 0, math.pi * 0.5);
|
||||
cr.arc(x + self._radius, y + height - self._radius,
|
||||
self._radius, math.pi * 0.5, math.pi);
|
||||
cr.arc(x + self._radius, y + self._radius, self._radius,
|
||||
math.pi, math.pi * 1.5);
|
||||
|
||||
cr.set_source_rgba(*self._background_color.get_rgba())
|
||||
cr.fill_preserve();
|
||||
|
||||
def do_allocate(self, width, height, origin_changed):
|
||||
hippo.CanvasBox.do_allocate(self, width, height, origin_changed)
|
||||
|
||||
[width, height] = self._canvas_widget.get_request()
|
||||
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.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.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.emit_paint_needed(0, 0, -1, -1)
|
||||
logging.debug('_entry_focus_out_event_cb')
|
52
tests/test-entry.py
Executable file
52
tests/test-entry.py
Executable file
@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Copyright (C) 2007, One Laptop Per Child
|
||||
#
|
||||
# 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 gtk
|
||||
import hippo
|
||||
|
||||
from sugar.graphics.toolbar import Toolbar
|
||||
from sugar.graphics.frame import Frame
|
||||
from sugar.graphics.button import Button
|
||||
from sugar.graphics.entry import Entry
|
||||
|
||||
window = gtk.Window()
|
||||
window.connect("destroy", lambda w: gtk.main_quit())
|
||||
window.show()
|
||||
|
||||
canvas = hippo.Canvas()
|
||||
window.add(canvas)
|
||||
canvas.show()
|
||||
|
||||
vbox = hippo.CanvasBox()
|
||||
canvas.set_root(vbox)
|
||||
|
||||
toolbar = Toolbar()
|
||||
vbox.append(toolbar)
|
||||
|
||||
frame = Frame()
|
||||
toolbar.append(frame)
|
||||
|
||||
button = Button('theme:stock-close')
|
||||
frame.append(button)
|
||||
|
||||
entry = Entry()
|
||||
toolbar.append(entry, hippo.PACK_EXPAND)
|
||||
|
||||
entry2 = Entry()
|
||||
toolbar.append(entry2, hippo.PACK_EXPAND)
|
||||
|
||||
gtk.main()
|
Loading…
Reference in New Issue
Block a user