Mercurial > libervia-backend
annotate frontends/primitivus/chat.py @ 189:757518d05833
Primitivus: added nick completion
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 18 Aug 2010 20:50:45 +0800 |
parents | a566f654929e |
children | 31632472e857 |
rev | line source |
---|---|
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/python |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 """ |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 Primitivus: a SAT frontend |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 Copyright (C) 2009, 2010 Jérôme Poisson (goffi@goffi.org) |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 This program is free software: you can redistribute it and/or modify |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 it under the terms of the GNU General Public License as published by |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 the Free Software Foundation, either version 3 of the License, or |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 (at your option) any later version. |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 This program is distributed in the hope that it will be useful, |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 GNU General Public License for more details. |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 You should have received a copy of the GNU General Public License |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 along with this program. If not, see <http://www.gnu.org/licenses/>. |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 """ |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 import urwid |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 from quick_frontend.quick_contact_list import QuickContactList |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from quick_frontend.quick_chat import QuickChat |
124 | 25 import custom_widgets |
26 import time | |
27 from tools.jid import JID | |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
28 from card_game import CardGame |
176 | 29 from files_management import FileDialog |
124 | 30 |
31 | |
32 class ChatText(urwid.FlowWidget): | |
33 """Manage the printing of chat message""" | |
34 | |
35 def __init__(self, parent, timestamp, my_jid, from_jid, message, align='left'): | |
36 self.parent = parent | |
37 self.timestamp = time.localtime(timestamp) | |
38 self.my_jid = my_jid | |
39 self.from_jid = from_jid | |
40 self.message = unicode(message) | |
41 self.align = align | |
42 | |
43 def selectable(self): | |
44 return True | |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 |
124 | 46 def keypress(self, size, key): |
47 return key | |
48 | |
49 def rows(self,size,focus=False): | |
50 return self.display_widget(size, focus).rows(size, focus) | |
51 | |
52 def render(self, size, focus=False): | |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
53 canvas = urwid.CompositeCanvas(self.display_widget(size, focus).render(size, focus)) |
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
54 if focus: |
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
55 canvas.set_cursor(self.get_cursor_coords(size)) |
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
56 return canvas |
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
57 |
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
58 def get_cursor_coords(self, size): |
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
59 #(maxcol,) = size |
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
60 return 0, 0 |
124 | 61 |
62 def display_widget(self, size, focus): | |
63 my_mess = (self.from_jid.resource == self.parent.nick) if self.parent.type == "group" else (self.from_jid.short == self.my_jid.short) #mymess = True if message comes from local user | |
64 render_txt = [] | |
65 if self.parent.show_timestamp: | |
66 time_format = "%c" if self.timestamp < self.parent.day_change else "%H:%M" #if the message was sent before today, we print the full date | |
67 render_txt.append(('date',"[%s]" % time.strftime(time_format, self.timestamp))) | |
68 if self.parent.show_short_nick: | |
69 render_txt.append(('my_nick' if my_mess else 'other_nick',"**" if my_mess else "*")) | |
70 else: | |
126
1b33b681ebd8
Primitivus: sexy nick in chat window
Goffi <goffi@goffi.org>
parents:
125
diff
changeset
|
71 nick = self.from_jid.resource if self.parent.type == "group" else (self.parent.host.CM.getAttr(self.from_jid,'nick') or self.parent.host.CM.getAttr(self.from_jid,'name') or self.from_jid.node) |
1b33b681ebd8
Primitivus: sexy nick in chat window
Goffi <goffi@goffi.org>
parents:
125
diff
changeset
|
72 render_txt.append(('my_nick' if my_mess else 'other_nick',"[%s] " % nick)) |
124 | 73 render_txt.append(self.message) |
74 return urwid.Text(render_txt, align=self.align) | |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 class Chat(urwid.WidgetWrap, QuickChat): |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 def __init__(self, target, host, type='one2one'): |
124 | 79 self.target = target |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 QuickChat.__init__(self, target, host, type) |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 self.content = urwid.SimpleListWalker([]) |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 self.text_list = urwid.ListBox(self.content) |
124 | 83 self.chat_widget = urwid.Frame(self.text_list) |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
84 self.chat_colums = urwid.Columns([('weight', 8, self.chat_widget)]) |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
85 self.chat_colums = urwid.Columns([('weight', 8, self.chat_widget)]) |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
86 self.pile = urwid.Pile([self.chat_colums]) |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
87 urwid.WidgetWrap.__init__(self, self.__getDecoration(self.pile)) |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 self.setType(type) |
124 | 89 self.day_change = time.strptime(time.strftime("%a %b %d 00:00:00 %Y")) #struct_time of day changing time |
90 self.show_timestamp = True | |
91 self.show_short_nick = False | |
130
5a88ad24ccc0
Primitivus: subject in group chat can now be shown in 3 ways: clip, full, or hidden
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
92 self.show_title = 1 #0: clip title; 1: full title; 2: no title |
124 | 93 self.subject = None |
94 | |
95 def keypress(self, size, key): | |
96 if key == "meta p": #user wants to (un)hide the presents panel | |
97 if self.type == 'group': | |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
98 widgets = self.chat_colums.widget_list |
124 | 99 if self.present_panel in widgets: |
100 self.__removePresentPanel() | |
101 else: | |
102 self.__appendPresentPanel() | |
103 elif key == "meta t": #user wants to (un)hide timestamp | |
104 self.show_timestamp = not self.show_timestamp | |
105 for wid in self.content: | |
106 wid._invalidate() | |
107 elif key == "meta n": #user wants to (not) use short nick | |
108 self.show_short_nick = not self.show_short_nick | |
109 for wid in self.content: | |
110 wid._invalidate() | |
111 elif key == "meta l": #user wants to (un)hide widget decoration | |
153
f197b52796ee
Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents:
144
diff
changeset
|
112 show = not isinstance(self._w, custom_widgets.LabelLine) |
124 | 113 self.showDecoration(show) |
114 self._invalidate() | |
181 | 115 elif key == "meta s": #user wants to (un)hide group's subject or change its apperance |
124 | 116 if self.subject: |
130
5a88ad24ccc0
Primitivus: subject in group chat can now be shown in 3 ways: clip, full, or hidden
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
117 self.show_title = (self.show_title + 1) % 3 |
5a88ad24ccc0
Primitivus: subject in group chat can now be shown in 3 ways: clip, full, or hidden
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
118 if self.show_title == 0: |
5a88ad24ccc0
Primitivus: subject in group chat can now be shown in 3 ways: clip, full, or hidden
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
119 self.setSubject(self.subject,'clip') |
5a88ad24ccc0
Primitivus: subject in group chat can now be shown in 3 ways: clip, full, or hidden
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
120 elif self.show_title == 1: |
5a88ad24ccc0
Primitivus: subject in group chat can now be shown in 3 ways: clip, full, or hidden
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
121 self.setSubject(self.subject,'space') |
5a88ad24ccc0
Primitivus: subject in group chat can now be shown in 3 ways: clip, full, or hidden
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
122 elif self.show_title == 2: |
124 | 123 self.chat_widget.header = None |
124 self._invalidate() | |
125 | |
126 | |
127 return super(Chat, self).keypress(size, key) | |
137
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
128 |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
129 def getMenu(self): |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
130 """Return Menu bar""" |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
131 menu = custom_widgets.Menu(self.host.loop) |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
132 if self.type == 'group': |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
133 game = _("Game") |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
134 menu.addMenu(game, "Tarot", self.onTarotRequest) |
176 | 135 elif self.type == 'one2one': |
136 menu.addMenu(_("Action"), _("Send file"), self.onSendFileRequest) | |
137
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
137 return menu |
124 | 138 |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 def setType(self, type): |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 QuickChat.setType(self, type) |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 if type == 'one2one': |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 self.historyPrint(profile=self.host.profile) |
124 | 143 elif type == 'group': |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
144 if len(self.chat_colums.widget_list) == 1: |
124 | 145 present_widget = self.__buildPresentList() |
146 self.present_panel = custom_widgets.VerticalSeparator(present_widget) | |
147 self.__appendPresentPanel() | |
148 | |
149 def __getDecoration(self, widget): | |
150 return custom_widgets.LabelLine(widget, custom_widgets.SurroundedText(unicode(self.target))) | |
151 | |
152 def showDecoration(self, show=True): | |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
153 """Show/Hide the decoration around the chat window""" |
124 | 154 if show: |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
155 main_widget = self.__getDecoration(self.pile) |
124 | 156 else: |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
157 main_widget = self.pile |
124 | 158 self._w = main_widget |
159 | |
160 | |
161 def __buildPresentList(self): | |
125
8d611eb9ae48
primitivus: contact list enhancement
Goffi <goffi@goffi.org>
parents:
124
diff
changeset
|
162 self.present_wid = custom_widgets.GenericList([],option_type = custom_widgets.ClickableText) |
124 | 163 return self.present_wid |
164 | |
165 def __appendPresentPanel(self): | |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
166 self.chat_colums.widget_list.append(self.present_panel) |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
167 self.chat_colums.column_types.append(('weight', 2)) |
124 | 168 |
169 def __removePresentPanel(self): | |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
170 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 |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
171 self.chat_colums.widget_list.remove(self.present_panel) |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
172 del self.chat_colums.column_types[-1] |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
173 |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
174 def __appendGamePanel(self, widget): |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
175 assert (len(self.pile.widget_list) == 1) |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
176 self.pile.widget_list.insert(0,widget) |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
177 self.pile.item_types.insert(0,('weight', 1)) |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
178 self.pile.widget_list.insert(1,urwid.Filler(urwid.Divider('-'))) |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
179 self.pile.item_types.insert(1,('fixed', 1)) |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
180 self.host.redraw() |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
181 |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
182 def __removeGamePanel(self): |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
183 assert (len(self.pile.widget_list) == 3) |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
184 self.pile.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 |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
185 del self.pile.widget_list[0] |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
186 del self.pile.item_types[0] |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
187 self.host.redraw() |
124 | 188 |
130
5a88ad24ccc0
Primitivus: subject in group chat can now be shown in 3 ways: clip, full, or hidden
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
189 def setSubject(self, subject, wrap='space'): |
120 | 190 """Set title for a group chat""" |
191 QuickChat.setSubject(self, subject) | |
124 | 192 self.subject = subject |
130
5a88ad24ccc0
Primitivus: subject in group chat can now be shown in 3 ways: clip, full, or hidden
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
193 self.subj_wid = urwid.Text(unicode(subject.replace('\n','|') if wrap == 'clip' else subject ), |
5a88ad24ccc0
Primitivus: subject in group chat can now be shown in 3 ways: clip, full, or hidden
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
194 align='left' if wrap=='clip' else 'center',wrap=wrap) |
5a88ad24ccc0
Primitivus: subject in group chat can now be shown in 3 ways: clip, full, or hidden
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
195 self.chat_widget.header = urwid.AttrMap(self.subj_wid,'title') |
5a88ad24ccc0
Primitivus: subject in group chat can now be shown in 3 ways: clip, full, or hidden
Goffi <goffi@goffi.org>
parents:
126
diff
changeset
|
196 self.host.redraw() |
124 | 197 |
198 def setPresents(self, param_nicks): | |
199 """Set the users presents in the contact list for a group chat | |
200 @param nicks: list of nicknames | |
201 """ | |
202 nicks = [unicode(nick) for nick in param_nicks] #FIXME: should be done in DBus bridge | |
203 nicks.sort() | |
204 QuickChat.setPresents(self, nicks) | |
205 self.present_wid.changeValues(nicks) | |
206 self.host.redraw() | |
120 | 207 |
124 | 208 def replaceUser(self, param_nick): |
209 """Add user if it is not in the group list""" | |
210 nick = unicode(param_nick) #FIXME: should be done in DBus bridge | |
211 if "facebook" in nick: | |
212 self.host.debug() | |
213 QuickChat.replaceUser(self, nick) | |
214 presents = self.present_wid.getAllValues() | |
215 if nick not in presents: | |
216 presents.append(nick) | |
217 presents.sort() | |
218 self.present_wid.changeValues(presents) | |
219 self.host.redraw() | |
220 | |
221 def removeUser(self, param_nick): | |
222 """Remove a user from the group list""" | |
223 nick = unicode(param_nick) #FIXME: should be done in DBus bridge | |
224 QuickChat.removeUser(self, nick) | |
225 self.present_wid.deleteValue(nick) | |
226 self.host.redraw() | |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
227 |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
228 def printMessage(self, from_jid, msg, profile, timestamp=""): |
153
f197b52796ee
Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents:
144
diff
changeset
|
229 assert isinstance(from_jid, JID) |
124 | 230 my_jid = self.host.profiles[profile]['whoami'] |
231 self.content.append(ChatText(self, timestamp or None, my_jid, from_jid, msg)) | |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
232 self.text_list.set_focus(len(self.content)-1) |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
233 self.host.redraw() |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
234 |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
235 def startGame(self, game_type, referee, players): |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
236 """Configure the chat window to start a game""" |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
237 if game_type=="Tarot": |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
238 try: |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
239 self.tarot_wid = CardGame(self, referee, players, self.nick) |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
240 self.__appendGamePanel(self.tarot_wid) |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
241 except e: |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
242 self.host.debug() |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
243 |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
244 def getGame(self, game_type): |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
245 """Return class managing the game type""" |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
246 #TODO: check that the game is launched, and manage errors |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
247 if game_type=="Tarot": |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
248 return self.tarot_wid |
137
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
249 |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
250 #MENU EVENTS# |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
251 def onTarotRequest(self, menu): |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
252 if len(self.occupants) != 4: |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
253 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)) |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
254 else: |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
255 self.host.bridge.tarotGameCreate(self.id, list(self.occupants), self.host.profile) |
176 | 256 |
257 def onSendFileRequest(self, menu): | |
180
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
258 dialog = FileDialog(ok_cb=self.onFileSelected, cancel_cb=self.host.removePopUp) |
176 | 259 self.host.showPopUp(dialog, 80, 80) |
260 | |
180
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
261 #MISC EVENTS# |
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
262 def onFileSelected(self, filepath): |
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
263 self.host.removePopUp() |
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
264 full_jid = self.host.CM.get_full(self.target) |
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
265 id = self.host.bridge.sendFile(full_jid, filepath) |
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
266 self.host.addProgress(id,filepath) |