merged kivy-state-variable

This commit is contained in:
shekhar-cis 2022-05-09 14:10:08 +05:30
commit 8b0da145ac
Signed by untrusted user: shekhar-cis
GPG Key ID: F4F00AB04E83F9A7
5 changed files with 88 additions and 16 deletions

View File

@ -8,6 +8,8 @@ from struct import pack, unpack
from debug import logger
from bmconfigparser import BMConfigParser
ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
@ -276,3 +278,15 @@ def addBMIfNotPresent(address):
"""Prepend BM- to an address if it doesn't already have it"""
address = str(address).strip()
return address if address[:3] == 'BM-' else 'BM-' + address
def disable_addresses(address):
""""To disable the Address"""
BMConfigParser().set(str(address), 'enabled', 'false')
BMConfigParser().save()
def enable_addresses(address):
""""To enable the Address"""
BMConfigParser().set(address, 'enabled', 'true')
BMConfigParser().save()

View File

@ -16,9 +16,10 @@ from kivy.properties import (
NumericProperty,
StringProperty
)
from kivymd.uix.label import MDLabel
import state
ThemeClsColor = [0.12, 0.58, 0.95, 1]
@ -71,7 +72,7 @@ def chipTag(text):
def toast(text):
"""Method will display the toast message"""
"""Function will display the toast message"""
kivytoast.toast(text)
def showLimitedCnt(total_msg):
@ -82,16 +83,14 @@ def showLimitedCnt(total_msg):
def avatarImageFirstLetter(letter_string):
"""This function is used to the first letter for the avatar image"""
try:
if letter_string[0].upper() >= 'A' and letter_string[0].upper() <= 'Z':
img_latter = letter_string[0].upper()
elif int(letter_string[0]) >= 0 and int(letter_string[0]) <= 9:
img_latter = letter_string[0]
if isinstance(letter_string, int):
return letter_string[0]
elif isinstance(letter_string, str) and letter_string[0].isalnum():
return letter_string.title()[0]
else:
img_latter = '!'
except ValueError:
img_latter = '!'
return img_latter if img_latter else '!'
return '!'
except IndexError:
return '!'
def AddTimeWidget(time): # pylint: disable=redefined-outer-name, W0201
"""This method is used to create TimeWidget"""
@ -145,14 +144,25 @@ class CutsomSwipeToDeleteItem(MDCardSwipe):
opening_time = NumericProperty(0.5)
def empty_screen_label(label_str):
"""This function returns default message while no address is there."""
# empty_screen_msg = "yet no message for this account!!!!!!!!!!!!!"
def empty_screen_label(label_str=None, no_search_res_found=None):
"""Returns default text on screen when no address is there."""
content = MDLabel(
font_style='Caption',
theme_text_color='Primary',
text=label_str,
text=no_search_res_found if state.searcing_text else label_str,
halign='center',
size_hint_y=None,
valign='top')
return content
def mdlist_message_content(queryreturn, data, max_len=25, min_len=10):
for mail in queryreturn:
third_text = mail[3].replace('\n', ' ')
data.append({
'text': mail[1].strip(),
'secondary_text': mail[2][:10] + '...........' if len(
mail[2]) > 10 else mail[2] + '\n' + " " + (
third_text[:25] + '...!') if len(
third_text) > 25 else third_text,
'ackdata': mail[5], 'senttime': mail[6]})

View File

@ -0,0 +1,36 @@
# pylint: disable=too-many-instance-attributes, too-few-public-methods
"""
Kivy State variables are assigned here, they are separated from state.py
=================================
"""
class KivyStateVariables(object):
"""This Class hold all the kivy state variables"""
def __init__(self):
self.association = ''
self.navinstance = None
self.mail_id = 0
self.myAddressObj = None
self.detailPageType = None
self.ackdata = None
self.status = None
self.screen_density = None
self.msg_counter_objs = None
self.check_sent_acc = None
self.sent_count = 0
self.inbox_count = 0
self.trash_count = 0
self.draft_count = 0
self.all_count = 0
self.searcing_text = ''
self.search_screen = ''
self.send_draft_mail = None
self.is_allmail = False
self.in_composer = False
self.availabe_credit = 0
self.in_sent_method = False
self.in_search_mode = False
self.imageDir = None

View File

@ -61,6 +61,9 @@ from bitmessagekivy.baseclass.common import toast
from qr_scanner.zbarcam import ZBarCam
from pyzbar.pyzbar import ZBarSymbol
# import pdb; pdb.set_trace()
from bitmessagekivy.kivy_state import KivyStateVariables
if platform != "android":
from kivy.config import Config
Config.set("input", "mouse", "mouse, multitouch_on_demand")
@ -208,8 +211,12 @@ class CustomSpinner(Spinner):
class NavigateApp(MDApp):
"""Navigation Layout of class"""
# pylint: disable=too-many-public-methods,inconsistent-return-statements
kivyy = KivyStateVariables()
# theme_cls = ThemeManager()
def __init__(self):
super(NavigateApp, self).__init__()
self.kivy_state_obj = KivyStateVariables()
previous_date = ObjectProperty()
obj_1 = ObjectProperty()
variable_1 = ListProperty(addr for addr in BMConfigParser().addresses()

View File

@ -194,3 +194,8 @@ class BMConfigParser(configparser.ConfigParser):
if value < 0 or value > 8:
return False
return True
@staticmethod
def search_addresses(address, searched_text):
return [x for x in [BMConfigParser().get(address, 'label').lower(), address.lower()]
if searched_text in x]