comparison frontends/src/primitivus/primitivus @ 737:378af36155c2

frontends: set and retrieve your own presence and status
author souliane <souliane@mailoo.org>
date Mon, 25 Nov 2013 01:56:07 +0100
parents 6246eb6d64a0
children e867f146d49f
comparison
equal deleted inserted replaced
736:6246eb6d64a0 737:378af36155c2
31 from sat_frontends.primitivus.xmlui import XMLUI 31 from sat_frontends.primitivus.xmlui import XMLUI
32 from sat_frontends.primitivus.progress import Progress 32 from sat_frontends.primitivus.progress import Progress
33 from sat_frontends.primitivus.notify import Notify 33 from sat_frontends.primitivus.notify import Notify
34 from sat_frontends.tools.misc import InputHistory 34 from sat_frontends.tools.misc import InputHistory
35 from sat_frontends.primitivus.constants import Const 35 from sat_frontends.primitivus.constants import Const
36 from sat_frontends.constants import Const as commonConst
36 import logging 37 import logging
37 from logging import debug, info, error 38 from logging import debug, info, error
38 from sat.tools.jid import JID 39 from sat.tools.jid import JID
39 from os.path import join 40 from os.path import join
40 41
117 # and completion method 118 # and completion method
118 command = self.get_edit_text() 119 command = self.get_edit_text()
119 if command == 'quit': 120 if command == 'quit':
120 self.app.onExit() 121 self.app.onExit()
121 raise urwid.ExitMainLoop() 122 raise urwid.ExitMainLoop()
123 elif command == 'presence':
124 self.app.status_bar.onPresenceClick()
125 elif command in ['presence %s' % show for show in commonConst.PRESENCE.keys()]:
126 self.app.status_bar.onChange(user_data=sat_widgets.ClickableText(commonConst.PRESENCE[command[9:]]))
127 elif command == 'status':
128 self.app.status_bar.onStatusClick()
129 elif command.startswith('status '):
130 self.app.status_bar.onChange(user_data=sat_widgets.AdvancedEdit(command[7:]))
131 else:
132 return
133 self.set_edit_text('')
122 134
123 def keypress(self, size, key): 135 def keypress(self, size, key):
124 """Callback when a key is pressed. Send "composing" states 136 """Callback when a key is pressed. Send "composing" states
125 and move the index of the temporary history stack.""" 137 and move the index of the temporary history stack."""
126 def history_cb(text): 138 def history_cb(text):
149 def __init__(self): 161 def __init__(self):
150 QuickApp.__init__(self) 162 QuickApp.__init__(self)
151 163
152 ## main loop setup ## 164 ## main loop setup ##
153 self.main_widget = ProfileManager(self) 165 self.main_widget = ProfileManager(self)
154 self.loop = urwid.MainLoop(self.main_widget, const.PALETTE, event_loop=urwid.GLibEventLoop(), input_filter=self.inputFilter, unhandled_input=self.keyHandler) 166 self.loop = urwid.MainLoop(self.main_widget, Const.PALETTE, event_loop=urwid.GLibEventLoop(), input_filter=self.inputFilter, unhandled_input=self.keyHandler)
155 167
156 ##misc setup## 168 ##misc setup##
157 self.chat_wins = ChatList(self) 169 self.chat_wins = ChatList(self)
158 self.notBar = sat_widgets.NotificationBar() 170 self.notBar = sat_widgets.NotificationBar()
159 urwid.connect_signal(self.notBar, 'change', self.onNotification) 171 urwid.connect_signal(self.notBar, 'change', self.onNotification)
319 next_popup = self.notBar.getNextPopup() 331 next_popup = self.notBar.getNextPopup()
320 if next_popup: 332 if next_popup:
321 #we still have popup to show, we display it 333 #we still have popup to show, we display it
322 self.showPopUp(next_popup) 334 self.showPopUp(next_popup)
323 335
324 def showPopUp(self, pop_up_widget, perc_width=40, perc_height=40, valign='middle'): 336 def showPopUp(self, pop_up_widget, perc_width=40, perc_height=40, align='center', valign='middle'):
325 "Show a pop-up window if possible, else put it in queue" 337 "Show a pop-up window if possible, else put it in queue"
326 if not isinstance(self.loop.widget, urwid.Overlay): 338 if not isinstance(self.loop.widget, urwid.Overlay):
327 display_widget = urwid.Overlay(pop_up_widget, self.main_widget, 'center', ('relative', perc_width), valign, ('relative', perc_height)) 339 display_widget = urwid.Overlay(pop_up_widget, self.main_widget, align, ('relative', perc_width), valign, ('relative', perc_height))
328 self.loop.widget = display_widget 340 self.loop.widget = display_widget
329 self.redraw() 341 self.redraw()
330 else: 342 else:
331 self.notBar.addPopUp(pop_up_widget) 343 self.notBar.addPopUp(pop_up_widget)
332 344
588 else: 600 else:
589 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) 601 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)
590 self.showPopUp(pop_up_widget) 602 self.showPopUp(pop_up_widget)
591 603
592 def onAboutRequest(self, menu): 604 def onAboutRequest(self, menu):
593 self.showPopUp(sat_widgets.Alert(_("About"), const.APP_NAME + " v" + self.bridge.getVersion(), ok_cb=self.removePopUp)) 605 self.showPopUp(sat_widgets.Alert(_("About"), Const.APP_NAME + " v" + self.bridge.getVersion(), ok_cb=self.removePopUp))
594 606
595 #MISC CALLBACKS# 607 #MISC CALLBACKS#
596 608
597 def onGatewaysFound(self, data): 609 def onGatewaysFound(self, data):
598 """Called when SàT has found the server gateways""" 610 """Called when SàT has found the server gateways"""
625 637
626 from_bare = JID(from_jid_s).bare 638 from_bare = JID(from_jid_s).bare
627 if from_bare in self.chat_wins: 639 if from_bare in self.chat_wins:
628 self.chat_wins[from_bare].updateChatState(state) 640 self.chat_wins[from_bare].updateChatState(state)
629 641
642 def setStatusOnline(self, online=True, show="", statuses={}):
643 if not online or not show or not statuses:
644 return
645 try:
646 self.status_bar.setPresenceStatus(show, statuses['default'])
647 except (KeyError, TypeError):
648 pass
649
630 sat = PrimitivusApp() 650 sat = PrimitivusApp()
631 sat.start() 651 sat.start()