Mercurial > libervia-backend
annotate frontends/src/primitivus/chat.py @ 517:59b32c04e105
plugin text commands: added /help command
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 20 Oct 2012 19:22:51 +0200 |
parents | fe79a724e6fa |
children | 75216d94a89d |
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 |
459 | 6 Copyright (C) 2009, 2010, 2011, 2012 Jérôme Poisson (goffi@goffi.org) |
119
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 |
480
2a072735e459
Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
9 it under the terms of the GNU Affero General Public License as published by |
119
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 |
480
2a072735e459
Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
16 GNU Affero General Public License for more details. |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 |
480
2a072735e459
Licence modification: the full project is now under AGPL v3+ instead of GPL v3+
Goffi <goffi@goffi.org>
parents:
459
diff
changeset
|
18 You should have received a copy of the GNU Affero General Public License |
119
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 |
222
3198bfd66daa
primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents:
202
diff
changeset
|
23 from urwid_satext import sat_widgets |
225
fd9b7834d98a
distutils installation script, draft
Goffi <goffi@goffi.org>
parents:
223
diff
changeset
|
24 from urwid_satext.files_management import FileDialog |
fd9b7834d98a
distutils installation script, draft
Goffi <goffi@goffi.org>
parents:
223
diff
changeset
|
25 from sat_frontends.quick_frontend.quick_chat import QuickChat |
fd9b7834d98a
distutils installation script, draft
Goffi <goffi@goffi.org>
parents:
223
diff
changeset
|
26 from sat_frontends.primitivus.card_game import CardGame |
511
62f7f2403093
Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents:
510
diff
changeset
|
27 from sat_frontends.quick_frontend.quick_utils import escapePrivate, unescapePrivate |
124 | 28 import time |
225
fd9b7834d98a
distutils installation script, draft
Goffi <goffi@goffi.org>
parents:
223
diff
changeset
|
29 from sat.tools.jid import JID |
124 | 30 |
31 | |
32 class ChatText(urwid.FlowWidget): | |
33 """Manage the printing of chat message""" | |
34 | |
190
31632472e857
quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
35 def __init__(self, parent, timestamp, nick, my_mess, message, align='left'): |
124 | 36 self.parent = parent |
37 self.timestamp = time.localtime(timestamp) | |
190
31632472e857
quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
38 self.nick = nick |
31632472e857
quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
39 self.my_mess = my_mess |
124 | 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 render_txt = [] | |
64 if self.parent.show_timestamp: | |
65 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 | |
202
754e12eaea14
primitivus: fixed unicode issue on date in chat window
Goffi <goffi@goffi.org>
parents:
190
diff
changeset
|
66 render_txt.append(('date',"[%s]" % time.strftime(time_format, self.timestamp).decode('utf-8'))) |
124 | 67 if self.parent.show_short_nick: |
190
31632472e857
quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
68 render_txt.append(('my_nick' if self.my_mess else 'other_nick',"**" if self.my_mess else "*")) |
124 | 69 else: |
190
31632472e857
quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
70 render_txt.append(('my_nick' if self.my_mess else 'other_nick',"[%s] " % self.nick)) |
124 | 71 render_txt.append(self.message) |
72 return urwid.Text(render_txt, align=self.align) | |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 class Chat(urwid.WidgetWrap, QuickChat): |
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 def __init__(self, target, host, type='one2one'): |
124 | 77 self.target = target |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 QuickChat.__init__(self, target, host, type) |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 self.content = urwid.SimpleListWalker([]) |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 self.text_list = urwid.ListBox(self.content) |
124 | 81 self.chat_widget = urwid.Frame(self.text_list) |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
82 self.chat_colums = urwid.Columns([('weight', 8, self.chat_widget)]) |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
83 self.chat_colums = urwid.Columns([('weight', 8, self.chat_widget)]) |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
84 self.pile = urwid.Pile([self.chat_colums]) |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
85 urwid.WidgetWrap.__init__(self, self.__getDecoration(self.pile)) |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 self.setType(type) |
124 | 87 self.day_change = time.strptime(time.strftime("%a %b %d 00:00:00 %Y")) #struct_time of day changing time |
88 self.show_timestamp = True | |
89 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
|
90 self.show_title = 1 #0: clip title; 1: full title; 2: no title |
124 | 91 self.subject = None |
92 | |
93 def keypress(self, size, key): | |
94 if key == "meta p": #user wants to (un)hide the presents panel | |
95 if self.type == 'group': | |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
96 widgets = self.chat_colums.widget_list |
124 | 97 if self.present_panel in widgets: |
98 self.__removePresentPanel() | |
99 else: | |
100 self.__appendPresentPanel() | |
101 elif key == "meta t": #user wants to (un)hide timestamp | |
102 self.show_timestamp = not self.show_timestamp | |
103 for wid in self.content: | |
104 wid._invalidate() | |
105 elif key == "meta n": #user wants to (not) use short nick | |
106 self.show_short_nick = not self.show_short_nick | |
107 for wid in self.content: | |
108 wid._invalidate() | |
109 elif key == "meta l": #user wants to (un)hide widget decoration | |
222
3198bfd66daa
primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents:
202
diff
changeset
|
110 show = not isinstance(self._w, sat_widgets.LabelLine) |
124 | 111 self.showDecoration(show) |
112 self._invalidate() | |
181 | 113 elif key == "meta s": #user wants to (un)hide group's subject or change its apperance |
124 | 114 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
|
115 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
|
116 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
|
117 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
|
118 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
|
119 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
|
120 elif self.show_title == 2: |
124 | 121 self.chat_widget.header = None |
122 self._invalidate() | |
123 | |
124 | |
125 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
|
126 |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
127 def getMenu(self): |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
128 """Return Menu bar""" |
222
3198bfd66daa
primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents:
202
diff
changeset
|
129 menu = sat_widgets.Menu(self.host.loop) |
137
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
130 if self.type == 'group': |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
131 game = _("Game") |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
132 menu.addMenu(game, "Tarot", self.onTarotRequest) |
176 | 133 elif self.type == 'one2one': |
134 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
|
135 return menu |
124 | 136 |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 def setType(self, type): |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 QuickChat.setType(self, type) |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 if type == 'one2one': |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 self.historyPrint(profile=self.host.profile) |
124 | 141 elif type == 'group': |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
142 if len(self.chat_colums.widget_list) == 1: |
124 | 143 present_widget = self.__buildPresentList() |
222
3198bfd66daa
primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents:
202
diff
changeset
|
144 self.present_panel = sat_widgets.VerticalSeparator(present_widget) |
124 | 145 self.__appendPresentPanel() |
146 | |
147 def __getDecoration(self, widget): | |
510
886754295efe
quick frontend, primitivus, wix: MUC private messages management
Goffi <goffi@goffi.org>
parents:
507
diff
changeset
|
148 return sat_widgets.LabelLine(widget, sat_widgets.SurroundedText(unicode(unescapePrivate(self.target)))) |
124 | 149 |
150 def showDecoration(self, show=True): | |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
151 """Show/Hide the decoration around the chat window""" |
124 | 152 if show: |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
153 main_widget = self.__getDecoration(self.pile) |
124 | 154 else: |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
155 main_widget = self.pile |
124 | 156 self._w = main_widget |
157 | |
511
62f7f2403093
Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents:
510
diff
changeset
|
158 def _presentClicked(self, list_wid, clicked_wid): |
62f7f2403093
Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents:
510
diff
changeset
|
159 assert(self.type == 'group') |
62f7f2403093
Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents:
510
diff
changeset
|
160 nick = clicked_wid.getValue() |
62f7f2403093
Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents:
510
diff
changeset
|
161 if nick == self.getUserNick(): |
62f7f2403093
Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents:
510
diff
changeset
|
162 #We ignore click on our own nick |
62f7f2403093
Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents:
510
diff
changeset
|
163 return |
62f7f2403093
Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents:
510
diff
changeset
|
164 #we have a click on a nick, we add the private conversation to the contact_list |
62f7f2403093
Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents:
510
diff
changeset
|
165 full_jid = JID("%s/%s" % (self.target.short, nick)) |
62f7f2403093
Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents:
510
diff
changeset
|
166 new_jid = escapePrivate(full_jid) |
62f7f2403093
Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents:
510
diff
changeset
|
167 if new_jid not in self.host.contact_list: |
62f7f2403093
Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents:
510
diff
changeset
|
168 self.host.contact_list.add(new_jid) |
62f7f2403093
Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents:
510
diff
changeset
|
169 |
62f7f2403093
Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents:
510
diff
changeset
|
170 #now we select the new window |
62f7f2403093
Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents:
510
diff
changeset
|
171 self.host.contact_list.setFocus(full_jid, True) |
124 | 172 |
173 def __buildPresentList(self): | |
511
62f7f2403093
Primitivus: present contacts in groups chat can now be clicked
Goffi <goffi@goffi.org>
parents:
510
diff
changeset
|
174 self.present_wid = sat_widgets.GenericList([],option_type = sat_widgets.ClickableText, on_click=self._presentClicked) |
124 | 175 return self.present_wid |
176 | |
177 def __appendPresentPanel(self): | |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
178 self.chat_colums.widget_list.append(self.present_panel) |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
179 self.chat_colums.column_types.append(('weight', 2)) |
124 | 180 |
181 def __removePresentPanel(self): | |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
182 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
|
183 self.chat_colums.widget_list.remove(self.present_panel) |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
184 del self.chat_colums.column_types[-1] |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
185 |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
186 def __appendGamePanel(self, widget): |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
187 assert (len(self.pile.widget_list) == 1) |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
188 self.pile.widget_list.insert(0,widget) |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
189 self.pile.item_types.insert(0,('weight', 1)) |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
190 self.pile.widget_list.insert(1,urwid.Filler(urwid.Divider('-'))) |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
191 self.pile.item_types.insert(1,('fixed', 1)) |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
192 self.host.redraw() |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
193 |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
194 def __removeGamePanel(self): |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
195 assert (len(self.pile.widget_list) == 3) |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
196 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
|
197 del self.pile.widget_list[0] |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
198 del self.pile.item_types[0] |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
199 self.host.redraw() |
124 | 200 |
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
|
201 def setSubject(self, subject, wrap='space'): |
120 | 202 """Set title for a group chat""" |
203 QuickChat.setSubject(self, subject) | |
124 | 204 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
|
205 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
|
206 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
|
207 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
|
208 self.host.redraw() |
124 | 209 |
210 def setPresents(self, param_nicks): | |
211 """Set the users presents in the contact list for a group chat | |
212 @param nicks: list of nicknames | |
213 """ | |
214 nicks = [unicode(nick) for nick in param_nicks] #FIXME: should be done in DBus bridge | |
215 nicks.sort() | |
216 QuickChat.setPresents(self, nicks) | |
217 self.present_wid.changeValues(nicks) | |
218 self.host.redraw() | |
120 | 219 |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
220 def replaceUser(self, param_nick, show_info=True): |
124 | 221 """Add user if it is not in the group list""" |
222 nick = unicode(param_nick) #FIXME: should be done in DBus bridge | |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
223 QuickChat.replaceUser(self, nick, show_info) |
124 | 224 presents = self.present_wid.getAllValues() |
225 if nick not in presents: | |
226 presents.append(nick) | |
227 presents.sort() | |
228 self.present_wid.changeValues(presents) | |
229 self.host.redraw() | |
230 | |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
231 def removeUser(self, param_nick, show_info=True): |
124 | 232 """Remove a user from the group list""" |
233 nick = unicode(param_nick) #FIXME: should be done in DBus bridge | |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
234 QuickChat.removeUser(self, nick, show_info) |
124 | 235 self.present_wid.deleteValue(nick) |
236 self.host.redraw() | |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
237 |
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
238 def printMessage(self, from_jid, msg, profile, timestamp=""): |
153
f197b52796ee
Primitivus: begining of management for actionResult
Goffi <goffi@goffi.org>
parents:
144
diff
changeset
|
239 assert isinstance(from_jid, JID) |
190
31632472e857
quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
240 try: |
31632472e857
quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
241 jid,nick,mymess = QuickChat.printMessage(self, from_jid, msg, profile, timestamp) |
31632472e857
quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
242 except TypeError: |
31632472e857
quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
243 return |
514
fe79a724e6fa
Primitivus: avoid double messages in case of backlog/history conflict
Goffi <goffi@goffi.org>
parents:
511
diff
changeset
|
244 if timestamp: |
fe79a724e6fa
Primitivus: avoid double messages in case of backlog/history conflict
Goffi <goffi@goffi.org>
parents:
511
diff
changeset
|
245 for _chat_text in self.content: |
fe79a724e6fa
Primitivus: avoid double messages in case of backlog/history conflict
Goffi <goffi@goffi.org>
parents:
511
diff
changeset
|
246 if (msg == _chat_text.message and |
fe79a724e6fa
Primitivus: avoid double messages in case of backlog/history conflict
Goffi <goffi@goffi.org>
parents:
511
diff
changeset
|
247 timestamp - time.mktime(_chat_text.timestamp) < 5): |
fe79a724e6fa
Primitivus: avoid double messages in case of backlog/history conflict
Goffi <goffi@goffi.org>
parents:
511
diff
changeset
|
248 #we discard double messages, to avoid backlog / history conflict |
fe79a724e6fa
Primitivus: avoid double messages in case of backlog/history conflict
Goffi <goffi@goffi.org>
parents:
511
diff
changeset
|
249 return |
124 | 250 my_jid = self.host.profiles[profile]['whoami'] |
190
31632472e857
quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
251 self.content.append(ChatText(self, timestamp or None, nick, mymess, msg)) |
430
7c7ec2347b56
primitivus: chat window is not scrolled anymore when user is watching history and a new message is received
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
252 if self.text_list.get_focus()[1] == len(self.content)-2: |
7c7ec2347b56
primitivus: chat window is not scrolled anymore when user is watching history and a new message is received
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
253 #we don't change focus if user is not at the bottom |
7c7ec2347b56
primitivus: chat window is not scrolled anymore when user is watching history and a new message is received
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
254 #as that mean that he is probably watching discussion history |
7c7ec2347b56
primitivus: chat window is not scrolled anymore when user is watching history and a new message is received
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
255 self.text_list.set_focus(len(self.content)-1) |
190
31632472e857
quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
256 self.host.redraw() |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
257 if not self.host.x_notify.hasFocus(): |
380
ede26abf6ca1
primitivus: freedesktop notifications (if available) when somebody is talking to us and we have not focus, or our nick is pinged and we have not focus.
Goffi <goffi@goffi.org>
parents:
325
diff
changeset
|
258 if self.type=="one2one": |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
259 self.host.x_notify.sendNotification(_("Primitivus: %s is talking to you") % from_jid) |
380
ede26abf6ca1
primitivus: freedesktop notifications (if available) when somebody is talking to us and we have not focus, or our nick is pinged and we have not focus.
Goffi <goffi@goffi.org>
parents:
325
diff
changeset
|
260 elif self.getUserNick().lower() in msg.lower(): |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
261 self.host.x_notify.sendNotification(_("Primitivus: Somebody pinged your name in %s room") % self.target) |
190
31632472e857
quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
262 |
31632472e857
quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
263 def printInfo(self, msg, type='normal'): |
31632472e857
quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
264 """Print general info |
31632472e857
quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
265 @param msg: message to print |
31632472e857
quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
266 @type: one of: |
31632472e857
quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
267 normal: general info like "toto has joined the room" |
31632472e857
quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
268 me: "/me" information like "/me clenches his fist" ==> "toto clenches his fist" |
31632472e857
quick_frontend, wix, primitivus: informations in chat window
Goffi <goffi@goffi.org>
parents:
181
diff
changeset
|
269 """ |
222
3198bfd66daa
primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents:
202
diff
changeset
|
270 self.content.append(sat_widgets.ClickableText(msg)) |
430
7c7ec2347b56
primitivus: chat window is not scrolled anymore when user is watching history and a new message is received
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
271 if self.text_list.get_focus()[1] == len(self.content)-2: |
7c7ec2347b56
primitivus: chat window is not scrolled anymore when user is watching history and a new message is received
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
272 #we don't change focus if user is not at the bottom |
7c7ec2347b56
primitivus: chat window is not scrolled anymore when user is watching history and a new message is received
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
273 #as that mean that he is probably watching discussion history |
7c7ec2347b56
primitivus: chat window is not scrolled anymore when user is watching history and a new message is received
Goffi <goffi@goffi.org>
parents:
387
diff
changeset
|
274 self.text_list.set_focus(len(self.content)-1) |
119
ded2431cea5a
Primitivus: chat window / text sending.
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
275 self.host.redraw() |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
276 if not self.host.x_notify.hasFocus(): |
380
ede26abf6ca1
primitivus: freedesktop notifications (if available) when somebody is talking to us and we have not focus, or our nick is pinged and we have not focus.
Goffi <goffi@goffi.org>
parents:
325
diff
changeset
|
277 if self.type=="one2one": |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
278 self.host.x_notify.sendNotification(_("Primitivus: there is a message about you")) |
380
ede26abf6ca1
primitivus: freedesktop notifications (if available) when somebody is talking to us and we have not focus, or our nick is pinged and we have not focus.
Goffi <goffi@goffi.org>
parents:
325
diff
changeset
|
279 elif self.getUserNick().lower() in msg.lower(): |
507
f98bef71a918
frontends, core, plugin XEP-0045: leave implementation + better nick change
Goffi <goffi@goffi.org>
parents:
501
diff
changeset
|
280 self.host.x_notify.sendNotification(_("Primitivus: Somebody is talking about you in %s room") % self.target) |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
281 |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
282 def startGame(self, game_type, referee, players): |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
283 """Configure the chat window to start a game""" |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
284 if game_type=="Tarot": |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
285 self.tarot_wid = CardGame(self, referee, players, self.nick) |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
286 self.__appendGamePanel(self.tarot_wid) |
144
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
287 |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
288 def getGame(self, game_type): |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
289 """Return class managing the game type""" |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
290 #TODO: check that the game is launched, and manage errors |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
291 if game_type=="Tarot": |
80661755ea8d
Primitivus: Tarot card game implementation
Goffi <goffi@goffi.org>
parents:
137
diff
changeset
|
292 return self.tarot_wid |
137
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
293 |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
294 #MENU EVENTS# |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
295 def onTarotRequest(self, menu): |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
296 if len(self.occupants) != 4: |
222
3198bfd66daa
primitivus: refactoring to use urwid-satext which is now a separate project
Goffi <goffi@goffi.org>
parents:
202
diff
changeset
|
297 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)) |
137
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
298 else: |
227394eb080c
Primitivus: menu are now managed and fully working
Goffi <goffi@goffi.org>
parents:
130
diff
changeset
|
299 self.host.bridge.tarotGameCreate(self.id, list(self.occupants), self.host.profile) |
176 | 300 |
301 def onSendFileRequest(self, menu): | |
180
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
302 dialog = FileDialog(ok_cb=self.onFileSelected, cancel_cb=self.host.removePopUp) |
176 | 303 self.host.showPopUp(dialog, 80, 80) |
304 | |
180
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
305 #MISC EVENTS# |
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
306 def onFileSelected(self, filepath): |
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
307 self.host.removePopUp() |
501
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
308 #FIXME: check last_resource: what if self.target.resource exists ? |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
309 last_resource = self.host.bridge.getLastResource(unicode(self.target.short), self.host.profile) |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
310 if last_resource: |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
311 full_jid = JID("%s/%s" % (self.target.short, last_resource)) |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
312 else: |
e9634d2e7b38
core, quick_frontend, primitivus, wix: Contacts List refactoring phase 1:
Goffi <goffi@goffi.org>
parents:
480
diff
changeset
|
313 full_jid = self.target |
387
e66d300c5d42
frontends, bridge: sendFile method signature change + jid parameters in bridge now use _jid suffix
Goffi <goffi@goffi.org>
parents:
381
diff
changeset
|
314 id = self.host.bridge.sendFile(full_jid, filepath, {}, self.host.profile) |
180
fdb961f27ae9
Primitivus: file sending and progress management
Goffi <goffi@goffi.org>
parents:
176
diff
changeset
|
315 self.host.addProgress(id,filepath) |