base_navigation.py
1 # pylint: disable=unused-argument, no-name-in-module, too-few-public-methods 2 """ 3 Base class for Navigation Drawer 4 """ 5 6 from kivy.lang import Observable 7 8 from kivy.properties import ( 9 BooleanProperty, 10 NumericProperty, 11 StringProperty 12 ) 13 from kivy.metrics import dp 14 from kivy.uix.boxlayout import BoxLayout 15 from kivy.uix.spinner import Spinner 16 17 from kivy.clock import Clock 18 from kivy.core.window import Window 19 20 from kivymd.uix.list import ( 21 OneLineAvatarIconListItem, 22 OneLineListItem 23 ) 24 25 from pybitmessage.bmconfigparser import config 26 27 28 class BaseLanguage(Observable): 29 """UI Language""" 30 observers = [] 31 lang = None 32 33 def __init__(self, defaultlang): 34 super(BaseLanguage, self).__init__() 35 self.ugettext = None 36 self.lang = defaultlang 37 38 @staticmethod 39 def _(text): 40 return text 41 42 43 class BaseNavigationItem(OneLineAvatarIconListItem): 44 """NavigationItem class for kivy Ui""" 45 badge_text = StringProperty() 46 icon = StringProperty() 47 active = BooleanProperty(False) 48 49 def currentlyActive(self): 50 """Currenly active""" 51 for nav_obj in self.parent.children: 52 nav_obj.active = False 53 self.active = True 54 55 56 class BaseNavigationDrawerDivider(OneLineListItem): 57 """ 58 A small full-width divider that can be placed 59 in the :class:`MDNavigationDrawer` 60 """ 61 62 disabled = True 63 divider = None 64 _txt_top_pad = NumericProperty(dp(8)) 65 _txt_bot_pad = NumericProperty(dp(8)) 66 67 def __init__(self, **kwargs): 68 super(BaseNavigationDrawerDivider, self).__init__(**kwargs) 69 self.height = dp(16) 70 71 72 class BaseNavigationDrawerSubheader(OneLineListItem): 73 """ 74 A subheader for separating content in :class:`MDNavigationDrawer` 75 76 Works well alongside :class:`NavigationDrawerDivider` 77 """ 78 79 disabled = True 80 divider = None 81 theme_text_color = 'Secondary' 82 83 84 class BaseContentNavigationDrawer(BoxLayout): 85 """ContentNavigationDrawer class for kivy Uir""" 86 87 def __init__(self, *args, **kwargs): 88 """Method used for contentNavigationDrawer""" 89 super(BaseContentNavigationDrawer, self).__init__(*args, **kwargs) 90 Clock.schedule_once(self.init_ui, 0) 91 92 def init_ui(self, dt=0): 93 """Clock Schdule for class contentNavigationDrawer""" 94 self.ids.scroll_y.bind(scroll_y=self.check_scroll_y) 95 96 def check_scroll_y(self, instance, somethingelse): 97 """show data on scroll down""" 98 if self.ids.identity_dropdown.is_open: 99 self.ids.identity_dropdown.is_open = False 100 101 102 class BaseIdentitySpinner(Spinner): 103 """Base Class for Identity Spinner(Dropdown)""" 104 105 def __init__(self, *args, **kwargs): 106 """Method used for setting size of spinner""" 107 super(BaseIdentitySpinner, self).__init__(*args, **kwargs) 108 self.dropdown_cls.max_height = Window.size[1] / 3 109 self.values = list(addr for addr in config.addresses() 110 if config.getboolean(str(addr), 'enabled'))