customize main widget to allow for customization
this includes two test commands to move items up and down the initiative with < and >
This commit is contained in:
parent
eae1830fc5
commit
77b9d05823
@ -5,8 +5,43 @@ from npytabletracker.cmd import ManagementActionController
|
|||||||
from npytabletracker.data import TableState
|
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."""
|
||||||
|
|
||||||
ACTION_CONTROLLER = ManagementActionController
|
ACTION_CONTROLLER = ManagementActionController
|
||||||
DATA_CONTROLER = TableState
|
DATA_CONTROLER = TableState
|
||||||
|
MAIN_WIDGET_CLASS = CharacterList
|
||||||
|
|
||||||
|
def update_list(self):
|
||||||
|
"""Update data in the window and represent it."""
|
||||||
|
self.wMain.display()
|
||||||
|
Loading…
Reference in New Issue
Block a user