Compare commits
5 Commits
2a431f509f
...
77b9d05823
Author | SHA1 | Date | |
---|---|---|---|
77b9d05823 | |||
eae1830fc5 | |||
152a84d873 | |||
3f9c1585fb | |||
d8462e6941 |
@ -4,6 +4,7 @@ import npyscreen
|
|||||||
|
|
||||||
from npytabletracker.ui import TableTrackerDisplay
|
from npytabletracker.ui import TableTrackerDisplay
|
||||||
|
|
||||||
|
|
||||||
class TableTrackerApplication(npyscreen.NPSAppManaged):
|
class TableTrackerApplication(npyscreen.NPSAppManaged):
|
||||||
"""Combine the pieces of the application."""
|
"""Combine the pieces of the application."""
|
||||||
|
|
||||||
@ -11,5 +12,6 @@ class TableTrackerApplication(npyscreen.NPSAppManaged):
|
|||||||
"""Link necessary UI elements and state management and whatnot."""
|
"""Link necessary UI elements and state management and whatnot."""
|
||||||
self.addForm('MAIN', TableTrackerDisplay)
|
self.addForm('MAIN', TableTrackerDisplay)
|
||||||
|
|
||||||
|
|
||||||
app = TableTrackerApplication()
|
app = TableTrackerApplication()
|
||||||
app.run()
|
app.run()
|
||||||
|
29
npytabletracker/cmd.py
Normal file
29
npytabletracker/cmd.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
"""ActionController for command processing."""
|
||||||
|
import re
|
||||||
|
|
||||||
|
import npyscreen
|
||||||
|
|
||||||
|
|
||||||
|
class ManagementActionController(npyscreen.ActionControllerSimple):
|
||||||
|
"""Process commands from the command line and act on them."""
|
||||||
|
|
||||||
|
ADD_REGEX = r'^/add (.*)$'
|
||||||
|
TITLE_REGEX = r'^/title (.*)$'
|
||||||
|
|
||||||
|
def create(self):
|
||||||
|
"""Hook command handlers."""
|
||||||
|
self.add_action(self.ADD_REGEX, self.add_character, False)
|
||||||
|
self.add_action(self.TITLE_REGEX, self.title, False)
|
||||||
|
|
||||||
|
def add_character(self, command_line, widget_proxy, live):
|
||||||
|
"""Add a character to the list."""
|
||||||
|
match = re.search(self.ADD_REGEX, command_line, re.IGNORECASE)
|
||||||
|
self.parent.value.characters.append(match.group(1))
|
||||||
|
self.parent.wMain.values = self.parent.value.characters
|
||||||
|
self.parent.wMain.display()
|
||||||
|
|
||||||
|
def title(self, command_line, widget_proxy, live):
|
||||||
|
"""Set the title in the top status bar."""
|
||||||
|
match = re.search(self.TITLE_REGEX, command_line, re.IGNORECASE)
|
||||||
|
self.parent.wStatus1.value = match.group(1)
|
||||||
|
self.parent.wStatus1.display()
|
9
npytabletracker/data.py
Normal file
9
npytabletracker/data.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
"""Maintain state in an object for use as a DATA_CONTROLLER."""
|
||||||
|
|
||||||
|
|
||||||
|
class TableState(object):
|
||||||
|
"""Track character initiative, hit points, etc."""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
"""Initialize data."""
|
||||||
|
self.characters = []
|
@ -1,6 +1,47 @@
|
|||||||
"""UI elements for the npytabletracker application."""
|
"""UI elements for the npytabletracker application."""
|
||||||
import npyscreen
|
import npyscreen
|
||||||
|
|
||||||
|
from npytabletracker.cmd import ManagementActionController
|
||||||
|
from npytabletracker.data import TableState
|
||||||
|
|
||||||
|
|
||||||
|
class CharacterList(npyscreen.MultiLineAction):
|
||||||
|
"""Display characters' initiative order and allow for operations on them."""
|
||||||
|
|
||||||
|
def __init__(self, *args, **keywords):
|
||||||
|
"""Set up some extra handlers when selecting characters in the list."""
|
||||||
|
super(CharacterList, self).__init__(*args, **keywords)
|
||||||
|
self.add_handlers({
|
||||||
|
">": self.when_init_move_down,
|
||||||
|
"<": self.when_init_move_up
|
||||||
|
})
|
||||||
|
|
||||||
|
def when_init_move_down(self, *args, **keywords):
|
||||||
|
"""Move the selected character down one spot in the initiative table."""
|
||||||
|
if self.cursor_line < len(self.parent.value.characters) - 1:
|
||||||
|
chars = self.parent.value.characters
|
||||||
|
pos = self.cursor_line
|
||||||
|
chars[pos], chars[pos+1] = chars[pos+1], chars[pos]
|
||||||
|
self.parent.update_list()
|
||||||
|
self.cursor_line += 1
|
||||||
|
|
||||||
|
def when_init_move_up(self, *args, **keywords):
|
||||||
|
"""Move the selected character up one spot in the initiative table."""
|
||||||
|
if self.cursor_line - 1 >= 0:
|
||||||
|
chars = self.parent.value.characters
|
||||||
|
pos = self.cursor_line
|
||||||
|
chars[pos], chars[pos-1] = chars[pos-1], chars[pos]
|
||||||
|
self.parent.update_list()
|
||||||
|
self.cursor_line -= 1
|
||||||
|
|
||||||
|
|
||||||
class TableTrackerDisplay(npyscreen.FormMuttActiveTraditional):
|
class TableTrackerDisplay(npyscreen.FormMuttActiveTraditional):
|
||||||
"""Create the high level form, which is organized like mutt/irssi."""
|
"""Create the high level form, which is organized like mutt/irssi."""
|
||||||
pass
|
|
||||||
|
ACTION_CONTROLLER = ManagementActionController
|
||||||
|
DATA_CONTROLER = TableState
|
||||||
|
MAIN_WIDGET_CLASS = CharacterList
|
||||||
|
|
||||||
|
def update_list(self):
|
||||||
|
"""Update data in the window and represent it."""
|
||||||
|
self.wMain.display()
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
-r requirements.in
|
-r requirements.in
|
||||||
|
|
||||||
|
flake8
|
||||||
pip-tools
|
pip-tools
|
||||||
|
@ -5,6 +5,11 @@
|
|||||||
# pip-compile --output-file=requirements/requirements-dev.txt requirements/requirements-dev.in
|
# pip-compile --output-file=requirements/requirements-dev.txt requirements/requirements-dev.in
|
||||||
#
|
#
|
||||||
click==7.0 # via pip-tools
|
click==7.0 # via pip-tools
|
||||||
|
entrypoints==0.3 # via flake8
|
||||||
|
flake8==3.7.9
|
||||||
|
mccabe==0.6.1 # via flake8
|
||||||
npyscreen==4.10.5
|
npyscreen==4.10.5
|
||||||
pip-tools==4.4.1
|
pip-tools==4.4.1
|
||||||
|
pycodestyle==2.5.0 # via flake8
|
||||||
|
pyflakes==2.1.1 # via flake8
|
||||||
six==1.14.0 # via pip-tools
|
six==1.14.0 # via pip-tools
|
||||||
|
Loading…
x
Reference in New Issue
Block a user