Source code for elide.charsview
# This file is part of Elide, frontend to Lisien, a framework for life simulation games.
# Copyright (c) Zachary Spector, public@zacharyspector.com
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from functools import partial
from kivy.app import App
from kivy.clock import Clock
from kivy.properties import ListProperty, ObjectProperty, StringProperty
from kivy.uix.recycleview import RecycleView
from kivy.uix.screenmanager import Screen
from .util import SelectableRecycleBoxLayout, load_string_once
# TODO: Visual preview
# TODO: Background image chooser
[docs]
class CharactersRecycleBoxLayout(SelectableRecycleBoxLayout):
character_name = StringProperty()
[docs]
def apply_selection(self, index, view, is_selected):
super().apply_selection(index, view, is_selected)
if is_selected:
self.character_name = view.text
[docs]
class CharactersView(RecycleView):
character_name = StringProperty()
def __init__(self, **kwargs):
self.i2name = {}
self.name2i = {}
super().__init__(**kwargs)
load_string_once("""
#: import resource_find kivy.resources.resource_find
<CharactersView>:
viewclass: 'RecycleToggleButton'
character_name: boxl.character_name
CharactersRecycleBoxLayout:
id: boxl
multiselect: False
default_size: None, dp(56)
default_size_hint: 1, None
size_hint_y: None
height: self.minimum_height
orientation: 'vertical'
<CharactersScreen>:
name: 'chars'
charsview: charsview
BoxLayout:
id: chars
orientation: 'vertical'
CharactersView:
id: charsview
size_hint_y: 0.8
character_name: root.character_name
TextInput:
id: newname
size_hint_y: 0.1
hint_text: 'New character name'
write_tab: False
multiline: False
Button:
text: '+'
on_release: root._trigger_new_character(newname.text)
size_hint_y: 0.05
Button:
text: 'Close'
on_release: root.toggle()
size_hint_y: 0.05
""")