Mercurial > libervia-desktop-kivy
comparison cagou/plugins/plugin_wid_chat.py @ 135:091e288838e1
plugin chat: use new Symbol widget to display encryption button
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 06 Apr 2018 16:13:08 +0200 |
parents | cd99f70ea592 |
children | 53fb221ad084 |
comparison
equal
deleted
inserted
replaced
134:1cca97e27a69 | 135:091e288838e1 |
---|---|
30 from sat_frontends.quick_frontend import quick_widgets | 30 from sat_frontends.quick_frontend import quick_widgets |
31 from sat_frontends.quick_frontend import quick_chat | 31 from sat_frontends.quick_frontend import quick_chat |
32 from sat_frontends.tools import jid | 32 from sat_frontends.tools import jid |
33 from cagou.core import cagou_widget | 33 from cagou.core import cagou_widget |
34 from cagou.core.image import Image | 34 from cagou.core.image import Image |
35 from cagou.core.common import IconButton, JidWidget | 35 from cagou.core.common import SymbolButton, JidWidget |
36 from kivy.uix.dropdown import DropDown | 36 from kivy.uix.dropdown import DropDown |
37 from cagou import G | 37 from cagou import G |
38 import mimetypes | 38 import mimetypes |
39 | 39 |
40 | 40 |
128 | 128 |
129 class MessagesWidget(GridLayout): | 129 class MessagesWidget(GridLayout): |
130 pass | 130 pass |
131 | 131 |
132 | 132 |
133 class EncryptionButton(IconButton): | 133 class EncryptionButton(SymbolButton): |
134 | 134 |
135 def __init__(self, chat, **kwargs): | 135 def __init__(self, chat, **kwargs): |
136 """ | 136 """ |
137 @param chat(Chat): Chat instance | 137 @param chat(Chat): Chat instance |
138 """ | 138 """ |
140 # for now we do a simple ContextMenu as we have only OTR | 140 # for now we do a simple ContextMenu as we have only OTR |
141 self.otr_menu = OtrMenu(chat) | 141 self.otr_menu = OtrMenu(chat) |
142 super(EncryptionButton, self).__init__(**kwargs) | 142 super(EncryptionButton, self).__init__(**kwargs) |
143 self.bind(on_release=self.otr_menu.open) | 143 self.bind(on_release=self.otr_menu.open) |
144 | 144 |
145 def getIconSource(self): | 145 def getColor(self): |
146 """get path of icon""" | |
147 # TODO: use a more generic method to get icon name | |
148 if self.chat.otr_state_encryption == OTR_STATE_UNENCRYPTED: | 146 if self.chat.otr_state_encryption == OTR_STATE_UNENCRYPTED: |
149 icon_name = 'cadenas_ouvert' | 147 return (0.4, 0.4, 0.4, 1) |
150 else: | 148 elif self.chat.otr_state_trust == OTR_STATE_TRUSTED: |
151 if self.chat.otr_state_trust == OTR_STATE_TRUSTED: | 149 return (0.29,0.87,0.0,1) |
152 icon_name = 'cadenas_ferme' | 150 else: |
153 else: | 151 return (0.4, 0.4, 0.4, 1) |
154 icon_name = 'cadenas_ferme_pas_authenthifie' | 152 |
155 | 153 def getSymbol(self): |
156 return G.host.app.expand("{media}/icons/muchoslava/png/" + icon_name + "_30.png") | 154 if self.chat.otr_state_encryption == OTR_STATE_UNENCRYPTED: |
155 return 'lock-open' | |
156 elif self.chat.otr_state_trust == OTR_STATE_TRUSTED: | |
157 return 'lock-filled' | |
158 else: | |
159 return 'lock' | |
157 | 160 |
158 | 161 |
159 class OtrMenu(DropDown): | 162 class OtrMenu(DropDown): |
160 | 163 |
161 def __init__(self, chat, **kwargs): | 164 def __init__(self, chat, **kwargs): |
443 elif state in OTR_STATE_TRUST: | 446 elif state in OTR_STATE_TRUST: |
444 self.otr_state_trust = state | 447 self.otr_state_trust = state |
445 else: | 448 else: |
446 log.error(_(u"Unknown OTR state received: {}".format(state))) | 449 log.error(_(u"Unknown OTR state received: {}".format(state))) |
447 return | 450 return |
448 self.encryption_btn.source = self.encryption_btn.getIconSource() | 451 self.encryption_btn.symbol = self.encryption_btn.getSymbol() |
452 self.encryption_btn.color = self.encryption_btn.getColor() | |
449 | 453 |
450 def onDelete(self, force=False): | 454 def onDelete(self, force=False): |
451 if force==True: | 455 if force==True: |
452 return self._onDelete() | 456 return self._onDelete() |
453 if len(list(G.host.widgets.getWidgets(self.__class__, self.target, profiles=self.profiles))) > 1: | 457 if len(list(G.host.widgets.getWidgets(self.__class__, self.target, profiles=self.profiles))) > 1: |