worked on implementing toggle button funcationality on myaddress screen

This commit is contained in:
navjot 2020-01-29 21:44:39 +05:30
parent 787b77d80d
commit 34f9ed0153
No known key found for this signature in database
GPG Key ID: 9EE70AFD71357F1C
3 changed files with 81 additions and 58 deletions

View File

@ -56,3 +56,10 @@
center_x: self.parent.center_x center_x: self.parent.center_x
center_y: self.parent.center_y center_y: self.parent.center_y
size: 20, 20 size: 20, 20
<ToggleBtn>:
#size_hint: None, None
size: dp(36), dp(48)
pos_hint: {'center_x': .95, 'center_y': .4}
on_press: app.root.ids.sc10.toggleAction(self)

View File

@ -21,4 +21,3 @@
MDList: MDList:
id: ml id: ml
Loader: Loader:
ComposerButton:

View File

@ -55,7 +55,7 @@ from kivymd.uix.list import (
# MDNavigationDrawer, # MDNavigationDrawer,
# NavigationDrawerHeaderBase # NavigationDrawerHeaderBase
# ) # )
from kivymd.uix.selectioncontrol import MDCheckbox from kivymd.uix.selectioncontrol import MDCheckbox, MDSwitch
import queues import queues
from semaphores import kivyuisignaler from semaphores import kivyuisignaler
@ -263,17 +263,11 @@ class Inbox(Screen):
"""Delete inbox mail from inbox listing""" """Delete inbox mail from inbox listing"""
sqlExecute( sqlExecute(
"UPDATE inbox SET folder = 'trash' WHERE msgid = ?;", data_index) "UPDATE inbox SET folder = 'trash' WHERE msgid = ?;", data_index)
try: msg_count_objs = self.parent.parent.ids.content_drawer.ids
msg_count_objs = (
self.parent.parent.parent.parent.children[2].children[0].ids)
except Exception:
msg_count_objs = (
self.parent.parent.parent.parent.parent.children[
2].children[0].ids)
if int(state.inbox_count) > 0: if int(state.inbox_count) > 0:
msg_count_objs.inbox_cnt.badge_text = showLimitedCnt(int(state.inbox_count) - 1) msg_count_objs.inbox_cnt.children[0].children[0].text = showLimitedCnt(int(state.inbox_count) - 1)
msg_count_objs.trash_cnt.badge_text = showLimitedCnt(int(state.trash_count) + 1) msg_count_objs.trash_cnt.children[0].children[0].text = showLimitedCnt(int(state.trash_count) + 1)
msg_count_objs.allmail_cnt.badge_text = showLimitedCnt(int(state.all_count) - 1) msg_count_objs.allmail_cnt.children[0].children[0].text = showLimitedCnt(int(state.all_count) - 1)
state.inbox_count = str( state.inbox_count = str(
int(state.inbox_count) - 1) int(state.inbox_count) - 1)
state.trash_count = str( state.trash_count = str(
@ -378,29 +372,37 @@ class MyAddress(Screen):
text=item['text'], secondary_text=item['secondary_text'], text=item['text'], secondary_text=item['secondary_text'],
theme_text_color='Custom' if is_enable == 'true' else 'Primary', theme_text_color='Custom' if is_enable == 'true' else 'Primary',
text_color=NavigateApp().theme_cls.primary_color, text_color=NavigateApp().theme_cls.primary_color,
disabled=False if is_enable == 'true' else True) )
meny.add_widget(AvatarSampleWidget( meny.add_widget(AvatarSampleWidget(
source='./images/text_images/{}.png'.format( source='./images/text_images/{}.png'.format(
avatarImageFirstLetter(item['text'].strip())))) avatarImageFirstLetter(item['text'].strip()))))
meny.bind(on_press=partial( meny.bind(on_press=partial(
self.myadd_detail, item['secondary_text'], item['text'])) self.myadd_detail, item['secondary_text'], item['text']))
carousel = Carousel(direction='right') if state.association == item['secondary_text']:
carousel.height = meny.height meny.add_widget(BadgeText(size_hint= (None, None),
carousel.size_hint_y = None text='Active', halign='right',
carousel.ignore_perpendicular_swipes = True font_style='Body1', size= [50,60],
carousel.data_index = 0 theme_text_color='Custom',
carousel.min_move = 0.2 text_color=NavigateApp().theme_cls.primary_color))
del_btn = Button(text='Disable' if is_enable == 'true' else 'Enable') else:
if is_enable == 'true': meny.add_widget(ToggleBtn(active = True if is_enable == 'true' else False))
del_btn.background_normal = '' # carousel = Carousel(direction='right')
del_btn.background_color = (1, 0, 0, 1) if is_enable == 'true' else (0, 1, 0, 1) # carousel.height = meny.height
del_btn.bind( # carousel.size_hint_y = None
on_press=partial( # carousel.ignore_perpendicular_swipes = True
self.disableAddress if is_enable == 'true' else self.enableAddress , item['secondary_text'])) # carousel.data_index = 0
carousel.add_widget(del_btn) # carousel.min_move = 0.2
carousel.add_widget(meny) # del_btn = Button(text='Disable' if is_enable == 'true' else 'Enable')
carousel.index = 1 # if is_enable == 'true':
self.ids.ml.add_widget(carousel) # del_btn.background_normal = ''
# del_btn.background_color = (1, 0, 0, 1) if is_enable == 'true' else (0, 1, 0, 1)
# del_btn.bind(
# on_press=partial(
# self.disableAddress if is_enable == 'true' else self.enableAddress , item['secondary_text']))
# carousel.add_widget(del_btn)
# carousel.add_widget(meny)
# carousel.index = 1
self.ids.ml.add_widget(meny)
def check_scroll_y(self, instance, somethingelse): def check_scroll_y(self, instance, somethingelse):
"""Load data on scroll down""" """Load data on scroll down"""
@ -421,9 +423,10 @@ class MyAddress(Screen):
@staticmethod @staticmethod
def myadd_detail(fromaddress, label, *args): def myadd_detail(fromaddress, label, *args):
"""Load myaddresses details""" """Load myaddresses details"""
p = MyaddDetailPopup() if BMConfigParser().get(fromaddress, 'enabled') == 'true':
p.open() p = MyaddDetailPopup()
p.set_address(fromaddress, label) p.open()
p.set_address(fromaddress, label)
def refresh_callback(self, *args): def refresh_callback(self, *args):
"""Method updates the state of application, """Method updates the state of application,
@ -432,8 +435,7 @@ class MyAddress(Screen):
"""Method used for loading the myaddress screen data""" """Method used for loading the myaddress screen data"""
state.searcing_text = '' state.searcing_text = ''
# state.kivyapp.root.ids.sc10.children[2].active = False # state.kivyapp.root.ids.sc10.children[2].active = False
# self.children[2].children[2].ids.search_field.text = '' self.children[2].children[2].ids.search_field.text = ''
self.children[3].children[2].ids.search_field.text = ''
self.has_refreshed = True self.has_refreshed = True
self.ids.ml.clear_widgets() self.ids.ml.clear_widgets()
self.init_ui() self.init_ui()
@ -454,34 +456,39 @@ class MyAddress(Screen):
return True return True
return False return False
def disableAddress(self, address, instance, *args):
def disableAddress(self, address, instance):
"""This method is use for disabling address""" """This method is use for disabling address"""
BMConfigParser().set(str(address), 'enabled', 'false') BMConfigParser().set(str(address), 'enabled', 'false')
BMConfigParser().save() BMConfigParser().save()
state.kivyapp.loadMyAddressScreen(True) instance.parent.parent.theme_text_color = 'Primary'
state.kivyapp.root.ids.sc10.ids.ml.clear_widgets() toast('Address disabled')
Clock.schedule_once(self.address_permision_callback, 0) Clock.schedule_once(self.address_permision_callback, 0)
# state.kivyapp.root.ids.sc10.init_ui()
pass
def enableAddress(self, address, instance, *args): def enableAddress(self, address, instance):
"""This method is use for enabling address""" """This method is use for enabling address"""
BMConfigParser().set(address, 'enabled', 'true') BMConfigParser().set(address, 'enabled', 'true')
BMConfigParser().save() BMConfigParser().save()
state.kivyapp.loadMyAddressScreen(True) instance.parent.parent.theme_text_color = 'Custom'
state.kivyapp.root.ids.sc10.ids.ml.clear_widgets() toast('Address Enabled')
Clock.schedule_once(self.address_permision_callback, 0) Clock.schedule_once(self.address_permision_callback, 0)
# @staticmethod
def address_permision_callback(self, dt=0): def address_permision_callback(self, dt=0):
"""New address created""" """callback for enable or disable addresses"""
state.kivyapp.loadMyAddressScreen(False)
state.kivyapp.root.ids.sc10.init_ui()
addresses = [addr for addr in BMConfigParser().addresses() addresses = [addr for addr in BMConfigParser().addresses()
if BMConfigParser().get(str(addr), 'enabled') == 'true'] if BMConfigParser().get(str(addr), 'enabled') == 'true']
self.parent.parent.ids.content_drawer.ids.btn.values = addresses self.parent.parent.ids.content_drawer.ids.btn.values = addresses
self.parent.parent.ids.sc3.children[1].ids.btn.values = addresses self.parent.parent.ids.sc3.children[1].ids.btn.values = addresses
def toggleAction(self, instance):
"""This method is used for enable or disable address"""
addr = instance.parent.parent.secondary_text
if instance.active:
self.disableAddress(addr, instance)
else:
self.enableAddress(addr, instance)
class AddressBook(Screen): class AddressBook(Screen):
"""AddressBook Screen uses screen to show widgets of screens""" """AddressBook Screen uses screen to show widgets of screens"""
@ -1105,7 +1112,7 @@ class Sent(Screen):
src_mng_obj = state.kivyapp.root.ids.content_drawer.ids.send_cnt src_mng_obj = state.kivyapp.root.ids.content_drawer.ids.send_cnt
if state.association: if state.association:
src_mng_obj.children[0].children[0].text = showLimitedCnt(int(total_sent)) src_mng_obj.children[0].children[0].text = showLimitedCnt(int(total_sent))
# state.sent_count = str(total_sent) state.sent_count = str(total_sent)
else: else:
src_mng_obj.children[0].children[0].text = '0' src_mng_obj.children[0].children[0].text = '0'
@ -1419,6 +1426,9 @@ class NavigateApp(MDApp):
self.root.ids.sc17.clear_widgets() self.root.ids.sc17.clear_widgets()
self.root.ids.sc17.add_widget(Allmails()) self.root.ids.sc17.add_widget(Allmails())
self.root.ids.sc10.ids.ml.clear_widgets()
self.root.ids.sc10.init_ui()
self.root.ids.scr_mngr.current = 'inbox' self.root.ids.scr_mngr.current = 'inbox'
@staticmethod @staticmethod
@ -1547,10 +1557,10 @@ class NavigateApp(MDApp):
def loadMyAddressScreen(self, action): def loadMyAddressScreen(self, action):
"""loadMyAddressScreen method spin the loader""" """loadMyAddressScreen method spin the loader"""
if len(self.root.ids.sc10.children) <= 3: if len(self.root.ids.sc10.children) <= 2:
self.root.ids.sc10.children[1].active = action self.root.ids.sc10.children[0].active = action
else: else:
self.root.ids.sc10.children[2].active = action self.root.ids.sc10.children[1].active = action
def save_draft(self): def save_draft(self):
"""Saving drafts messages""" """Saving drafts messages"""
@ -1750,7 +1760,7 @@ class NavigateApp(MDApp):
elif state.search_screen == 'myaddress': elif state.search_screen == 'myaddress':
try: try:
self.root.ids.sc10.children[ self.root.ids.sc10.children[
3].children[2].ids.search_field.text = '' 1].children[2].ids.search_field.text = ''
except Exception: except Exception:
self.root.ids.sc10.children[ self.root.ids.sc10.children[
2].children[2].ids.search_field.text = '' 2].children[2].ids.search_field.text = ''
@ -1810,12 +1820,14 @@ class NavigateApp(MDApp):
self.root.ids.sc1.loadMessagelist(state.association) self.root.ids.sc1.loadMessagelist(state.association)
self.root.ids.sc1.children[1].active = False self.root.ids.sc1.children[1].active = False
elif instance.text == 'All Mails': elif instance.text == 'All Mails':
if len(self.root.ids.sc17.ids.ml.children) <= 2: # if len(self.root.ids.sc17.ids.ml.children) <= 2:
self.root.ids.sc17.clear_widgets() # self.root.ids.sc17.clear_widgets()
self.root.ids.sc17.add_widget(Allmails()) # self.root.ids.sc17.add_widget(Allmails())
else: # else:
self.root.ids.sc17.ids.ml.clear_widgets() # self.root.ids.sc17.ids.ml.clear_widgets()
self.root.ids.sc17.loadMessagelist() # self.root.ids.sc17.loadMessagelist()
self.root.ids.sc17.clear_widgets()
self.root.ids.sc17.add_widget(Allmails())
try: try:
self.root.ids.sc17.children[1].active = False self.root.ids.sc17.children[1].active = False
except Exception: except Exception:
@ -1960,6 +1972,11 @@ class IconRightSampleWidget(IRightBodyTouch, MDCheckbox):
pass pass
class ToggleBtn(IRightBodyTouch, MDSwitch):
"""Right toggle button widget"""
pass
class MailDetail(Screen): class MailDetail(Screen):
"""MailDetail Screen uses to show the detail of mails""" """MailDetail Screen uses to show the detail of mails"""