misc: improve mypy health

This commit is contained in:
rr-
2019-01-04 20:13:52 +01:00
parent 3d8034b285
commit 021d7eb602
12 changed files with 45 additions and 37 deletions
@@ -20,6 +20,7 @@ class ChooseCharacterNameView(BaseView):
self.on_cancel = EventHandler()
self.on_confirm = EventHandler()
self._win: T.Optional[T.Any] = None
self._text = character_name or generate_name()
def start(self) -> None:
@@ -143,6 +144,9 @@ class ChooseCharacterStatsView(BaseView):
self.on_cancel = EventHandler()
self.on_confirm = EventHandler()
self._win: T.Optional[T.Any] = None
self._stats_win: T.Optional[T.Any] = None
self._stats_builder = StatsBuilder()
self._stats = self._stats_builder.roll()
@@ -184,7 +188,7 @@ class ChooseCharacterStatsView(BaseView):
self._render()
def _render(self) -> None:
if not self._win:
if not self._win or not self._stats_win:
return
y, x = self._win.getbegyx()
+10 -7
View File
@@ -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)
+3 -3
View File
@@ -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)