Mercurial > libervia-backend
comparison frontends/src/primitivus/chat.py @ 587:952322b1d490
Remove trailing whitespaces.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 18 Jan 2013 17:55:34 +0100 |
parents | ca13633d3b6b |
children | c123dddaea6b |
comparison
equal
deleted
inserted
replaced
586:6a718ede8be1 | 587:952322b1d490 |
---|---|
29 from sat.tools.jid import JID | 29 from sat.tools.jid import JID |
30 | 30 |
31 | 31 |
32 class ChatText(urwid.FlowWidget): | 32 class ChatText(urwid.FlowWidget): |
33 """Manage the printing of chat message""" | 33 """Manage the printing of chat message""" |
34 | 34 |
35 def __init__(self, parent, timestamp, nick, my_mess, message, align='left', is_info=False): | 35 def __init__(self, parent, timestamp, nick, my_mess, message, align='left', is_info=False): |
36 self.parent = parent | 36 self.parent = parent |
37 self.timestamp = time.localtime(timestamp) | 37 self.timestamp = time.localtime(timestamp) |
38 self.nick = nick | 38 self.nick = nick |
39 self.my_mess = my_mess | 39 self.my_mess = my_mess |
122 elif self.show_title == 2: | 122 elif self.show_title == 2: |
123 self.chat_widget.header = None | 123 self.chat_widget.header = None |
124 self._invalidate() | 124 self._invalidate() |
125 | 125 |
126 | 126 |
127 return super(Chat, self).keypress(size, key) | 127 return super(Chat, self).keypress(size, key) |
128 | 128 |
129 def getMenu(self): | 129 def getMenu(self): |
130 """Return Menu bar""" | 130 """Return Menu bar""" |
131 menu = sat_widgets.Menu(self.host.loop) | 131 menu = sat_widgets.Menu(self.host.loop) |
132 if self.type == 'group': | 132 if self.type == 'group': |
133 game = _("Game") | 133 game = _("Game") |
143 elif type == 'group': | 143 elif type == 'group': |
144 if len(self.chat_colums.widget_list) == 1: | 144 if len(self.chat_colums.widget_list) == 1: |
145 present_widget = self.__buildPresentList() | 145 present_widget = self.__buildPresentList() |
146 self.present_panel = sat_widgets.VerticalSeparator(present_widget) | 146 self.present_panel = sat_widgets.VerticalSeparator(present_widget) |
147 self.__appendPresentPanel() | 147 self.__appendPresentPanel() |
148 | 148 |
149 def __getDecoration(self, widget): | 149 def __getDecoration(self, widget): |
150 return sat_widgets.LabelLine(widget, sat_widgets.SurroundedText(unicode(unescapePrivate(self.target)))) | 150 return sat_widgets.LabelLine(widget, sat_widgets.SurroundedText(unicode(unescapePrivate(self.target)))) |
151 | 151 |
152 def showDecoration(self, show=True): | 152 def showDecoration(self, show=True): |
153 """Show/Hide the decoration around the chat window""" | 153 """Show/Hide the decoration around the chat window""" |
173 self.host.contact_list.setFocus(full_jid, True) | 173 self.host.contact_list.setFocus(full_jid, True) |
174 | 174 |
175 def __buildPresentList(self): | 175 def __buildPresentList(self): |
176 self.present_wid = sat_widgets.GenericList([],option_type = sat_widgets.ClickableText, on_click=self._presentClicked) | 176 self.present_wid = sat_widgets.GenericList([],option_type = sat_widgets.ClickableText, on_click=self._presentClicked) |
177 return self.present_wid | 177 return self.present_wid |
178 | 178 |
179 def __appendPresentPanel(self): | 179 def __appendPresentPanel(self): |
180 self.chat_colums.widget_list.append(self.present_panel) | 180 self.chat_colums.widget_list.append(self.present_panel) |
181 self.chat_colums.column_types.append(('weight', 2)) | 181 self.chat_colums.column_types.append(('weight', 2)) |
182 | 182 |
183 def __removePresentPanel(self): | 183 def __removePresentPanel(self): |
184 self.chat_colums.set_focus(0) #necessary as the focus change to the next object, we can go out of range if we are on the last object of self.chat_colums | 184 self.chat_colums.set_focus(0) #necessary as the focus change to the next object, we can go out of range if we are on the last object of self.chat_colums |
185 self.chat_colums.widget_list.remove(self.present_panel) | 185 self.chat_colums.widget_list.remove(self.present_panel) |
186 del self.chat_colums.column_types[-1] | 186 del self.chat_colums.column_types[-1] |
187 | 187 |
188 def __appendGamePanel(self, widget): | 188 def __appendGamePanel(self, widget): |
189 assert (len(self.pile.widget_list) == 1) | 189 assert (len(self.pile.widget_list) == 1) |
190 self.pile.widget_list.insert(0,widget) | 190 self.pile.widget_list.insert(0,widget) |
191 self.pile.item_types.insert(0,('weight', 1)) | 191 self.pile.item_types.insert(0,('weight', 1)) |
192 self.pile.widget_list.insert(1,urwid.Filler(urwid.Divider('-'))) | 192 self.pile.widget_list.insert(1,urwid.Filler(urwid.Divider('-'))) |
243 jid,nick,mymess = QuickChat.printMessage(self, from_jid, msg, profile, timestamp) | 243 jid,nick,mymess = QuickChat.printMessage(self, from_jid, msg, profile, timestamp) |
244 except TypeError: | 244 except TypeError: |
245 return | 245 return |
246 | 246 |
247 new_text = ChatText(self, timestamp or None, nick, mymess, msg) | 247 new_text = ChatText(self, timestamp or None, nick, mymess, msg) |
248 | 248 |
249 if timestamp and self.content: | 249 if timestamp and self.content: |
250 for idx in range(len(self.content)-1,-1,-1): | 250 for idx in range(len(self.content)-1,-1,-1): |
251 current_text = self.content[idx] | 251 current_text = self.content[idx] |
252 if new_text.timestamp < current_text.timestamp and idx > 0: | 252 if new_text.timestamp < current_text.timestamp and idx > 0: |
253 continue #the new message is older, we need to insert it upper | 253 continue #the new message is older, we need to insert it upper |
254 | 254 |
255 #we discard double messages, to avoid backlog / history conflict | 255 #we discard double messages, to avoid backlog / history conflict |
256 if ((idx and self.content[idx-1].message == msg) or | 256 if ((idx and self.content[idx-1].message == msg) or |
257 (self.content[idx].message == msg) or | 257 (self.content[idx].message == msg) or |
258 (idx<len(self.content)-2 and self.content[idx+1].message)): | 258 (idx<len(self.content)-2 and self.content[idx+1].message)): |
259 return | 259 return |
260 | 260 |
261 self.content.insert(idx+1, new_text) | 261 self.content.insert(idx+1, new_text) |
262 break | 262 break |
263 else: | 263 else: |
264 self.content.append(new_text) | 264 self.content.append(new_text) |
265 | 265 |
266 if self.text_list.get_focus()[1] == len(self.content)-2: | 266 if self.text_list.get_focus()[1] == len(self.content)-2: |
267 #we don't change focus if user is not at the bottom | 267 #we don't change focus if user is not at the bottom |
268 #as that mean that he is probably watching discussion history | 268 #as that mean that he is probably watching discussion history |
269 self.text_list.set_focus(len(self.content)-1) | 269 self.text_list.set_focus(len(self.content)-1) |
270 self.host.redraw() | 270 self.host.redraw() |
271 if not self.host.x_notify.hasFocus(): | 271 if not self.host.x_notify.hasFocus(): |
272 if self.type=="one2one": | 272 if self.type=="one2one": |
273 self.host.x_notify.sendNotification(_("Primitivus: %s is talking to you") % from_jid) | 273 self.host.x_notify.sendNotification(_("Primitivus: %s is talking to you") % from_jid) |
274 elif self.getUserNick().lower() in msg.lower(): | 274 elif self.getUserNick().lower() in msg.lower(): |
275 self.host.x_notify.sendNotification(_("Primitivus: Somebody pinged your name in %s room") % self.target) | 275 self.host.x_notify.sendNotification(_("Primitivus: Somebody pinged your name in %s room") % self.target) |
276 | 276 |
277 def printInfo(self, msg, type='normal', timestamp=""): | 277 def printInfo(self, msg, type='normal', timestamp=""): |
278 """Print general info | 278 """Print general info |
279 @param msg: message to print | 279 @param msg: message to print |
280 @type: one of: | 280 @type: one of: |
281 normal: general info like "toto has joined the room" | 281 normal: general info like "toto has joined the room" |
290 self.text_list.set_focus(len(self.content)-1) | 290 self.text_list.set_focus(len(self.content)-1) |
291 self.host.redraw() | 291 self.host.redraw() |
292 if not self.host.x_notify.hasFocus(): | 292 if not self.host.x_notify.hasFocus(): |
293 if self.type=="one2one": | 293 if self.type=="one2one": |
294 self.host.x_notify.sendNotification(_("Primitivus: there is a message about you")) | 294 self.host.x_notify.sendNotification(_("Primitivus: there is a message about you")) |
295 elif self.getUserNick().lower() in msg.lower(): | 295 elif self.getUserNick().lower() in msg.lower(): |
296 self.host.x_notify.sendNotification(_("Primitivus: Somebody is talking about you in %s room") % self.target) | 296 self.host.x_notify.sendNotification(_("Primitivus: Somebody is talking about you in %s room") % self.target) |
297 | 297 |
298 def startGame(self, game_type, referee, players): | 298 def startGame(self, game_type, referee, players): |
299 """Configure the chat window to start a game""" | 299 """Configure the chat window to start a game""" |
300 if game_type=="Tarot": | 300 if game_type=="Tarot": |
301 self.tarot_wid = CardGame(self, referee, players, self.nick) | 301 self.tarot_wid = CardGame(self, referee, players, self.nick) |
302 self.__appendGamePanel(self.tarot_wid) | 302 self.__appendGamePanel(self.tarot_wid) |
303 | 303 |
304 def getGame(self, game_type): | 304 def getGame(self, game_type): |
305 """Return class managing the game type""" | 305 """Return class managing the game type""" |
306 #TODO: check that the game is launched, and manage errors | 306 #TODO: check that the game is launched, and manage errors |
307 if game_type=="Tarot": | 307 if game_type=="Tarot": |
308 return self.tarot_wid | 308 return self.tarot_wid |
309 | 309 |
310 #MENU EVENTS# | 310 #MENU EVENTS# |
311 def onTarotRequest(self, menu): | 311 def onTarotRequest(self, menu): |
312 if len(self.occupants) != 4: | 312 if len(self.occupants) != 4: |
313 self.host.showPopUp(sat_widgets.Alert(_("Can't start game"), _("You need to be exactly 4 peoples in the room to start a Tarot game"), ok_cb=self.host.removePopUp)) | 313 self.host.showPopUp(sat_widgets.Alert(_("Can't start game"), _("You need to be exactly 4 peoples in the room to start a Tarot game"), ok_cb=self.host.removePopUp)) |
314 else: | 314 else: |
315 self.host.bridge.tarotGameCreate(self.id, list(self.occupants), self.host.profile) | 315 self.host.bridge.tarotGameCreate(self.id, list(self.occupants), self.host.profile) |
316 | 316 |
317 def onSendFileRequest(self, menu): | 317 def onSendFileRequest(self, menu): |
318 dialog = FileDialog(ok_cb=self.onFileSelected, cancel_cb=self.host.removePopUp) | 318 dialog = FileDialog(ok_cb=self.onFileSelected, cancel_cb=self.host.removePopUp) |
319 self.host.showPopUp(dialog, 80, 80) | 319 self.host.showPopUp(dialog, 80, 80) |
320 | 320 |
321 #MISC EVENTS# | 321 #MISC EVENTS# |
326 if last_resource: | 326 if last_resource: |
327 full_jid = JID("%s/%s" % (self.target.short, last_resource)) | 327 full_jid = JID("%s/%s" % (self.target.short, last_resource)) |
328 else: | 328 else: |
329 full_jid = self.target | 329 full_jid = self.target |
330 progress_id = self.host.bridge.sendFile(full_jid, filepath, {}, self.host.profile) | 330 progress_id = self.host.bridge.sendFile(full_jid, filepath, {}, self.host.profile) |
331 self.host.addProgress(progress_id,filepath) | 331 self.host.addProgress(progress_id,filepath) |