summaryrefslogtreecommitdiff
path: root/gui/plist.py
blob: a009a324004b7d956be27996c0d2c74e05120dce (plain) (blame)
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
from kivy.app import App
from kivy.adapters.listadapter import ListAdapter
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.properties import StringProperty, ListProperty
from kivy.uix.listview import ListView, ListItemLabel


class PlayersListItem(BoxLayout, ListItemLabel):
    nick = StringProperty(allow_none=False)

    def on_touch_down(self, touch):
        if not self.collide_point(*touch.pos):
            return False
        touch.grab(self)
        return True

    def on_touch_up(self, touch):
        if not self.collide_point(*touch.pos):
            return False
        if touch.grab_current is self:
            app = App.get_running_app()
            app.root.chat_input.text = '/w "{}" '.format(self.nick)
            app.root.chat_input.focus = True
            touch.ungrab(self)
            return True


class PlayersList(FloatLayout):
    items = ListProperty([])

    def __init__(self, **kwargs):
        super(PlayersList, self).__init__(**kwargs)

        player_args_coverter = lambda row_index, nick: {"nick" : nick,
            "size_hint_y": None, "height": "30dp", "pos_hint_y": 0.9 }

        list_adapter = ListAdapter(
            data=["Ginaria", "Celestia"],
            args_converter=player_args_coverter,
            selection_mode='single',
            allow_empty_selection=True,
            cls=PlayersListItem)

        list_view = ListView(adapter=list_adapter,
                             size_hint=(1.0, 1.0),
                             pos_hint={'center_x': 0.5})

        def data_changed(instance, value):
            list_adapter.data = value

        self.bind(items=data_changed)

        self.add_widget(list_view)