changeset 193:284cb5c467b0

core (common): split JidItem in 3 classes: - JidItem to only view an Entity - JidButton to allow to click - JidToggle to select
author Goffi <goffi@goffi.org>
date Wed, 23 May 2018 18:40:58 +0200
parents 62198e00a2b7
children a68c9baa6694
files cagou/core/common.py cagou/kv/common.kv cagou/plugins/plugin_wid_chat.py
diffstat 3 files changed, 28 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/cagou/core/common.py	Tue May 22 19:25:23 2018 +0200
+++ b/cagou/core/common.py	Wed May 23 18:40:58 2018 +0200
@@ -23,7 +23,9 @@
 from kivy.uix.image import Image
 from kivy.uix.label import Label
 from kivy.uix.behaviors import ButtonBehavior
+from kivy.uix.behaviors import ToggleButtonBehavior
 from kivy.uix.boxlayout import BoxLayout
+from cagou.core.constants import Const as C
 from kivy import properties
 from cagou import G
 import json
@@ -38,7 +40,9 @@
     pass
 
 
-class JidItem(ButtonBehavior, BoxLayout):
+class JidItem(BoxLayout):
+    bg_color = properties.ListProperty([0.2, 0.2, 0.2, 1])
+    color = properties.ListProperty([1, 1, 1, 1])
 
     def __init__(self, jid, profile, **kwargs):
         self.jid = jid
@@ -55,6 +59,14 @@
             return host.getAvatar(self.jid, profile=self.profile) or host.getDefaultAvatar(self.jid)
 
 
+class JidButton(ButtonBehavior, JidItem):
+    pass
+
+
+class JidToggle(ToggleButtonBehavior, JidItem):
+    selected_color = properties.ListProperty(C.COLOR_SEC_DARK)
+
+
 class Symbol(Label):
     symbol_map = None
     symbol = properties.StringProperty()
--- a/cagou/kv/common.kv	Tue May 22 19:25:23 2018 +0200
+++ b/cagou/kv/common.kv	Wed May 23 18:40:58 2018 +0200
@@ -16,11 +16,11 @@
 
 
 <JidItem>:
-    size_hint: None, None
+    size_hint: 1, None
     height: dp(70)
     canvas.before:
         Color:
-            rgba: 0.2, 0.2, 0.2, 1
+            rgba: self.bg_color
         Rectangle:
             pos: self.pos
             size: self.size
@@ -29,14 +29,22 @@
         size_hint: None, None
         size: dp(64), dp(64)
     Label:
-        color: 1, 1, 1, 1
+        size_hint: 1, 1
+        text_size: self.size
+        color: root.color
         bold: True
         text: root.jid
-        text_size: self.size
         halign: 'left'
         valign: 'middle'
-        padding_x: dp(20)
+        padding_x: dp(5)
 
+<JidToggle>:
+    canvas.before:
+        Color:
+            rgba: self.selected_color if self.state == 'down' else self.bg_color
+        Rectangle:
+            pos: self.pos
+            size: self.size
 
 <Symbol>:
     font_name: app.expand('{media}/fonts/fontello/font/fontello.ttf')
--- a/cagou/plugins/plugin_wid_chat.py	Tue May 22 19:25:23 2018 +0200
+++ b/cagou/plugins/plugin_wid_chat.py	Wed May 23 18:40:58 2018 +0200
@@ -32,7 +32,7 @@
 from sat_frontends.tools import jid
 from cagou.core import cagou_widget
 from cagou.core.image import Image
-from cagou.core.common import SymbolButton, JidItem
+from cagou.core.common import SymbolButton, JidButton
 from kivy.uix.dropdown import DropDown
 from kivy.core.window import Window
 from cagou import G
@@ -318,7 +318,7 @@
             for jid_, jid_data in comp_data:
                 nick = jid_data.get(u'nick', u'')
                 if text in jid_.bare or text in nick.lower():
-                    btn = JidItem(
+                    btn = JidButton(
                         jid = jid_.bare,
                         profile = profile,
                         size_hint = (0.5, None),