comparison libervia/desktop_kivy/core/cagou_main.py @ 505:bbef1a413515

core (main): add methods to deleted notifications: This will be used notably in Calls feature to remove a notification if an incoming call is cancelled before being handler by user. rel 425
author Goffi <goffi@goffi.org>
date Wed, 25 Oct 2023 15:24:42 +0200
parents 3b627382e681
children d78728d7fd6a
comparison
equal deleted inserted replaced
504:fe0bdc476576 505:bbef1a413515
109 callback(*args, **kwargs) 109 callback(*args, **kwargs)
110 110
111 def add_notif(self, callback, *args, **kwargs): 111 def add_notif(self, callback, *args, **kwargs):
112 self.notifs.append((callback, args, kwargs)) 112 self.notifs.append((callback, args, kwargs))
113 113
114 def del_notif(self, callback, *args, **kwargs):
115 try:
116 self.notifs.remove((callback, args, kwargs))
117 except ValueError:
118 log.debug("The notification to delete doesn't exist anymore.")
119
114 120
115 class Note(Label): 121 class Note(Label):
116 title = properties.StringProperty() 122 title = properties.StringProperty()
117 message = properties.StringProperty() 123 message = properties.StringProperty()
118 level = properties.OptionProperty(C.XMLUI_DATA_LVL_DEFAULT, 124 level = properties.OptionProperty(C.XMLUI_DATA_LVL_DEFAULT,
204 self.notifs_icon.add_notif(ui.show, force=True) 210 self.notifs_icon.add_notif(ui.show, force=True)
205 211
206 def add_notif_widget(self, widget): 212 def add_notif_widget(self, widget):
207 app = App.get_running_app() 213 app = App.get_running_app()
208 self.notifs_icon.add_notif(app.host.show_extra_ui, widget=widget) 214 self.notifs_icon.add_notif(app.host.show_extra_ui, widget=widget)
215
216 def del_notif_widget(self, widget):
217 app = App.get_running_app()
218 self.notifs_icon.del_notif(app.host.show_extra_ui, widget=widget)
209 219
210 def _display_next_note(self, __=None): 220 def _display_next_note(self, __=None):
211 screen = Screen() 221 screen = Screen()
212 try: 222 try:
213 idx = self.notes.index(self.notes_last) + 1 223 idx = self.notes.index(self.notes_last) + 1
282 def add_notif_ui(self, ui): 292 def add_notif_ui(self, ui):
283 self.head_widget.add_notif_ui(ui) 293 self.head_widget.add_notif_ui(ui)
284 294
285 def add_notif_widget(self, widget): 295 def add_notif_widget(self, widget):
286 self.head_widget.add_notif_widget(widget) 296 self.head_widget.add_notif_widget(widget)
297
298 def del_notif_widget(self, widget):
299 self.head_widget.del_notif_widget(widget)
287 300
288 301
289 class LiberviaDesktopKivyApp(App): 302 class LiberviaDesktopKivyApp(App):
290 """Kivy App for LiberviaDesktopKivy""" 303 """Kivy App for LiberviaDesktopKivy"""
291 c_prim = properties.ListProperty(C.COLOR_PRIM) 304 c_prim = properties.ListProperty(C.COLOR_PRIM)
456 self.app.title = C.APP_NAME 469 self.app.title = C.APP_NAME
457 # main widgets plugins 470 # main widgets plugins
458 self._plg_wids = [] 471 self._plg_wids = []
459 # transfer widgets plugins 472 # transfer widgets plugins
460 self._plg_wids_transfer = [] 473 self._plg_wids_transfer = []
461 self._import_plugins() 474
475 Clock.schedule_once(lambda __: self._import_plugins(), 0)
462 # visible widgets by classes 476 # visible widgets by classes
463 self._visible_widgets = {} 477 self._visible_widgets = {}
464 # used to keep track of last selected widget in "main" screen when changing 478 # used to keep track of last selected widget in "main" screen when changing
465 # root screen 479 # root screen
466 self._selected_widget_main = None 480 self._selected_widget_main = None
1040 1054
1041 @param widget(kivy.uix.Widget): widget to attach to notification 1055 @param widget(kivy.uix.Widget): widget to attach to notification
1042 """ 1056 """
1043 self.app.root.add_notif_widget(widget) 1057 self.app.root.add_notif_widget(widget)
1044 1058
1059 def del_notif_widget(self, widget):
1060 """del a notification with a Kivy widget attached
1061
1062 @param widget(kivy.uix.Widget): widget to attach to notification
1063 """
1064 if self.selected_widget == widget:
1065 self.close_ui()
1066 else:
1067 self.app.root.del_notif_widget(widget)
1068
1045 def show_ui(self, ui): 1069 def show_ui(self, ui):
1046 """show a XMLUI""" 1070 """show a XMLUI"""
1047 self.app.root.change_widget(ui, "xmlui") 1071 self.app.root.change_widget(ui, "xmlui")
1048 self.app.root.show("xmlui") 1072 self.app.root.show("xmlui")
1049 self._selected_widget_main = self.selected_widget 1073 self._selected_widget_main = self.selected_widget
1055 self.app.root.show("extra") 1079 self.app.root.show("extra")
1056 self._selected_widget_main = self.selected_widget 1080 self._selected_widget_main = self.selected_widget
1057 self.selected_widget = widget 1081 self.selected_widget = widget
1058 1082
1059 def close_ui(self): 1083 def close_ui(self):
1084 """Close current UI in extra screen"""
1060 self.app.root.show() 1085 self.app.root.show()
1061 self.selected_widget = self._selected_widget_main 1086 self.selected_widget = self._selected_widget_main
1062 self._selected_widget_main = None 1087 self._selected_widget_main = None
1063 screen = self.app.root._manager.get_screen("extra") 1088 screen = self.app.root._manager.get_screen("extra")
1064 screen.clear_widgets() 1089 screen.clear_widgets()
1087 no_cb=self._dialog_cb(answer_cb, 1112 no_cb=self._dialog_cb(answer_cb,
1088 False, 1113 False,
1089 answer_data) 1114 answer_data)
1090 ) 1115 )
1091 self.add_notif_widget(wid) 1116 self.add_notif_widget(wid)
1117 return wid
1092 else: 1118 else:
1093 log.warning(_("unknown dialog type: {dialog_type}").format(dialog_type=type)) 1119 log.warning(_("unknown dialog type: {dialog_type}").format(dialog_type=type))
1094 1120
1095 def share(self, media_type, data): 1121 def share(self, media_type, data):
1096 share_wid = ShareWidget(media_type=media_type, data=data) 1122 share_wid = ShareWidget(media_type=media_type, data=data)