Merge branch 'Kivy-UI-Enhancement' into kivy-state-variable
This commit is contained in:
commit
d024deb977
|
@ -8,6 +8,8 @@ from struct import pack, unpack
|
||||||
|
|
||||||
from debug import logger
|
from debug import logger
|
||||||
|
|
||||||
|
from bmconfigparser import BMConfigParser
|
||||||
|
|
||||||
ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
||||||
|
|
||||||
|
|
||||||
|
@ -276,3 +278,15 @@ def addBMIfNotPresent(address):
|
||||||
"""Prepend BM- to an address if it doesn't already have it"""
|
"""Prepend BM- to an address if it doesn't already have it"""
|
||||||
address = str(address).strip()
|
address = str(address).strip()
|
||||||
return address if address[:3] == 'BM-' else 'BM-' + address
|
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()
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
from turtle import pd
|
|
||||||
from bitmessagekivy.get_platform import platform
|
from bitmessagekivy.get_platform import platform
|
||||||
from bitmessagekivy import kivy_helper_search
|
from bitmessagekivy import kivy_helper_search
|
||||||
from helper_sql import sqlExecute
|
from helper_sql import sqlExecute
|
||||||
|
@ -14,21 +13,26 @@ from kivymd.uix.label import MDLabel
|
||||||
from kivy.uix.screenmanager import Screen
|
from kivy.uix.screenmanager import Screen
|
||||||
|
|
||||||
import state
|
import state
|
||||||
|
import os
|
||||||
|
|
||||||
|
from debug import logger
|
||||||
from bitmessagekivy.baseclass.common import (
|
from bitmessagekivy.baseclass.common import (
|
||||||
avatarImageFirstLetter, toast,
|
avatarImageFirstLetter, toast, empty_screen_label,
|
||||||
ThemeClsColor, SwipeToDeleteItem
|
ThemeClsColor, SwipeToDeleteItem
|
||||||
)
|
)
|
||||||
from bitmessagekivy.baseclass.popup import AddbookDetailPopup
|
from bitmessagekivy.baseclass.popup import AddbookDetailPopup
|
||||||
from bitmessagekivy.baseclass.addressbook_widgets import HelperAddressBook
|
from bitmessagekivy.baseclass.addressbook_widgets import HelperAddressBook
|
||||||
|
|
||||||
class AddressBook(Screen):
|
|
||||||
|
class AddressBook(Screen, HelperAddressBook):
|
||||||
"""AddressBook Screen class for kivy Ui"""
|
"""AddressBook Screen class for kivy Ui"""
|
||||||
|
|
||||||
queryreturn = ListProperty()
|
queryreturn = ListProperty()
|
||||||
has_refreshed = True
|
has_refreshed = True
|
||||||
address_label = StringProperty()
|
address_label = StringProperty()
|
||||||
address = StringProperty()
|
address = StringProperty()
|
||||||
|
label_str = "No contact found yet......"
|
||||||
|
no_search_res_found = "No search result found"
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
"""Getting AddressBook Details"""
|
"""Getting AddressBook Details"""
|
||||||
|
@ -39,7 +43,7 @@ class AddressBook(Screen):
|
||||||
def init_ui(self, dt=0):
|
def init_ui(self, dt=0):
|
||||||
"""Clock Schdule for method AddressBook"""
|
"""Clock Schdule for method AddressBook"""
|
||||||
self.loadAddresslist(None, 'All', '')
|
self.loadAddresslist(None, 'All', '')
|
||||||
print(dt)
|
logger.debug(dt)
|
||||||
|
|
||||||
def loadAddresslist(self, account, where="", what=""):
|
def loadAddresslist(self, account, where="", what=""):
|
||||||
"""Clock Schdule for method AddressBook"""
|
"""Clock Schdule for method AddressBook"""
|
||||||
|
@ -58,6 +62,7 @@ class AddressBook(Screen):
|
||||||
self.set_mdList(0, 20)
|
self.set_mdList(0, 20)
|
||||||
self.ids.scroll_y.bind(scroll_y=self.check_scroll_y)
|
self.ids.scroll_y.bind(scroll_y=self.check_scroll_y)
|
||||||
else:
|
else:
|
||||||
|
"""This is still exprimental, may need to make changes somewhere"""
|
||||||
# content = MDLabel(
|
# content = MDLabel(
|
||||||
# font_style='Caption',
|
# font_style='Caption',
|
||||||
# theme_text_color='Primary',
|
# theme_text_color='Primary',
|
||||||
|
@ -66,18 +71,7 @@ class AddressBook(Screen):
|
||||||
# halign='center',
|
# halign='center',
|
||||||
# size_hint_y=None,
|
# size_hint_y=None,
|
||||||
# valign='top')
|
# valign='top')
|
||||||
self.ids.ml.add_widget(HelperAddressBook.default_label_while_empty())
|
self.ids.ml.add_widget(empty_screen_label(self.label_str, self.no_search_res_found))
|
||||||
|
|
||||||
# def show_default_content(self):
|
|
||||||
# content = MDLabel(
|
|
||||||
# font_style='Caption',
|
|
||||||
# theme_text_color='Primary',
|
|
||||||
# text="No contact found!" if state.searcing_text
|
|
||||||
# else "No contact found yet...... ",
|
|
||||||
# halign='center',
|
|
||||||
# size_hint_y=None,
|
|
||||||
# valign='top')
|
|
||||||
# return content
|
|
||||||
|
|
||||||
def set_mdList(self, start_index, end_index):
|
def set_mdList(self, start_index, end_index):
|
||||||
"""Creating the mdList"""
|
"""Creating the mdList"""
|
||||||
|
@ -92,8 +86,9 @@ class AddressBook(Screen):
|
||||||
# listItem.add_widget(AvatarSampleWidget(
|
# listItem.add_widget(AvatarSampleWidget(
|
||||||
# source=state.imageDir + '/text_images/{}.png'.format(
|
# source=state.imageDir + '/text_images/{}.png'.format(
|
||||||
# avatarImageFirstLetter(item[0].strip()))))
|
# avatarImageFirstLetter(item[0].strip()))))
|
||||||
image = state.imageDir + "/text_images/{}.png".format(
|
image = os.path.join(
|
||||||
avatarImageFirstLetter(item[0].strip()))
|
state.imageDir, "text_images", "{}.png".format(avatarImageFirstLetter(item[0].strip()))
|
||||||
|
)
|
||||||
message_row.ids.avater_img.source = image
|
message_row.ids.avater_img.source = image
|
||||||
listItem.bind(on_release=partial(
|
listItem.bind(on_release=partial(
|
||||||
self.addBook_detail, item[1], item[0], message_row))
|
self.addBook_detail, item[1], item[0], message_row))
|
||||||
|
@ -127,11 +122,10 @@ class AddressBook(Screen):
|
||||||
if instance.state == 'closed':
|
if instance.state == 'closed':
|
||||||
instance.ids.delete_msg.disabled = True
|
instance.ids.delete_msg.disabled = True
|
||||||
if instance.open_progress == 0.0:
|
if instance.open_progress == 0.0:
|
||||||
HelperAddressBook.address_detail_popup(self, address, label, instance)
|
obj = AddbookDetailPopup()
|
||||||
# obj = AddbookDetailPopup()
|
self.address_label = obj.address_label = label
|
||||||
# self.address_label = obj.address_label = label
|
self.address = obj.address = address
|
||||||
# self.address = obj.address = address
|
width = .9 if platform == 'android' else .8
|
||||||
# width = .9 if platform == 'android' else .8
|
|
||||||
# self.addbook_popup = MDDialog(
|
# self.addbook_popup = MDDialog(
|
||||||
# type="custom",
|
# type="custom",
|
||||||
# size_hint=(width, .25),
|
# size_hint=(width, .25),
|
||||||
|
@ -151,10 +145,12 @@ class AddressBook(Screen):
|
||||||
# ),
|
# ),
|
||||||
# ],
|
# ],
|
||||||
# )
|
# )
|
||||||
# # self.addbook_popup.set_normal_height()
|
# self.addbook_popup.set_normal_height()
|
||||||
# self.addbook_popup = HelperAddressBook.address_detail_popup(self)
|
self.addbook_popup = self.address_detail_popup(
|
||||||
# self.addbook_popup.auto_dismiss = False
|
obj, self.send_message_to, self.update_addbook_label,
|
||||||
# self.addbook_popup.open()
|
self.close_pop, width)
|
||||||
|
self.addbook_popup.auto_dismiss = False
|
||||||
|
self.addbook_popup.open()
|
||||||
else:
|
else:
|
||||||
instance.ids.delete_msg.disabled = False
|
instance.ids.delete_msg.disabled = False
|
||||||
|
|
||||||
|
@ -165,7 +161,7 @@ class AddressBook(Screen):
|
||||||
if self.ids.ml.children is not None:
|
if self.ids.ml.children is not None:
|
||||||
self.ids.tag_label.text = ''
|
self.ids.tag_label.text = ''
|
||||||
sqlExecute(
|
sqlExecute(
|
||||||
"DELETE FROM addressbook WHERE address = '{}';".format(address))
|
"DELETE FROM addressbook WHERE address = ?", address)
|
||||||
toast('Address Deleted')
|
toast('Address Deleted')
|
||||||
|
|
||||||
def close_pop(self, instance):
|
def close_pop(self, instance):
|
||||||
|
@ -183,9 +179,8 @@ class AddressBook(Screen):
|
||||||
stored_labels.remove(label)
|
stored_labels.remove(label)
|
||||||
if label and label not in stored_labels:
|
if label and label not in stored_labels:
|
||||||
sqlExecute(
|
sqlExecute(
|
||||||
"UPDATE addressbook SET label = '{}' WHERE"
|
"UPDATE addressbook SET label = ? WHERE"
|
||||||
" address = '{}';".format(
|
"address = ?", label, self.addbook_popup.content_cls.address)
|
||||||
label, self.addbook_popup.content_cls.address))
|
|
||||||
state.kivyapp.root.ids.sc11.ids.ml.clear_widgets()
|
state.kivyapp.root.ids.sc11.ids.ml.clear_widgets()
|
||||||
state.kivyapp.root.ids.sc11.loadAddresslist(None, 'All', '')
|
state.kivyapp.root.ids.sc11.loadAddresslist(None, 'All', '')
|
||||||
self.addbook_popup.dismiss()
|
self.addbook_popup.dismiss()
|
||||||
|
@ -194,11 +189,13 @@ class AddressBook(Screen):
|
||||||
def send_message_to(self, instance):
|
def send_message_to(self, instance):
|
||||||
"""Method used to fill to_address of composer autofield"""
|
"""Method used to fill to_address of composer autofield"""
|
||||||
state.kivyapp.set_navbar_for_composer()
|
state.kivyapp.set_navbar_for_composer()
|
||||||
window_obj = state.kivyapp.root.ids
|
# import pdb; pdb.set_trace()
|
||||||
window_obj.sc3.children[1].ids.txt_input.text = self.address
|
self.compose_message(None, self.address, None, None)
|
||||||
window_obj.sc3.children[1].ids.ti.text = ''
|
# window_obj = state.kivyapp.root.ids
|
||||||
window_obj.sc3.children[1].ids.btn.text = 'Select'
|
# window_obj.sc3.children[1].ids.txt_input.text = self.address
|
||||||
window_obj.sc3.children[1].ids.subject.text = ''
|
# window_obj.sc3.children[1].ids.ti.text = ''
|
||||||
window_obj.sc3.children[1].ids.body.text = ''
|
# window_obj.sc3.children[1].ids.btn.text = 'Select'
|
||||||
window_obj.scr_mngr.current = 'create'
|
# window_obj.sc3.children[1].ids.subject.text = ''
|
||||||
|
# window_obj.sc3.children[1].ids.body.text = ''
|
||||||
|
# window_obj.scr_mngr.current = 'create'
|
||||||
self.addbook_popup.dismiss()
|
self.addbook_popup.dismiss()
|
||||||
|
|
|
@ -8,41 +8,62 @@ from kivymd.uix.label import MDLabel
|
||||||
|
|
||||||
from bitmessagekivy.baseclass.popup import AddbookDetailPopup
|
from bitmessagekivy.baseclass.popup import AddbookDetailPopup
|
||||||
|
|
||||||
class HelperAddressBook:
|
|
||||||
def default_label_while_empty():
|
|
||||||
content = MDLabel(
|
|
||||||
font_style='Caption',
|
|
||||||
theme_text_color='Primary',
|
|
||||||
text="No contact found!" if state.searcing_text
|
|
||||||
else "No contact found yet...... ",
|
|
||||||
halign='center',
|
|
||||||
size_hint_y=None,
|
|
||||||
valign='top')
|
|
||||||
return content
|
|
||||||
|
|
||||||
def address_detail_popup(self, address, label, instance):
|
label_str = "No contact found yet......"
|
||||||
obj = AddbookDetailPopup()
|
no_search_res_found = "No contact found!"
|
||||||
self.address_label = obj.address_label = label
|
|
||||||
self.address = obj.address = address
|
|
||||||
width = .9 if platform == 'android' else .8
|
class DefaultLabelMixin(object):
|
||||||
self.addbook_popup = MDDialog(
|
pass
|
||||||
|
"""
|
||||||
|
# @staticmethod
|
||||||
|
# def default_label_when_empty():
|
||||||
|
# content = MDLabel(
|
||||||
|
# font_style='Caption',
|
||||||
|
# theme_text_color='Primary',
|
||||||
|
# # TODO: searcing_text(typo) need to create a kivy_state.py and add kivy related variables
|
||||||
|
# text=no_search_res_found if state.searcing_text else label_str,
|
||||||
|
# halign='center',
|
||||||
|
# size_hint_y=None,
|
||||||
|
# valign='top')
|
||||||
|
# return content
|
||||||
|
"""
|
||||||
|
|
||||||
|
class HelperAddressBook(DefaultLabelMixin):
|
||||||
|
"""Widget used in Addressbook are here"""
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def address_detail_popup(obj, send_message, update_address, close_popup, width):
|
||||||
|
retval = MDDialog(
|
||||||
type="custom",
|
type="custom",
|
||||||
size_hint=(width, .25),
|
size_hint=(width, .25),
|
||||||
content_cls=obj,
|
content_cls=obj,
|
||||||
buttons=[
|
buttons=[
|
||||||
MDRaisedButton(
|
MDRaisedButton(
|
||||||
text="Send message to",
|
text="Send message to",
|
||||||
on_release=self.send_message_to,
|
on_release=send_message,
|
||||||
),
|
),
|
||||||
MDRaisedButton(
|
MDRaisedButton(
|
||||||
text="Save",
|
text="Save",
|
||||||
on_release=self.update_addbook_label,
|
on_release=update_address,
|
||||||
),
|
),
|
||||||
MDRaisedButton(
|
MDRaisedButton(
|
||||||
text="Cancel",
|
text="Cancel",
|
||||||
on_release=self.close_pop,
|
on_release=close_popup,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
self.addbook_popup.auto_dismiss = False
|
return retval
|
||||||
self.addbook_popup.open()
|
|
||||||
|
@staticmethod
|
||||||
|
def compose_message(from_addr=None, to_addr=None, subject=None, body=None):
|
||||||
|
window_obj = state.kivyapp.root.ids
|
||||||
|
if to_addr:
|
||||||
|
window_obj.sc3.children[1].ids.txt_input.text = to_addr
|
||||||
|
if from_addr:
|
||||||
|
window_obj.sc3.children[1].ids.txt_input.text = from_addr
|
||||||
|
window_obj.sc3.children[1].ids.ti.text = ''
|
||||||
|
window_obj.sc3.children[1].ids.btn.text = 'Select'
|
||||||
|
window_obj.sc3.children[1].ids.subject.text = ''
|
||||||
|
window_obj.sc3.children[1].ids.body.text = ''
|
||||||
|
window_obj.scr_mngr.current = 'create'
|
||||||
|
|
|
@ -16,7 +16,9 @@ from kivy.properties import (
|
||||||
NumericProperty,
|
NumericProperty,
|
||||||
StringProperty
|
StringProperty
|
||||||
)
|
)
|
||||||
|
from kivymd.uix.label import MDLabel
|
||||||
|
|
||||||
|
import state
|
||||||
|
|
||||||
ThemeClsColor = [0.12, 0.58, 0.95, 1]
|
ThemeClsColor = [0.12, 0.58, 0.95, 1]
|
||||||
|
|
||||||
|
@ -70,7 +72,7 @@ def chipTag(text):
|
||||||
|
|
||||||
|
|
||||||
def toast(text):
|
def toast(text):
|
||||||
"""Method will display the toast message"""
|
"""Function will display the toast message"""
|
||||||
kivytoast.toast(text)
|
kivytoast.toast(text)
|
||||||
|
|
||||||
def showLimitedCnt(total_msg):
|
def showLimitedCnt(total_msg):
|
||||||
|
@ -81,16 +83,14 @@ def showLimitedCnt(total_msg):
|
||||||
def avatarImageFirstLetter(letter_string):
|
def avatarImageFirstLetter(letter_string):
|
||||||
"""This function is used to the first letter for the avatar image"""
|
"""This function is used to the first letter for the avatar image"""
|
||||||
try:
|
try:
|
||||||
if letter_string[0].upper() >= 'A' and letter_string[0].upper() <= 'Z':
|
if isinstance(letter_string, int):
|
||||||
img_latter = letter_string[0].upper()
|
return letter_string[0]
|
||||||
elif int(letter_string[0]) >= 0 and int(letter_string[0]) <= 9:
|
elif isinstance(letter_string, str) and letter_string[0].isalnum():
|
||||||
img_latter = letter_string[0]
|
return letter_string.title()[0]
|
||||||
else:
|
else:
|
||||||
img_latter = '!'
|
return '!'
|
||||||
except ValueError:
|
except IndexError:
|
||||||
img_latter = '!'
|
return '!'
|
||||||
return img_latter if img_latter else '!'
|
|
||||||
|
|
||||||
|
|
||||||
def AddTimeWidget(time): # pylint: disable=redefined-outer-name, W0201
|
def AddTimeWidget(time): # pylint: disable=redefined-outer-name, W0201
|
||||||
"""This method is used to create TimeWidget"""
|
"""This method is used to create TimeWidget"""
|
||||||
|
@ -142,3 +142,27 @@ class CutsomSwipeToDeleteItem(MDCardSwipe):
|
||||||
cla = Window.size[0] / 2
|
cla = Window.size[0] / 2
|
||||||
swipe_distance = NumericProperty(cla)
|
swipe_distance = NumericProperty(cla)
|
||||||
opening_time = NumericProperty(0.5)
|
opening_time = NumericProperty(0.5)
|
||||||
|
|
||||||
|
|
||||||
|
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=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]})
|
||||||
|
|
|
@ -80,7 +80,7 @@
|
||||||
icon: "chevron-double-right"
|
icon: "chevron-double-right"
|
||||||
text: app.tr._("Proceed Next")
|
text: app.tr._("Proceed Next")
|
||||||
on_release:
|
on_release:
|
||||||
app.root.set_screen('random')
|
app.set_screen('random')
|
||||||
on_press:
|
on_press:
|
||||||
app.root.ids.sc7.reset_address_label()
|
app.root.ids.sc7.reset_address_label()
|
||||||
|
|
||||||
|
|
|
@ -194,3 +194,8 @@ class BMConfigParser(configparser.ConfigParser):
|
||||||
if value < 0 or value > 8:
|
if value < 0 or value > 8:
|
||||||
return False
|
return False
|
||||||
return True
|
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]
|
||||||
|
|
Reference in New Issue
Block a user