Fix flake8 issues

This commit is contained in:
surbhi 2018-08-31 16:49:57 +05:30
parent f98acd3ae0
commit 686967c36d
No known key found for this signature in database
GPG Key ID: 88928762974D3618
2 changed files with 59 additions and 18 deletions

View File

@ -43,7 +43,7 @@ BoxLayout:
orientation: 'vertical' orientation: 'vertical'
Toolbar: Toolbar:
id: toolbar id: toolbar
title: 'PyBitmessage' title: app.getCurrentAccount()
background_color: app.theme_cls.primary_dark background_color: app.theme_cls.primary_dark
left_action_items: [['menu', lambda x: app.nav_drawer.toggle()]] left_action_items: [['menu', lambda x: app.nav_drawer.toggle()]]
Button: Button:
@ -51,7 +51,7 @@ BoxLayout:
color: 0,0,0,1 color: 0,0,0,1
background_color: (0,0,0,0) background_color: (0,0,0,0)
size_hint_y: 0.4 size_hint_y: 0.4
size_hint_x: 0.5 size_hint_x: 0.1
pos_hint: {'x': 0.8, 'y':0.4} pos_hint: {'x': 0.8, 'y':0.4}
on_press: app.say_exit() on_press: app.say_exit()

View File

@ -1,43 +1,41 @@
import os
import kivy_helper_search import kivy_helper_search
import os
import queues import queues
import random
import shutdown import shutdown
import time import time
from kivy.app import App from kivy.app import App
from kivy.lang import Builder from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import BooleanProperty from kivy.properties import BooleanProperty
from kivy.uix.button import Button
from kivy.clock import Clock from kivy.clock import Clock
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.image import Image
from kivy.uix.label import Label
from kivy.uix.listview import ListItemButton
from navigationdrawer import NavigationDrawer from navigationdrawer import NavigationDrawer
from kivy.properties import ObjectProperty, StringProperty, ListProperty, NumericProperty from kivy.properties import ObjectProperty, StringProperty, ListProperty
from kivy.uix.screenmanager import Screen from kivy.uix.screenmanager import Screen
from kivy.uix.textinput import TextInput from kivy.uix.textinput import TextInput
from kivymd.theming import ThemeManager from kivymd.theming import ThemeManager
from kivymd.toolbar import Toolbar from kivymd.toolbar import Toolbar
from kivy.uix.widget import Widget
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
from helper_ackPayload import genAckPayload from helper_ackPayload import genAckPayload
from addresses import decodeAddress, addBMIfNotPresent from addresses import decodeAddress, addBMIfNotPresent
from helper_sql import sqlExecute from helper_sql import sqlExecute
statusIconColor = 'red' statusIconColor = 'red'
avatarlist = os.listdir("images/ngletteravatar")
global belonging global belonging
belonging = '' belonging = ''
class NavigateApp(App, TextInput): class NavigateApp(App, TextInput):
"""Application uses kivy in which base Class of Navigate App inherits from the App class."""
theme_cls = ThemeManager() theme_cls = ThemeManager()
nav_drawer = ObjectProperty() nav_drawer = ObjectProperty()
def build(self): def build(self):
"""Return a main_widget as a root widget.
An application can be built if you return a widget on build(), or if you set
self.root.
"""
global main_widget global main_widget
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'))
@ -45,6 +43,7 @@ class NavigateApp(App, TextInput):
return main_widget return main_widget
def getCurrentAccountData(self, text): def getCurrentAccountData(self, text):
"""Get Current Address Account Data."""
global belonging global belonging
belonging = text belonging = text
main_widget.ids.sc1.clear_widgets() main_widget.ids.sc1.clear_widgets()
@ -53,22 +52,27 @@ class NavigateApp(App, TextInput):
main_widget.ids.sc1.add_widget(Inbox()) main_widget.ids.sc1.add_widget(Inbox())
main_widget.ids.sc2.add_widget(Sent()) main_widget.ids.sc2.add_widget(Sent())
main_widget.ids.sc3.add_widget(Trash()) main_widget.ids.sc3.add_widget(Trash())
main_widget.ids.toolbar.title = BMConfigParser().get(
belonging, 'label') + '({})'.format(belonging)
Inbox() Inbox()
Sent() Sent()
Trash() Trash()
def say_exit(self): def say_exit(self):
"""Exit the application as uses shutdown PyBitmessage."""
print("**************************EXITING FROM APPLICATION*****************************") print("**************************EXITING FROM APPLICATION*****************************")
App.get_running_app().stop() App.get_running_app().stop()
shutdown.doCleanShutdown() shutdown.doCleanShutdown()
def showmeaddresses(self, name="text"): def showmeaddresses(self, name="text"):
"""Show the addresses in spinner to make as dropdown."""
if name == "text": if name == "text":
return BMConfigParser().addresses()[0] return BMConfigParser().addresses()[0]
elif name == "values": elif name == "values":
return BMConfigParser().addresses() return BMConfigParser().addresses()
def update_index(self, data_index, index): def update_index(self, data_index, index):
"""Update index after archieve message to trash."""
if self.root.ids.scr_mngr.current == 'inbox': if self.root.ids.scr_mngr.current == 'inbox':
self.root.ids.sc1.data[data_index]['index'] = index self.root.ids.sc1.data[data_index]['index'] = index
elif self.root.ids.scr_mngr.current == 'sent': elif self.root.ids.scr_mngr.current == 'sent':
@ -77,14 +81,17 @@ class NavigateApp(App, TextInput):
self.root.ids.sc3.data[data_index]['index'] = index self.root.ids.sc3.data[data_index]['index'] = index
def delete(self, data_index): def delete(self, data_index):
"""It will make delete using remove function."""
print("delete {}".format(data_index)) print("delete {}".format(data_index))
self._remove(data_index) self._remove(data_index)
def archive(self, data_index): def archive(self, data_index):
"""It will make archieve using remove function."""
print("archive {}".format(data_index)) print("archive {}".format(data_index))
self._remove(data_index) self._remove(data_index)
def _remove(self, data_index): def _remove(self, data_index):
"""It will remove message by resetting the values in recycleview data."""
if self.root.ids.scr_mngr.current == 'inbox': if self.root.ids.scr_mngr.current == 'inbox':
self.root.ids.sc1.data.pop(data_index) self.root.ids.sc1.data.pop(data_index)
self.root.ids.sc1.data = [{ self.root.ids.sc1.data = [{
@ -114,19 +121,35 @@ class NavigateApp(App, TextInput):
] ]
def getInboxMessageDetail(self, instance): def getInboxMessageDetail(self, instance):
"""It will get message detail after make selected message description."""
try: try:
self.root.ids.scr_mngr.current = 'page' self.root.ids.scr_mngr.current = 'page'
except AttributeError: except AttributeError:
self.parent.manager.current = 'page' self.parent.manager.current = 'page'
print('Message Clicked {}'.format(instance)) print('Message Clicked {}'.format(instance))
def getCurrentAccount(self):
"""It uses to get current account label."""
global belonging
return BMConfigParser().get(belonging, 'label') + '({})'.format(belonging)
class Navigator(NavigationDrawer): class Navigator(NavigationDrawer):
"""Navigator class uses NavigationDrawer.
It is an UI panel that shows our app's main navigation menu
It is hidden when not in use, but appears when the user swipes
a finger from the left edge of the screen or, when at the top
level of the app, the user touches the drawer icon in the app bar
"""
image_source = StringProperty('images/qidenticon_two.png') image_source = StringProperty('images/qidenticon_two.png')
title = StringProperty('Navigation') title = StringProperty('Navigation')
class Inbox(Screen): class Inbox(Screen):
"""Inbox Screen uses screen to show widgets of screens."""
data = ListProperty() data = ListProperty()
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
@ -148,7 +171,8 @@ class Inbox(Screen):
def loadMessagelist(self, account, folder, where="", what="", unreadOnly=False): def loadMessagelist(self, account, folder, where="", what="", unreadOnly=False):
xAddress = "toaddress" xAddress = "toaddress"
queryreturn = kivy_helper_search.search_sql(xAddress, account, folder, where, what, unreadOnly) queryreturn = kivy_helper_search.search_sql(
xAddress, account, folder, where, what, unreadOnly)
if queryreturn: if queryreturn:
self.data = [{ self.data = [{
'data_index': i, 'data_index': i,
@ -175,6 +199,8 @@ class AddressSuccessful(Screen):
class Sent(Screen): class Sent(Screen):
"""Sent Screen uses screen to show widgets of screens."""
data = ListProperty() data = ListProperty()
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
@ -196,7 +222,8 @@ class Sent(Screen):
def loadSent(self, account, where="", what=""): def loadSent(self, account, where="", what=""):
xAddress = 'fromaddress' xAddress = 'fromaddress'
queryreturn = kivy_helper_search.search_sql(xAddress, account, "sent", where, what, False) queryreturn = kivy_helper_search.search_sql(
xAddress, account, "sent", where, what, False)
if queryreturn: if queryreturn:
self.data = [{ self.data = [{
'data_index': i, 'data_index': i,
@ -222,6 +249,8 @@ class Sent(Screen):
class Trash(Screen): class Trash(Screen):
"""Trash Screen uses screen to show widgets of screens."""
data = ListProperty() data = ListProperty()
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
@ -243,7 +272,8 @@ class Trash(Screen):
def loadTrashlist(self, account, folder, where="", what="", unreadOnly=False): def loadTrashlist(self, account, folder, where="", what="", unreadOnly=False):
xAddress = "toaddress" xAddress = "toaddress"
queryreturn = kivy_helper_search.search_sql(xAddress, account, folder, where, what, unreadOnly) queryreturn = kivy_helper_search.search_sql(
xAddress, account, folder, where, what, unreadOnly)
if queryreturn: if queryreturn:
self.data = [{ self.data = [{
'data_index': i, 'data_index': i,
@ -270,6 +300,7 @@ class Test(Screen):
class Create(Screen): class Create(Screen):
"""Create Screen uses screen to show widgets of screens."""
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(Create, self).__init__(*args, **kwargs) super(Create, self).__init__(*args, **kwargs)
@ -279,7 +310,7 @@ class Create(Screen):
pass pass
def send(self): def send(self):
# toAddress = self.ids.recipent.text """Send message from one address to another."""
fromAddress = self.ids.spinner_id.text fromAddress = self.ids.spinner_id.text
# For now we are using static address i.e we are not using recipent field value. # For now we are using static address i.e we are not using recipent field value.
toAddress = "BM-2cWyUfBdY2FbgyuCb7abFZ49JYxSzUhNFe" toAddress = "BM-2cWyUfBdY2FbgyuCb7abFZ49JYxSzUhNFe"
@ -332,6 +363,7 @@ class Create(Screen):
return None return None
def cancel(self): def cancel(self):
"""Reset values for send message."""
self.ids.message.text = '' self.ids.message.text = ''
self.ids.spinner_id.text = '<select>' self.ids.spinner_id.text = '<select>'
self.ids.subject.text = '' self.ids.subject.text = ''
@ -340,11 +372,14 @@ class Create(Screen):
class NewIdentity(Screen): class NewIdentity(Screen):
"""Create new address for PyBitmessage."""
is_active = BooleanProperty(False) is_active = BooleanProperty(False)
checked = StringProperty("") checked = StringProperty("")
# self.manager.parent.ids.create.children[0].source = 'images/plus-4-xxl.png' # self.manager.parent.ids.create.children[0].source = 'images/plus-4-xxl.png'
def generateaddress(self): def generateaddress(self):
"""Generate new address."""
if self.checked == 'use a random number generator to make an address': if self.checked == 'use a random number generator to make an address':
queues.apiAddressGeneratorReturnQueue.queue.clear() queues.apiAddressGeneratorReturnQueue.queue.clear()
streamNumberForAddress = 1 streamNumberForAddress = 1
@ -352,10 +387,16 @@ class NewIdentity(Screen):
eighteenByteRipe = False eighteenByteRipe = False
nonceTrialsPerByte = 1000 nonceTrialsPerByte = 1000
payloadLengthExtraBytes = 1000 payloadLengthExtraBytes = 1000
queues.addressGeneratorQueue.put(( queues.addressGeneratorQueue.put((
'createRandomAddress', 4, streamNumberForAddress, label, 1, "", eighteenByteRipe, nonceTrialsPerByte, payloadLengthExtraBytes) 'createRandomAddress',
4, streamNumberForAddress,
label, 1, "", eighteenByteRipe,
nonceTrialsPerByte,
payloadLengthExtraBytes)
) )
self.manager.current = 'add_sucess' self.manager.current = 'add_sucess'
if __name__ == '__main__': if __name__ == '__main__':
NavigateApp().run() NavigateApp().run()