Mercurial > libervia-backend
comparison frontends/sortilege_old/sortilege @ 587:952322b1d490
Remove trailing whitespaces.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 18 Jan 2013 17:55:34 +0100 |
parents | 2a072735e459 |
children | f7878ad3c846 |
comparison
equal
deleted
inserted
replaced
586:6a718ede8be1 | 587:952322b1d490 |
---|---|
37 import sys, os | 37 import sys, os |
38 import gobject | 38 import gobject |
39 import time | 39 import time |
40 from curses import ascii | 40 from curses import ascii |
41 import locale | 41 import locale |
42 from signal import signal, SIGWINCH | 42 from signal import signal, SIGWINCH |
43 import fcntl | 43 import fcntl |
44 import struct | 44 import struct |
45 import termios | 45 import termios |
46 from boxsizer import BoxSizer | 46 from boxsizer import BoxSizer |
47 | 47 |
66 """return the value of Ctrl+key""" | 66 """return the value of Ctrl+key""" |
67 return ord(ascii.ctrl(k)) | 67 return ord(ascii.ctrl(k)) |
68 | 68 |
69 class ChatList(QuickChatList): | 69 class ChatList(QuickChatList): |
70 """This class manage the list of chat windows""" | 70 """This class manage the list of chat windows""" |
71 | 71 |
72 def __init__(self, host): | 72 def __init__(self, host): |
73 QuickChatList.__init__(self, host) | 73 QuickChatList.__init__(self, host) |
74 self.sizer=host.sizer | 74 self.sizer=host.sizer |
75 | 75 |
76 def createChat(self, name): | 76 def createChat(self, name): |
77 chat = Chat(name, self.host) | 77 chat = Chat(name, self.host) |
78 self.sizer.appendColum(0,chat) | 78 self.sizer.appendColum(0,chat) |
79 self.sizer.update() | 79 self.sizer.update() |
80 return chat | 80 return chat |
81 | 81 |
82 class ContactList(Window, QuickContactList): | 82 class ContactList(Window, QuickContactList): |
83 | 83 |
84 def __init__(self, host, CM): | 84 def __init__(self, host, CM): |
85 QuickContactList.__init__(self, CM) | 85 QuickContactList.__init__(self, CM) |
86 self.host = host | 86 self.host = host |
87 self.jid_list = [] | 87 self.jid_list = [] |
88 self.__index=0 #indicate which contact is selected (ie: where we are) | 88 self.__index=0 #indicate which contact is selected (ie: where we are) |
95 def resizeAdapt(self): | 95 def resizeAdapt(self): |
96 """Adapt window size to stdscr size. | 96 """Adapt window size to stdscr size. |
97 Must be called when stdscr is resized.""" | 97 Must be called when stdscr is resized.""" |
98 self.resize(stdscr.getmaxyx()[0]-2,const_CONTACT_WIDTH,0,0) | 98 self.resize(stdscr.getmaxyx()[0]-2,const_CONTACT_WIDTH,0,0) |
99 self.update() | 99 self.update() |
100 | 100 |
101 def registerEnterCB(self, CB): | 101 def registerEnterCB(self, CB): |
102 self.__enterCB=CB | 102 self.__enterCB=CB |
103 | 103 |
104 def clear_contacts(self): | 104 def clear_contacts(self): |
105 """clear all the contact list""" | 105 """clear all the contact list""" |
116 def indexUp(self): | 116 def indexUp(self): |
117 """increment select contact index""" | 117 """increment select contact index""" |
118 if self.__index < len(self.jid_list)-1: #we dont want to select a missing contact | 118 if self.__index < len(self.jid_list)-1: #we dont want to select a missing contact |
119 self.__index = self.__index + 1 | 119 self.__index = self.__index + 1 |
120 self.update() | 120 self.update() |
121 | 121 |
122 def indexDown(self): | 122 def indexDown(self): |
123 """decrement select contact index""" | 123 """decrement select contact index""" |
124 if self.__index > 0: | 124 if self.__index > 0: |
125 self.__index = self.__index - 1 | 125 self.__index = self.__index - 1 |
126 self.update() | 126 self.update() |
140 """redraw all the window""" | 140 """redraw all the window""" |
141 if self.isHidden(): | 141 if self.isHidden(): |
142 return | 142 return |
143 Window.update(self) | 143 Window.update(self) |
144 self.jid_list.sort() | 144 self.jid_list.sort() |
145 begin=0 if self.__index<self.rHeight else self.__index-self.rHeight+1 | 145 begin=0 if self.__index<self.rHeight else self.__index-self.rHeight+1 |
146 idx=0 | 146 idx=0 |
147 for item in self.jid_list[begin:self.rHeight+begin]: | 147 for item in self.jid_list[begin:self.rHeight+begin]: |
148 attr = curses.A_REVERSE if ( self.isActive() and (idx+begin) == self.__index ) else 0 | 148 attr = curses.A_REVERSE if ( self.isActive() and (idx+begin) == self.__index ) else 0 |
149 centered = item.center(self.rWidth) ## it's nicer in the center :) | 149 centered = item.center(self.rWidth) ## it's nicer in the center :) |
150 self.addYXStr(idx, 0, centered, attr) | 150 self.addYXStr(idx, 0, centered, attr) |
162 return | 162 return |
163 try: | 163 try: |
164 self.__enterCB(self.jid_list[self.__index]) | 164 self.__enterCB(self.jid_list[self.__index]) |
165 except NameError: | 165 except NameError: |
166 pass # TODO: thrown an error here | 166 pass # TODO: thrown an error here |
167 | 167 |
168 class SortilegeApp(QuickApp): | 168 class SortilegeApp(QuickApp): |
169 | 169 |
170 def __init__(self): | 170 def __init__(self): |
171 #debug(const_APP_NAME+" init...") | 171 #debug(const_APP_NAME+" init...") |
172 | 172 |
173 ## unicode support ## | 173 ## unicode support ## |
174 locale.setlocale(locale.LC_ALL, '') | 174 locale.setlocale(locale.LC_ALL, '') |
243 curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK) | 243 curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK) |
244 else: | 244 else: |
245 debug (_("Deactivating colors")) | 245 debug (_("Deactivating colors")) |
246 curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLACK) | 246 curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLACK) |
247 curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_BLACK) | 247 curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_BLACK) |
248 | 248 |
249 | 249 |
250 def showChat(self, chat): | 250 def showChat(self, chat): |
251 debug (_("show chat")) | 251 debug (_("show chat")) |
252 if self.currentChat: | 252 if self.currentChat: |
253 debug (_("hiding %s"), self.currentChat) | 253 debug (_("hiding %s"), self.currentChat) |
254 self.chat_wins[self.currentChat].hide() | 254 self.chat_wins[self.currentChat].hide() |
255 self.currentChat=chat | 255 self.currentChat=chat |
256 debug (_("showing %s"), self.currentChat) | 256 debug (_("showing %s"), self.currentChat) |
257 self.chat_wins[self.currentChat].show() | 257 self.chat_wins[self.currentChat].show() |
258 self.chat_wins[self.currentChat].update() | 258 self.chat_wins[self.currentChat].update() |
259 | 259 |
260 | 260 |
261 ### EVENTS ### | 261 ### EVENTS ### |
262 | 262 |
263 def onContactChoosed(self, jid_txt): | 263 def onContactChoosed(self, jid_txt): |
264 """Called when a contact is selected in contact list.""" | 264 """Called when a contact is selected in contact list.""" |
300 addr=JID(to_jid) | 300 addr=JID(to_jid) |
301 win = addr if sender.short == self.whoami.short else sender #FIXME: duplicate code with QuickApp | 301 win = addr if sender.short == self.whoami.short else sender #FIXME: duplicate code with QuickApp |
302 if (self.currentChat==None): | 302 if (self.currentChat==None): |
303 self.currentChat=win.short | 303 self.currentChat=win.short |
304 self.showChat(win.short) | 304 self.showChat(win.short) |
305 | 305 |
306 # we show the window in the status bar | 306 # we show the window in the status bar |
307 if not self.currentChat == win.short: | 307 if not self.currentChat == win.short: |
308 self.statusBar.add_item(win.short) | 308 self.statusBar.add_item(win.short) |
309 self.statusBar.show() | 309 self.statusBar.show() |
310 self.sizer.update() | 310 self.sizer.update() |
317 """Called on SIGWINCH. | 317 """Called on SIGWINCH. |
318 resize the screen and launch the loop""" | 318 resize the screen and launch the loop""" |
319 height, width = ttysize() | 319 height, width = ttysize() |
320 curses.resizeterm(height, width) | 320 curses.resizeterm(height, width) |
321 gobject.idle_add(self.callOnceLoop) | 321 gobject.idle_add(self.callOnceLoop) |
322 | 322 |
323 def callOnceLoop(self): | 323 def callOnceLoop(self): |
324 """Call the loop and return false (for not being called again by gobject mainloop). | 324 """Call the loop and return false (for not being called again by gobject mainloop). |
325 Usefull for calling loop when there is no input in stdin""" | 325 Usefull for calling loop when there is no input in stdin""" |
326 self.loopCB() | 326 self.loopCB() |
327 return False | 327 return False |
349 self.contactList.activate(False) #TODO: auto deactivation when hiding ? | 349 self.contactList.activate(False) #TODO: auto deactivation when hiding ? |
350 if self.currentChat: | 350 if self.currentChat: |
351 self.editBar.activate(True) | 351 self.editBar.activate(True) |
352 self.sizer.update() | 352 self.sizer.update() |
353 | 353 |
354 ## Chat Params ## | 354 ## Chat Params ## |
355 elif k == C('c'): | 355 elif k == C('c'): |
356 self.chatParams["color"] = not self.chatParams["color"] | 356 self.chatParams["color"] = not self.chatParams["color"] |
357 self.color(self.chatParams["color"]) | 357 self.color(self.chatParams["color"]) |
358 elif k == C('t'): | 358 elif k == C('t'): |
359 self.chatParams["timestamp"] = not self.chatParams["timestamp"] | 359 self.chatParams["timestamp"] = not self.chatParams["timestamp"] |
374 for win in self.chat_wins.keys(): | 374 for win in self.chat_wins.keys(): |
375 self.chat_wins[win].resizeAdapt() | 375 self.chat_wins[win].resizeAdapt() |
376 self.sizer.update() # FIXME: everything need to be managed by the sizer | 376 self.sizer.update() # FIXME: everything need to be managed by the sizer |
377 | 377 |
378 ## we now throw the key to win handlers ## | 378 ## we now throw the key to win handlers ## |
379 else: | 379 else: |
380 for win in self.listWins: | 380 for win in self.listWins: |
381 if win.isActive(): | 381 if win.isActive(): |
382 win.handleKey(k) | 382 win.handleKey(k) |
383 if self.currentChat: | 383 if self.currentChat: |
384 self.chat_wins[self.currentChat].handleKey(k) | 384 self.chat_wins[self.currentChat].handleKey(k) |
389 pressed = stdscr.getch() | 389 pressed = stdscr.getch() |
390 if pressed != curses.ERR: | 390 if pressed != curses.ERR: |
391 self.__key_handling(pressed) | 391 self.__key_handling(pressed) |
392 self.editBar.replace_cur() | 392 self.editBar.replace_cur() |
393 curses.doupdate() | 393 curses.doupdate() |
394 | 394 |
395 | 395 |
396 return True | 396 return True |
397 | 397 |
398 | 398 |
399 sat = SortilegeApp() | 399 sat = SortilegeApp() |