draft.py
1 # pylint: disable=unused-argument, import-error, too-many-arguments 2 # pylint: disable=unnecessary-comprehension, no-member, no-name-in-module 3 4 """ 5 draft.py 6 ============== 7 8 Draft screen for managing draft messages in Kivy UI. 9 """ 10 from kivy.clock import Clock 11 from kivy.properties import ListProperty, StringProperty 12 from kivy.uix.screenmanager import Screen 13 from kivy.app import App 14 from pybitmessage.bitmessagekivy.baseclass.common import ( 15 show_limited_cnt, empty_screen_label, kivy_state_variables 16 ) 17 import logging 18 19 logger = logging.getLogger('default') 20 21 22 class Draft(Screen): 23 """Draft screen class for Kivy UI""" 24 25 data = ListProperty() 26 account = StringProperty() 27 queryreturn = ListProperty() 28 has_refreshed = True 29 label_str = "Yet no message for this account!" 30 31 def __init__(self, *args, **kwargs): 32 """Initialize the Draft screen and set the default account""" 33 super().__init__(*args, **kwargs) 34 self.kivy_state = kivy_state_variables() 35 if not self.kivy_state.selected_address: 36 if App.get_running_app().identity_list: 37 self.kivy_state.selected_address = App.get_running_app().identity_list[0] 38 Clock.schedule_once(self.init_ui, 0) 39 40 def init_ui(self, dt=0): 41 """Initialize the UI and load draft messages""" 42 self.load_draft() 43 logger.debug(f"UI initialized with dt: {dt}") # noqa: E999 44 45 def load_draft(self, where="", what=""): 46 """Load the list of draft messages""" 47 self.set_draft_count('0') 48 self.ids.ml.add_widget(empty_screen_label(self.label_str)) 49 50 @staticmethod 51 def set_draft_count(count): 52 """Set the count of draft messages in the UI""" 53 draft_count_obj = App.get_running_app().root.ids.content_drawer.ids.draft_cnt 54 draft_count_obj.ids.badge_txt.text = show_limited_cnt(int(count))