Actually make theme object a singleton

This commit is contained in:
Dan Williams 2006-08-23 08:13:15 -04:00
parent 3b9d3daa3b
commit 4eb5a61276
3 changed files with 13 additions and 4 deletions

View File

@ -5,12 +5,12 @@ import goocanvas
from sugar.canvas.IconItem import IconItem from sugar.canvas.IconItem import IconItem
from sugar.canvas.IconItem import IconColor from sugar.canvas.IconItem import IconColor
from Theme import Theme import Theme
class Model(goocanvas.CanvasModelSimple): class Model(goocanvas.CanvasModelSimple):
def __init__(self, data_model): def __init__(self, data_model):
goocanvas.CanvasModelSimple.__init__(self) goocanvas.CanvasModelSimple.__init__(self)
self._theme = Theme() self._theme = Theme.get_instance()
self._theme.connect("theme-changed", self.__theme_changed_cb) self._theme.connect("theme-changed", self.__theme_changed_cb)
root = self.get_root_item() root = self.get_root_item()

View File

@ -8,7 +8,7 @@ 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 import Theme
class TasksItem(DonutItem): class TasksItem(DonutItem):
def __init__(self, shell): def __init__(self, shell):
@ -43,7 +43,7 @@ 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 = Theme.get_instance()
self._theme.connect("theme-changed", self.__theme_changed_cb) self._theme.connect("theme-changed", self.__theme_changed_cb)
color = self._theme.get_home_colors()[1] color = self._theme.get_home_colors()[1]

View File

@ -39,3 +39,12 @@ class Theme(gobject.GObject):
def get_home_colors(self): def get_home_colors(self):
return self.__colors[self._cur_theme] return self.__colors[self._cur_theme]
# Use this accessor, don't create more than one theme object
_theme = None
def get_instance():
global _theme
if not _theme:
_theme = Theme()
return _theme