Mercurial > libervia-backend
comparison frontends/primitivus/chat.py @ 222:3198bfd66daa
primitivus: refactoring to use urwid-satext which is now a separate project
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 28 Dec 2010 23:10:13 +0100 |
parents | 754e12eaea14 |
children |
comparison
equal
deleted
inserted
replaced
221:96186f36d8cb | 222:3198bfd66daa |
---|---|
20 """ | 20 """ |
21 | 21 |
22 import urwid | 22 import urwid |
23 from quick_frontend.quick_contact_list import QuickContactList | 23 from quick_frontend.quick_contact_list import QuickContactList |
24 from quick_frontend.quick_chat import QuickChat | 24 from quick_frontend.quick_chat import QuickChat |
25 import custom_widgets | 25 from urwid_satext import sat_widgets |
26 import time | 26 import time |
27 from tools.jid import JID | 27 from tools.jid import JID |
28 from card_game import CardGame | 28 from card_game import CardGame |
29 from files_management import FileDialog | 29 from urwid_satext.files_management import FileDialog |
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 |
105 elif key == "meta n": #user wants to (not) use short nick | 105 elif key == "meta n": #user wants to (not) use short nick |
106 self.show_short_nick = not self.show_short_nick | 106 self.show_short_nick = not self.show_short_nick |
107 for wid in self.content: | 107 for wid in self.content: |
108 wid._invalidate() | 108 wid._invalidate() |
109 elif key == "meta l": #user wants to (un)hide widget decoration | 109 elif key == "meta l": #user wants to (un)hide widget decoration |
110 show = not isinstance(self._w, custom_widgets.LabelLine) | 110 show = not isinstance(self._w, sat_widgets.LabelLine) |
111 self.showDecoration(show) | 111 self.showDecoration(show) |
112 self._invalidate() | 112 self._invalidate() |
113 elif key == "meta s": #user wants to (un)hide group's subject or change its apperance | 113 elif key == "meta s": #user wants to (un)hide group's subject or change its apperance |
114 if self.subject: | 114 if self.subject: |
115 self.show_title = (self.show_title + 1) % 3 | 115 self.show_title = (self.show_title + 1) % 3 |
124 | 124 |
125 return super(Chat, self).keypress(size, key) | 125 return super(Chat, self).keypress(size, key) |
126 | 126 |
127 def getMenu(self): | 127 def getMenu(self): |
128 """Return Menu bar""" | 128 """Return Menu bar""" |
129 menu = custom_widgets.Menu(self.host.loop) | 129 menu = sat_widgets.Menu(self.host.loop) |
130 if self.type == 'group': | 130 if self.type == 'group': |
131 game = _("Game") | 131 game = _("Game") |
132 menu.addMenu(game, "Tarot", self.onTarotRequest) | 132 menu.addMenu(game, "Tarot", self.onTarotRequest) |
133 elif self.type == 'one2one': | 133 elif self.type == 'one2one': |
134 menu.addMenu(_("Action"), _("Send file"), self.onSendFileRequest) | 134 menu.addMenu(_("Action"), _("Send file"), self.onSendFileRequest) |
139 if type == 'one2one': | 139 if type == 'one2one': |
140 self.historyPrint(profile=self.host.profile) | 140 self.historyPrint(profile=self.host.profile) |
141 elif type == 'group': | 141 elif type == 'group': |
142 if len(self.chat_colums.widget_list) == 1: | 142 if len(self.chat_colums.widget_list) == 1: |
143 present_widget = self.__buildPresentList() | 143 present_widget = self.__buildPresentList() |
144 self.present_panel = custom_widgets.VerticalSeparator(present_widget) | 144 self.present_panel = sat_widgets.VerticalSeparator(present_widget) |
145 self.__appendPresentPanel() | 145 self.__appendPresentPanel() |
146 | 146 |
147 def __getDecoration(self, widget): | 147 def __getDecoration(self, widget): |
148 return custom_widgets.LabelLine(widget, custom_widgets.SurroundedText(unicode(self.target))) | 148 return sat_widgets.LabelLine(widget, sat_widgets.SurroundedText(unicode(self.target))) |
149 | 149 |
150 def showDecoration(self, show=True): | 150 def showDecoration(self, show=True): |
151 """Show/Hide the decoration around the chat window""" | 151 """Show/Hide the decoration around the chat window""" |
152 if show: | 152 if show: |
153 main_widget = self.__getDecoration(self.pile) | 153 main_widget = self.__getDecoration(self.pile) |
155 main_widget = self.pile | 155 main_widget = self.pile |
156 self._w = main_widget | 156 self._w = main_widget |
157 | 157 |
158 | 158 |
159 def __buildPresentList(self): | 159 def __buildPresentList(self): |
160 self.present_wid = custom_widgets.GenericList([],option_type = custom_widgets.ClickableText) | 160 self.present_wid = sat_widgets.GenericList([],option_type = sat_widgets.ClickableText) |
161 return self.present_wid | 161 return self.present_wid |
162 | 162 |
163 def __appendPresentPanel(self): | 163 def __appendPresentPanel(self): |
164 self.chat_colums.widget_list.append(self.present_panel) | 164 self.chat_colums.widget_list.append(self.present_panel) |
165 self.chat_colums.column_types.append(('weight', 2)) | 165 self.chat_colums.column_types.append(('weight', 2)) |
239 @param msg: message to print | 239 @param msg: message to print |
240 @type: one of: | 240 @type: one of: |
241 normal: general info like "toto has joined the room" | 241 normal: general info like "toto has joined the room" |
242 me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist" | 242 me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist" |
243 """ | 243 """ |
244 self.content.append(custom_widgets.ClickableText(msg)) | 244 self.content.append(sat_widgets.ClickableText(msg)) |
245 self.text_list.set_focus(len(self.content)-1) | 245 self.text_list.set_focus(len(self.content)-1) |
246 self.host.redraw() | 246 self.host.redraw() |
247 | 247 |
248 def startGame(self, game_type, referee, players): | 248 def startGame(self, game_type, referee, players): |
249 """Configure the chat window to start a game""" | 249 """Configure the chat window to start a game""" |
261 return self.tarot_wid | 261 return self.tarot_wid |
262 | 262 |
263 #MENU EVENTS# | 263 #MENU EVENTS# |
264 def onTarotRequest(self, menu): | 264 def onTarotRequest(self, menu): |
265 if len(self.occupants) != 4: | 265 if len(self.occupants) != 4: |
266 self.host.showPopUp(custom_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)) | 266 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)) |
267 else: | 267 else: |
268 self.host.bridge.tarotGameCreate(self.id, list(self.occupants), self.host.profile) | 268 self.host.bridge.tarotGameCreate(self.id, list(self.occupants), self.host.profile) |
269 | 269 |
270 def onSendFileRequest(self, menu): | 270 def onSendFileRequest(self, menu): |
271 dialog = FileDialog(ok_cb=self.onFileSelected, cancel_cb=self.host.removePopUp) | 271 dialog = FileDialog(ok_cb=self.onFileSelected, cancel_cb=self.host.removePopUp) |