diff options
author | Jesús Eduardo <heckyel@hyperbola.info> | 2018-01-13 21:03:13 -0500 |
---|---|---|
committer | Jesús Eduardo <heckyel@hyperbola.info> | 2018-01-13 21:03:13 -0500 |
commit | 584e3522df80c3c631fa6b5e40e46cb2b6560b6c (patch) | |
tree | cb92d7d1d6abf5478812ed310622d57cacd28aba | |
parent | 463be01df9b46fb7cc2679aaa047a081ec5c11ee (diff) | |
download | librevideoconverter-584e3522df80c3c631fa6b5e40e46cb2b6560b6c.tar.lz librevideoconverter-584e3522df80c3c631fa6b5e40e46cb2b6560b6c.tar.xz librevideoconverter-584e3522df80c3c631fa6b5e40e46cb2b6560b6c.zip |
pep8 en lvc/widgets/osx/layout.py
-rw-r--r-- | lvc/widgets/osx/layout.py | 121 |
1 files changed, 76 insertions, 45 deletions
diff --git a/lvc/widgets/osx/layout.py b/lvc/widgets/osx/layout.py index f18a47f..0048689 100644 --- a/lvc/widgets/osx/layout.py +++ b/lvc/widgets/osx/layout.py @@ -59,6 +59,7 @@ NSScrollerKnobStyleLight = 2 NSScrollerStyleLegacy = 0 NSScrollerStyleOverlay = 1 + def _extra_space_iter(extra_length, count): """Utility function to allocate extra space left over in containers.""" if count == 0: @@ -71,6 +72,7 @@ def _extra_space_iter(extra_length, count): while True: yield extra_space + class BoxPacking: """Utility class to store how we are packing a single widget.""" @@ -79,6 +81,7 @@ class BoxPacking: self.expand = expand self.padding = padding + class Box(Container): """Base class for HBox and VBox. """ CREATES_VIEW = False @@ -152,7 +155,7 @@ class Box(Container): self.translate_widget_size(packing.widget) length += child_length if packing.padding: - length += packing.padding * 2 # Need to pad on both sides + length += packing.padding * 2 # Need to pad on both sides breadth = max(breadth, child_breadth) spaces = max(0, len(self.packing_start) + len(self.packing_end) - 1) length += spaces * self.spacing @@ -164,23 +167,24 @@ class Box(Container): total_length, dummy = self.translate_size((ps.width, ps.height)) total_extra_space = total_length - request_length extra_space_iter = _extra_space_iter(total_extra_space, - self.expand_count) + self.expand_count) start_end = self._place_packing_list(self.packing_start, - extra_space_iter, 0) + extra_space_iter, 0) if self.expand_count == 0 and total_extra_space > 0: # account for empty space after the end of pack_start list and # before the pack_end list. self.draw_empty_space(start_end, total_extra_space) start_end += total_extra_space self._place_packing_list(reversed(self.packing_end), extra_space_iter, - start_end) + start_end) def draw_empty_space(self, start, length): empty_rect = self.make_child_rect(start, length) my_view = self.viewport.view opaque_view = my_view.opaqueAncestor() if opaque_view is not None: - empty_rect2 = opaque_view.convertRect_fromView_(empty_rect, my_view) + empty_rect2 = opaque_view.convertRect_fromView_(empty_rect, + my_view) opaque_view.setNeedsDisplayInRect_(empty_rect2) def _place_packing_list(self, packing_list, extra_space_iter, position): @@ -189,11 +193,11 @@ class Box(Container): self.translate_widget_size(packing.widget) if packing.expand: child_length += extra_space_iter.next() - if packing.padding: # space before + if packing.padding: # space before self.draw_empty_space(position, packing.padding) position += packing.padding child_rect = self.make_child_rect(position, child_length) - if packing.padding: # space after + if packing.padding: # space after self.draw_empty_space(position, packing.padding) position += packing.padding packing.widget.place(child_rect, self.viewport.view) @@ -213,8 +217,10 @@ class Box(Container): for mem in self.children: mem.disable() + class VBox(Box): - """See https://develop.participatoryculture.org/index.php/WidgetAPI for a description of the API for this class.""" + """See https://develop.participatoryculture.org/index.php/WidgetAPI + for a description of the API for this class.""" def translate_size(self, size): return (size[1], size[0]) @@ -224,10 +230,12 @@ class VBox(Box): def make_child_rect(self, position, length): placement = self.viewport.placement return NSMakeRect(placement.origin.x, placement.origin.y + position, - placement.size.width, length) + placement.size.width, length) + class HBox(Box): - """See https://develop.participatoryculture.org/index.php/WidgetAPI for a description of the API for this class.""" + """See https://develop.participatoryculture.org/index.php/WidgetAPI + for a description of the API for this class.""" def translate_size(self, size): return (size[0], size[1]) @@ -237,14 +245,16 @@ class HBox(Box): def make_child_rect(self, position, length): placement = self.viewport.placement return NSMakeRect(placement.origin.x + position, placement.origin.y, - length, placement.size.height) + length, placement.size.height) + class Alignment(Bin): - """See https://develop.participatoryculture.org/index.php/WidgetAPI for a description of the API for this class.""" + """See https://develop.participatoryculture.org/index.php/WidgetAPI + for a description of the API for this class.""" CREATES_VIEW = False def __init__(self, xalign=0.0, yalign=0.0, xscale=0.0, yscale=0.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): Bin.__init__(self) self.xalign = xalign self.yalign = yalign @@ -304,23 +314,28 @@ class Alignment(Bin): total_height -= self.vertical_pad() request_width, request_height = self.child.get_size_request() - child_width = self.calc_size(request_width, total_width, self.xscale) - child_height = self.calc_size(request_height, total_height, self.yscale) + child_width = self.calc_size(request_width, total_width, + self.xscale) + child_height = self.calc_size(request_height, total_height, + self.yscale) child_x = self.calc_position(child_width, total_width, self.xalign) child_y = self.calc_position(child_height, total_height, self.yalign) child_x += self.left_pad child_y += self.top_pad my_origin = self.viewport.area().origin - child_rect = NSMakeRect(my_origin.x + child_x, my_origin.y + child_y, child_width, child_height) + child_rect = NSMakeRect(my_origin.x + child_x, my_origin.y + child_y, + child_width, child_height) self.child.place(child_rect, self.viewport.view) # Make sure the space not taken up by our child is redrawn. self.viewport.queue_redraw() + class DetachedWindowHolder(Alignment): def __init__(self): Alignment.__init__(self, bottom_pad=16, xscale=1.0, yscale=1.0) + class _TablePacking(object): """Utility class to help with packing Table widgets.""" def __init__(self, widget, column, row, column_span, row_span): @@ -336,14 +351,16 @@ class _TablePacking(object): def row_indexes(self): return range(self.row, self.row + self.row_span) + class Table(Container): - """See https://develop.participatoryculture.org/index.php/WidgetAPI for a description of the API for this class.""" + """See https://develop.participatoryculture.org/index.php/WidgetAPI + for a description of the API for this class.""" CREATES_VIEW = False def __init__(self, columns, rows): Container.__init__(self) self._cells = Matrix(columns, rows) - self._children = [] # List of _TablePacking objects + self._children = [] # List of _TablePacking objects self._children_sorted = True self.rows = rows self.columns = columns @@ -373,15 +390,15 @@ class Table(Container): child_width, child_height = tp.widget.get_size_request() # recalc the width of the child's columns self._recalc_dimension(child_width, self.column_widths, - tp.column_indexes()) + tp.column_indexes()) # recalc the height of the child's rows self._recalc_dimension(child_height, self.row_heights, - tp.row_indexes()) + tp.row_indexes()) self.total_width = (self.column_spacing * (self.columns - 1) + - sum(self.column_widths)) + sum(self.column_widths)) self.total_height = (self.row_spacing * (self.rows - 1) + - sum(self.row_heights)) + sum(self.row_heights)) def _recalc_dimension(self, child_size, size_array, positions): current_size = sum(size_array[p] for p in positions) @@ -398,12 +415,13 @@ class Table(Container): self.get_size_request() column_positions = [0] for width in self.column_widths[:-1]: - column_positions.append(width + column_positions[-1] + self.column_spacing) + column_positions.append(width + column_positions[-1] + + self.column_spacing) row_positions = [0] for height in self.row_heights[:-1]: row_positions.append(height + row_positions[-1] + self.row_spacing) - my_x= self.viewport.placement.origin.x + my_x = self.viewport.placement.origin.x my_y = self.viewport.placement.origin.y for tp in self._children: x = my_x + column_positions[tp.column] @@ -444,33 +462,40 @@ class Table(Container): def enable(self, row=None, column=None): Container.enable(self) - if row != None and column != None: + if row is not None and column is not None: if self._cells[column, row]: self._cells[column, row].enable() - elif row != None: + elif row is not None: for mem in self._cells.row(row): - if mem: mem.enable() - elif column != None: + if mem: + mem.enable() + elif column is not None: for mem in self._cells.column(column): - if mem: mem.enable() + if mem: + mem.enable() else: for mem in self._cells: - if mem: mem.enable() + if mem: + mem.enable() def disable(self, row=None, column=None): Container.disable(self) - if row != None and column != None: + if row is not None and column is not None: if self._cells[column, row]: self._cells[column, row].disable() - elif row != None: + elif row is not None: for mem in self._cells.row(row): - if mem: mem.disable() - elif column != None: + if mem: + mem.disable() + elif column is not None: for mem in self._cells.column(column): - if mem: mem.disable() + if mem: + mem.disable() else: for mem in self._cells: - if mem: mem.disable() + if mem: + mem.disable() + class MiroScrollView(NSScrollView): def tile(self): @@ -483,8 +508,10 @@ class MiroScrollView(NSScrollView): if wrapper is not None: wrapper.invalidate_size_request() + class Scroller(Bin): - """See https://develop.participatoryculture.org/index.php/WidgetAPI for a description of the API for this class.""" + """See https://develop.participatoryculture.org/index.php/WidgetAPI + for a description of the API for this class.""" def __init__(self, horizontal, vertical): Bin.__init__(self) self.view = MiroScrollView.alloc().init() @@ -567,8 +594,9 @@ class Scroller(Bin): child_width, child_height = self.child.get_size_request() child_width = max(child_width, scroll_view_size.width) child_height = max(child_height, scroll_view_size.height) - frame = NSRect(NSPoint(0,0), NSSize(child_width, child_height)) - if isinstance(self.child, tableview.TableView) and self.child.is_showing_headers(): + frame = NSRect(NSPoint(0, 0), NSSize(child_width, child_height)) + if isinstance(self.child, tableview.TableView) and \ + self.child.is_showing_headers(): # Hack to allow the content of a table view to scroll, but not # the headers self.child.place(frame, self.document_view) @@ -581,6 +609,7 @@ class Scroller(Bin): self.view.setNeedsDisplay_(YES) self.child.emit('place-in-scroller') + class ExpanderView(FlippedView): def init(self): self = super(ExpanderView, self).init() @@ -616,6 +645,7 @@ class ExpanderView(FlippedView): self.button.setNextState() self.buttonChanged_(self.button) + class Expander(Bin): BUTTON_PAD_TOP = 2 BUTTON_PAD_LEFT = 4 @@ -630,7 +660,7 @@ class Expander(Bin): self.view = ExpanderView.alloc().init() self.button = self.view.button self.button.setFrameOrigin_(NSPoint(self.BUTTON_PAD_LEFT, - self.BUTTON_PAD_TOP)) + self.BUTTON_PAD_TOP)) self.content_view = self.view.content_view def remove_viewport(self): @@ -680,15 +710,15 @@ class Expander(Bin): button_width = self.button.bounds().size.width label_x = self.BUTTON_PAD_LEFT + button_width + self.LABEL_SPACING label_rect = NSMakeRect(label_x, self.BUTTON_PAD_TOP, - label_width, label_height) + label_width, label_height) self.label.place(label_rect, self.viewport.view) self.view.label_rect = label_rect if self.child: size = self.viewport.area().size child_rect = NSMakeRect(0, 0, size.width, size.height - - top_height) + top_height) self.content_view.setFrame_(NSMakeRect(0, top_height, size.width, - size.height - top_height)) + size.height - top_height)) self.child.place(child_rect, self.content_view) @@ -697,10 +727,11 @@ class TabViewDelegate(NSObject): try: wrapper = wrappermap.wrapper(tab_view) except KeyError: - pass # The NSTabView hasn't been placed yet, don't worry about it. + pass # The NSTabView hasn't been placed yet, don't worry about it. else: wrapper.place_child_with_item(tab_view_item) + class TabContainer(Container): def __init__(self): Container.__init__(self) @@ -729,7 +760,7 @@ class TabContainer(Container): def place_child_with_item(self, tab_view_item): child = self.item_to_child[tab_view_item] child_view = tab_view_item.view() - content_rect =self.view.contentRect() + content_rect = self.view.contentRect() child_view.setFrame_(content_rect) child.place(child_view.bounds(), child_view) |