added custom avtar add and reset feature

This commit is contained in:
cis 2021-06-07 18:34:27 +05:30
parent 967bd1a4b4
commit c9c54029a6
No known key found for this signature in database
GPG Key ID: 11DC6F36E8B65B24
9 changed files with 129 additions and 31 deletions

View File

@ -32,8 +32,8 @@ class Allmails(Screen):
"""Method Parsing the address"""
super(Allmails, self).__init__(*args, **kwargs)
if state.association == '':
if BMConfigParser().addresses():
state.association = BMConfigParser().addresses()[0]
if state.kivyapp.variable_1:
state.association = state.kivyapp.variable_1[0]
Clock.schedule_once(self.init_ui, 0)
def init_ui(self, dt=0):

View File

@ -34,8 +34,8 @@ class Draft(Screen):
"""Method used for storing draft messages"""
super(Draft, self).__init__(*args, **kwargs)
if state.association == '':
if BMConfigParser().addresses():
state.association = BMConfigParser().addresses()[0]
if state.kivyapp.variable_1:
state.association = state.kivyapp.variable_1[0]
Clock.schedule_once(self.init_ui, 0)
def init_ui(self, dt=0):

View File

@ -40,8 +40,8 @@ class Inbox(Screen):
def set_defaultAddress():
"""This method set's default address"""
if state.association == "":
if BMConfigParser().addresses():
state.association = BMConfigParser().addresses()[0]
if state.kivyapp.variable_1:
state.association = state.kivyapp.variable_1[0]
def init_ui(self, dt=0):
"""Clock schdule for method inbox accounts"""

View File

@ -240,6 +240,7 @@ class MyAddress(Screen):
if BMConfigParser().get(str(addr), 'enabled') == 'true']
self.parent.parent.ids.content_drawer.ids.btn.values = addresses
self.parent.parent.ids.sc3.children[1].ids.btn.values = addresses
state.kivyapp.variable_1 = addresses
def toggleAction(self, instance):
"""This method is used for enable or disable address"""

View File

@ -30,8 +30,8 @@ class Sent(Screen):
"""Association with the screen"""
super(Sent, self).__init__(*args, **kwargs)
if state.association == '':
if BMConfigParser().addresses():
state.association = BMConfigParser().addresses()[0]
if state.kivyapp.variable_1:
state.association = state.kivyapp.variable_1[0]
Clock.schedule_once(self.init_ui, 0)
def init_ui(self, dt=0):

View File

@ -37,8 +37,8 @@ class Trash(Screen):
def init_ui(self, dt=0):
"""Clock Schdule for method trash screen"""
if state.association == '':
if BMConfigParser().addresses():
state.association = BMConfigParser().addresses()[0]
if state.kivyapp.variable_1:
state.association = state.kivyapp.variable_1[0]
self.ids.tag_label.text = ''
self.trashDataQuery(0, 20)
if len(self.trash_messages):

View File

@ -0,0 +1,81 @@
"""
Core classes for loading images and converting them to a Texture.
The raw image data can be keep in memory for further access
"""
import hashlib
from io import BytesIO
from PIL import Image
from kivy.core.image import Image as CoreImage
from kivy.uix.image import Image as kiImage
# pylint: disable=import-error
# constants
RESOLUTION = 300, 300
V_RESOLUTION = 7, 7
BACKGROUND_COLOR = 255, 255, 255, 255
MODE = "RGB"
def generate(Generate_string=None):
"""Generating string"""
hash_string = generate_hash(Generate_string)
color = random_color(hash_string)
image = Image.new(MODE, V_RESOLUTION, BACKGROUND_COLOR)
image = generate_image(image, color, hash_string)
image = image.resize(RESOLUTION, 0)
data = BytesIO()
image.save(data, format='png')
data.seek(0)
# yes you actually need this
im = CoreImage(BytesIO(data.read()), ext='png')
beeld = kiImage()
# only use this line in first code instance
beeld.texture = im.texture
return beeld
# image.show()
def generate_hash(string):
"""Generating hash"""
try:
# make input case insensitive
string = str.lower(string)
hash_object = hashlib.md5(str.encode(string))
print(hash_object.hexdigest())
# returned object is a hex string
return hash_object.hexdigest()
except IndexError:
print("Error: Please enter a string as an argument.")
def random_color(hash_string):
"""Getting random color"""
# remove first three digits from hex string
split = 6
rgb = hash_string[:split]
split = 2
r = rgb[:split]
g = rgb[split:2 * split]
b = rgb[2 * split:3 * split]
color = (int(r, 16), int(g, 16), int(b, 16), 0xFF)
return color
def generate_image(image, color, hash_string):
"""Generating images"""
hash_string = hash_string[6:]
lower_x = 1
lower_y = 1
upper_x = int(V_RESOLUTION[0] / 2) + 1
upper_y = V_RESOLUTION[1] - 1
limit_x = V_RESOLUTION[0] - 1
index = 0
for x in range(lower_x, upper_x):
for y in range(lower_y, upper_y):
if int(hash_string[index], 16) % 2 == 0:
image.putpixel((x, y), color)
image.putpixel((limit_x - x, y), color)
index = index + 1
return image

View File

@ -74,8 +74,8 @@
on_release: app.rest_default_avatar_img()
theme_text_color: "Custom"
text_color: app.theme_cls.primary_color
opacity: 1 if app.current_address_label() else 0
disabled: False if app.current_address_label() else True
# opacity: 1 if app.current_address_label() else 0
# disabled: False if app.current_address_label() else True
opacity: 0
disabled: True
@ -89,8 +89,8 @@
# md_bg_color: app.theme_cls.primary_color
theme_text_color: "Custom"
text_color: app.theme_cls.primary_color
opacity: 0
disabled: True
opacity: 1 if app.current_address_label() else 0
disabled: False if app.current_address_label() else True
BoxLayout:
id: top_box
@ -100,8 +100,8 @@
x: root.parent.x
pos_hint: {"top": 1}
Image:
source: './images/drawer_logo1.png'
# source: app.get_default_logo()
#source: './images/drawer_logo1.png'
source: app.get_default_logo(self)
ScrollView:
id: scroll_y

View File

@ -11,7 +11,7 @@ Bitmessage android(mobile) interface
from bitmessagekivy.get_platform import platform
import os
# from bitmessagekivy import identiconGeneration
from bitmessagekivy import identiconGeneration
from bitmessagekivy import kivy_helper_search
from bitmessagekivy.uikivysignaler import UIkivySignaler
from bmconfigparser import BMConfigParser
@ -274,7 +274,7 @@ class NavigateApp(MDApp):
if os.path.exists(state.imageDir + '/default_identicon/{}.png'.format(text)):
self.load_selected_Image(text)
else:
# self.set_identicon(text)
self.set_identicon(text)
self.root.ids.content_drawer.ids.reset_image.opacity = 0
self.root.ids.content_drawer.ids.reset_image.disabled = True
address_label = self.current_address_label(
@ -295,8 +295,8 @@ class NavigateApp(MDApp):
"""This method is for file manager setting"""
if not self.root.ids.content_drawer.ids.file_manager.opacity and \
self.root.ids.content_drawer.ids.file_manager.disabled:
self.root.ids.content_drawer.ids.file_manager.opacity = 0
self.root.ids.content_drawer.ids.file_manager.disabled = True
self.root.ids.content_drawer.ids.file_manager.opacity = 1
self.root.ids.content_drawer.ids.file_manager.disabled = False
def setCurrentAccountData(self, dt=0):
"""This method set the current accout data on all the screens"""
@ -418,10 +418,11 @@ class NavigateApp(MDApp):
def getDefaultAccData(self, instance):
"""Getting Default Account Data"""
if BMConfigParser().addresses():
first_addr = BMConfigParser().addresses()[0]
if BMConfigParser().get(str(first_addr), 'enabled') == 'true':
if self.variable_1:
state.association = first_addr = self.variable_1[0]
# if BMConfigParser().get(str(first_addr), 'enabled') == 'true':
# img = identiconGeneration.generate(first_addr)
# print('line...........................................426')
# self.createFolder(state.imageDir + '/default_identicon/')
# if platform == 'android':
# # android_path = os.path.expanduser
@ -439,11 +440,24 @@ class NavigateApp(MDApp):
# BMConfigParser().addresses()[0]))
# instance.parent.parent.parent.parent.parent.ids.top_box.children[0].texture = (
# img.texture)
return first_addr
# instance.parent.parent.parent.parent.parent.ids.top_box.children[0].source = (
# state.imageDir + '/drawer_logo1.png')
return first_addr
return 'Select Address'
def get_default_logo(self, instance):
"""Getting default logo image"""
if self.variable_1:
first_addr = self.variable_1[0]
if BMConfigParser().get(str(first_addr), 'enabled') == 'true':
if os.path.exists(
state.imageDir + '/default_identicon/{}.png'.format(first_addr)):
return state.imageDir + '/default_identicon/{}.png'.format(
first_addr)
else:
img = identiconGeneration.generate(first_addr)
instance.texture = img.texture
return
return state.imageDir + '/drawer_logo1.png'
@staticmethod
def addressexist():
"""Checking address existence"""
@ -689,12 +703,14 @@ class NavigateApp(MDApp):
@staticmethod
def current_address_label(current_add_label=None, current_addr=None):
"""Getting current address labels"""
if BMConfigParser().addresses():
addresses = [addr for addr in BMConfigParser().addresses()
if BMConfigParser().get(str(addr), 'enabled') == 'true']
if addresses:
if current_add_label:
first_name = current_add_label
addr = current_addr
else:
addr = BMConfigParser().addresses()[0]
addr = addresses[0]
first_name = BMConfigParser().get(addr, 'label')
if BMConfigParser().get(addr, 'enabled') != 'true':
return ''
@ -770,10 +786,10 @@ class NavigateApp(MDApp):
def set_identicon(self, text):
"""Show identicon in address spinner"""
# img = identiconGeneration.generate(text)
img = identiconGeneration.generate(text)
# self.root.children[0].children[0].ids.btn.children[1].texture = (img.texture)
# below line is for displaing logo
# self.root.ids.content_drawer.ids.top_box.children[0].texture = (img.texture)
self.root.ids.content_drawer.ids.top_box.children[0].texture = (img.texture)
def set_mail_detail_header(self):
"""Setting the details of the page"""
@ -911,7 +927,7 @@ class NavigateApp(MDApp):
def rest_default_avatar_img(self):
"""set default avatar generated image"""
# self.set_identicon(state.association)
self.set_identicon(state.association)
img_path = state.imageDir + '/default_identicon/{}.png'.format(state.association)
try:
if os.path.exists(img_path):