aboutsummaryrefslogtreecommitdiffstats
path: root/lvc
diff options
context:
space:
mode:
authorJesús Eduardo <heckyel@hyperbola.info>2018-01-14 12:11:42 -0500
committerJesús Eduardo <heckyel@hyperbola.info>2018-01-14 12:11:42 -0500
commit0b5b789b596a5194c00a1e4b33afec8c876e6176 (patch)
tree699bf37ea82b402845a3d4f7d69deb108085acde /lvc
parent584e3522df80c3c631fa6b5e40e46cb2b6560b6c (diff)
downloadlibrevideoconverter-0b5b789b596a5194c00a1e4b33afec8c876e6176.tar.lz
librevideoconverter-0b5b789b596a5194c00a1e4b33afec8c876e6176.tar.xz
librevideoconverter-0b5b789b596a5194c00a1e4b33afec8c876e6176.zip
pep8 en lvc/widgets/osx/layoutmanager.py
C: 49, 0: Line too long (200/100) (line-too-long) C: 66, 0: Line too long (104/100) (line-too-long) C:302, 0: Line too long (151/100) (line-too-long)
Diffstat (limited to 'lvc')
-rw-r--r--lvc/widgets/osx/layoutmanager.py57
1 files changed, 42 insertions, 15 deletions
diff --git a/lvc/widgets/osx/layoutmanager.py b/lvc/widgets/osx/layoutmanager.py
index de4301b..cbc5e41 100644
--- a/lvc/widgets/osx/layoutmanager.py
+++ b/lvc/widgets/osx/layoutmanager.py
@@ -40,14 +40,17 @@ from objc import YES, NO, nil
import drawing
-INFINITE = 1000000 # size of an "infinite" dimension
+INFINITE = 1000000 # size of an "infinite" dimension
+
class MiroLayoutManager(NSLayoutManager):
"""Overide NSLayoutManager to draw better underlines."""
def drawUnderlineForGlyphRange_underlineType_baselineOffset_lineFragmentRect_lineFragmentGlyphRange_containerOrigin_(self, glyph_range, typ, offset, line_rect, line_glyph_range, container_origin):
container, _ = self.textContainerForGlyphAtIndex_effectiveRange_(glyph_range.location, None)
- rect = self.boundingRectForGlyphRange_inTextContainer_(glyph_range, container)
+ rect = \
+ self.boundingRectForGlyphRange_inTextContainer_(glyph_range,
+ container)
x = container_origin.x + rect.origin.x
y = (container_origin.y + rect.origin.y + rect.size.height - offset)
underline_height, offset = self.calc_underline_extents(glyph_range)
@@ -68,6 +71,7 @@ class MiroLayoutManager(NSLayoutManager):
offset = max(1.0, round(0.1 * height))
return height, offset
+
class TextBoxPool(object):
"""Handles a pool of TextBox objects. We monitor the TextBox objects and
when those objects die, we reclaim them for the pool.
@@ -100,6 +104,7 @@ class TextBoxPool(object):
text_box_pool = TextBoxPool()
+
class Font(object):
line_height_sizer = NSLayoutManager.alloc().init()
@@ -115,6 +120,7 @@ class Font(object):
def line_height(self):
return Font.line_height_sizer.defaultLineHeightForFont_(self.nsfont)
+
class FontPool(object):
def __init__(self):
self._cached_fonts = {}
@@ -149,6 +155,7 @@ class FontPool(object):
nsfont = NSFont.systemFontOfSize_(size)
return Font(nsfont)
+
class LayoutManager(object):
font_pool = FontPool()
default_font = font_pool.get(1.0, False, False, None)
@@ -172,7 +179,11 @@ class LayoutManager(object):
def textbox(self, text, underline=False):
text_box = text_box_pool.get()
- color = NSColor.colorWithDeviceRed_green_blue_alpha_(self.text_color[0], self.text_color[1], self.text_color[2], 1.0)
+ color = \
+ NSColor.colorWithDeviceRed_green_blue_alpha_(self.text_color[0],
+ self.text_color[1],
+ self.text_color[2],
+ 1.0)
text_box.reset(text, self.current_font, color, self.shadow, underline)
return text_box
@@ -188,6 +199,7 @@ class LayoutManager(object):
self.text_color = (0, 0, 0)
self.shadow = None
+
class TextBox(object):
def __init__(self):
self.layout_manager = MiroLayoutManager.alloc().init()
@@ -201,8 +213,7 @@ class TextBox(object):
def reset(self, text, font, color, shadow, underline):
"""Reset the text box so it's ready to be used by a new owner."""
- self.text_storage.deleteCharactersInRange_(NSRange(0,
- self.text_storage.length()))
+ self.text_storage.deleteCharactersInRange_(NSRange(0, self.text_storage.length()))
self.text_container.setContainerSize_(NSSize(INFINITE, INFINITE))
self.paragraph_style = NSMutableParagraphStyle.alloc().init()
self.font = font
@@ -214,17 +225,24 @@ class TextBox(object):
def make_attr_string(self, text, color, font, underline):
attributes = NSMutableDictionary.alloc().init()
if color is not None:
- nscolor = NSColor.colorWithDeviceRed_green_blue_alpha_(color[0], color[1], color[2], 1.0)
- attributes.setObject_forKey_(nscolor, NSForegroundColorAttributeName)
+ nscolor = NSColor.colorWithDeviceRed_green_blue_alpha_(color[0],
+ color[1],
+ color[2],
+ 1.0)
+ attributes.setObject_forKey_(nscolor,
+ NSForegroundColorAttributeName)
else:
- attributes.setObject_forKey_(self.color, NSForegroundColorAttributeName)
+ attributes.setObject_forKey_(self.color,
+ NSForegroundColorAttributeName)
if font is not None:
attributes.setObject_forKey_(font.nsfont, NSFontAttributeName)
else:
attributes.setObject_forKey_(self.font.nsfont, NSFontAttributeName)
if underline:
- attributes.setObject_forKey_(NSUnderlineStyleSingle, NSUnderlineStyleAttributeName)
- attributes.setObject_forKey_(self.paragraph_style.copy(), NSParagraphStyleAttributeName)
+ attributes.setObject_forKey_(NSUnderlineStyleSingle,
+ NSUnderlineStyleAttributeName)
+ attributes.setObject_forKey_(self.paragraph_style.copy(),
+ NSParagraphStyleAttributeName)
if text is None:
text = ""
return NSAttributedString.alloc().initWithString_attributes_(text, attributes)
@@ -289,7 +307,8 @@ class TextBox(object):
def draw(self, context, x, y, width, height):
if self.shadow is not None:
context.save()
- context.set_shadow(self.shadow.color, self.shadow.opacity, self.shadow.offset, self.shadow.blur_radius)
+ context.set_shadow(self.shadow.color, self.shadow.opacity,
+ self.shadow.offset, self.shadow.blur_radius)
self.width = width
self.text_container.setContainerSize_(NSSize(width, height))
glyph_range = self.layout_manager.glyphRangeForTextContainer_(self.text_container)
@@ -298,6 +317,7 @@ class TextBox(object):
context.restore()
context.path.removeAllPoints()
+
class NativeButton(object):
def __init__(self, text, font, pressed, disabled=False):
@@ -330,6 +350,7 @@ class NativeButton(object):
NSGraphicsContext.currentContext().restoreGraphicsState()
context.path.removeAllPoints()
+
class StyledButton(object):
PAD_HORIZONTAL = 11
BIG_PAD_VERTICAL = 4
@@ -352,7 +373,10 @@ class StyledButton(object):
color = self.DISABLED_TEXT_COLOR
else:
color = self.TEXT_COLOR
- nscolor = NSColor.colorWithDeviceRed_green_blue_alpha_(color[0], color[1], color[2], 1.0)
+ nscolor = NSColor.colorWithDeviceRed_green_blue_alpha_(color[0],
+ color[1],
+ color[2],
+ 1.0)
attributes.setObject_forKey_(nscolor, NSForegroundColorAttributeName)
self.title = NSAttributedString.alloc().initWithString_attributes_(text, attributes)
self.image = None
@@ -407,16 +431,19 @@ class StyledButton(object):
inner_width = width - radius * 2
context.move_to(x + radius, y)
context.rel_line_to(inner_width, 0)
- context.arc(x + width - radius, y+radius, radius, -math.pi/2, math.pi/2)
+ context.arc(x + width - radius,
+ y+radius, radius, -math.pi/2, math.pi/2)
context.rel_line_to(-inner_width, 0)
context.arc(x + radius, y+radius, radius, math.pi/2, -math.pi/2)
def _draw_path_reverse(self, context, x, y, width, height, radius):
inner_width = width - radius * 2
context.move_to(x + radius, y)
- context.arc_negative(x + radius, y+radius, radius, -math.pi/2, math.pi/2)
+ context.arc_negative(x + radius,
+ y+radius, radius, -math.pi/2, math.pi/2)
context.rel_line_to(inner_width, 0)
- context.arc_negative(x + width - radius, y+radius, radius, math.pi/2, -math.pi/2)
+ context.arc_negative(x + width - radius,
+ y+radius, radius, math.pi/2, -math.pi/2)
context.rel_line_to(-inner_width, 0)
def _draw_border(self, context, x, y, width, height, radius):