inbox.py
1 # pylint: disable=unused-import, too-many-public-methods, unused-variable, too-many-ancestors 2 # pylint: disable=no-name-in-module, too-few-public-methods, import-error, unused-argument, too-many-arguments 3 # pylint: disable=attribute-defined-outside-init, global-variable-not-assigned, too-many-instance-attributes 4 5 """ 6 Kivy UI for inbox screen 7 """ 8 from kivy.clock import Clock 9 from kivy.properties import ListProperty, StringProperty 10 from kivy.app import App 11 from kivy.uix.screenmanager import Screen 12 from pybitmessage.bitmessagekivy.baseclass.common import kivy_state_variables, load_image_path 13 14 15 class Inbox(Screen): 16 """Inbox Screen class for Kivy UI""" 17 18 queryreturn = ListProperty() 19 has_refreshed = True 20 account = StringProperty() 21 no_search_res_found = "No search result found" 22 label_str = "Yet no message for this account!" 23 24 def __init__(self, *args, **kwargs): 25 """Initialize Kivy variables and set up the UI""" 26 super().__init__(*args, **kwargs) # pylint: disable=missing-super-argument 27 self.kivy_running_app = App.get_running_app() 28 self.kivy_state = kivy_state_variables() 29 self.image_dir = load_image_path() 30 Clock.schedule_once(self.init_ui, 0) 31 32 def set_default_address(self): 33 """Set the default address if none is selected""" 34 if not self.kivy_state.selected_address and self.kivy_running_app.identity_list: 35 self.kivy_state.selected_address = self.kivy_running_app.identity_list[0] 36 37 def init_ui(self, dt=0): 38 """Initialize UI and load message list""" 39 self.loadMessagelist() 40 41 def loadMessagelist(self, where="", what=""): 42 """Load inbox messages""" 43 self.set_default_address() 44 self.account = self.kivy_state.selected_address 45 46 def refresh_callback(self, *args): 47 """Refresh the inbox messages while showing a loading spinner""" 48 49 def refresh_on_scroll_down(interval): 50 """Reset search fields and reload data on scroll""" 51 self.kivy_state.searching_text = "" 52 self.children[2].children[1].ids.search_field.text = "" 53 self.ids.ml.clear_widgets() 54 self.loadMessagelist(self.kivy_state.selected_address) 55 self.has_refreshed = True 56 self.ids.refresh_layout.refresh_done() 57 self.tick = 0 58 59 Clock.schedule_once(refresh_on_scroll_down, 1)