1
0
mirror of https://github.com/ihabunek/toot.git synced 2024-11-03 04:17:21 -05:00

Added framework for action buttons with "Confirm/Cancel" behavior

Buttons with confirm/cancel behavior are in place and working
TBD: implement actions when user gives confirmation.
This commit is contained in:
Daniel Schwarz 2023-02-03 21:28:18 -05:00 committed by Ivan Habunek
parent a1490461bd
commit 876ad1f53d
No known key found for this signature in database
GPG Key ID: F5F0623FF5EBCB3D
2 changed files with 52 additions and 19 deletions

View File

@ -1,12 +0,0 @@
from os import getenv
def initialize_debugger():
import multiprocessing
if multiprocessing.current_process().pid > 1:
import debugpy
debugpy.listen(("0.0.0.0", 9000))
print("VSCode Debugger is ready to be attached on port 9000, press F5", flush=True)
debugpy.wait_for_client()
print("VSCode Debugger is now attached", flush=True)

View File

@ -206,17 +206,32 @@ class Help(urwid.Padding):
class Account(urwid.ListBox):
"""Shows account data and provides various actions"""
def __init__(self, account, relationship):
actions = list(self.generate_contents(account, relationship))
self.last_action = None
self.account = account
self.relationship = relationship
self.setup_listbox()
def setup_listbox(self):
actions = list(self.generate_contents(self.account, self.relationship, self.last_action))
walker = urwid.SimpleListWalker(actions)
super().__init__(walker)
def generate_contents(self, account, relationship):
if relationship['requested']:
yield urwid.Text(("light grey", "< Follow request is pending >"))
def generate_contents(self, account, relationship=None, last_action=None):
if self.last_action and not self.last_action.startswith("Confirm"):
yield Button(f"Confirm {self.last_action}", on_press=take_action, user_data=self)
yield Button("Cancel", on_press=cancel_action, user_data=self)
else:
yield Button("Unfollow" if relationship['following'] else "Follow")
yield Button("Unmute" if relationship['muting'] else "Mute")
yield Button("Unblock" if relationship['blocking'] else "Block")
if relationship['requested']:
yield urwid.Text(("light grey", "< Follow request is pending >"))
else:
yield Button("Unfollow" if relationship['following'] else "Follow",
on_press=confirm_action, user_data=self)
yield Button("Unmute" if relationship['muting'] else "Mute",
on_press=confirm_action, user_data=self)
yield Button("Unblock" if relationship['blocking'] else "Block",
on_press=confirm_action, user_data=self)
yield urwid.Divider("")
yield urwid.Divider()
yield urwid.Text([('green', f"@{account['acct']}"), f" {account['display_name']}"])
@ -265,6 +280,36 @@ class Account(urwid.ListBox):
yield link("", account["url"])
def take_action(button: Button, self: Account):
action = button.get_label()
if action == "Confirm Follow":
pass
elif action == "Confirm Unfollow":
pass
elif action == "Confirm Mute":
pass
elif action == "Confirm Unmute":
pass
elif action == "Confirm Block":
pass
elif action == "Confirm Unblock":
pass
self.last_action = None
self.setup_listbox()
def confirm_action(button: Button, self: Account):
self.last_action = button.get_label()
self.setup_listbox()
def cancel_action(button: Button, self: Account):
self.last_action = None
self.setup_listbox()
def link(text, url):
attr_map = {"link": "link_focused"}
text = SelectableText([text, ("link", url)])