Skip to content

Commit

Permalink
Merge pull request #2067 from ogayot/urwid-core24-deprecations
Browse files Browse the repository at this point in the history
Fix some deprecation warnings on core24
  • Loading branch information
ogayot authored Aug 30, 2024
2 parents 8aaac20 + 38315ad commit 7090443
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 43 deletions.
4 changes: 2 additions & 2 deletions console_conf/ui/views/chooser.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def __init__(self, controller, systems):
Action(label=act.title.capitalize(), value=act, enabled=True)
)
menu = ActionMenu(actions)
connect_signal(menu, "action", self._system_action, s)
connect_signal(menu, "action", self._system_action, user_args=[s])
srow = make_action_menu_row(
[
Text(s.label),
Expand Down Expand Up @@ -162,7 +162,7 @@ def __init__(self, controller, systems):
),
)

def _system_action(self, sender, action, system):
def _system_action(self, system, sender, action):
self.controller.select(system, action)

def back(self, result):
Expand Down
6 changes: 3 additions & 3 deletions subiquity/ui/views/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def __init__(self, app):
self.report_to_row = {}
self.app.error_reporter.load_reports()
for report in self.app.error_reporter.reports:
connect_signal(report, "changed", self._report_changed, report)
connect_signal(report, "changed", self._report_changed, user_args=[report])
r = self.report_to_row[report] = self.row_for_report(report)
rows.append(r)
self.table = TablePile(rows, colspecs={1: ColSpec(can_shrink=True)})
Expand All @@ -410,7 +410,7 @@ def __init__(self, app):
]
super().__init__("", widgets, 2, 2)

def open_report(self, sender, report):
def open_report(self, report, sender):
self.app.add_global_overlay(ErrorReportStretchy(self.app, report, False))

def state_for_report(self, report):
Expand All @@ -421,7 +421,7 @@ def state_for_report(self, report):
def cells_for_report(self, report):
date = report.pr.get("Date", "???")
icon = ClickableIcon(date)
connect_signal(icon, "click", self.open_report, report)
connect_signal(icon, "click", self.open_report, user_args=[report])
return [
Text("["),
icon,
Expand Down
6 changes: 4 additions & 2 deletions subiquity/ui/views/filesystem/compound.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def _state_change_device(self, sender, state, device):
del self.devices[device]
self._emit("change", self.devices)

def _select_active_spare(self, sender, value, device):
def _select_active_spare(self, device, sender, value):
self.devices[device] = value
self._emit("change", self.devices)

Expand Down Expand Up @@ -151,7 +151,9 @@ def set_bound_form_field(self, bff):
self.all_rows.append(Color.menu_button(TableRow([box, size])))
self.no_selector_rows.append(self.all_rows[-1])
selector = Selector(["active", "spare"])
connect_signal(selector, "select", self._select_active_spare, device)
connect_signal(
selector, "select", self._select_active_spare, user_args=[device]
)
selector = Toggleable(
UrwidPadding(Color.menu_button(selector), left=len(prefix))
)
Expand Down
8 changes: 4 additions & 4 deletions subiquity/ui/views/filesystem/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def __init__(self, parent):
)
super().__init__(self.table)

def _mount_action(self, sender, action, mount):
def _mount_action(self, mount, sender, action):
log.debug("_mount_action %s %s", action, mount)
if action == "unmount":
self.parent.controller.delete_mount(mount)
Expand Down Expand Up @@ -168,7 +168,7 @@ def refresh_model_inputs(self):
]
actions = [(_("Unmount"), mi.mount.can_delete(), "unmount")]
menu = ActionMenu(actions)
connect_signal(menu, "action", self._mount_action, mi.mount)
connect_signal(menu, "action", self._mount_action, user_args=[mi.mount])
cells = [
Text("["),
Text(path_markup),
Expand Down Expand Up @@ -306,7 +306,7 @@ def _disk_TOGGLE_BOOT(self, disk):
lambda parent, gap: PartitionStretchy(parent, gap.device, gap=gap)
)

def _action(self, sender, value, device):
def _action(self, device, sender, value):
action, meth = value
log.debug("_action %s %s", action, device.id)
meth(device)
Expand Down Expand Up @@ -365,7 +365,7 @@ def _action_menu_for_device(self, device):
if not device_actions:
return Text("")
menu = ActionMenu(device_actions)
connect_signal(menu, "action", self._action, device)
connect_signal(menu, "action", self._action, user_args=[device])
return menu

def refresh_model_inputs(self):
Expand Down
2 changes: 1 addition & 1 deletion subiquity/ui/views/installprogress.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def _add_line(self, lb, line):
at_end = len(walker) == 0 or lb.focus_position == len(walker) - 1
walker.append(line)
if at_end:
lb.set_focus(len(walker) - 1)
lb.focus_position = len(walker) - 1
lb.set_focus_valign("bottom")

def event_start(self, context_id, context_parent_id, message):
Expand Down
4 changes: 2 additions & 2 deletions subiquity/ui/views/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,11 @@ def refresh_keys_table(self):
menu,
)
)
connect_signal(menu, "action", self._action, key)
connect_signal(menu, "action", self._action, user_args=[key])

self.keys_table.set_contents(rows)

def _action(self, sender, value, key):
def _action(self, key, sender, value):
if value == "delete":
self.remove_key_from_table(key)
self.refresh_keys_table()
Expand Down
4 changes: 2 additions & 2 deletions subiquity/ui/views/zdev.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async def _zdev_action(self, action, zdevinfo):
self.update(new_zdevinfos)
self.parent.request_redraw_if_visible()

def zdev_action(self, sender, action, zdevinfo):
def zdev_action(self, zdevinfo, sender, action):
run_bg_task(self._zdev_action(action, zdevinfo))

def update(self, zdevinfos):
Expand Down Expand Up @@ -120,7 +120,7 @@ def update(self, zdevinfos):
(_("Disable"), zdevinfo.on, "disable"),
]
menu = ActionMenu(actions)
connect_signal(menu, "action", self.zdev_action, zdevinfo)
connect_signal(menu, "action", self.zdev_action, user_args=[zdevinfo])
cells = [
Text(zdevinfo.id),
status(zdevinfo),
Expand Down
2 changes: 1 addition & 1 deletion subiquitycore/controllers/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ async def _answers_action(self, action):
table = self._action_get(action["obj"])
meth = getattr(self.ui.body, "_action_{}".format(action["action"]))
action_obj = getattr(NetDevAction, action["action"])
self.ui.body._action(None, (action_obj, meth), table)
self.ui.body._action(table, None, (action_obj, meth))
yield
body = self.ui.body._w
if action["action"] == "DELETE":
Expand Down
10 changes: 6 additions & 4 deletions subiquitycore/ui/actionmenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import attr
from urwid import (
ACTIVATE,
AttrWrap,
AttrMap,
Button,
LineBox,
PopUpLauncher,
Expand Down Expand Up @@ -63,7 +63,9 @@ def __init__(self, parent):
else:
btn = Color.menu_button(ActionMenuButton(action.label))
width = max(width, len(btn.base_widget.label))
connect_signal(btn.base_widget, "click", self.click, action.value)
connect_signal(
btn.base_widget, "click", self.click, user_args=[action.value]
)
else:
label = action.label
if isinstance(label, Widget):
Expand All @@ -81,15 +83,15 @@ def __init__(self, parent):
],
dividechars=1,
)
btn = AttrWrap(btn, "info_minor")
btn = AttrMap(btn, "info_minor")
group.append(btn)
self.width = width
super().__init__(Color.body(LineBox(ListBox(group))))

def close(self, sender):
self.parent.close_pop_up()

def click(self, btn, value):
def click(self, value, btn):
self.parent._action(value)
self.parent.close_pop_up()

Expand Down
27 changes: 13 additions & 14 deletions subiquitycore/ui/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ def _select_first_selectable(self):
"""Select first selectable child (possibily recursively)."""
for i, (w, o) in enumerate(self.contents):
if w.selectable():
self.set_focus(i)
self.focus_position = i
_maybe_call(w, "_select_first_selectable")
return

def _select_last_selectable(self):
"""Select last selectable child (possibily recursively)."""
for i, (w, o) in reversed(list(enumerate(self.contents))):
if w.selectable():
self.set_focus(i)
self.focus_position = i
_maybe_call(w, "_select_last_selectable")
return

Expand Down Expand Up @@ -189,7 +189,7 @@ def keypress(self, size, key):
next_fp = self.focus_position + 1
for i, (w, o) in enumerate(self._contents[next_fp:], next_fp):
if w.selectable():
self.set_focus(i)
self.focus_position = i
_maybe_call(w, "_select_first_selectable")
return
if not key.endswith(" no wrap"):
Expand All @@ -199,7 +199,7 @@ def keypress(self, size, key):
positions = self._contents[: self.focus_position]
for i, (w, o) in reversed(list(enumerate(positions))):
if w.selectable():
self.set_focus(i)
self.focus_position = i
_maybe_call(w, "_select_last_selectable")
return
if not key.endswith(" no wrap"):
Expand Down Expand Up @@ -265,15 +265,15 @@ def _select_first_selectable(self):
"""Select first selectable child (possibily recursively)."""
for i, (w, o) in enumerate(self.contents):
if w.selectable():
self.set_focus(i)
self.focus_position = i
_maybe_call(w, "_select_first_selectable")
return

def _select_last_selectable(self):
"""Select last selectable child (possibily recursively)."""
for i, (w, o) in reversed(list(enumerate(self.contents))):
if w.selectable():
self.set_focus(i)
self.focus_position = i
_maybe_call(w, "_select_last_selectable")
return

Expand All @@ -289,14 +289,14 @@ def __init__(self, body):
super().__init__(body)

def _set_focus_no_move(self, i):
# We call set_focus twice because otherwise the listbox
# attempts to do the minimal amount of scrolling required to
# We set the focus_position property twice because otherwise the
# listbox attempts to do the minimal amount of scrolling required to
# get the new focus widget into view, which is not what we
# want, as if our first widget is a compound widget it results
# its last widget being focused -- in fact the opposite of
# what we want!
self.set_focus(i)
self.set_focus(i)
self.focus_position = i
self.focus_position = i
# I don't really understand why this is required but it seems it is.
self._invalidate()

Expand Down Expand Up @@ -334,7 +334,7 @@ def keypress(self, size, key):
next_fp = self.focus_position + 1
for i, w in enumerate(self.body[next_fp:], next_fp):
if w.selectable():
self.set_focus(i)
self.focus_position = i
_maybe_call(w, "_select_first_selectable")
return None
if not key.endswith(" no wrap"):
Expand All @@ -344,7 +344,7 @@ def keypress(self, size, key):
positions = self.body[: self.focus_position]
for i, w in reversed(list(enumerate(positions))):
if w.selectable():
self.set_focus(i)
self.focus_position = i
_maybe_call(w, "_select_last_selectable")
return None
if not key.endswith(" no wrap"):
Expand Down Expand Up @@ -465,12 +465,11 @@ def render(self, size, focus=False):

seen_focus = False
height = height_before_focus = 0
focus_widget, focus_pos = lb.body.get_focus()
# Scan through the rows calculating total height and the
# height of the rows before the focus widget.
for widget in lb.body:
rows = widget.rows((maxcol - 1,))
if widget is focus_widget:
if widget is lb.focus:
seen_focus = True
elif not seen_focus:
height_before_focus += rows
Expand Down
12 changes: 6 additions & 6 deletions subiquitycore/ui/selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from urwid import ACTIVATE, AttrWrap, CompositeCanvas, LineBox
from urwid import ACTIVATE, AttrMap, CompositeCanvas, LineBox
from urwid import Padding as UrwidPadding
from urwid import PopUpLauncher, Text, connect_signal

Expand Down Expand Up @@ -60,7 +60,7 @@ def __init__(self, parent, cur_index):
for i, option in enumerate(self.parent._options):
if option.enabled:
btn = ClickableThing(option.label)
connect_signal(btn, "click", self.click, i)
connect_signal(btn, "click", self.click, user_args=[i])
if i == cur_index:
rhs = "\N{BLACK LEFT-POINTING SMALL TRIANGLE} "
else:
Expand All @@ -76,16 +76,16 @@ def __init__(self, parent, cur_index):
]
)
if option.enabled:
row = AttrWrap(row, "menu_button", "menu_button focus")
row = AttrMap(row, "menu_button", "menu_button focus")
else:
row = AttrWrap(row, "info_minor")
row = AttrMap(row, "info_minor")
btn = UrwidPadding(row, width=self.parent._padding.width)
group.append(btn)
list_box = ListBox(group)
list_box.base_widget.focus_position = cur_index
super().__init__(Color.body(LineBox(list_box)))

def click(self, btn, index):
def click(self, index, btn):
self.parent.index = index
self.parent.close_pop_up()

Expand Down Expand Up @@ -162,7 +162,7 @@ class Selector(WidgetWrap):
def __init__(self, opts, index=0):
self._icon = ClickableThing(Text(""))
self._padding = UrwidPadding(
AttrWrap(
AttrMap(
Columns(
[
(1, Text("[")),
Expand Down
4 changes: 2 additions & 2 deletions subiquitycore/ui/views/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def _create(self):
actions.append((action.str(), True, (action, meth), opens_dialog))

menu = ActionMenu(actions)
connect_signal(menu, "action", self.parent._action, self)
connect_signal(menu, "action", self.parent._action, user_args=[self])

trows = [
make_action_menu_row(
Expand Down Expand Up @@ -344,7 +344,7 @@ def _action_DELETE(self, name, dev_info):
self.controller.delete_link(dev_info.name)
self.del_link(dev_info)

def _action(self, sender, action, netdev_table):
def _action(self, netdev_table, sender, action):
action, meth = action
dev_info = netdev_table.dev_info
meth("{}/{}".format(dev_info.name, action.name), dev_info)
Expand Down

0 comments on commit 7090443

Please sign in to comment.