ui: use custom button

This commit is contained in:
rr-
2018-11-05 21:04:39 +01:00
parent 7a1febe16e
commit cbc7a1a6d7
5 changed files with 31 additions and 10 deletions
+8 -1
View File
@@ -17,11 +17,18 @@ urwid.command_map["H"] = "cursor left"
urwid.command_map["l"] = "cursor right"
urwid.command_map["L"] = "cursor right"
PALETTE: T.List[T.Tuple[str]] = [
("button", "", ""),
("button-focus", "black", "light red"),
]
class Ui:
def __init__(self, roster: Roster) -> None:
self.roster = roster
self.loop = urwid.MainLoop(None, unhandled_input=self.unhandled_input)
self.loop = urwid.MainLoop(
None, PALETTE, unhandled_input=self.unhandled_input
)
self.old_view: T.Optional[urwid.Widget] = None
self.switch_to_roster_view()
+11
View File
@@ -0,0 +1,11 @@
import urwid
class MenuButton(urwid.Button):
def __init__(self, label, *args, **kwargs):
super().__init__("", *args, **kwargs)
self._w = urwid.AttrMap(
urwid.SelectableIcon(["\N{BULLET} ", label], 2),
"button",
"button-focus",
)
+3 -2
View File
@@ -3,6 +3,7 @@ import typing as T
import urwid
from pqcli.game_state import Roster
from pqcli.ui.button import MenuButton
class ExitView(urwid.Overlay):
@@ -13,8 +14,8 @@ class ExitView(urwid.Overlay):
self.on_cancel = on_cancel
question = urwid.Text(("bold", "Really quit?"), "center")
yes_btn = urwid.Button("Yes", lambda _user_data: self.on_exit())
no_btn = urwid.Button("No", lambda _user_data: self.on_cancel())
yes_btn = MenuButton("Yes", lambda _user_data: self.on_exit())
no_btn = MenuButton("No", lambda _user_data: self.on_cancel())
line_box = urwid.LineBox(
urwid.ListBox(
+5 -4
View File
@@ -6,6 +6,7 @@ import urwid_readline
from pqcli.game_state import Player, StatsBuilder, generate_name, create_player
from pqcli.config import RACES, CLASSES, PRIME_STATS
from pqcli.ui.button import MenuButton
class StatsGroupBox(urwid.Pile):
@@ -16,8 +17,8 @@ class StatsGroupBox(urwid.Pile):
self.total_label = urwid.Text("0")
self.update_values()
roll_button = urwid.Button("Roll", on_press=self.on_roll_press)
unroll_button = urwid.Button("Unroll", on_press=self.on_unroll_press)
roll_button = MenuButton("Roll", on_press=self.on_roll_press)
unroll_button = MenuButton("Unroll", on_press=self.on_unroll_press)
value_texts = list(self.stat_labels.values()) + [self.total_label]
label_texts = [
@@ -87,8 +88,8 @@ class NewGameView(urwid.Pile):
self.char_name_edit = urwid_readline.ReadlineEdit(
"Name: ", self.player.name
)
generate_char_name_btn = urwid.Button(
"?", on_press=self.on_generate_char_name_press
generate_char_name_btn = MenuButton(
"Generate", on_press=self.on_generate_char_name_press
)
urwid.connect_signal(
+4 -3
View File
@@ -3,6 +3,7 @@ import typing as T
import urwid
from pqcli.game_state import Roster
from pqcli.ui.button import MenuButton
class RosterView(urwid.ListBox):
@@ -24,7 +25,7 @@ class RosterView(urwid.ListBox):
buttons = []
for player in self.roster.players:
buttons.append(
urwid.Button(
MenuButton(
label=player.name,
on_press=self.on_resume_game_press,
user_data=player.name,
@@ -32,12 +33,12 @@ class RosterView(urwid.ListBox):
)
buttons.append(
urwid.Button(
MenuButton(
label="Create a new character", on_press=self.on_new_game_press
)
)
buttons.append(urwid.Button(label="Exit", on_press=self.on_exit_press))
buttons.append(MenuButton(label="Exit", on_press=self.on_exit_press))
super().__init__(
[