Compare commits

...

5 Commits

Author SHA1 Message Date
77b9d05823 customize main widget to allow for customization
this includes two test commands to move items up and down the initiative
with < and >
2020-02-08 20:11:47 -06:00
eae1830fc5 configure line length as 120 in flake8 2020-02-08 19:47:25 -06:00
152a84d873 clean up bin/tabletracker a bit 2020-02-08 19:47:25 -06:00
3f9c1585fb add flake8 to requirements-dev.in 2020-02-08 19:47:25 -06:00
d8462e6941 implement /title and /add commands
this is still just a basic POC step for learning the library, but it
works, now just to understand some stuff
2020-02-08 19:47:20 -06:00
7 changed files with 91 additions and 2 deletions

View File

@ -4,12 +4,14 @@ import npyscreen
from npytabletracker.ui import TableTrackerDisplay
class TableTrackerApplication(npyscreen.NPSAppManaged):
"""Combine the pieces of the application."""
def onStart(self):
"""Link necessary UI elements and state management and whatnot."""
self.addForm('MAIN', TableTrackerDisplay)
app = TableTrackerApplication()
app.run()

29
npytabletracker/cmd.py Normal file
View 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
View 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 = []

View File

@ -1,6 +1,47 @@
"""UI elements for the npytabletracker application."""
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):
"""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()

View File

@ -1,3 +1,4 @@
-r requirements.in
flake8
pip-tools

View File

@ -5,6 +5,11 @@
# pip-compile --output-file=requirements/requirements-dev.txt requirements/requirements-dev.in
#
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
pip-tools==4.4.1
pycodestyle==2.5.0 # via flake8
pyflakes==2.1.1 # via flake8
six==1.14.0 # via pip-tools

2
setup.cfg Normal file
View File

@ -0,0 +1,2 @@
[flake8]
max-line-length = 120