aboutsummaryrefslogtreecommitdiffstats
path: root/lvc
diff options
context:
space:
mode:
authorJesús Eduardo <heckyel@hyperbola.info>2018-01-14 20:32:36 -0500
committerJesús Eduardo <heckyel@hyperbola.info>2018-01-14 20:32:36 -0500
commit95f84ec255bcfc999bc5d4d37c6f183339117687 (patch)
treed986784ec89e3226c1f7923f237f02bb416b3944 /lvc
parentad9d4dc4282de973b777789972e7014100d83826 (diff)
downloadlibrevideoconverter-95f84ec255bcfc999bc5d4d37c6f183339117687.tar.lz
librevideoconverter-95f84ec255bcfc999bc5d4d37c6f183339117687.tar.xz
librevideoconverter-95f84ec255bcfc999bc5d4d37c6f183339117687.zip
pep8 en lvc/widgets/gtk/layoutmanager.py
Diffstat (limited to 'lvc')
-rw-r--r--lvc/widgets/gtk/layoutmanager.py47
1 files changed, 27 insertions, 20 deletions
diff --git a/lvc/widgets/gtk/layoutmanager.py b/lvc/widgets/gtk/layoutmanager.py
index 8097b2e..e24e09c 100644
--- a/lvc/widgets/gtk/layoutmanager.py
+++ b/lvc/widgets/gtk/layoutmanager.py
@@ -40,7 +40,8 @@ import pango
from lvc import utils
-use_native_buttons = False # not implemented in MVC
+use_native_buttons = False # not implemented in MVC
+
class FontCache(utils.Cache):
def get(self, context, description, scale_factor, bold, italic):
@@ -53,6 +54,7 @@ class FontCache(utils.Cache):
_font_cache = FontCache(512)
+
class LayoutManager(object):
def __init__(self, widget):
self.pango_context = widget.get_pango_context()
@@ -90,7 +92,7 @@ class LayoutManager(object):
def font(self, scale_factor, bold=False, italic=False, family=None):
return _font_cache.get(self.pango_context, self.style_font_desc,
- scale_factor, bold, italic)
+ scale_factor, bold, italic)
def set_font(self, scale_factor, bold=False, italic=False, family=None):
self.current_font = self.font(scale_factor, bold, italic)
@@ -103,24 +105,25 @@ class LayoutManager(object):
def textbox(self, text, underline=False):
textbox = TextBox(self.pango_context, self.current_font,
- self.text_color, self.text_shadow)
+ self.text_color, self.text_shadow)
textbox.set_text(text, underline=underline)
return textbox
def button(self, text, pressed=False, disabled=False, style='normal'):
if style == 'webby':
return StyledButton(text, self.pango_context, self.current_font,
- pressed, disabled)
+ pressed, disabled)
elif use_native_buttons:
return NativeButton(text, self.pango_context, self.current_font,
- pressed, self.style, self.widget)
+ pressed, self.style, self.widget)
else:
return StyledButton(text, self.pango_context, self.current_font,
- pressed)
+ pressed)
def update_cairo_context(self, cairo_context):
cairo_context.update_context(self.pango_context)
+
class Font(object):
def __init__(self, context, style_font_desc, scale, bold, italic):
self.context = context
@@ -150,6 +153,7 @@ class Font(object):
return (pango.PIXELS(metrics.get_ascent()) +
pango.PIXELS(metrics.get_descent()) + 1)
+
class TextBox(object):
def __init__(self, context, font, color, shadow):
self.layout = pango.Layout(context)
@@ -168,7 +172,7 @@ class TextBox(object):
self.append_text(text, font, color, underline)
def append_text(self, text, font=None, color=None, underline=False):
- if text == None:
+ if text is None:
text = u""
startpos = self.text_length
self.text_chunks.append(text)
@@ -182,7 +186,7 @@ class TextBox(object):
def convert(value):
return int(round(value * 65535))
attr = pango.AttrForeground(convert(color[0]), convert(color[1]),
- convert(color[2]), startpos, endpos)
+ convert(color[2]), startpos, endpos)
self.attributes.append(attr)
self.text_set = False
@@ -244,7 +248,7 @@ class TextBox(object):
return -1
chars_per_line = (self.width * pango.SCALE //
- self.font.get_font_metrics().get_approximate_char_width())
+ self.font.get_font_metrics().get_approximate_char_width())
lines_available = self.height // self.font.line_height()
# overestimate these because it's better to have too many characters
# than too little.
@@ -270,17 +274,16 @@ class TextBox(object):
# check that (x, y) is actually inside that char's
# bounding box
char_x, char_y, char_w, char_h = self.layout.index_to_pos(index)
- if char_w > 0: # the glyph is LTR
+ if char_w > 0: # the glyph is LTR
left = char_x
right = char_x + char_w
- else: # the glyph is RTL
+ else: # the glyph is RTL
left = char_x + char_w
right = char_x
if left <= x < right:
return index
return None
-
def draw(self, context, x, y, width, height):
self.set_width(width)
self.set_height(height)
@@ -292,11 +295,12 @@ class TextBox(object):
# draw shadow first so that it's underneath the regular text
# FIXME: we don't use the blur_radius setting
cairo_context.set_source_rgba(self.shadow.color[0],
- self.shadow.color[1], self.shadow.color[2],
- self.shadow.opacity)
+ self.shadow.color[1],
+ self.shadow.color[2],
+ self.shadow.opacity)
self._draw_layout(context, x + self.shadow.offset[0],
- y + self.shadow.offset[1], width, height,
- underline_drawer)
+ y + self.shadow.offset[1], width, height,
+ underline_drawer)
cairo_context.set_source_rgb(*self.color)
self._draw_layout(context, x, y, width, height, underline_drawer)
cairo_context.restore()
@@ -323,6 +327,7 @@ class TextBox(object):
underline_drawer.draw(context, line_x, baseline, line)
line_height = next_line_height
+
class UnderlineDrawer(object):
"""Class to draw our own underlines because cairo's don't look
that great at small fonts. We make sure that the underline is
@@ -363,6 +368,7 @@ class UnderlineDrawer(object):
else:
self.next_underline()
+
class NativeButton(object):
ICON_PAD = 4
@@ -420,7 +426,7 @@ class NativeButton(object):
self.draw_text(context.window, text_x, text_y)
if self.icon:
self.icon.draw(context, icon_x, icon_y, self.icon.width,
- self.icon.height)
+ self.icon.height)
def draw_box(self, window, x, y, width, height):
if self.pressed:
@@ -438,7 +444,7 @@ class NativeButton(object):
widget = self.widget
self.style.paint_box(window, state, shadow, None, widget, "button",
- int(x), int(y), int(width), int(height))
+ int(x), int(y), int(width), int(height))
def draw_text(self, window, x, y):
if self.pressed:
@@ -446,7 +452,8 @@ class NativeButton(object):
else:
state = gtk.STATE_NORMAL
self.style.paint_layout(window, state, True, None, None, None,
- int(x), int(y), self.layout)
+ int(x), int(y), self.layout)
+
class StyledButton(object):
PAD_HORIZONTAL = 4
@@ -538,7 +545,7 @@ class StyledButton(object):
text_x += (self.icon.width + self.ICON_PAD) / 2
icon_y = y + (height - self.icon.height) / 2
self.icon.draw(context, icon_x, icon_y, self.icon.width,
- self.icon.height)
+ self.icon.height)
self.draw_text(context, text_x, text_y, width, height, radius)
def draw_text(self, context, x, y, width, height, radius):