mirror of
https://github.com/rr-/pq-cli.git
synced 2026-09-29 06:44:00 -06:00
misc: improve mypy health
This commit is contained in:
@@ -7,11 +7,12 @@ from pqcli.mechanic import Player, Simulation
|
||||
from pqcli.roster import Roster
|
||||
from pqcli.ui.curses.event_handler import EventHandler
|
||||
from pqcli.ui.curses.util import KEYS_DOWN, KEYS_LEFT, KEYS_RIGHT, KEYS_UP
|
||||
from pqcli.ui.curses.views.base_view import BaseView
|
||||
from pqcli.ui.curses.widgets import Scrollable, Widget
|
||||
|
||||
from ..base_view import BaseView
|
||||
from .character_sheet_window import CharacterSheetWindow
|
||||
from .equipment_window import EquipmentWindow
|
||||
from .focusable import Focusable
|
||||
from .inventory_window import InventoryWindow
|
||||
from .plot_window import PlotWindow
|
||||
from .quest_book_window import QuestBookWindow
|
||||
@@ -186,14 +187,16 @@ class GameView(BaseView):
|
||||
x=0,
|
||||
)
|
||||
|
||||
self._children: T.List[Widget] = [
|
||||
self._focusable_children: T.List[Focusable] = [
|
||||
self._char_sheet_win,
|
||||
self._spell_book_win,
|
||||
self._equipment_win,
|
||||
self._inventory_win,
|
||||
self._plot_win,
|
||||
self._quest_book_win,
|
||||
self._task_win,
|
||||
]
|
||||
self._children: T.List[Widget] = self._focusable_children + [
|
||||
self._task_win
|
||||
]
|
||||
|
||||
def stop(self) -> None:
|
||||
@@ -213,12 +216,12 @@ class GameView(BaseView):
|
||||
curses.doupdate()
|
||||
|
||||
@property
|
||||
def focused(self) -> Widget:
|
||||
for widget in self._children:
|
||||
def focused(self) -> Focusable:
|
||||
for widget in self._focusable_children:
|
||||
if widget.focused:
|
||||
return widget
|
||||
return None
|
||||
raise AssertionError
|
||||
|
||||
def focus(self, widget: Widget):
|
||||
def focus(self, widget: Focusable) -> None:
|
||||
self.focused.focused = False
|
||||
widget.focused = True
|
||||
|
||||
@@ -47,7 +47,7 @@ class EquipmentWindow(Focusable, WindowWrapper):
|
||||
if not self._win:
|
||||
return
|
||||
|
||||
with self._focus_standout(self._win):
|
||||
with self.focus_standout(self._win):
|
||||
self._win.box()
|
||||
text = " Equipment "
|
||||
x = max(0, (self.getmaxyx()[1] - len(text)) // 2)
|
||||
|
||||
@@ -20,9 +20,9 @@ class Focusable:
|
||||
self._on_focus_change()
|
||||
|
||||
@contextlib.contextmanager
|
||||
def _focus_standout(self, win: T.Any) -> T.Generator:
|
||||
def focus_standout(self, win: T.Any) -> T.Generator:
|
||||
if self._focused:
|
||||
self._win.standout()
|
||||
win.standout()
|
||||
yield
|
||||
if self._focused:
|
||||
self._win.standend()
|
||||
win.standend()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import curses
|
||||
import typing as T
|
||||
|
||||
from pqcli.ui.curses.views.game_view.focusable import Focusable
|
||||
from pqcli.ui.curses.widgets import (
|
||||
DataTable,
|
||||
ListBox,
|
||||
@@ -8,8 +9,6 @@ from pqcli.ui.curses.widgets import (
|
||||
WindowWrapper,
|
||||
)
|
||||
|
||||
from .focusable import Focusable
|
||||
|
||||
|
||||
class ProgressBarWindow(WindowWrapper):
|
||||
def __init__(
|
||||
@@ -25,8 +24,8 @@ class ProgressBarWindow(WindowWrapper):
|
||||
super().__init__(parent, h, w, y, x)
|
||||
|
||||
self._title = title
|
||||
self._cur_pos = 0
|
||||
self._max_pos = 1
|
||||
self._cur_pos = 0.0
|
||||
self._max_pos = 1.0
|
||||
self._progress_title = ""
|
||||
|
||||
try:
|
||||
@@ -52,11 +51,7 @@ class ProgressBarWindow(WindowWrapper):
|
||||
|
||||
self._progress_bar_win.erase()
|
||||
|
||||
if self._focused:
|
||||
# with self._focus_standout(self._progress_bar_win):
|
||||
self._progress_bar_win.standout()
|
||||
|
||||
if True:
|
||||
with Focusable.focus_standout(self, self._progress_bar_win):
|
||||
self._progress_bar_win.border(
|
||||
curses.ACS_VLINE,
|
||||
curses.ACS_VLINE,
|
||||
@@ -77,9 +72,6 @@ class ProgressBarWindow(WindowWrapper):
|
||||
min(len(text), self._progress_bar_win.getmaxyx()[1]),
|
||||
)
|
||||
|
||||
if self._focused:
|
||||
self._progress_bar_win.standend()
|
||||
|
||||
self._progress_bar.set_position(self._cur_pos, self._max_pos)
|
||||
self._progress_bar_win.noutrefresh()
|
||||
|
||||
@@ -110,7 +102,7 @@ class DataTableProgressBarWindow(ProgressBarWindow):
|
||||
if not self._win:
|
||||
return
|
||||
|
||||
with self._focus_standout(self._win):
|
||||
with Focusable.focus_standout(self, self._win):
|
||||
self._win.box()
|
||||
x = max(0, (self.getmaxyx()[1] - len(self._title)) // 2)
|
||||
self._win.addnstr(
|
||||
@@ -148,7 +140,7 @@ class ListBoxProgressBarWindow(ProgressBarWindow):
|
||||
if not self._win:
|
||||
return
|
||||
|
||||
with self._focus_standout(self._win):
|
||||
with Focusable.focus_standout(self, self._win):
|
||||
self._win.box()
|
||||
x = max(0, (self.getmaxyx()[1] - len(self._title)) // 2)
|
||||
self._win.addnstr(
|
||||
|
||||
@@ -57,7 +57,7 @@ class SpellBookWindow(Focusable, WindowWrapper):
|
||||
if not self._win:
|
||||
return
|
||||
|
||||
with self._focus_standout(self._win):
|
||||
with self.focus_standout(self._win):
|
||||
self._win.box()
|
||||
text = " Spell Book "
|
||||
x = max(0, (self.getmaxyx()[1] - len(text)) // 2)
|
||||
|
||||
Reference in New Issue
Block a user