Add simple theme support to pick up color themes in the Home Window
This commit is contained in:
parent
1b688469c1
commit
f3435bb914
@ -8,6 +8,8 @@ from sugar.canvas.DonutItem import DonutItem
|
|||||||
from sugar.canvas.DonutItem import PieceItem
|
from sugar.canvas.DonutItem import PieceItem
|
||||||
from sugar.canvas.DonutItem import PieceIcon
|
from sugar.canvas.DonutItem import PieceIcon
|
||||||
|
|
||||||
|
from Theme import Theme
|
||||||
|
|
||||||
class TasksItem(DonutItem):
|
class TasksItem(DonutItem):
|
||||||
def __init__(self, shell):
|
def __init__(self, shell):
|
||||||
DonutItem.__init__(self, 250)
|
DonutItem.__init__(self, 250)
|
||||||
@ -41,16 +43,31 @@ class TasksItem(DonutItem):
|
|||||||
class Background(goocanvas.Group):
|
class Background(goocanvas.Group):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
goocanvas.Group.__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,
|
color = self._theme.get_home_colors()[1]
|
||||||
fill_color="#d8d8d8")
|
self._outer_rect = goocanvas.Rect(width=1200, height=900,
|
||||||
self.add_child(item)
|
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",
|
item = goocanvas.Text(text="My Activities",
|
||||||
x=12, y=12, fill_color="black",
|
x=12, y=12, fill_color="black",
|
||||||
font="Sans 21")
|
font="Sans 21")
|
||||||
self.add_child(item)
|
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):
|
class Model(goocanvas.CanvasModelSimple):
|
||||||
def __init__(self, shell):
|
def __init__(self, shell):
|
||||||
goocanvas.CanvasModelSimple.__init__(self)
|
goocanvas.CanvasModelSimple.__init__(self)
|
||||||
|
41
shell/home/Theme.py
Normal file
41
shell/home/Theme.py
Normal 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]
|
Loading…
Reference in New Issue
Block a user