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.
The raw image data can be keep in memory for further access
"""
import hashlib
from io import BytesIO
@ -26,7 +25,6 @@ def generate(Generate_string=None):
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)
@ -46,10 +44,8 @@ def generate_hash(string):
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.")
@ -59,29 +55,24 @@ def random_color(hash_string):
# 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:
@ -89,5 +80,4 @@ def generate_image(image, color, hash_string):
image.putpixel((limit_x - x, y), color)
index = index + 1
return image

View File

@ -4,25 +4,25 @@ Sql queries for bitmessagekivy
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"""
# pylint: disable=too-many-arguments, too-many-branches
if what is not None and what != "":
what = "%" + what + "%"
else:
what = None
if folder == "sent" or folder == "draft":
sqlStatementBase = (
'''SELECT toaddress, fromaddress, subject, message, status, ackdata,'''
''' lastactiontime FROM sent ''')
'''SELECT toaddress, fromaddress, subject, message, status,'''
''' ackdata, lastactiontime FROM sent ''')
elif folder == "addressbook":
sqlStatementBase = '''SELECT label, address From addressbook '''
else:
sqlStatementBase = (
'''SELECT folder, msgid, toaddress, message, fromaddress, subject,'''
''' received, read FROM inbox ''')
'''SELECT folder, msgid, toaddress, message, fromaddress,'''
''' subject, received, read FROM inbox ''')
sqlStatementParts = []
sqlArguments = []
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")
if sqlStatementParts:
sqlStatementBase += "WHERE " + " AND ".join(sqlStatementParts)
# if folder in ("sent", "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":
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":
# sqlStatementBase += " limit {0}, {1}".format(start_indx, end_indx)
return sqlQuery(sqlStatementBase, sqlArguments)

View File

@ -1,8 +1,8 @@
"""
Bitmessage android(mobile) interface
"""
# pylint: disable=relative-import, import-error, no-name-in-module
# pylint: disable=too-few-public-methods, too-many-lines, unused-argument
# pylint: disable=import-error, no-name-in-module, too-many-lines
# pylint: disable=too-few-public-methods, unused-argument, too-many-ancestors
import os
import time
from bmconfigparser import BMConfigParser
@ -36,9 +36,7 @@ from kivy.uix.screenmanager import Screen
from kivy.uix.spinner import Spinner
from kivy.uix.textinput import TextInput
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.dialog import MDDialog
from kivymd.uix.label import MDLabel
@ -48,7 +46,6 @@ from kivymd.uix.list import (
IRightBodyTouch,
TwoLineAvatarIconListItem,
TwoLineListItem,
OneLineIconListItem
)
from kivymd.uix.navigationdrawer import (
MDNavigationDrawer,
@ -525,7 +522,7 @@ class AddressBook(Screen):
class SelectableRecycleBoxLayout(
FocusBehavior, LayoutSelectionBehavior, RecycleBoxLayout):
"""Adds selection and focus behaviour to the view"""
# pylint: disable = too-many-ancestors, duplicate-bases
# pylint: disable = duplicate-bases
pass
@ -541,7 +538,6 @@ class SelectableLabel(RecycleDataViewBehavior, Label):
return super(SelectableLabel, self).refresh_view_attrs(
rv, index, data)
# pylint: disable=inconsistent-return-statements
def on_touch_down(self, touch):
"""Add selection on touch down"""
if super(SelectableLabel, self).on_touch_down(touch):
@ -568,7 +564,6 @@ class RV(RecycleView):
class DropDownWidget(BoxLayout):
"""Adding Dropdown Widget"""
# pylint: disable=too-many-statements, too-many-locals
# pylint: disable=inconsistent-return-statements
txt_input = ObjectProperty()
rv = ObjectProperty()
@ -579,7 +574,7 @@ class DropDownWidget(BoxLayout):
subject = self.ids.subject.text.strip()
message = self.ids.subject.text.strip()
encoding = 3
print ("message: ", self.ids.body.text)
print("message: ", self.ids.body.text)
sendMessageToPeople = True
if sendMessageToPeople:
if toAddress != '' and subject and message:
@ -606,12 +601,11 @@ class DropDownWidget(BoxLayout):
statusIconColor = 'red'
if (addressVersionNumber > 4) or (
addressVersionNumber <= 1):
print ("addressVersionNumber > 4"\
" or addressVersionNumber <= 1")
print("addressVersionNumber > 4 or addressVersionNumber <= 1")
if streamNumber > 1 or streamNumber == 0:
print ("streamNumber > 1 or streamNumber == 0")
print("streamNumber > 1 or streamNumber == 0")
if statusIconColor == 'red':
print ("shared.statusIconColor == 'red'")
print("shared.statusIconColor == 'red'")
stealthLevel = BMConfigParser().safeGetInt(
'bitmessagesettings', 'ackstealthlevel')
from helper_ackPayload import genAckPayload
@ -652,7 +646,7 @@ class DropDownWidget(BoxLayout):
# self.parent.parent.screens[16].add_widget(Allmails())
Clock.schedule_once(self.callback_for_msgsend, 3)
queues.workerQueue.put(('sendmessage', toAddress))
print ("sqlExecute successfully #######################")
print("sqlExecute successfully #######################")
state.in_composer = True
return
else:
@ -708,7 +702,7 @@ class MyTextInput(TextInput):
starting_no = NumericProperty(3)
suggestion_text = ''
def __init__(self, **kwargs): # pylint: disable=useless-super-delegation
def __init__(self, **kwargs): # pylint: disable=useless-super-delegation
"""Getting Text Input."""
super(MyTextInput, self).__init__(**kwargs)
@ -802,6 +796,7 @@ class NetworkStat(Screen):
class ContentNavigationDrawer(Navigatorss):
"""Navigate Content Drawer"""
# pylint: disable=too-many-arguments
pass
@ -1283,8 +1278,6 @@ class NavigateApp(App): # pylint: disable=too-many-public-methods
def build(self):
"""Method builds the widget"""
print("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSss")
print(os.path.join(os.path.dirname(__file__), 'main.kv'))
main_widget = Builder.load_file(
os.path.join(os.path.dirname(__file__), 'main.kv'))
self.nav_drawer = Navigatorss()
@ -1385,7 +1378,7 @@ class NavigateApp(App): # pylint: disable=too-many-public-methods
if not os.path.exists(directory):
os.makedirs(directory)
except OSError:
print ('Error: Creating directory. ' + directory)
print('Error: Creating directory. ' + directory)
@staticmethod
def get_default_image():
@ -1586,7 +1579,7 @@ class NavigateApp(App): # pylint: disable=too-many-public-methods
@staticmethod
def on_stop():
"""On stop methos is used for stoping the runing script"""
print ("*******************EXITING FROM APPLICATION*******************")
print("*******************EXITING FROM APPLICATION*******************")
import shutdown
shutdown.doCleanShutdown()
@ -1699,7 +1692,7 @@ class NavigateApp(App): # pylint: disable=too-many-public-methods
self.root.ids.scr_mngr.current = 'allmails'
try:
self.root.ids.sc17.children[1].active = True
except Exception as e:
except Exception:
self.root.ids.sc17.children[0].children[1].active = True
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())
try:
self.root.ids.sc17.children[1].active = False
except Exception as e:
except Exception:
self.root.ids.sc17.children[0].children[1].active = False
@ -2328,9 +2321,7 @@ class Draft(Screen):
0,
'draft',
encoding,
int(BMConfigParser().safeGet(
'bitmessagesettings', 'ttl')))
int(BMConfigParser().safeGet('bitmessagesettings', 'ttl')))
state.msg_counter_objs = src_object.children[2].children[0].ids
state.draft_count = str(int(state.draft_count) + 1)
src_object.ids.sc16.clear_widgets()
@ -2366,7 +2357,7 @@ class Allmails(Screen):
def init_ui(self, dt=0):
"""Clock Schdule for method all mails"""
self.loadMessagelist()
print (dt)
print(dt)
def loadMessagelist(self):
"""Load Inbox, Sent anf Draft list of messages."""

View File

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