annotate frontends/sortilege/sortilege.py @ 0:c4bc297b82f0

sat: - first public release, initial commit
author goffi@necton2
date Sat, 29 Aug 2009 13:34:59 +0200
parents
children bb72c29f3432
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
goffi@necton2
parents:
diff changeset
1 #!/usr/bin/python
goffi@necton2
parents:
diff changeset
2 # -*- coding: utf-8 -*-
goffi@necton2
parents:
diff changeset
3
goffi@necton2
parents:
diff changeset
4 """
goffi@necton2
parents:
diff changeset
5 sortilege: a SAT frontend
goffi@necton2
parents:
diff changeset
6 Copyright (C) 2009 Jérôme Poisson (goffi@goffi.org)
goffi@necton2
parents:
diff changeset
7
goffi@necton2
parents:
diff changeset
8 This program is free software: you can redistribute it and/or modify
goffi@necton2
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
goffi@necton2
parents:
diff changeset
10 the Free Software Foundation, either version 3 of the License, or
goffi@necton2
parents:
diff changeset
11 (at your option) any later version.
goffi@necton2
parents:
diff changeset
12
goffi@necton2
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
goffi@necton2
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
goffi@necton2
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
goffi@necton2
parents:
diff changeset
16 GNU General Public License for more details.
goffi@necton2
parents:
diff changeset
17
goffi@necton2
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
goffi@necton2
parents:
diff changeset
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
goffi@necton2
parents:
diff changeset
20 """
goffi@necton2
parents:
diff changeset
21
goffi@necton2
parents:
diff changeset
22
goffi@necton2
parents:
diff changeset
23 import curses
goffi@necton2
parents:
diff changeset
24 import pdb
goffi@necton2
parents:
diff changeset
25 from window import Window
goffi@necton2
parents:
diff changeset
26 from editbox import EditBox
goffi@necton2
parents:
diff changeset
27 from statusbar import StatusBar
goffi@necton2
parents:
diff changeset
28 from chat import Chat
goffi@necton2
parents:
diff changeset
29 from tools.jid import JID
goffi@necton2
parents:
diff changeset
30 import logging
goffi@necton2
parents:
diff changeset
31 from logging import debug, info, error
goffi@necton2
parents:
diff changeset
32 import locale
goffi@necton2
parents:
diff changeset
33 import sys, os
goffi@necton2
parents:
diff changeset
34 import gobject
goffi@necton2
parents:
diff changeset
35 import time
goffi@necton2
parents:
diff changeset
36 from curses import ascii
goffi@necton2
parents:
diff changeset
37 import locale
goffi@necton2
parents:
diff changeset
38 from signal import signal, SIGWINCH
goffi@necton2
parents:
diff changeset
39 import fcntl
goffi@necton2
parents:
diff changeset
40 import struct
goffi@necton2
parents:
diff changeset
41 import termios
goffi@necton2
parents:
diff changeset
42 from boxsizer import BoxSizer
goffi@necton2
parents:
diff changeset
43 from quick_frontend.quick_chat_list import QuickChatList
goffi@necton2
parents:
diff changeset
44 from quick_frontend.quick_contact_list import QuickContactList
goffi@necton2
parents:
diff changeset
45 from quick_frontend.quick_app import QuickApp
goffi@necton2
parents:
diff changeset
46
goffi@necton2
parents:
diff changeset
47 ### logging configuration FIXME: put this elsewhere ###
goffi@necton2
parents:
diff changeset
48 logging.basicConfig(level=logging.CRITICAL, #TODO: configure it top put messages in a log file
goffi@necton2
parents:
diff changeset
49 format='%(message)s')
goffi@necton2
parents:
diff changeset
50 ###
goffi@necton2
parents:
diff changeset
51
goffi@necton2
parents:
diff changeset
52 const_APP_NAME = "Sortilège"
goffi@necton2
parents:
diff changeset
53 const_CONTACT_WIDTH = 30
goffi@necton2
parents:
diff changeset
54
goffi@necton2
parents:
diff changeset
55 def ttysize():
goffi@necton2
parents:
diff changeset
56 """This function return term size.
goffi@necton2
parents:
diff changeset
57 Comes from Donn Cave from python list mailing list"""
goffi@necton2
parents:
diff changeset
58 buf = 'abcdefgh'
goffi@necton2
parents:
diff changeset
59 buf = fcntl.ioctl(0, termios.TIOCGWINSZ, buf)
goffi@necton2
parents:
diff changeset
60 row, col, rpx, cpx = struct.unpack('hhhh', buf)
goffi@necton2
parents:
diff changeset
61 return row, col
goffi@necton2
parents:
diff changeset
62
goffi@necton2
parents:
diff changeset
63 def C(k):
goffi@necton2
parents:
diff changeset
64 """return the value of Ctrl+key"""
goffi@necton2
parents:
diff changeset
65 return ord(ascii.ctrl(k))
goffi@necton2
parents:
diff changeset
66
goffi@necton2
parents:
diff changeset
67 class ChatList(QuickChatList):
goffi@necton2
parents:
diff changeset
68 """This class manage the list of chat windows"""
goffi@necton2
parents:
diff changeset
69
goffi@necton2
parents:
diff changeset
70 def __init__(self, host):
goffi@necton2
parents:
diff changeset
71 QuickChatList.__init__(self, host)
goffi@necton2
parents:
diff changeset
72 self.sizer=host.sizer
goffi@necton2
parents:
diff changeset
73
goffi@necton2
parents:
diff changeset
74 def createChat(self, name):
goffi@necton2
parents:
diff changeset
75 chat = Chat(name, self.host)
goffi@necton2
parents:
diff changeset
76 self.sizer.appendColum(0,chat)
goffi@necton2
parents:
diff changeset
77 self.sizer.update()
goffi@necton2
parents:
diff changeset
78 return chat
goffi@necton2
parents:
diff changeset
79
goffi@necton2
parents:
diff changeset
80
goffi@necton2
parents:
diff changeset
81 class ContactList(Window, QuickContactList):
goffi@necton2
parents:
diff changeset
82
goffi@necton2
parents:
diff changeset
83 def __init__(self):
goffi@necton2
parents:
diff changeset
84 QuickContactList.__init__(self)
goffi@necton2
parents:
diff changeset
85 self.__index=0 #indicate which contact is selected (ie: where we are)
goffi@necton2
parents:
diff changeset
86 Window.__init__(self, stdscr, stdscr.getmaxyx()[0]-2,const_CONTACT_WIDTH,0,0, True, "Contact List", code=code)
goffi@necton2
parents:
diff changeset
87
goffi@necton2
parents:
diff changeset
88 def resize(self, height, width, y, x):
goffi@necton2
parents:
diff changeset
89 Window.resize(self, height, width, y, x)
goffi@necton2
parents:
diff changeset
90 self.update()
goffi@necton2
parents:
diff changeset
91
goffi@necton2
parents:
diff changeset
92 def resizeAdapt(self):
goffi@necton2
parents:
diff changeset
93 """Adapt window size to stdscr size.
goffi@necton2
parents:
diff changeset
94 Must be called when stdscr is resized."""
goffi@necton2
parents:
diff changeset
95 self.resize(stdscr.getmaxyx()[0]-2,const_CONTACT_WIDTH,0,0)
goffi@necton2
parents:
diff changeset
96 self.update()
goffi@necton2
parents:
diff changeset
97
goffi@necton2
parents:
diff changeset
98 def registerEnterCB(self, CB):
goffi@necton2
parents:
diff changeset
99 self.__enterCB=CB
goffi@necton2
parents:
diff changeset
100
goffi@necton2
parents:
diff changeset
101 def replace(self, jid, name="", show="", status="", group=""):
goffi@necton2
parents:
diff changeset
102 """add a contact to the list"""
goffi@necton2
parents:
diff changeset
103 self.jid_ids[jid] = name or jid
goffi@necton2
parents:
diff changeset
104 self.update()
goffi@necton2
parents:
diff changeset
105
goffi@necton2
parents:
diff changeset
106 def indexUp(self):
goffi@necton2
parents:
diff changeset
107 """increment select contact index"""
goffi@necton2
parents:
diff changeset
108 if self.__index < len(self.jid_ids)-1: #we dont want to select a missing contact
goffi@necton2
parents:
diff changeset
109 self.__index = self.__index + 1
goffi@necton2
parents:
diff changeset
110 self.update()
goffi@necton2
parents:
diff changeset
111
goffi@necton2
parents:
diff changeset
112 def indexDown(self):
goffi@necton2
parents:
diff changeset
113 """decrement select contact index"""
goffi@necton2
parents:
diff changeset
114 if self.__index > 0:
goffi@necton2
parents:
diff changeset
115 self.__index = self.__index - 1
goffi@necton2
parents:
diff changeset
116 self.update()
goffi@necton2
parents:
diff changeset
117
goffi@necton2
parents:
diff changeset
118 def remove(self, jid):
goffi@necton2
parents:
diff changeset
119 """remove a contact from the list"""
goffi@necton2
parents:
diff changeset
120 del self.jid_ids[jid]
goffi@necton2
parents:
diff changeset
121 if self.__index >= len(self.jid_ids) and self.__index > 0: #if select index is out of border, we put it on the last contact
goffi@necton2
parents:
diff changeset
122 self.__index = len(self.jid_ids)-1
goffi@necton2
parents:
diff changeset
123 self.update()
goffi@necton2
parents:
diff changeset
124
goffi@necton2
parents:
diff changeset
125 def update(self):
goffi@necton2
parents:
diff changeset
126 """redraw all the window"""
goffi@necton2
parents:
diff changeset
127 if self.isHidden():
goffi@necton2
parents:
diff changeset
128 return
goffi@necton2
parents:
diff changeset
129 Window.update(self)
goffi@necton2
parents:
diff changeset
130 viewList=[]
goffi@necton2
parents:
diff changeset
131 for jid in self.jid_ids:
goffi@necton2
parents:
diff changeset
132 viewList.append(self.jid_ids[jid])
goffi@necton2
parents:
diff changeset
133 viewList.sort()
goffi@necton2
parents:
diff changeset
134 begin=0 if self.__index<self.rHeight else self.__index-self.rHeight+1
goffi@necton2
parents:
diff changeset
135 idx=0
goffi@necton2
parents:
diff changeset
136 for item in viewList[begin:self.rHeight+begin]:
goffi@necton2
parents:
diff changeset
137 attr = curses.A_REVERSE if ( self.isActive() and (idx+begin) == self.__index ) else 0
goffi@necton2
parents:
diff changeset
138 centered = item.center(self.rWidth) ## it's nicer in the center :)
goffi@necton2
parents:
diff changeset
139 self.addYXStr(idx, 0, centered, attr)
goffi@necton2
parents:
diff changeset
140 idx = idx + 1
goffi@necton2
parents:
diff changeset
141
goffi@necton2
parents:
diff changeset
142 self.noutrefresh()
goffi@necton2
parents:
diff changeset
143
goffi@necton2
parents:
diff changeset
144 def handleKey(self, k):
goffi@necton2
parents:
diff changeset
145 if k == curses.KEY_UP:
goffi@necton2
parents:
diff changeset
146 self.indexDown()
goffi@necton2
parents:
diff changeset
147 elif k == curses.KEY_DOWN:
goffi@necton2
parents:
diff changeset
148 self.indexUp()
goffi@necton2
parents:
diff changeset
149 elif k == ascii.NL:
goffi@necton2
parents:
diff changeset
150 if not self.jid_ids:
goffi@necton2
parents:
diff changeset
151 return
goffi@necton2
parents:
diff changeset
152 try:
goffi@necton2
parents:
diff changeset
153 self.__enterCB(self.jid_ids.keys()[self.__index])
goffi@necton2
parents:
diff changeset
154 except NameError:
goffi@necton2
parents:
diff changeset
155 pass # TODO: thrown an error here
goffi@necton2
parents:
diff changeset
156
goffi@necton2
parents:
diff changeset
157 class SortilegeApp(QuickApp):
goffi@necton2
parents:
diff changeset
158
goffi@necton2
parents:
diff changeset
159 def __init__(self):
goffi@necton2
parents:
diff changeset
160 #debug(const_APP_NAME+" init...")
goffi@necton2
parents:
diff changeset
161
goffi@necton2
parents:
diff changeset
162 ## unicode support ##
goffi@necton2
parents:
diff changeset
163 locale.setlocale(locale.LC_ALL, '')
goffi@necton2
parents:
diff changeset
164 global code
goffi@necton2
parents:
diff changeset
165 code = locale.getpreferredencoding()
goffi@necton2
parents:
diff changeset
166 self.code=code
goffi@necton2
parents:
diff changeset
167
goffi@necton2
parents:
diff changeset
168 ## main loop setup ##
goffi@necton2
parents:
diff changeset
169 self.loop=gobject.MainLoop()
goffi@necton2
parents:
diff changeset
170 gobject.io_add_watch(0, gobject.IO_IN, self.loopCB)
goffi@necton2
parents:
diff changeset
171
goffi@necton2
parents:
diff changeset
172 ## misc init stuff ##
goffi@necton2
parents:
diff changeset
173 self.listWins=[]
goffi@necton2
parents:
diff changeset
174 self.chatParams={'timestamp':True,
goffi@necton2
parents:
diff changeset
175 'color':True,
goffi@necton2
parents:
diff changeset
176 'short_nick':False}
goffi@necton2
parents:
diff changeset
177
goffi@necton2
parents:
diff changeset
178 def start(self):
goffi@necton2
parents:
diff changeset
179 curses.wrapper(self.start_curses)
goffi@necton2
parents:
diff changeset
180
goffi@necton2
parents:
diff changeset
181 def start_curses(self, win):
goffi@necton2
parents:
diff changeset
182 global stdscr
goffi@necton2
parents:
diff changeset
183 stdscr = win
goffi@necton2
parents:
diff changeset
184 self.stdscr = stdscr
goffi@necton2
parents:
diff changeset
185 curses.raw() #we handle everything ourself
goffi@necton2
parents:
diff changeset
186 curses.curs_set(False)
goffi@necton2
parents:
diff changeset
187 stdscr.nodelay(True)
goffi@necton2
parents:
diff changeset
188
goffi@necton2
parents:
diff changeset
189 ## colours ##
goffi@necton2
parents:
diff changeset
190 self.color(True)
goffi@necton2
parents:
diff changeset
191
goffi@necton2
parents:
diff changeset
192 ## windows ##
goffi@necton2
parents:
diff changeset
193 self.contactList = ContactList()
goffi@necton2
parents:
diff changeset
194 self.editBar = EditBox(stdscr, "> ", self.code)
goffi@necton2
parents:
diff changeset
195 self.editBar.activate(False)
goffi@necton2
parents:
diff changeset
196 self.statusBar = StatusBar(stdscr, self.code)
goffi@necton2
parents:
diff changeset
197 self.statusBar.hide(True)
goffi@necton2
parents:
diff changeset
198 self.addWin(self.contactList)
goffi@necton2
parents:
diff changeset
199 self.addWin(self.editBar)
goffi@necton2
parents:
diff changeset
200 self.addWin(self.statusBar)
goffi@necton2
parents:
diff changeset
201 self.sizer=BoxSizer(stdscr)
goffi@necton2
parents:
diff changeset
202 self.sizer.appendRow(self.contactList)
goffi@necton2
parents:
diff changeset
203 self.sizer.appendRow(self.statusBar)
goffi@necton2
parents:
diff changeset
204 self.sizer.appendRow(self.editBar)
goffi@necton2
parents:
diff changeset
205 self.currentChat=None
goffi@necton2
parents:
diff changeset
206
goffi@necton2
parents:
diff changeset
207 self.contactList.registerEnterCB(self.onContactChoosed)
goffi@necton2
parents:
diff changeset
208 self.editBar.registerEnterCB(self.onTextEntered)
goffi@necton2
parents:
diff changeset
209
goffi@necton2
parents:
diff changeset
210 self.chat_wins=ChatList(self)
goffi@necton2
parents:
diff changeset
211
goffi@necton2
parents:
diff changeset
212 QuickApp.__init__(self) #XXX: yes it's an unusual place for the constructor of a parent class, but the init order is important
goffi@necton2
parents:
diff changeset
213
goffi@necton2
parents:
diff changeset
214 signal (SIGWINCH, self.onResize) #we manage SIGWINCH ourselves, because the loop is not called otherwise
goffi@necton2
parents:
diff changeset
215
goffi@necton2
parents:
diff changeset
216 #last but not least, we adapt windows' sizes
goffi@necton2
parents:
diff changeset
217 self.sizer.update()
goffi@necton2
parents:
diff changeset
218 self.editBar.replace_cur()
goffi@necton2
parents:
diff changeset
219 curses.doupdate()
goffi@necton2
parents:
diff changeset
220
goffi@necton2
parents:
diff changeset
221 self.loop.run()
goffi@necton2
parents:
diff changeset
222
goffi@necton2
parents:
diff changeset
223 def addWin(self, win):
goffi@necton2
parents:
diff changeset
224 self.listWins.append(win)
goffi@necton2
parents:
diff changeset
225
goffi@necton2
parents:
diff changeset
226 def color(self, activate=True):
goffi@necton2
parents:
diff changeset
227 if activate:
goffi@necton2
parents:
diff changeset
228 debug ("Activation des couleurs")
goffi@necton2
parents:
diff changeset
229 curses.init_pair(1, curses.COLOR_BLUE, curses.COLOR_BLACK)
goffi@necton2
parents:
diff changeset
230 curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK)
goffi@necton2
parents:
diff changeset
231 else:
goffi@necton2
parents:
diff changeset
232 debug ("Desactivation des couleurs")
goffi@necton2
parents:
diff changeset
233 curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLACK)
goffi@necton2
parents:
diff changeset
234 curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_BLACK)
goffi@necton2
parents:
diff changeset
235
goffi@necton2
parents:
diff changeset
236
goffi@necton2
parents:
diff changeset
237 def showChat(self, chat):
goffi@necton2
parents:
diff changeset
238 debug ("show chat")
goffi@necton2
parents:
diff changeset
239 if self.currentChat:
goffi@necton2
parents:
diff changeset
240 debug ("hide de %s", self.currentChat)
goffi@necton2
parents:
diff changeset
241 self.chat_wins[self.currentChat].hide()
goffi@necton2
parents:
diff changeset
242 self.currentChat=chat
goffi@necton2
parents:
diff changeset
243 debug ("show de %s", self.currentChat)
goffi@necton2
parents:
diff changeset
244 self.chat_wins[self.currentChat].show()
goffi@necton2
parents:
diff changeset
245 self.chat_wins[self.currentChat].update()
goffi@necton2
parents:
diff changeset
246
goffi@necton2
parents:
diff changeset
247
goffi@necton2
parents:
diff changeset
248 ### EVENTS ###
goffi@necton2
parents:
diff changeset
249
goffi@necton2
parents:
diff changeset
250 def onContactChoosed(self, jid_txt):
goffi@necton2
parents:
diff changeset
251 """Called when a contact is selected in contact list."""
goffi@necton2
parents:
diff changeset
252 jid=JID(jid_txt)
goffi@necton2
parents:
diff changeset
253 debug ("contact choose: %s", jid)
goffi@necton2
parents:
diff changeset
254 self.showChat(jid.short)
goffi@necton2
parents:
diff changeset
255 self.statusBar.remove_item(jid.short)
goffi@necton2
parents:
diff changeset
256 if len(self.statusBar)==0:
goffi@necton2
parents:
diff changeset
257 self.statusBar.hide()
goffi@necton2
parents:
diff changeset
258 self.sizer.update()
goffi@necton2
parents:
diff changeset
259
goffi@necton2
parents:
diff changeset
260
goffi@necton2
parents:
diff changeset
261 def onTextEntered(self, text):
goffi@necton2
parents:
diff changeset
262 jid=JID(self.whoami)
goffi@necton2
parents:
diff changeset
263 self.bridge.sendMessage(self.currentChat, text)
goffi@necton2
parents:
diff changeset
264
goffi@necton2
parents:
diff changeset
265 def showDialog(self, message, title, type="info"):
goffi@necton2
parents:
diff changeset
266 if type==question:
goffi@necton2
parents:
diff changeset
267 raise NotImplementedError
goffi@necton2
parents:
diff changeset
268 pass
goffi@necton2
parents:
diff changeset
269
goffi@necton2
parents:
diff changeset
270
goffi@necton2
parents:
diff changeset
271 def presenceUpdate(self, jabber_id, type, show, status, priority):
goffi@necton2
parents:
diff changeset
272 QuickApp.presenceUpdate(self, jabber_id, type, show, status, priority)
goffi@necton2
parents:
diff changeset
273 self.editBar.replace_cur()
goffi@necton2
parents:
diff changeset
274 curses.doupdate()
goffi@necton2
parents:
diff changeset
275
goffi@necton2
parents:
diff changeset
276 def newMessage(self, from_jid, msg, type, to_jid):
goffi@necton2
parents:
diff changeset
277 QuickApp.newMessage(self, from_jid, msg, type, to_jid)
goffi@necton2
parents:
diff changeset
278 sender=JID(from_jid)
goffi@necton2
parents:
diff changeset
279 addr=JID(to_jid)
goffi@necton2
parents:
diff changeset
280 win = addr if sender.short == self.whoami.short else sender #FIXME: duplicate code with QuickApp
goffi@necton2
parents:
diff changeset
281 if (self.currentChat==None):
goffi@necton2
parents:
diff changeset
282 self.currentChat=win.short
goffi@necton2
parents:
diff changeset
283 self.showChat(win.short)
goffi@necton2
parents:
diff changeset
284
goffi@necton2
parents:
diff changeset
285 # we show the window in the status bar
goffi@necton2
parents:
diff changeset
286 if not self.currentChat == win.short:
goffi@necton2
parents:
diff changeset
287 self.statusBar.add_item(win.short)
goffi@necton2
parents:
diff changeset
288 self.statusBar.show()
goffi@necton2
parents:
diff changeset
289 self.sizer.update()
goffi@necton2
parents:
diff changeset
290 self.statusBar.update()
goffi@necton2
parents:
diff changeset
291
goffi@necton2
parents:
diff changeset
292 self.editBar.replace_cur()
goffi@necton2
parents:
diff changeset
293 curses.doupdate()
goffi@necton2
parents:
diff changeset
294
goffi@necton2
parents:
diff changeset
295 def onResize(self, sig, stack):
goffi@necton2
parents:
diff changeset
296 """Called on SIGWINCH.
goffi@necton2
parents:
diff changeset
297 resize the screen and launch the loop"""
goffi@necton2
parents:
diff changeset
298 height, width = ttysize()
goffi@necton2
parents:
diff changeset
299 curses.resizeterm(height, width)
goffi@necton2
parents:
diff changeset
300 gobject.idle_add(self.callOnceLoop)
goffi@necton2
parents:
diff changeset
301
goffi@necton2
parents:
diff changeset
302 def callOnceLoop(self):
goffi@necton2
parents:
diff changeset
303 """Call the loop and return false (for not being called again by gobject mainloop).
goffi@necton2
parents:
diff changeset
304 Usefull for calling loop when there is no input in stdin"""
goffi@necton2
parents:
diff changeset
305 self.loopCB()
goffi@necton2
parents:
diff changeset
306 return False
goffi@necton2
parents:
diff changeset
307
goffi@necton2
parents:
diff changeset
308 def __key_handling(self, k):
goffi@necton2
parents:
diff changeset
309 """Handle key and transmit to active window."""
goffi@necton2
parents:
diff changeset
310
goffi@necton2
parents:
diff changeset
311 ### General keys, handled _everytime_ ###
goffi@necton2
parents:
diff changeset
312 if k == C('x'):
goffi@necton2
parents:
diff changeset
313 if os.getenv('TERM')=='screen':
goffi@necton2
parents:
diff changeset
314 os.system('screen -X remove')
goffi@necton2
parents:
diff changeset
315 else:
goffi@necton2
parents:
diff changeset
316 self.loop.quit()
goffi@necton2
parents:
diff changeset
317
goffi@necton2
parents:
diff changeset
318 ## windows navigation
goffi@necton2
parents:
diff changeset
319 elif k == C('l') and not self.contactList.isHidden():
goffi@necton2
parents:
diff changeset
320 """We go to the contact list"""
goffi@necton2
parents:
diff changeset
321 self.contactList.activate(not self.contactList.isActive())
goffi@necton2
parents:
diff changeset
322 if self.currentChat:
goffi@necton2
parents:
diff changeset
323 self.editBar.activate(not self.contactList.isActive())
goffi@necton2
parents:
diff changeset
324
goffi@necton2
parents:
diff changeset
325 elif k == curses.KEY_F2:
goffi@necton2
parents:
diff changeset
326 self.contactList.hide(not self.contactList.isHidden())
goffi@necton2
parents:
diff changeset
327 if self.contactList.isHidden():
goffi@necton2
parents:
diff changeset
328 self.contactList.activate(False) #TODO: auto deactivation when hiding ?
goffi@necton2
parents:
diff changeset
329 if self.currentChat:
goffi@necton2
parents:
diff changeset
330 self.editBar.activate(True)
goffi@necton2
parents:
diff changeset
331 self.sizer.update()
goffi@necton2
parents:
diff changeset
332
goffi@necton2
parents:
diff changeset
333 ## Chat Params ##
goffi@necton2
parents:
diff changeset
334 elif k == C('c'):
goffi@necton2
parents:
diff changeset
335 self.chatParams["color"] = not self.chatParams["color"]
goffi@necton2
parents:
diff changeset
336 self.color(self.chatParams["color"])
goffi@necton2
parents:
diff changeset
337 elif k == C('t'):
goffi@necton2
parents:
diff changeset
338 self.chatParams["timestamp"] = not self.chatParams["timestamp"]
goffi@necton2
parents:
diff changeset
339 self.chat_wins[self.currentChat].update()
goffi@necton2
parents:
diff changeset
340 elif k == C('s'):
goffi@necton2
parents:
diff changeset
341 self.chatParams["short_nick"] = not self.chatParams["short_nick"]
goffi@necton2
parents:
diff changeset
342 self.chat_wins[self.currentChat].update()
goffi@necton2
parents:
diff changeset
343
goffi@necton2
parents:
diff changeset
344 ## misc ##
goffi@necton2
parents:
diff changeset
345 elif k == curses.KEY_RESIZE:
goffi@necton2
parents:
diff changeset
346 stdscr.erase()
goffi@necton2
parents:
diff changeset
347 height, width = stdscr.getmaxyx()
goffi@necton2
parents:
diff changeset
348 if height<5 and width<35:
goffi@necton2
parents:
diff changeset
349 stdscr.addstr("Pleeeeasse, I can't even breathe !")
goffi@necton2
parents:
diff changeset
350 else:
goffi@necton2
parents:
diff changeset
351 for win in self.listWins:
goffi@necton2
parents:
diff changeset
352 win.resizeAdapt()
goffi@necton2
parents:
diff changeset
353 for win in self.chat_wins.keys():
goffi@necton2
parents:
diff changeset
354 self.chat_wins[win].resizeAdapt()
goffi@necton2
parents:
diff changeset
355 self.sizer.update() # FIXME: everything need to be managed by the sizer
goffi@necton2
parents:
diff changeset
356
goffi@necton2
parents:
diff changeset
357 ## we now throw the key to win handlers ##
goffi@necton2
parents:
diff changeset
358 else:
goffi@necton2
parents:
diff changeset
359 for win in self.listWins:
goffi@necton2
parents:
diff changeset
360 if win.isActive():
goffi@necton2
parents:
diff changeset
361 win.handleKey(k)
goffi@necton2
parents:
diff changeset
362 if self.currentChat:
goffi@necton2
parents:
diff changeset
363 self.chat_wins[self.currentChat].handleKey(k)
goffi@necton2
parents:
diff changeset
364
goffi@necton2
parents:
diff changeset
365 def loopCB(self, source="", cb_condition=""):
goffi@necton2
parents:
diff changeset
366 """This callback is called by the main loop"""
goffi@necton2
parents:
diff changeset
367 #pressed = self.contactList.window.getch()
goffi@necton2
parents:
diff changeset
368 pressed = stdscr.getch()
goffi@necton2
parents:
diff changeset
369 if pressed != curses.ERR:
goffi@necton2
parents:
diff changeset
370 self.__key_handling(pressed)
goffi@necton2
parents:
diff changeset
371 self.editBar.replace_cur()
goffi@necton2
parents:
diff changeset
372 curses.doupdate()
goffi@necton2
parents:
diff changeset
373
goffi@necton2
parents:
diff changeset
374
goffi@necton2
parents:
diff changeset
375 return True
goffi@necton2
parents:
diff changeset
376
goffi@necton2
parents:
diff changeset
377
goffi@necton2
parents:
diff changeset
378 sat = SortilegeApp()
goffi@necton2
parents:
diff changeset
379 sat.start()