Mercurial > libervia-backend
comparison frontends/src/primitivus/chat.py @ 2029:62a99c214b57
primitivus, quick frontend (chat): moved time text generation to QuickChat
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 08 Aug 2016 21:05:04 +0200 |
parents | 01aff34e8873 |
children | 7834743705f0 |
comparison
equal
deleted
inserted
replaced
2028:70bd7b242a9e | 2029:62a99c214b57 |
---|---|
28 from sat_frontends.primitivus import game_tarot | 28 from sat_frontends.primitivus import game_tarot |
29 from sat_frontends.primitivus.constants import Const as C | 29 from sat_frontends.primitivus.constants import Const as C |
30 from sat_frontends.primitivus.keys import action_key_map as a_key | 30 from sat_frontends.primitivus.keys import action_key_map as a_key |
31 from sat_frontends.primitivus.widget import PrimitivusWidget | 31 from sat_frontends.primitivus.widget import PrimitivusWidget |
32 from sat_frontends.primitivus.contact_list import ContactList | 32 from sat_frontends.primitivus.contact_list import ContactList |
33 import time | |
34 import locale | |
35 from functools import total_ordering | 33 from functools import total_ordering |
36 import bisect | 34 import bisect |
37 | 35 |
38 | 36 |
39 OCCUPANTS_FOOTER = _(u"{} occupants") | 37 OCCUPANTS_FOOTER = _(u"{} occupants") |
45 @param mess_data(quick_chat.Message, None): message data | 43 @param mess_data(quick_chat.Message, None): message data |
46 None: used only for non text widgets (e.g.: focus separator) | 44 None: used only for non text widgets (e.g.: focus separator) |
47 """ | 45 """ |
48 self.mess_data = mess_data | 46 self.mess_data = mess_data |
49 mess_data.widgets.add(self) | 47 mess_data.widgets.add(self) |
50 self.timestamp = time.localtime(mess_data.timestamp) | |
51 super(MessageWidget, self).__init__(urwid.Text(self.markup)) | 48 super(MessageWidget, self).__init__(urwid.Text(self.markup)) |
52 | 49 |
53 @property | 50 @property |
54 def markup(self): | 51 def markup(self): |
55 return self._generateInfoMarkup() if self.mess_data.type == C.MESS_TYPE_INFO else self._generateMarkup() | 52 return self._generateInfoMarkup() if self.mess_data.type == C.MESS_TYPE_INFO else self._generateMarkup() |
117 else: | 114 else: |
118 log.warning(u"Unknown status: {}".format(d.status)) | 115 log.warning(u"Unknown status: {}".format(d.status)) |
119 | 116 |
120 # timestamp | 117 # timestamp |
121 if self.parent.show_timestamp: | 118 if self.parent.show_timestamp: |
122 # if the message was sent before today, we print the full date | |
123 time_format = u"%c" if self.timestamp < self.parent.day_change else u"%H:%M" | |
124 attr = 'msg_mention' if mention else 'date' | 119 attr = 'msg_mention' if mention else 'date' |
125 markup.append((attr, u"[{}]".format(time.strftime(time_format, self.timestamp).decode(locale.getlocale()[1])))) | 120 markup.append((attr, u"[{}]".format(d.time_text))) |
126 else: | 121 else: |
127 if mention: | 122 if mention: |
128 markup.append(('msg_mention', '[*]')) | 123 markup.append(('msg_mention', '[*]')) |
129 | 124 |
130 # nickname | 125 # nickname |
282 self.host.addListener('presence', self.presenceListener, [profiles]) | 277 self.host.addListener('presence', self.presenceListener, [profiles]) |
283 | 278 |
284 # focus marker is a separator indicated last visible message before focus was lost | 279 # focus marker is a separator indicated last visible message before focus was lost |
285 self.focus_marker = None # link to current marker | 280 self.focus_marker = None # link to current marker |
286 self.focus_marker_set = None # True if a new marker has been inserted | 281 self.focus_marker_set = None # True if a new marker has been inserted |
287 self.day_change = time.strptime(time.strftime("%a %b %d 00:00:00 %Y")) # struct_time of day changing time | |
288 self.show_timestamp = True | 282 self.show_timestamp = True |
289 self.show_short_nick = False | 283 self.show_short_nick = False |
290 self.show_title = 1 # 0: clip title; 1: full title; 2: no title | 284 self.show_title = 1 # 0: clip title; 1: full title; 2: no title |
291 self.postInit() | 285 self.postInit() |
292 | 286 |