pep8 fixes for subiquitycore/ui/container.py

This commit is contained in:
Ryan Harper 2018-05-22 11:33:55 -05:00
parent 2d6cca8281
commit 860edbc7b5
1 changed files with 52 additions and 34 deletions

View File

@ -14,26 +14,28 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This is adapted from
# https://github.com/pimutils/khal/commit/bd7c5f928a7670de9afae5657e66c6dc846688ac, which has this license:
# https://github.com/pimutils/khal/commit/bd7c5f928a7670de9afae5657e66c6dc846688ac # noqa
#
#
# Copyright (c) 2013-2015 Christian Geier et al.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to
# deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR OPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
"""Extended versions of urwid containers.
@ -107,7 +109,6 @@ def _has_other_selectable(widgets, cur_focus):
return False
for key, command in list(urwid.command_map._command.items()):
if command in ('next selectable', 'prev selectable', urwid.ACTIVATE):
urwid.command_map[key + ' no wrap'] = command
@ -149,7 +150,7 @@ class TabCyclingPile(urwid.Pile):
# reason we can't do this via simple subclassing is the need to
# call _select_{first,last}_selectable on the newly focused
# element when the focus changes.
def keypress(self, size, key ):
def keypress(self, size, key):
"""Pass the keypress to the widget in focus.
Unhandled 'up' and 'down' keys may cause a focus change."""
if not self.contents:
@ -157,7 +158,9 @@ class TabCyclingPile(urwid.Pile):
# start subiquity change: new code
downkey = key
if not key.endswith(' no wrap') and self._command_map[key] in ('next selectable', 'prev selectable'):
if not key.endswith(' no wrap') and (self._command_map[key] in
('next selectable',
'prev selectable')):
if _has_other_selectable(self._widgets(), self.focus_position):
downkey += ' no wrap'
# end subiquity change
@ -169,9 +172,12 @@ class TabCyclingPile(urwid.Pile):
i = self.focus_position
if self.selectable():
tsize = self.get_item_size(size, i, True, item_rows)
# start subiquity change: pass downkey to focus, not key, do not return if command_map[upkey] is next/prev selectable
# start subiquity change: pass downkey to focus, not key,
# do not return if command_map[upkey] is next/prev selectable
upkey = self.focus.keypress(tsize, downkey)
if self._command_map[upkey] not in ('cursor up', 'cursor down', 'next selectable', 'prev selectable'):
if self._command_map[upkey] not in ('cursor up', 'cursor down',
'next selectable',
'prev selectable'):
return upkey
# end subiquity change
@ -187,7 +193,8 @@ class TabCyclingPile(urwid.Pile):
self._select_first_selectable()
return key
elif self._command_map[key] == 'prev selectable':
for i, (w, o) in reversed(list(enumerate(self._contents[:self.focus_position]))):
positions = self._contents[:self.focus_position]
for i, (w, o) in reversed(list(enumerate(positions))):
if w.selectable():
self.set_focus(i)
_maybe_call(w, "_select_last_selectable")
@ -238,14 +245,15 @@ class TabCyclingPile(urwid.Pile):
class OneSelectableColumns(urwid.Columns):
def __init__(self, widget_list, dividechars=0, focus_column=None,
min_width=1, box_columns=None):
super().__init__(widget_list, dividechars, focus_column, min_width, box_columns)
super().__init__(widget_list, dividechars, focus_column,
min_width, box_columns)
selectables = 0
for w, o in self._contents:
if w.selectable():
selectables +=1
selectables += 1
if selectables > 1:
raise Exception("subiquity only supports one selectable in a Columns")
raise Exception(
"subiquity only supports one selectable in a Columns")
class TabCyclingListBox(urwid.ListBox):
@ -288,7 +296,9 @@ class TabCyclingListBox(urwid.ListBox):
def keypress(self, size, key):
downkey = key
if not key.endswith(' no wrap') and self._command_map[key] in ('next selectable', 'prev selectable'):
if not key.endswith(' no wrap') and (self._command_map[key] in
('next selectable',
'prev selectable')):
if _has_other_selectable(self.body, self.focus_position):
downkey += ' no wrap'
upkey = super().keypress(size, downkey)
@ -309,7 +319,8 @@ class TabCyclingListBox(urwid.ListBox):
self._select_first_selectable()
return key
elif self._command_map[key] == 'prev selectable':
for i, w in reversed(list(enumerate(self.body[:self.focus_position]))):
positions = self.body[:self.focus_position]
for i, w in reversed(list(enumerate(positions))):
if w.selectable():
self.set_focus(i)
_maybe_call(w, "_select_last_selectable")
@ -352,6 +363,7 @@ class FocusTrackingMixin:
class FocusTrackingPile(FocusTrackingMixin, TabCyclingPile):
pass
class FocusTrackingColumns(FocusTrackingMixin, OneSelectableColumns):
pass
@ -386,6 +398,7 @@ class FocusTrackingListBox(TabCyclingListBox):
Columns = FocusTrackingColumns
Pile = FocusTrackingPile
class ScrollBarListBox(urwid.WidgetDecoration):
def __init__(self, lb):
@ -396,9 +409,11 @@ class ScrollBarListBox(urwid.WidgetDecoration):
f("\N{FULL BLOCK}", 'scrollbar_fg'),
]
self.bar = Pile([
('weight', 1, f("\N{BOX DRAWINGS LIGHT VERTICAL}", 'scrollbar_bg')),
('weight', 1, f("\N{BOX DRAWINGS LIGHT VERTICAL}",
'scrollbar_bg')),
('weight', 1, self.boxes[0]),
('weight', 1, f("\N{BOX DRAWINGS LIGHT VERTICAL}", 'scrollbar_bg')),
('weight', 1, f("\N{BOX DRAWINGS LIGHT VERTICAL}",
'scrollbar_bg')),
])
super().__init__(lb)
@ -418,7 +433,9 @@ class ScrollBarListBox(urwid.WidgetDecoration):
# case for all the listboxes we have in subiquity today.
maxcol, maxrow = size
offset, inset = self.original_widget.get_focus_offset_inset((maxcol - 1, maxrow))
offset, inset = (
self.original_widget.get_focus_offset_inset((maxcol - 1,
maxrow)))
seen_focus = False
height = height_before_focus = 0
@ -464,7 +481,8 @@ class ScrollBarListBox(urwid.WidgetDecoration):
(self.bar.contents[2][0], self.bar.options('weight', bottom)),
]
canvases = [
(self.original_widget.render((maxcol - 1, maxrow), focus), self.original_widget.focus_position, True, maxcol - 1),
(self.original_widget.render((maxcol - 1, maxrow), focus),
self.original_widget.focus_position, True, maxcol - 1),
(self.bar.render((1, maxrow)), None, False, 1)
]
return urwid.CanvasJoin(canvases)