comparison frontends/src/primitivus/primitivus @ 587:952322b1d490

Remove trailing whitespaces.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 18 Jan 2013 17:55:34 +0100
parents ca13633d3b6b
children c8b129a3c209
comparison
equal deleted inserted replaced
586:6a718ede8be1 587:952322b1d490
42 42
43 ### logging configuration FIXME: put this elsewhere ### 43 ### logging configuration FIXME: put this elsewhere ###
44 logging.basicConfig(level=logging.CRITICAL, #TODO: configure it to put messages in a log file 44 logging.basicConfig(level=logging.CRITICAL, #TODO: configure it to put messages in a log file
45 format='%(message)s') 45 format='%(message)s')
46 ### 46 ###
47 47
48 class ChatList(QuickChatList): 48 class ChatList(QuickChatList):
49 """This class manage the list of chat windows""" 49 """This class manage the list of chat windows"""
50 50
51 def createChat(self, target): 51 def createChat(self, target):
52 return Chat(target, self.host) 52 return Chat(target, self.host)
53 53
54 class PrimitivusApp(QuickApp): 54 class PrimitivusApp(QuickApp):
55 55
56 def __init__(self): 56 def __init__(self):
57 QuickApp.__init__(self) 57 QuickApp.__init__(self)
58 58
59 ## main loop setup ## 59 ## main loop setup ##
60 self.main_widget = ProfileManager(self) 60 self.main_widget = ProfileManager(self)
61 self.loop = urwid.MainLoop(self.main_widget, const_PALETTE, event_loop=urwid.GLibEventLoop(), input_filter=self.inputFilter, unhandled_input=self.keyHandler) 61 self.loop = urwid.MainLoop(self.main_widget, const_PALETTE, event_loop=urwid.GLibEventLoop(), input_filter=self.inputFilter, unhandled_input=self.keyHandler)
62 62
63 ##misc setup## 63 ##misc setup##
80 80
81 def modeHint(self, value): 81 def modeHint(self, value):
82 """Change mode if make sens (i.e.: if there is nothing in the editBar""" 82 """Change mode if make sens (i.e.: if there is nothing in the editBar"""
83 if not self.editBar.get_edit_text(): 83 if not self.editBar.get_edit_text():
84 self.mode = value 84 self.mode = value
85 85
86 def debug(self): 86 def debug(self):
87 """convenient method to reset screen and launch p(u)db""" 87 """convenient method to reset screen and launch p(u)db"""
88 try: 88 try:
89 import pudb 89 import pudb
90 pudb.set_trace() 90 pudb.set_trace()
207 self.current_action_ids.add(id) 207 self.current_action_ids.add(id)
208 for new_menu in add_menus: 208 for new_menu in add_menus:
209 category,item,type = new_menu 209 category,item,type = new_menu
210 assert(type=="NORMAL") #TODO: manage other types 210 assert(type=="NORMAL") #TODO: manage other types
211 menu.addMenu(unicode(category), unicode(item), add_menu_cb) 211 menu.addMenu(unicode(category), unicode(item), add_menu_cb)
212 212
213 menu_roller = sat_widgets.MenuRoller([(_('Main menu'),menu)]) 213 menu_roller = sat_widgets.MenuRoller([(_('Main menu'),menu)])
214 return menu_roller 214 return menu_roller
215 215
216 def __buildMainWidget(self): 216 def __buildMainWidget(self):
217 self.contact_list = ContactList(self, on_click = self.contactSelected, on_change=lambda w: self.redraw()) 217 self.contact_list = ContactList(self, on_click = self.contactSelected, on_change=lambda w: self.redraw())
218 #self.center_part = urwid.Columns([('weight',2,self.contact_list),('weight',8,Chat('',self))]) 218 #self.center_part = urwid.Columns([('weight',2,self.contact_list),('weight',8,Chat('',self))])
219 self.center_part = urwid.Columns([('weight',2,self.contact_list), ('weight',8,urwid.Filler(urwid.Text('')))]) 219 self.center_part = urwid.Columns([('weight',2,self.contact_list), ('weight',8,urwid.Filler(urwid.Text('')))])
255 for idx in range(start_idx,len(nicks)) + range(0,start_idx): 255 for idx in range(start_idx,len(nicks)) + range(0,start_idx):
256 if nicks[idx].lower().startswith(start.lower()): 256 if nicks[idx].lower().startswith(start.lower()):
257 completion_data['last_nick'] = nicks[idx] 257 completion_data['last_nick'] = nicks[idx]
258 return text[:space+1] + nicks[idx] + (': ' if space < 0 else '') 258 return text[:space+1] + nicks[idx] + (': ' if space < 0 else '')
259 return text 259 return text
260 260
261 261
262 262
263 def plug_profile(self, profile_key='@DEFAULT@'): 263 def plug_profile(self, profile_key='@DEFAULT@'):
264 self.loop.widget = self.__buildMainWidget() 264 self.loop.widget = self.__buildMainWidget()
265 self.redraw() 265 self.redraw()
266 QuickApp.plug_profile(self, profile_key) 266 QuickApp.plug_profile(self, profile_key)
267 267
268 def removePopUp(self, widget=None): 268 def removePopUp(self, widget=None):
269 "Remove current pop-up, and if there is other in queue, show it" 269 "Remove current pop-up, and if there is other in queue, show it"
270 self.loop.widget = self.main_widget 270 self.loop.widget = self.main_widget
271 next_popup = self.notBar.getNextPopup() 271 next_popup = self.notBar.getNextPopup()
272 if next_popup: 272 if next_popup:
303 assert(len(self.center_part.widget_list)<=2) 303 assert(len(self.center_part.widget_list)<=2)
304 wid_idx = len(self.center_part.widget_list)-1 304 wid_idx = len(self.center_part.widget_list)-1
305 self.center_part.widget_list[wid_idx] = urwid.Filler(urwid.Text('')) 305 self.center_part.widget_list[wid_idx] = urwid.Filler(urwid.Text(''))
306 self.center_part.set_focus(0) 306 self.center_part.set_focus(0)
307 self.redraw() 307 self.redraw()
308 308
309 def addProgress (self, id, message): 309 def addProgress (self, id, message):
310 """Follow a SàT progress bar 310 """Follow a SàT progress bar
311 @param id: SàT id of the progression 311 @param id: SàT id of the progression
312 @param message: message to show to identify the progression""" 312 @param message: message to show to identify the progression"""
313 self.progress_wid.addProgress(id, message) 313 self.progress_wid.addProgress(id, message)
340 elif self.mode == 'COMMAND': 340 elif self.mode == 'COMMAND':
341 self.commandHandler(editBar) 341 self.commandHandler(editBar)
342 342
343 def newMessage(self, from_jid, to_jid, msg, _type, extra, profile): 343 def newMessage(self, from_jid, to_jid, msg, _type, extra, profile):
344 QuickApp.newMessage(self, from_jid, to_jid, msg, _type, extra, profile) 344 QuickApp.newMessage(self, from_jid, to_jid, msg, _type, extra, profile)
345 345
346 if not from_jid in self.contact_list and from_jid.short != self.profiles[profile]['whoami'].short: 346 if not from_jid in self.contact_list and from_jid.short != self.profiles[profile]['whoami'].short:
347 #XXX: needed to show entities which haven't sent any 347 #XXX: needed to show entities which haven't sent any
348 # presence information and which are not in roster 348 # presence information and which are not in roster
349 #TODO: put these entities in a "not in roster" list 349 #TODO: put these entities in a "not in roster" list
350 self.contact_list.replace(from_jid) 350 self.contact_list.replace(from_jid)
351 351
352 if JID(self.contact_list.selected).short != from_jid.short: 352 if JID(self.contact_list.selected).short != from_jid.short:
353 self.contact_list.putAlert(from_jid) 353 self.contact_list.putAlert(from_jid)
354 354
355 def _dialogOkCb(self, widget, data): 355 def _dialogOkCb(self, widget, data):
356 self.removePopUp() 356 self.removePopUp()
361 def _dialogCancelCb(self, widget, data): 361 def _dialogCancelCb(self, widget, data):
362 self.removePopUp() 362 self.removePopUp()
363 answer_cb = data[0] 363 answer_cb = data[0]
364 answer_data = [data[1]] if data[1] else [] 364 answer_data = [data[1]] if data[1] else []
365 answer_cb(False, *answer_data) 365 answer_cb(False, *answer_data)
366 366
367 367
368 def showDialog(self, message, title="", type="info", answer_cb = None, answer_data = None): 368 def showDialog(self, message, title="", type="info", answer_cb = None, answer_data = None):
369 if type == 'info': 369 if type == 'info':
370 popup = sat_widgets.Alert(unicode(title), unicode(message), ok_cb=answer_cb or self.removePopUp) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore 370 popup = sat_widgets.Alert(unicode(title), unicode(message), ok_cb=answer_cb or self.removePopUp) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore
371 elif type == 'error': 371 elif type == 'error':
372 popup = sat_widgets.Alert(unicode(title), unicode(message), ok_cb=answer_cb or self.removePopUp) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore 372 popup = sat_widgets.Alert(unicode(title), unicode(message), ok_cb=answer_cb or self.removePopUp) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore
373 elif type == 'yes/no': 373 elif type == 'yes/no':
374 popup = sat_widgets.ConfirmDialog(unicode(message), 374 popup = sat_widgets.ConfirmDialog(unicode(message),
375 yes_cb=self._dialogOkCb, yes_value = (answer_cb, answer_data), 375 yes_cb=self._dialogOkCb, yes_value = (answer_cb, answer_data),
376 no_cb=self._dialogCancelCb, no_value = (answer_cb, answer_data)) 376 no_cb=self._dialogCancelCb, no_value = (answer_cb, answer_data))
377 else: 377 else:
378 popup = sat_widgets.Alert(unicode(title), unicode(message), ok_cb=answer_cb or self.removePopUp) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore 378 popup = sat_widgets.Alert(unicode(title), unicode(message), ok_cb=answer_cb or self.removePopUp) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore
379 error(_('unmanaged dialog type: %s'), type) 379 error(_('unmanaged dialog type: %s'), type)
380 self.showPopUp(popup) 380 self.showPopUp(popup)
381 381
382 def onNotification(self, notBar): 382 def onNotification(self, notBar):
383 """Called when a new notification has been received""" 383 """Called when a new notification has been received"""
384 if not isinstance(self.main_widget, sat_widgets.FocusFrame): 384 if not isinstance(self.main_widget, sat_widgets.FocusFrame):
385 #if we are not in the main configuration, we ignore the notifications bar 385 #if we are not in the main configuration, we ignore the notifications bar
386 return 386 return
399 399
400 def askConfirmation(self, confirmation_id, confirmation_type, data, profile): 400 def askConfirmation(self, confirmation_id, confirmation_type, data, profile):
401 if not self.check_profile(profile): 401 if not self.check_profile(profile):
402 return 402 return
403 answer_data={} 403 answer_data={}
404 404
405 def dir_selected_cb(path): 405 def dir_selected_cb(path):
406 dest_path = join(path, data['filename']) 406 dest_path = join(path, data['filename'])
407 answer_data["dest_path"] = getNewPath(dest_path) 407 answer_data["dest_path"] = getNewPath(dest_path)
408 self.addProgress(confirmation_id, dest_path) 408 self.addProgress(confirmation_id, dest_path)
409 accept_cb(None) 409 accept_cb(None)
410 410
411 def accept_file_transfer_cb(widget): 411 def accept_file_transfer_cb(widget):
412 self.removePopUp() 412 self.removePopUp()
413 pop_up_widget = FileDialog(dir_selected_cb, refuse_cb, title=_(u"Where do you want to save the file ?"), style=['dir']) 413 pop_up_widget = FileDialog(dir_selected_cb, refuse_cb, title=_(u"Where do you want to save the file ?"), style=['dir'])
414 self.showPopUp(pop_up_widget) 414 self.showPopUp(pop_up_widget)
415 415
416 def accept_cb(widget): 416 def accept_cb(widget):
417 self.removePopUp() 417 self.removePopUp()
418 self.bridge.confirmationAnswer(confirmation_id, True, answer_data, profile) 418 self.bridge.confirmationAnswer(confirmation_id, True, answer_data, profile)
419 419
420 def refuse_cb(widget): 420 def refuse_cb(widget):
421 self.removePopUp() 421 self.removePopUp()
422 self.bridge.confirmationAnswer(confirmation_id, False, answer_data, profile) 422 self.bridge.confirmationAnswer(confirmation_id, False, answer_data, profile)
423 423
424 if confirmation_type == "FILE_TRANSFER": 424 if confirmation_type == "FILE_TRANSFER":
425 pop_up_widget = sat_widgets.ConfirmDialog(_("The contact %(jid)s wants to send you the file %(filename)s\nDo you accept ?") % {'jid':data["from"], 'filename':data["filename"]}, no_cb=refuse_cb, yes_cb=accept_file_transfer_cb) 425 pop_up_widget = sat_widgets.ConfirmDialog(_("The contact %(jid)s wants to send you the file %(filename)s\nDo you accept ?") % {'jid':data["from"], 'filename':data["filename"]}, no_cb=refuse_cb, yes_cb=accept_file_transfer_cb)
426 self.showPopUp(pop_up_widget) 426 self.showPopUp(pop_up_widget)
427 427
428 elif confirmation_type == "YES/NO": 428 elif confirmation_type == "YES/NO":
430 self.showPopUp(pop_up_widget) 430 self.showPopUp(pop_up_widget)
431 431
432 def actionResult(self, type, id, data, profile): 432 def actionResult(self, type, id, data, profile):
433 if not self.check_profile(profile): 433 if not self.check_profile(profile):
434 return 434 return
435 435
436 if not id in self.current_action_ids: 436 if not id in self.current_action_ids:
437 debug (_('unknown id, ignoring')) 437 debug (_('unknown id, ignoring'))
438 return 438 return
439 if type == "SUPPRESS": 439 if type == "SUPPRESS":
440 self.current_action_ids.remove(id) 440 self.current_action_ids.remove(id)
453 ui.show('popup') 453 ui.show('popup')
454 else: 454 else:
455 ui.show('window') 455 ui.show('window')
456 elif type == "ERROR": 456 elif type == "ERROR":
457 self.current_action_ids.remove(id) 457 self.current_action_ids.remove(id)
458 self.showPopUp(sat_widgets.Alert(_("Error"), unicode(data["message"]), ok_cb=self.removePopUp)) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore 458 self.showPopUp(sat_widgets.Alert(_("Error"), unicode(data["message"]), ok_cb=self.removePopUp)) #FIXME: remove unicode here when DBus Bridge will no return dbus.String anymore
459 elif type == "RESULT": 459 elif type == "RESULT":
460 self.current_action_ids.remove(id) 460 self.current_action_ids.remove(id)
461 if self.current_action_ids_cb.has_key(id): 461 if self.current_action_ids_cb.has_key(id):
462 callback = self.current_action_ids_cb[id] 462 callback = self.current_action_ids_cb[id]
463 del self.current_action_ids_cb[id] 463 del self.current_action_ids_cb[id]
479 if room_jid.is_valid(): 479 if room_jid.is_valid():
480 self.bridge.joinMUC(room_jid, self.profiles[self.profile]['whoami'].node, {}, self.profile) 480 self.bridge.joinMUC(room_jid, self.profiles[self.profile]['whoami'].node, {}, self.profile)
481 else: 481 else:
482 message = _("'%s' is an invalid JID !") % room_jid 482 message = _("'%s' is an invalid JID !") % room_jid
483 error (message) 483 error (message)
484 self.showPopUp(sat_widgets.Alert(_("Error"), message, ok_cb=self.removePopUp)) 484 self.showPopUp(sat_widgets.Alert(_("Error"), message, ok_cb=self.removePopUp))
485 485
486 def onAddContact(self, button, edit): 486 def onAddContact(self, button, edit):
487 self.removePopUp() 487 self.removePopUp()
488 jid=JID(edit.get_edit_text()) 488 jid=JID(edit.get_edit_text())
489 if jid.is_valid(): 489 if jid.is_valid():
509 def success(params): 509 def success(params):
510 self.addWindow(XMLUI(self,xml_data=params)) 510 self.addWindow(XMLUI(self,xml_data=params))
511 def failure(error): 511 def failure(error):
512 self.showPopUp(sat_widgets.Alert(_("Error"), _("Can't get parameters"), ok_cb=self.removePopUp)) 512 self.showPopUp(sat_widgets.Alert(_("Error"), _("Can't get parameters"), ok_cb=self.removePopUp))
513 self.bridge.getParamsUI(self.profile, callback=success, errback=failure) 513 self.bridge.getParamsUI(self.profile, callback=success, errback=failure)
514 514
515 515
516 def onExitRequest(self, menu): 516 def onExitRequest(self, menu):
517 QuickApp.onExit(self) 517 QuickApp.onExit(self)
518 raise urwid.ExitMainLoop() 518 raise urwid.ExitMainLoop()
519 519
539 else: 539 else:
540 pop_up_widget = sat_widgets.ConfirmDialog(_("Are you sure you want to delete the contact [%s] ?" % contact), yes_cb=self.onRemoveContact, no_cb=self.removePopUp) 540 pop_up_widget = sat_widgets.ConfirmDialog(_("Are you sure you want to delete the contact [%s] ?" % contact), yes_cb=self.onRemoveContact, no_cb=self.removePopUp)
541 self.showPopUp(pop_up_widget) 541 self.showPopUp(pop_up_widget)
542 542
543 def onAboutRequest(self, menu): 543 def onAboutRequest(self, menu):
544 self.showPopUp(sat_widgets.Alert(_("About"), const_APP_NAME + " v" + self.bridge.getVersion(), ok_cb=self.removePopUp)) 544 self.showPopUp(sat_widgets.Alert(_("About"), const_APP_NAME + " v" + self.bridge.getVersion(), ok_cb=self.removePopUp))
545 545
546 #MISC CALLBACKS# 546 #MISC CALLBACKS#
547 547
548 def onGatewaysFound(self, data): 548 def onGatewaysFound(self, data):
549 """Called when SàT has found the server gateways""" 549 """Called when SàT has found the server gateways"""
550 target = data['__private__']['target'] 550 target = data['__private__']['target']