comparison urwid_satext/sat_widgets.py @ 114:bf38c1c0db3b

notificationBar: added removePopUp to remove a widget in the queue
author Goffi <goffi@goffi.org>
date Wed, 11 Nov 2015 18:16:25 +0100
parents 77ccc1dd2261
children 2b7eafea8bdb
comparison
equal deleted inserted replaced
113:77ccc1dd2261 114:bf38c1c0db3b
785 self.progress = ClickableText('') 785 self.progress = ClickableText('')
786 self.columns = urwid.Columns([('fixed',6,self.waitNotifs),self.message,('fixed',4,self.progress)]) 786 self.columns = urwid.Columns([('fixed',6,self.waitNotifs),self.message,('fixed',4,self.progress)])
787 urwid.WidgetWrap.__init__(self, urwid.AttrMap(self.columns,'notifs')) 787 urwid.WidgetWrap.__init__(self, urwid.AttrMap(self.columns,'notifs'))
788 self.notifs = [] 788 self.notifs = []
789 789
790 def __modQueue(self): 790 def _modQueue(self):
791 """must be called each time the notifications queue is changed""" 791 """must be called each time the notifications queue is changed"""
792 self.waitNotifs.set_text(('notifs',"(%i)" % len(self.notifs) if self.notifs else '')) 792 self.waitNotifs.set_text(('notifs',"(%i)" % len(self.notifs) if self.notifs else ''))
793 self._emit('change') 793 self._emit('change')
794 794
795 def setProgress(self,percentage): 795 def setProgress(self,percentage):
803 self._emit('change') 803 self._emit('change')
804 804
805 def addPopUp(self, pop_up_widget): 805 def addPopUp(self, pop_up_widget):
806 """Add a popup to the waiting queue""" 806 """Add a popup to the waiting queue"""
807 self.notifs.append(('popup',pop_up_widget)) 807 self.notifs.append(('popup',pop_up_widget))
808 self.__modQueue() 808 self._modQueue()
809
810 def removePopUp(self, pop_up_widget):
811 """Remove a popup from the waiting queue"""
812 self.notifs.remove(pop_up_widget)
813 self._modQueue()
809 814
810 def addMessage(self, message): 815 def addMessage(self, message):
811 "Add a message to the notificatio bar" 816 "Add a message to the notificatio bar"
812 if not self.message.get_text(): 817 if not self.message.get_text():
813 self.message.set_text(('notifs',message)) 818 self.message.set_text(('notifs',message))
814 self._invalidate() 819 self._invalidate()
815 self._emit('change') 820 self._emit('change')
816 else: 821 else:
817 self.notifs.append(('message',message)) 822 self.notifs.append(('message',message))
818 self.__modQueue() 823 self._modQueue()
819 824
820 def showNext(self): 825 def showNext(self):
821 """Show next message if any, else delete current message""" 826 """Show next message if any, else delete current message"""
822 found = None 827 found = None
823 for notif in self.notifs: 828 for notif in self.notifs:
825 found = notif 830 found = notif
826 break 831 break
827 if found: 832 if found:
828 self.notifs.remove(found) 833 self.notifs.remove(found)
829 self.message.set_text(('notifs',found[1])) 834 self.message.set_text(('notifs',found[1]))
830 self.__modQueue() 835 self._modQueue()
831 self.focus_possition = 1 836 self.focus_possition = 1
832 else: 837 else:
833 self.message.set_text('') 838 self.message.set_text('')
834 self._emit('change') 839 self._emit('change')
835 840
841 if notif[0] == 'popup': 846 if notif[0] == 'popup':
842 ret = notif[1] 847 ret = notif[1]
843 break 848 break
844 if ret: 849 if ret:
845 self.notifs.remove(notif) 850 self.notifs.remove(notif)
846 self.__modQueue() 851 self._modQueue()
847 return ret 852 return ret
848 853
849 def isQueueEmpty(self): 854 def isQueueEmpty(self):
850 return not bool(self.notifs) 855 return not bool(self.notifs)
851 856