Add simple theme support to pick up color themes in the Home Window

This commit is contained in:
Dan Williams 2006-08-23 07:09:10 -04:00
parent 1b688469c1
commit f3435bb914
2 changed files with 61 additions and 3 deletions

View File

@ -8,6 +8,8 @@ from sugar.canvas.DonutItem import DonutItem
from sugar.canvas.DonutItem import PieceItem
from sugar.canvas.DonutItem import PieceIcon
from Theme import Theme
class TasksItem(DonutItem):
def __init__(self, shell):
DonutItem.__init__(self, 250)
@ -41,16 +43,31 @@ class TasksItem(DonutItem):
class Background(goocanvas.Group):
def __init__(self):
goocanvas.Group.__init__(self)
self._theme = Theme()
self._theme.connect("theme-changed", self.__theme_changed_cb)
item = goocanvas.Rect(width=1200, height=900,
fill_color="#d8d8d8")
self.add_child(item)
color = self._theme.get_home_colors()[1]
self._outer_rect = goocanvas.Rect(width=1200, height=900,
fill_color=color)
self.add_child(self._outer_rect)
color = self._theme.get_home_colors()[0]
self._inner_rect = goocanvas.Rect(x=100, y=100, width=1000, height=700,
line_width=0, fill_color=color,
radius_x=30, radius_y=30)
self.add_child(self._inner_rect)
item = goocanvas.Text(text="My Activities",
x=12, y=12, fill_color="black",
font="Sans 21")
self.add_child(item)
def __theme_changed_cb(self, theme, colors):
color = self._theme.get_home_colors()[0]
self._inner_rect.set_property("fill-color", color)
color = self._theme.get_home_colors()[1]
self._outer_rect.set_property("fill-color", color)
class Model(goocanvas.CanvasModelSimple):
def __init__(self, shell):
goocanvas.CanvasModelSimple.__init__(self)

41
shell/home/Theme.py Normal file
View File

@ -0,0 +1,41 @@
import gobject
class Theme(gobject.GObject):
__gsignals__ = {
'theme-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
([]))
}
# from OLPC_PLAN_14.swf
__colors = {
'blue': ("#c7d2fb", "#bbc8fa", "#afbffa"),
'turquoise': ("#c8dce8", "#bdd4e3", "#b1cdde"),
'green': ("#ccebac", "#c1e79a", "#b6e388"),
'tan': ("#e8ead1", "#e4e5c8", "#dfe1be"),
'gray': ("#dbe1dd", "#d3dbd5", "#ccd5ce"),
'dark-gray': ("#dad1d4", "#d2c7cb", "#cabdc2")
}
def __init__(self):
gobject.GObject.__init__(self)
self._cur_theme = 'blue'
def set(self, theme):
updated = False
if type(theme) == type(""):
theme = theme.lower()
if self.__colors.has_key(theme):
self._cur_theme = theme
updated = True
elif type(theme) == type(1):
try:
theme = self.__colors.keys()[theme]
self._cur_theme = theme
updated = True
except IndexError:
pass
if updated:
self.emit('theme-changed')
def get_home_colors(self):
return self.__colors[self._cur_theme]