mpybit py3 fixes

This commit is contained in:
lakshyacis 2019-12-23 19:47:23 +05:30
parent cb883cab1b
commit 4dea6d5ced
No known key found for this signature in database
GPG Key ID: D2C539C8EC63E9EB
4 changed files with 38 additions and 50 deletions

View File

@ -2,7 +2,6 @@
Core classes for loading images and converting them to a Texture. Core classes for loading images and converting them to a Texture.
The raw image data can be keep in memory for further access The raw image data can be keep in memory for further access
""" """
import hashlib import hashlib
from io import BytesIO from io import BytesIO
@ -26,7 +25,6 @@ def generate(Generate_string=None):
image = Image.new(MODE, V_RESOLUTION, BACKGROUND_COLOR) image = Image.new(MODE, V_RESOLUTION, BACKGROUND_COLOR)
image = generate_image(image, color, hash_string) image = generate_image(image, color, hash_string)
image = image.resize(RESOLUTION, 0) image = image.resize(RESOLUTION, 0)
data = BytesIO() data = BytesIO()
image.save(data, format='png') image.save(data, format='png')
data.seek(0) data.seek(0)
@ -46,10 +44,8 @@ def generate_hash(string):
string = str.lower(string) string = str.lower(string)
hash_object = hashlib.md5(str.encode(string)) hash_object = hashlib.md5(str.encode(string))
print(hash_object.hexdigest()) print(hash_object.hexdigest())
# returned object is a hex string # returned object is a hex string
return hash_object.hexdigest() return hash_object.hexdigest()
except IndexError: except IndexError:
print("Error: Please enter a string as an argument.") print("Error: Please enter a string as an argument.")
@ -59,29 +55,24 @@ def random_color(hash_string):
# remove first three digits from hex string # remove first three digits from hex string
split = 6 split = 6
rgb = hash_string[:split] rgb = hash_string[:split]
split = 2 split = 2
r = rgb[:split] r = rgb[:split]
g = rgb[split:2 * split] g = rgb[split:2 * split]
b = rgb[2 * split:3 * split] b = rgb[2 * split:3 * split]
color = (int(r, 16), int(g, 16), color = (int(r, 16), int(g, 16),
int(b, 16), 0xFF) int(b, 16), 0xFF)
return color return color
def generate_image(image, color, hash_string): def generate_image(image, color, hash_string):
"""Generating images""" """Generating images"""
hash_string = hash_string[6:] hash_string = hash_string[6:]
lower_x = 1 lower_x = 1
lower_y = 1 lower_y = 1
upper_x = int(V_RESOLUTION[0] / 2) + 1 upper_x = int(V_RESOLUTION[0] / 2) + 1
upper_y = V_RESOLUTION[1] - 1 upper_y = V_RESOLUTION[1] - 1
limit_x = V_RESOLUTION[0] - 1 limit_x = V_RESOLUTION[0] - 1
index = 0 index = 0
for x in range(lower_x, upper_x): for x in range(lower_x, upper_x):
for y in range(lower_y, upper_y): for y in range(lower_y, upper_y):
if int(hash_string[index], 16) % 2 == 0: if int(hash_string[index], 16) % 2 == 0:
@ -89,5 +80,4 @@ def generate_image(image, color, hash_string):
image.putpixel((limit_x - x, y), color) image.putpixel((limit_x - x, y), color)
index = index + 1 index = index + 1
return image return image

View File

@ -4,25 +4,25 @@ Sql queries for bitmessagekivy
from helper_sql import sqlQuery from helper_sql import sqlQuery
def search_sql(xAddress="toaddress", account=None, folder="inbox", where=None, what=None, unreadOnly=False, start_indx=0, end_indx=20): def search_sql(
xAddress="toaddress", account=None, folder="inbox", where=None,
what=None, unreadOnly=False, start_indx=0, end_indx=20):
"""Method helping for searching mails""" """Method helping for searching mails"""
# pylint: disable=too-many-arguments, too-many-branches # pylint: disable=too-many-arguments, too-many-branches
if what is not None and what != "": if what is not None and what != "":
what = "%" + what + "%" what = "%" + what + "%"
else: else:
what = None what = None
if folder == "sent" or folder == "draft": if folder == "sent" or folder == "draft":
sqlStatementBase = ( sqlStatementBase = (
'''SELECT toaddress, fromaddress, subject, message, status, ackdata,''' '''SELECT toaddress, fromaddress, subject, message, status,'''
''' lastactiontime FROM sent ''') ''' ackdata, lastactiontime FROM sent ''')
elif folder == "addressbook": elif folder == "addressbook":
sqlStatementBase = '''SELECT label, address From addressbook ''' sqlStatementBase = '''SELECT label, address From addressbook '''
else: else:
sqlStatementBase = ( sqlStatementBase = (
'''SELECT folder, msgid, toaddress, message, fromaddress, subject,''' '''SELECT folder, msgid, toaddress, message, fromaddress,'''
''' received, read FROM inbox ''') ''' subject, received, read FROM inbox ''')
sqlStatementParts = [] sqlStatementParts = []
sqlArguments = [] sqlArguments = []
if account is not None: if account is not None:
@ -58,10 +58,15 @@ def search_sql(xAddress="toaddress", account=None, folder="inbox", where=None, w
sqlStatementParts.append("read = 0") sqlStatementParts.append("read = 0")
if sqlStatementParts: if sqlStatementParts:
sqlStatementBase += "WHERE " + " AND ".join(sqlStatementParts) sqlStatementBase += "WHERE " + " AND ".join(sqlStatementParts)
# if folder in ("sent", "draft"):
if folder == "sent" or folder == "draft": if folder == "sent" or folder == "draft":
sqlStatementBase += " ORDER BY lastactiontime DESC limit {0}, {1}".format(start_indx, end_indx) sqlStatementBase += \
"ORDER BY lastactiontime DESC limit {0}, {1}".format(
start_indx, end_indx)
elif folder == "inbox": elif folder == "inbox":
sqlStatementBase += " ORDER BY received DESC limit {0}, {1}".format(start_indx, end_indx) sqlStatementBase += \
"ORDER BY received DESC limit {0}, {1}".format(
start_indx, end_indx)
# elif folder == "addressbook": # elif folder == "addressbook":
# sqlStatementBase += " limit {0}, {1}".format(start_indx, end_indx) # sqlStatementBase += " limit {0}, {1}".format(start_indx, end_indx)
return sqlQuery(sqlStatementBase, sqlArguments) return sqlQuery(sqlStatementBase, sqlArguments)

View File

@ -1,8 +1,8 @@
""" """
Bitmessage android(mobile) interface Bitmessage android(mobile) interface
""" """
# pylint: disable=relative-import, import-error, no-name-in-module # pylint: disable=import-error, no-name-in-module, too-many-lines
# pylint: disable=too-few-public-methods, too-many-lines, unused-argument # pylint: disable=too-few-public-methods, unused-argument, too-many-ancestors
import os import os
import time import time
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
@ -36,8 +36,6 @@ from kivy.uix.screenmanager import Screen
from kivy.uix.spinner import Spinner from kivy.uix.spinner import Spinner
from kivy.uix.textinput import TextInput from kivy.uix.textinput import TextInput
from kivy.utils import platform from kivy.utils import platform
from bitmessagekivy import kivy_helper_search from bitmessagekivy import kivy_helper_search
from kivymd.uix.button import MDIconButton from kivymd.uix.button import MDIconButton
from kivymd.uix.dialog import MDDialog from kivymd.uix.dialog import MDDialog
@ -48,7 +46,6 @@ from kivymd.uix.list import (
IRightBodyTouch, IRightBodyTouch,
TwoLineAvatarIconListItem, TwoLineAvatarIconListItem,
TwoLineListItem, TwoLineListItem,
OneLineIconListItem
) )
from kivymd.uix.navigationdrawer import ( from kivymd.uix.navigationdrawer import (
MDNavigationDrawer, MDNavigationDrawer,
@ -525,7 +522,7 @@ class AddressBook(Screen):
class SelectableRecycleBoxLayout( class SelectableRecycleBoxLayout(
FocusBehavior, LayoutSelectionBehavior, RecycleBoxLayout): FocusBehavior, LayoutSelectionBehavior, RecycleBoxLayout):
"""Adds selection and focus behaviour to the view""" """Adds selection and focus behaviour to the view"""
# pylint: disable = too-many-ancestors, duplicate-bases # pylint: disable = duplicate-bases
pass pass
@ -541,7 +538,6 @@ class SelectableLabel(RecycleDataViewBehavior, Label):
return super(SelectableLabel, self).refresh_view_attrs( return super(SelectableLabel, self).refresh_view_attrs(
rv, index, data) rv, index, data)
# pylint: disable=inconsistent-return-statements
def on_touch_down(self, touch): def on_touch_down(self, touch):
"""Add selection on touch down""" """Add selection on touch down"""
if super(SelectableLabel, self).on_touch_down(touch): if super(SelectableLabel, self).on_touch_down(touch):
@ -568,7 +564,6 @@ class RV(RecycleView):
class DropDownWidget(BoxLayout): class DropDownWidget(BoxLayout):
"""Adding Dropdown Widget""" """Adding Dropdown Widget"""
# pylint: disable=too-many-statements, too-many-locals # pylint: disable=too-many-statements, too-many-locals
# pylint: disable=inconsistent-return-statements
txt_input = ObjectProperty() txt_input = ObjectProperty()
rv = ObjectProperty() rv = ObjectProperty()
@ -606,8 +601,7 @@ class DropDownWidget(BoxLayout):
statusIconColor = 'red' statusIconColor = 'red'
if (addressVersionNumber > 4) or ( if (addressVersionNumber > 4) or (
addressVersionNumber <= 1): addressVersionNumber <= 1):
print ("addressVersionNumber > 4"\ print("addressVersionNumber > 4 or addressVersionNumber <= 1")
" or addressVersionNumber <= 1")
if streamNumber > 1 or streamNumber == 0: if streamNumber > 1 or streamNumber == 0:
print("streamNumber > 1 or streamNumber == 0") print("streamNumber > 1 or streamNumber == 0")
if statusIconColor == 'red': if statusIconColor == 'red':
@ -802,6 +796,7 @@ class NetworkStat(Screen):
class ContentNavigationDrawer(Navigatorss): class ContentNavigationDrawer(Navigatorss):
"""Navigate Content Drawer""" """Navigate Content Drawer"""
# pylint: disable=too-many-arguments
pass pass
@ -1283,8 +1278,6 @@ class NavigateApp(App): # pylint: disable=too-many-public-methods
def build(self): def build(self):
"""Method builds the widget""" """Method builds the widget"""
print("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSss")
print(os.path.join(os.path.dirname(__file__), 'main.kv'))
main_widget = Builder.load_file( main_widget = Builder.load_file(
os.path.join(os.path.dirname(__file__), 'main.kv')) os.path.join(os.path.dirname(__file__), 'main.kv'))
self.nav_drawer = Navigatorss() self.nav_drawer = Navigatorss()
@ -1699,7 +1692,7 @@ class NavigateApp(App): # pylint: disable=too-many-public-methods
self.root.ids.scr_mngr.current = 'allmails' self.root.ids.scr_mngr.current = 'allmails'
try: try:
self.root.ids.sc17.children[1].active = True self.root.ids.sc17.children[1].active = True
except Exception as e: except Exception:
self.root.ids.sc17.children[0].children[1].active = True self.root.ids.sc17.children[0].children[1].active = True
Clock.schedule_once(partial(self.load_screen_callback, instance), 1) Clock.schedule_once(partial(self.load_screen_callback, instance), 1)
@ -1714,7 +1707,7 @@ class NavigateApp(App): # pylint: disable=too-many-public-methods
self.root.ids.sc17.add_widget(Allmails()) 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 as e: except Exception:
self.root.ids.sc17.children[0].children[1].active = False self.root.ids.sc17.children[0].children[1].active = False
@ -2328,9 +2321,7 @@ class Draft(Screen):
0, 0,
'draft', 'draft',
encoding, encoding,
int(BMConfigParser().safeGet( int(BMConfigParser().safeGet('bitmessagesettings', 'ttl')))
'bitmessagesettings', 'ttl')))
state.msg_counter_objs = src_object.children[2].children[0].ids state.msg_counter_objs = src_object.children[2].children[0].ids
state.draft_count = str(int(state.draft_count) + 1) state.draft_count = str(int(state.draft_count) + 1)
src_object.ids.sc16.clear_widgets() src_object.ids.sc16.clear_widgets()

View File

@ -1,12 +1,15 @@
"""
Ui Singnaler for kivy interface
"""
from threading import Thread from threading import Thread
import state
import queues import queues
import state
from semaphores import kivyuisignaler from semaphores import kivyuisignaler
from helper_sql import SqlBulkExecute, sqlExecute, sqlQuery, sqlStoredProcedure
class UIkivySignaler(Thread): class UIkivySignaler(Thread):
"""Kivy ui signaler"""
def run(self): def run(self):
kivyuisignaler.acquire() kivyuisignaler.acquire()
@ -14,13 +17,12 @@ class UIkivySignaler(Thread):
try: try:
command, data = queues.UISignalQueue.get() command, data = queues.UISignalQueue.get()
if command == 'writeNewAddressToTable': if command == 'writeNewAddressToTable':
label, address, streamNumber = data address = data[1]
state.kivyapp.variable_1.append(address) state.kivyapp.variable_1.append(address)
# elif command == 'rerenderAddressBook': # elif command == 'rerenderAddressBook':
# state.kivyapp.obj_1.refreshs() # state.kivyapp.obj_1.refreshs()
# Need to discuss this # Need to discuss this
elif command == 'updateSentItemStatusByAckdata': elif command == 'updateSentItemStatusByAckdata':
state.kivyapp.status_dispatching(data) state.kivyapp.status_dispatching(data)
except Exception as e: except Exception as e:
print(e) print(e)