diff --git a/sugar/graphics/Makefile.am b/sugar/graphics/Makefile.am index 62bd573a..d0d04aeb 100644 --- a/sugar/graphics/Makefile.am +++ b/sugar/graphics/Makefile.am @@ -4,7 +4,6 @@ sugar_PYTHON = \ bubble.py \ button.py \ canvasicon.py \ - color.py \ ClipboardBubble.py \ entry.py \ frame.py \ diff --git a/sugar/graphics/color.py b/sugar/graphics/color.py deleted file mode 100644 index 19e105e6..00000000 --- a/sugar/graphics/color.py +++ /dev/null @@ -1,76 +0,0 @@ -import gtk - -_system_colors = { - 'toolbar-background' : '#414141', - 'frame-border' : '#D1D1D2', - 'entry-background-focused' : '#FFFFFF', - 'entry-background-unfocused' : '#414141', - 'entry-selection-focused' : '#D1D1D2', - 'entry-selection-unfocused' : '#00FF00', - 'entry-text-focused' : '#000000', - 'entry-text-unfocused' : '#FFFFFF', - 'entry-border' : '#D1D1D2', - 'label-text' : '#FFFFFF', - 'desktop-background' : '#E2E2E3' -} - -def _html_to_rgb(html_color): - """ #RRGGBB -> (r, g, b) tuple (in float format) """ - - html_color = html_color.strip() - if html_color[0] == '#': - html_color = html_color[1:] - if len(html_color) != 6: - raise ValueError, "input #%s is not in #RRGGBB format" % html_color - - r, g, b = html_color[:2], html_color[2:4], html_color[4:] - r, g, b = [int(n, 16) for n in (r, g, b)] - r, g, b = (r / 255.0, g / 255.0, b / 255.0) - - return (r, g, b) - -def _rgba_to_int(r, g, b, a): - color = int(a * 255) + (int(b * 255) << 8) + \ - (int(g * 255) << 16) + (int(r * 255) << 24) - return color - -class RGBColor(object): - def __init__(self, r, g, b, a=1.0): - self._r = r - self._g = g - self._b = b - self._a = a - - def get_rgba(self): - return (self._r, self._g, self._b, self._a) - - 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]) - RGBColor.__init__(self, *rgb) - -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') - ENTRY_TEXT_FOCUSED = SystemColor('entry-text-focused') - ENTRY_TEXT_UNFOCUSED = SystemColor('entry-text-unfocused') - ENTRY_BORDER = SystemColor('entry-border') - LABEL_TEXT = SystemColor('label-text') - DESKTOP_BACKGROUND = SystemColor('desktop-background') diff --git a/sugar/graphics/entry.py b/sugar/graphics/entry.py index 9f67d1ba..62c1551b 100644 --- a/sugar/graphics/entry.py +++ b/sugar/graphics/entry.py @@ -23,7 +23,7 @@ import hippo import pango from sugar.graphics import style -from sugar.graphics.color import Color +from sugar.graphics.style import Color from sugar.graphics.button import Button from sugar.graphics.roundbox import RoundBox diff --git a/sugar/graphics/frame.py b/sugar/graphics/frame.py index 9bf96410..16ad76c9 100644 --- a/sugar/graphics/frame.py +++ b/sugar/graphics/frame.py @@ -15,7 +15,7 @@ # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. -from sugar.graphics.color import Color +from sugar.graphics.style import Color from sugar.graphics.roundbox import RoundBox class Frame(RoundBox): diff --git a/sugar/graphics/label.py b/sugar/graphics/label.py index 08deff3e..deb3762a 100644 --- a/sugar/graphics/label.py +++ b/sugar/graphics/label.py @@ -25,7 +25,7 @@ import pango from sugar.graphics import style from sugar.graphics.roundbox import RoundBox from sugar.graphics.button import Button -from sugar.graphics.color import Color +from sugar.graphics.style import Color class Label(hippo.CanvasBox, hippo.CanvasItem): __gtype_name__ = 'SugarLabel' diff --git a/sugar/graphics/roundbox.py b/sugar/graphics/roundbox.py index 5b89b779..b9580dec 100644 --- a/sugar/graphics/roundbox.py +++ b/sugar/graphics/roundbox.py @@ -20,7 +20,7 @@ import math import hippo from sugar.graphics import style -from sugar.graphics.color import Color +from sugar.graphics.style import Color class RoundBox(hippo.CanvasBox, hippo.CanvasItem): __gtype_name__ = 'SugarRoundBox' diff --git a/sugar/graphics/style.py b/sugar/graphics/style.py index d1dffdad..730f795e 100644 --- a/sugar/graphics/style.py +++ b/sugar/graphics/style.py @@ -14,10 +14,88 @@ # 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 logging import gtk +_system_colors = { + 'toolbar-background' : '#414141', + 'frame-border' : '#D1D1D2', + 'entry-background-focused' : '#FFFFFF', + 'entry-background-unfocused' : '#414141', + 'entry-selection-focused' : '#D1D1D2', + 'entry-selection-unfocused' : '#00FF00', + 'entry-text-focused' : '#000000', + 'entry-text-unfocused' : '#FFFFFF', + 'entry-border' : '#D1D1D2', + 'label-text' : '#FFFFFF', + 'desktop-background' : '#E2E2E3' +} + +def _html_to_rgb(html_color): + """ #RRGGBB -> (r, g, b) tuple (in float format) """ + + html_color = html_color.strip() + if html_color[0] == '#': + html_color = html_color[1:] + if len(html_color) != 6: + raise ValueError, "input #%s is not in #RRGGBB format" % html_color + + r, g, b = html_color[:2], html_color[2:4], html_color[4:] + r, g, b = [int(n, 16) for n in (r, g, b)] + r, g, b = (r / 255.0, g / 255.0, b / 255.0) + + return (r, g, b) + +def _rgba_to_int(r, g, b, a): + color = int(a * 255) + (int(b * 255) << 8) + \ + (int(g * 255) << 16) + (int(r * 255) << 24) + return color + +class RGBColor(object): + def __init__(self, r, g, b, a=1.0): + self._r = r + self._g = g + self._b = b + self._a = a + + def get_rgba(self): + return (self._r, self._g, self._b, self._a) + + 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]) + RGBColor.__init__(self, *rgb) + +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') + ENTRY_TEXT_FOCUSED = SystemColor('entry-text-focused') + ENTRY_TEXT_UNFOCUSED = SystemColor('entry-text-unfocused') + ENTRY_BORDER = SystemColor('entry-border') + LABEL_TEXT = SystemColor('label-text') + DESKTOP_BACKGROUND = SystemColor('desktop-background') + +### Deprecated: we should drop this once we removed stylesheets ### + _styles = {} screen_factor = gtk.gdk.screen_width() / 1200.0 diff --git a/tests/test-entry.py b/tests/test-entry.py index cdc89d66..7c4ac06c 100755 --- a/tests/test-entry.py +++ b/tests/test-entry.py @@ -22,7 +22,7 @@ from sugar.graphics.toolbar import Toolbar from sugar.graphics.frame import Frame from sugar.graphics.button import Button from sugar.graphics.entry import Entry -from sugar.graphics.color import Color +from sugar.graphics.style import Color def _entry_activated_cb(entry): print "_entry_activated_cb" diff --git a/tests/test-label.py b/tests/test-label.py index fd6b8410..890a528a 100755 --- a/tests/test-label.py +++ b/tests/test-label.py @@ -21,7 +21,7 @@ import hippo from sugar.graphics.toolbar import Toolbar from sugar.graphics.label import Label from sugar.graphics.button import Button -from sugar.graphics.color import Color +from sugar.graphics.style import Color BUTTON_DELETE = 1