mirror of
https://github.com/rr-/pq-cli.git
synced 2026-09-28 22:33:59 -06:00
ui: use custom button
This commit is contained in:
@@ -17,11 +17,18 @@ urwid.command_map["H"] = "cursor left"
|
|||||||
urwid.command_map["l"] = "cursor right"
|
urwid.command_map["l"] = "cursor right"
|
||||||
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:
|
class Ui:
|
||||||
def __init__(self, roster: Roster) -> None:
|
def __init__(self, roster: Roster) -> None:
|
||||||
self.roster = roster
|
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.old_view: T.Optional[urwid.Widget] = None
|
||||||
|
|
||||||
self.switch_to_roster_view()
|
self.switch_to_roster_view()
|
||||||
|
|||||||
@@ -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,6 +3,7 @@ import typing as T
|
|||||||
import urwid
|
import urwid
|
||||||
|
|
||||||
from pqcli.game_state import Roster
|
from pqcli.game_state import Roster
|
||||||
|
from pqcli.ui.button import MenuButton
|
||||||
|
|
||||||
|
|
||||||
class ExitView(urwid.Overlay):
|
class ExitView(urwid.Overlay):
|
||||||
@@ -13,8 +14,8 @@ class ExitView(urwid.Overlay):
|
|||||||
self.on_cancel = on_cancel
|
self.on_cancel = on_cancel
|
||||||
|
|
||||||
question = urwid.Text(("bold", "Really quit?"), "center")
|
question = urwid.Text(("bold", "Really quit?"), "center")
|
||||||
yes_btn = urwid.Button("Yes", lambda _user_data: self.on_exit())
|
yes_btn = MenuButton("Yes", lambda _user_data: self.on_exit())
|
||||||
no_btn = urwid.Button("No", lambda _user_data: self.on_cancel())
|
no_btn = MenuButton("No", lambda _user_data: self.on_cancel())
|
||||||
|
|
||||||
line_box = urwid.LineBox(
|
line_box = urwid.LineBox(
|
||||||
urwid.ListBox(
|
urwid.ListBox(
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import urwid_readline
|
|||||||
|
|
||||||
from pqcli.game_state import Player, StatsBuilder, generate_name, create_player
|
from pqcli.game_state import Player, StatsBuilder, generate_name, create_player
|
||||||
from pqcli.config import RACES, CLASSES, PRIME_STATS
|
from pqcli.config import RACES, CLASSES, PRIME_STATS
|
||||||
|
from pqcli.ui.button import MenuButton
|
||||||
|
|
||||||
|
|
||||||
class StatsGroupBox(urwid.Pile):
|
class StatsGroupBox(urwid.Pile):
|
||||||
@@ -16,8 +17,8 @@ class StatsGroupBox(urwid.Pile):
|
|||||||
self.total_label = urwid.Text("0")
|
self.total_label = urwid.Text("0")
|
||||||
self.update_values()
|
self.update_values()
|
||||||
|
|
||||||
roll_button = urwid.Button("Roll", on_press=self.on_roll_press)
|
roll_button = MenuButton("Roll", on_press=self.on_roll_press)
|
||||||
unroll_button = urwid.Button("Unroll", on_press=self.on_unroll_press)
|
unroll_button = MenuButton("Unroll", on_press=self.on_unroll_press)
|
||||||
|
|
||||||
value_texts = list(self.stat_labels.values()) + [self.total_label]
|
value_texts = list(self.stat_labels.values()) + [self.total_label]
|
||||||
label_texts = [
|
label_texts = [
|
||||||
@@ -87,8 +88,8 @@ class NewGameView(urwid.Pile):
|
|||||||
self.char_name_edit = urwid_readline.ReadlineEdit(
|
self.char_name_edit = urwid_readline.ReadlineEdit(
|
||||||
"Name: ", self.player.name
|
"Name: ", self.player.name
|
||||||
)
|
)
|
||||||
generate_char_name_btn = urwid.Button(
|
generate_char_name_btn = MenuButton(
|
||||||
"?", on_press=self.on_generate_char_name_press
|
"Generate", on_press=self.on_generate_char_name_press
|
||||||
)
|
)
|
||||||
|
|
||||||
urwid.connect_signal(
|
urwid.connect_signal(
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import typing as T
|
|||||||
import urwid
|
import urwid
|
||||||
|
|
||||||
from pqcli.game_state import Roster
|
from pqcli.game_state import Roster
|
||||||
|
from pqcli.ui.button import MenuButton
|
||||||
|
|
||||||
|
|
||||||
class RosterView(urwid.ListBox):
|
class RosterView(urwid.ListBox):
|
||||||
@@ -24,7 +25,7 @@ class RosterView(urwid.ListBox):
|
|||||||
buttons = []
|
buttons = []
|
||||||
for player in self.roster.players:
|
for player in self.roster.players:
|
||||||
buttons.append(
|
buttons.append(
|
||||||
urwid.Button(
|
MenuButton(
|
||||||
label=player.name,
|
label=player.name,
|
||||||
on_press=self.on_resume_game_press,
|
on_press=self.on_resume_game_press,
|
||||||
user_data=player.name,
|
user_data=player.name,
|
||||||
@@ -32,12 +33,12 @@ class RosterView(urwid.ListBox):
|
|||||||
)
|
)
|
||||||
|
|
||||||
buttons.append(
|
buttons.append(
|
||||||
urwid.Button(
|
MenuButton(
|
||||||
label="Create a new character", on_press=self.on_new_game_press
|
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__(
|
super().__init__(
|
||||||
[
|
[
|
||||||
|
|||||||
Reference in New Issue
Block a user