mirror of
https://github.com/ihabunek/toot
synced 2024-12-23 23:52:40 +01: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:
parent
a1490461bd
commit
876ad1f53d
@ -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)
|
@ -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)])
|
||||
|
Loading…
Reference in New Issue
Block a user