[pitivi] ui.common: check in code for manipulating color values
- From: Edward Hervey <edwardrv src gnome org>
- To: svn-commits-list gnome org
- Subject: [pitivi] ui.common: check in code for manipulating color values
- Date: Thu, 30 Apr 2009 12:19:40 -0400 (EDT)
commit 968568ff0f86bc41360833d385591c35cb2a6d60
Author: Brandon Lewis <brandon lewis berkeley edu>
Date: Wed Apr 29 21:39:51 2009 -0700
ui.common: check in code for manipulating color values
---
pitivi/settings.py | 2 +-
pitivi/ui/common.py | 39 +++++++++++++++++++++++++++++++++++++++
pitivi/ui/dynamic.py | 36 +++++++++++++++---------------------
3 files changed, 55 insertions(+), 22 deletions(-)
diff --git a/pitivi/settings.py b/pitivi/settings.py
index d877707..3902fff 100644
--- a/pitivi/settings.py
+++ b/pitivi/settings.py
@@ -165,7 +165,7 @@ class GlobalSettings(object, Signallable):
if not self._config.has_section(section):
continue
if key and self._config.has_option(section, key):
- if typ == int:
+ if typ == int or typ == long:
value = self._config.getint(section, key)
elif typ == float:
value = self._config.getfloat(section, key)
diff --git a/pitivi/ui/common.py b/pitivi/ui/common.py
index f8b8d1d..e56ac3f 100644
--- a/pitivi/ui/common.py
+++ b/pitivi/ui/common.py
@@ -1,7 +1,46 @@
from pitivi.settings import GlobalSettings
+import cairo
GlobalSettings.addConfigSection("user-interface")
LAYER_HEIGHT_EXPANDED = 50
LAYER_HEIGHT_COLLAPSED = 15
LAYER_SPACING = 5
TRACK_SPACING = 5
+
+def pack_color_32(red, green, blue, alpha = 0xFFFF):
+ red = red >> 8
+ green = green >> 8
+ blue = blue >> 8
+ alpha = alpha >> 8
+ return (red << 24 | green << 16 | blue << 8 | alpha)
+
+def pack_color_64(red, green, blue, alpha = 0xFFFF):
+ return (red << 48 | green << 32 | blue << 16 | alpha)
+
+def unpack_color(value):
+ if not (value >> 32):
+ return unpack_color_32(value)
+ else:
+ return unpack_color_64(value)
+
+def unpack_color_32(value):
+ red = (value >> 24); red = red | red << 8
+ green = (value >> 16) & 0xFF; green = green | green << 8
+ blue = (value >> 8) & 0xFF; blue = blue | blue << 8
+ alpha = value & 0xFF; alpha = alpha | alpha << 8
+ return red, green, blue, alpha
+
+def unpack_color_64(value):
+ red = (value >> 48) & 0xFFFF
+ green = (value >> 32) & 0xFFFF
+ blue = (value >> 16) & 0xFFFF
+ alpha = value & 0xFFFF
+ return red, green, blue, alpha
+
+def unpack_cairo_pattern(value):
+ red, green, blue, alpha = unpack_color(value)
+ return cairo.SolidPattern(
+ red / 65535.0,
+ green / 65535.0,
+ blue / 65535.0,
+ alpha / 65535.0)
diff --git a/pitivi/ui/dynamic.py b/pitivi/ui/dynamic.py
index 441f23e..b6521a2 100644
--- a/pitivi/ui/dynamic.py
+++ b/pitivi/ui/dynamic.py
@@ -28,6 +28,7 @@ import gtk
import re
import sys
from gettext import gettext as _
+from pitivi.ui.common import unpack_color, pack_color_32, pack_color_64
class DynamicWidget(object):
@@ -138,10 +139,10 @@ class NumericWidget(gtk.HBox):
self.pack_end(self.slider)
self.slider.show()
- if not upper:
- upper = float("Infinity")
- if not lower:
- lower = float("-Infinity")
+ if upper is None:
+ upper = gobject.G_MAXDOUBLE
+ if lower is None:
+ lower = gobject.G_MINDOUBLE
self.adjustment.props.lower = lower
self.adjustment.props.upper = upper
self.spinner = gtk.SpinButton(self.adjustment)
@@ -162,12 +163,12 @@ class NumericWidget(gtk.HBox):
step = 1.0
page = 10.0
elif type_ == float:
- minimum, maximum = (float("-Infinity"), float("Infinity"))
+ minimum, maximum = (gobject.G_MINDOUBLE, gobject.G_MAXDOUBLE)
step = 0.00001
page = 0.01
- if self.lower:
+ if self.lower is not None:
minimum = self.lower
- if self.upper:
+ if self.upper is not None:
maximum = self.upper
self.adjustment.set_all(value, minimum, maximum, step, page, 0)
self.spinner.props.climb_rate = 0.01 * abs(min(maximum, 1000) -
@@ -266,14 +267,11 @@ class ColorWidget(gtk.ColorButton):
def setWidgetValue(self, value):
type_ = type(value)
alpha = 0xFFFF
+
if type_ is str:
- color = gtk.Color(value)
- elif type_ is int:
- # FIXME: only handles 32-bit case
- red = (value >> 24); red = red | red << 8
- green = (value >> 16) & 0xFF; green = green | green << 8
- blue = (value >> 8) & 0xFF; blue = blue | blue << 8
- alpha = value & 0xFF; alpha = alpha | alpha << 8
+ color = gtk.gdk.Color(value)
+ elif (type_ is int) or (type_ is long):
+ red, green, blue, alpha = unpack_color(value)
color = gtk.gdk.Color(red, green, blue)
elif type_ is gtk.gdk.Color:
color = value
@@ -287,13 +285,9 @@ class ColorWidget(gtk.ColorButton):
color = self.get_color()
alpha = self.get_alpha()
if self.value_type is int:
- # FIXME: only handles 32-bit case
- red = color.red >> 8
- green = color.green >> 8
- blue = color.blue >> 8
- alpha = alpha >> 8
- ret = (red << 24 | green << 16 | blue << 8 | alpha)
- return ret
+ return pack_color_32(color.red, color.green, color.blue, alpha)
+ if self.value_type is long:
+ return pack_color_64(color.red, color.green, color.blue, alpha)
elif self.value_type is gtk.gdk.Color:
return color
return color.to_string()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]