-
Notifications
You must be signed in to change notification settings - Fork 0
/
players_tab.py
96 lines (70 loc) · 3 KB
/
players_tab.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.tabbedpanel import TabbedPanel, TabbedPanelItem
from models import Character
from models import session
from util import DarkTextInput
from constants import (
FONT_SMALL, FONT_MEDIUM, FONT_LARGE, FONT_XLARGE, FONT_XXLARGE, BLACK,
GREY, WHITE
)
from character_stats import StatTab
from character_backstory import BackstoryTab
from character_items import CharacterItemsTab
from character_spells import SpellTab
class CharacterSheet(TabbedPanelItem):
def __init__(self, character, font_size=FONT_MEDIUM, *args, **kwargs):
super(CharacterSheet, self).__init__(
font_size=font_size, *args, **kwargs)
self.character = character
self.text = character.name
details = TabbedPanel(
do_default_tab=False,
tab_width=350,
tab_height=80)
details.add_widget(StatTab(character))
details.add_widget(SpellTab())
details.add_widget(CharacterItemsTab(character))
details.add_widget(BackstoryTab(character))
self.add_widget(details)
class CharacterActionsTab(TabbedPanelItem):
def __init__(self, parent, *args, **kwargs):
super(CharacterActionsTab, self).__init__(*args, **kwargs)
self.text = '*'
self.content = BoxLayout(orientation='vertical')
new_character = BoxLayout(orientation='vertical')
character_prompt = BoxLayout(orientation='horizontal')
character_prompt.add_widget(Label(text='Character Name', size_hint=(.2, 1)))
character_name = DarkTextInput(font_size=FONT_XLARGE)
character_prompt.add_widget(character_name)
new_character.add_widget(character_prompt)
create_character = Button(
text='Add Character',
on_press=lambda *args: parent.new_character(
character_name.text.strip()))
new_character.add_widget(create_character)
self.content.add_widget(new_character)
class CharcterTab(TabbedPanelItem):
def __init__(self, text, font_size=FONT_MEDIUM, *args, **kwargs):
super(CharcterTab, self).__init__(font_size=font_size, *args, **kwargs)
self.text = text
# Non player characters
content = BoxLayout(orientation='vertical')
self.add_widget(content)
# Character sheets
self.character_sheets = TabbedPanel(
do_default_tab=False,
tab_width=200,
tab_height=100)
content.add_widget(self.character_sheets)
# self.character_sheets.add_widget(CharacterActionsTab(self))
def load_characters(self, cls):
for character in session.query(cls).all():
self.add_character(character)
def add_character(self, character):
character = session.merge(character)
session.commit()
self.character_sheets.add_widget(CharacterSheet(character))
def new_character(self, name):
self.add_character(Character(name=name))