aboutsummaryrefslogtreecommitdiffstats
path: root/lvc
diff options
context:
space:
mode:
Diffstat (limited to 'lvc')
-rw-r--r--lvc/widgets/widgetutil.py33
1 files changed, 26 insertions, 7 deletions
diff --git a/lvc/widgets/widgetutil.py b/lvc/widgets/widgetutil.py
index 861ed5f..bd3783a 100644
--- a/lvc/widgets/widgetutil.py
+++ b/lvc/widgets/widgetutil.py
@@ -2,6 +2,7 @@ from math import pi as PI
from lvc.widgets import widgetset
from lvc.resources import image_path
+
def make_surface(image_name, height=None):
path = image_path(image_name + '.png')
image = widgetset.Image(path)
@@ -9,6 +10,7 @@ def make_surface(image_name, height=None):
image = image.resize(image.width, height)
return widgetset.ImageSurface(image)
+
def font_scale_from_osx_points(points):
"""Create a font scale so that it's points large on OS X.
@@ -18,59 +20,69 @@ def font_scale_from_osx_points(points):
"""
return points / 13.0
+
def css_to_color(css_string):
parts = (css_string[1:3], css_string[3:5], css_string[5:7])
return tuple((int(value, 16) / 255.0) for value in parts)
+
def align(widget, xalign=0, yalign=0, xscale=0, yscale=0,
- top_pad=0, bottom_pad=0, left_pad=0, right_pad=0):
+ top_pad=0, bottom_pad=0, left_pad=0, right_pad=0):
"""Create an alignment, then add widget to it and return the alignment.
"""
alignment = widgetset.Alignment(xalign, yalign, xscale, yscale,
- top_pad, bottom_pad, left_pad, right_pad)
+ top_pad, bottom_pad, left_pad, right_pad)
alignment.add(widget)
return alignment
+
def align_center(widget, top_pad=0, bottom_pad=0, left_pad=0, right_pad=0):
"""Wrap a widget in an Alignment that will center it horizontally.
"""
return align(widget, 0.5, 0, 0, 1,
- top_pad, bottom_pad, left_pad, right_pad)
+ top_pad, bottom_pad, left_pad, right_pad)
+
def align_right(widget, top_pad=0, bottom_pad=0, left_pad=0, right_pad=0):
"""Wrap a widget in an Alignment that will align it left.
"""
return align(widget, 1, 0, 0, 1, top_pad, bottom_pad, left_pad, right_pad)
+
def align_left(widget, top_pad=0, bottom_pad=0, left_pad=0, right_pad=0):
"""Wrap a widget in an Alignment that will align it right.
"""
return align(widget, 0, 0, 0, 1, top_pad, bottom_pad, left_pad, right_pad)
+
def align_middle(widget, top_pad=0, bottom_pad=0, left_pad=0, right_pad=0):
"""Wrap a widget in an Alignment that will center it vertically.
"""
return align(widget, 0, 0.5, 1, 0,
- top_pad, bottom_pad, left_pad, right_pad)
+ top_pad, bottom_pad, left_pad, right_pad)
+
def align_top(widget, top_pad=0, bottom_pad=0, left_pad=0, right_pad=0):
"""Wrap a widget in an Alignment that will align to the top.
"""
return align(widget, 0, 0, 1, 0, top_pad, bottom_pad, left_pad, right_pad)
+
def align_bottom(widget, top_pad=0, bottom_pad=0, left_pad=0, right_pad=0):
"""Wrap a widget in an Alignment that will align to the bottom.
"""
return align(widget, 0, 1, 1, 0, top_pad, bottom_pad, left_pad, right_pad)
+
def pad(widget, top=0, bottom=0, left=0, right=0):
"""Wrap a widget in an Alignment that will pad it.
"""
alignment = widgetset.Alignment(0, 0, 1, 1,
- top, bottom, left, right)
+ top, bottom, left, right)
alignment.add(widget)
return alignment
+
def round_rect(context, x, y, width, height, edge_radius):
"""Specifies path of a rectangle with rounded corners.
"""
@@ -92,6 +104,7 @@ def round_rect(context, x, y, width, height, edge_radius):
context.rel_line_to(0, -inner_height)
context.arc(x_inner1, y_inner1, edge_radius, PI, PI*3/2)
+
def round_rect_reverse(context, x, y, width, height, edge_radius):
"""Specifies path of a rectangle with rounded corners.
@@ -115,6 +128,7 @@ def round_rect_reverse(context, x, y, width, height, edge_radius):
context.arc_negative(x_inner2, y_inner1, edge_radius, 0, -PI/2)
context.rel_line_to(-inner_width, 0)
+
def circular_rect(context, x, y, width, height):
"""Make a path for a rectangle with the left/right side being circles.
"""
@@ -130,6 +144,7 @@ def circular_rect(context, x, y, width, height):
context.rel_line_to(-inner_width, 0)
context.arc(inner_x1, inner_y, radius, PI/2, -PI/2)
+
def circular_rect_negative(context, x, y, width, height):
"""The same path as ``circular_rect()``, but going counter clockwise.
"""
@@ -145,6 +160,7 @@ def circular_rect_negative(context, x, y, width, height):
context.arc_negative(inner_x2, inner_y, radius, PI/2, -PI/2)
context.rel_line_to(-inner_width, 0)
+
class Shadow(object):
"""Encapsulates all parameters required to draw shadows.
"""
@@ -154,6 +170,7 @@ class Shadow(object):
self.offset = offset
self.blur_radius = blur_radius
+
class ThreeImageSurface(object):
"""Takes a left, center and right image and draws them to an arbitrary
width. If the width is greater than the combined width of the 3 images,
@@ -213,7 +230,8 @@ class ThreeImageSurface(object):
def draw(self, context, x, y, width, fraction=1.0):
left_width = min(self.left.width, width)
self.left.draw(context, x, y, left_width, self.height, fraction)
- self.draw_right(context, x + left_width, y, width - left_width, fraction)
+ self.draw_right(context, x + left_width,
+ y, width - left_width, fraction)
def draw_right(self, context, x, y, width, fraction=1.0):
# draws only the right two images
@@ -222,4 +240,5 @@ class ThreeImageSurface(object):
center_width = int(width - right_width)
self.center.draw(context, x, y, center_width, self.height, fraction)
- self.right.draw(context, x + center_width, y, right_width, self.height, fraction)
+ self.right.draw(context, x + center_width,
+ y, right_width, self.height, fraction)