Merge pull request #23 from cis-navjot-g/codequalitykivy

mpybit flake8 fix
This commit is contained in:
lakshyacis 2019-09-10 14:32:06 +05:30 committed by GitHub
commit 163ef2d715
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,11 +1,8 @@
"""Coding: utf-8.""" """Coding: utf-8."""
import time import time
from functools import partial from functools import partial
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
from helper_sql import sqlExecute, sqlQuery from helper_sql import sqlExecute, sqlQuery
from kivy.app import App from kivy.app import App
from kivy.clock import Clock from kivy.clock import Clock
from kivy.core.window import Window from kivy.core.window import Window
@ -33,9 +30,7 @@ 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
import kivy_helper_search import kivy_helper_search
from kivymd.button import MDIconButton from kivymd.button import MDIconButton
from kivymd.dialog import MDDialog from kivymd.dialog import MDDialog
from kivymd.label import MDLabel from kivymd.label import MDLabel
@ -52,23 +47,14 @@ from kivymd.navigationdrawer import (
from kivymd.selectioncontrols import MDCheckbox from kivymd.selectioncontrols import MDCheckbox
from kivymd.textfields import MDTextField from kivymd.textfields import MDTextField
from kivymd.theming import ThemeManager from kivymd.theming import ThemeManager
import queues import queues
from semaphores import kivyuisignaler from semaphores import kivyuisignaler
import state import state
from uikivysignaler import UIkivySignaler from uikivysignaler import UIkivySignaler
import identiconGeneration import identiconGeneration
import os import os
from kivy.core.clipboard import Clipboard from kivy.core.clipboard import Clipboard
# pylint: disable=unused-argument, too-few-public-methods
# pylint: disable=unused-argument
# pylint: disable=broad-except
def toast(text): def toast(text):
@ -82,7 +68,6 @@ def toast(text):
class Navigatorss(MDNavigationDrawer): class Navigatorss(MDNavigationDrawer):
"""Navigators class contains image, title and logo.""" """Navigators class contains image, title and logo."""
# pylint: disable=too-few-public-methods
image_source = StringProperty('images/qidenticon_two.png') image_source = StringProperty('images/qidenticon_two.png')
title = StringProperty('Navigation') title = StringProperty('Navigation')
drawer_logo = StringProperty() drawer_logo = StringProperty()
@ -126,7 +111,9 @@ class Inbox(Screen):
third_text = mail[3].replace('\n', ' ') third_text = mail[3].replace('\n', ' ')
data.append({ data.append({
'text': mail[4].strip(), 'text': mail[4].strip(),
'secondary_text': mail[5][:50] + '........' if len(mail[5]) >= 50 else (mail[5] + ',' + mail[3].replace('\n', ''))[0:50] + '........', 'secondary_text': mail[5][:50] + '........' if len(
mail[5]) >= 50 else (
mail[5] + ',' + mail[3].replace('\n', ''))[0:50] + '........',
'receivedTime': mail[6]}) 'receivedTime': mail[6]})
for item in data: for item in data:
meny = ThreeLineAvatarIconListItem( meny = ThreeLineAvatarIconListItem(
@ -138,7 +125,8 @@ class Inbox(Screen):
# item['secondary_text'][0].upper() >= 'A' and item[ # item['secondary_text'][0].upper() >= 'A' and item[
# 'secondary_text'][0].upper() <= 'Z') else '!' # 'secondary_text'][0].upper() <= 'Z') else '!'
meny.add_widget(AvatarSampleWidget( meny.add_widget(AvatarSampleWidget(
source='./images/text_images/{}.png'.format(avatarImageFirstLetter(item['secondary_text'].strip())))) source='./images/text_images/{}.png'.format(
avatarImageFirstLetter(item['secondary_text'].strip()))))
meny.bind(on_press=partial( meny.bind(on_press=partial(
self.inbox_detail, item['receivedTime'])) self.inbox_detail, item['receivedTime']))
carousel = Carousel(direction='right') carousel = Carousel(direction='right')
@ -255,10 +243,12 @@ class MyAddress(Screen):
def init_ui(self, dt=0): def init_ui(self, dt=0):
"""Clock Schdule for method inbox accounts.""" """Clock Schdule for method inbox accounts."""
# pylint: disable=unnecessary-lambda, deprecated-lambda
addresses_list = state.kivyapp.variable_1 addresses_list = state.kivyapp.variable_1
if state.searcing_text: if state.searcing_text:
filtered_list = filter(lambda addr: self.filter_address( filtered_list = filter(
addr), BMConfigParser().addresses()) lambda addr: self.filter_address(
addr), BMConfigParser().addresses())
addresses_list = filtered_list addresses_list = filtered_list
if addresses_list: if addresses_list:
data = [] data = []
@ -321,6 +311,7 @@ class MyAddress(Screen):
@staticmethod @staticmethod
def filter_address(address): def filter_address(address):
"""Method will filter the my address list data.""" """Method will filter the my address list data."""
# pylint: disable=deprecated-lambda
if filter(lambda x: (state.searcing_text).lower() in x, [ if filter(lambda x: (state.searcing_text).lower() in x, [
BMConfigParser().get( BMConfigParser().get(
address, 'label').lower(), address.lower()]): address, 'label').lower(), address.lower()]):
@ -413,7 +404,6 @@ class SelectableRecycleBoxLayout(FocusBehavior, LayoutSelectionBehavior,
RecycleBoxLayout): RecycleBoxLayout):
"""Adds selection and focus behaviour to the view.""" """Adds selection and focus behaviour to the view."""
# pylint: disable=too-few-public-methods
pass pass
@ -450,8 +440,7 @@ class SelectableLabel(RecycleDataViewBehavior, Label):
class RV(RecycleView): class RV(RecycleView):
"""Recycling View.""" """Recycling View."""
# pylint: disable=too-few-public-methods def __init__(self, **kwargs): # pylint: disable=useless-super-delegation
def __init__(self, **kwargs):
"""Recycling Method.""" """Recycling Method."""
super(RV, self).__init__(**kwargs) super(RV, self).__init__(**kwargs)
@ -462,7 +451,7 @@ class DropDownWidget(BoxLayout):
txt_input = ObjectProperty() txt_input = ObjectProperty()
rv = ObjectProperty() rv = ObjectProperty()
def send(self, navApp): def send(self, navApp): # pylint: disable=too-many-statements, inconsistent-return-statements
"""Send message from one address to another.""" """Send message from one address to another."""
# pylint: disable=too-many-locals # pylint: disable=too-many-locals
fromAddress = str(self.ids.ti.text) fromAddress = str(self.ids.ti.text)
@ -601,7 +590,7 @@ class MyTextInput(TextInput):
starting_no = NumericProperty(3) starting_no = NumericProperty(3)
suggestion_text = '' suggestion_text = ''
def __init__(self, **kwargs): def __init__(self, **kwargs): # pylint: disable=useless-super-delegation
"""Getting Text Input.""" """Getting Text Input."""
super(MyTextInput, self).__init__(**kwargs) super(MyTextInput, self).__init__(**kwargs)
@ -632,21 +621,18 @@ class MyTextInput(TextInput):
class Payment(Screen): class Payment(Screen):
"""Payment Method.""" """Payment Method."""
# pylint: disable=too-few-public-methods
pass pass
class Login(Screen): class Login(Screen):
"""Login Screeen.""" """Login Screeen."""
# pylint: disable=too-few-public-methods
pass pass
class NetworkStat(Screen): class NetworkStat(Screen):
"""Method used to show network stat.""" """Method used to show network stat."""
# pylint: disable=too-few-public-methods
text_variable_1 = StringProperty( text_variable_1 = StringProperty(
'{0}::{1}'.format('Total Connections', '0')) '{0}::{1}'.format('Total Connections', '0'))
text_variable_2 = StringProperty( text_variable_2 = StringProperty(
@ -682,14 +668,12 @@ class NetworkStat(Screen):
class ContentNavigationDrawer(Navigatorss): class ContentNavigationDrawer(Navigatorss):
"""Navigate Content Drawer.""" """Navigate Content Drawer."""
# pylint: disable=too-few-public-methods
pass pass
class Random(Screen): class Random(Screen):
"""Generates Random Address.""" """Generates Random Address."""
# pylint: disable=too-few-public-methods
is_active = BooleanProperty(False) is_active = BooleanProperty(False)
checked = StringProperty("") checked = StringProperty("")
@ -720,7 +704,6 @@ class Random(Screen):
class AddressSuccessful(Screen): class AddressSuccessful(Screen):
"""Getting Address Detail.""" """Getting Address Detail."""
# pylint: disable=too-few-public-methods
pass pass
@ -767,7 +750,9 @@ class Sent(Screen):
for mail in queryreturn: for mail in queryreturn:
self.data.append({ self.data.append({
'text': mail[1].strip(), 'text': mail[1].strip(),
'secondary_text': mail[2][:50] + '........' if len(mail[2]) >= 50 else (mail[2] + ',' + mail[3].replace('\n', ''))[0:50] + '........', 'secondary_text': mail[2][:50] + '........' if len(
mail[2]) >= 50 else (
mail[2] + ',' + mail[3].replace('\n', ''))[0:50] + '........',
'lastactiontime': mail[6]}) 'lastactiontime': mail[6]})
for item in self.data: for item in self.data:
meny = ThreeLineAvatarIconListItem( meny = ThreeLineAvatarIconListItem(
@ -776,7 +761,8 @@ class Sent(Screen):
theme_text_color='Custom', theme_text_color='Custom',
text_color=NavigateApp().theme_cls.primary_color) text_color=NavigateApp().theme_cls.primary_color)
meny.add_widget(AvatarSampleWidget( meny.add_widget(AvatarSampleWidget(
source='./images/text_images/{}.png'.format(avatarImageFirstLetter(item['secondary_text'].strip())))) source='./images/text_images/{}.png'.format(
avatarImageFirstLetter(item['secondary_text'].strip()))))
meny.bind(on_press=partial( meny.bind(on_press=partial(
self.sent_detail, item['lastactiontime'])) self.sent_detail, item['lastactiontime']))
carousel = Carousel(direction='right') carousel = Carousel(direction='right')
@ -877,8 +863,6 @@ class Sent(Screen):
class Trash(Screen): class Trash(Screen):
"""Trash Screen uses screen to show widgets of screens.""" """Trash Screen uses screen to show widgets of screens."""
# pylint: disable=too-few-public-methods
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
"""Trash method, delete sent message and add in Trash.""" """Trash method, delete sent message and add in Trash."""
super(Trash, self).__init__(*args, **kwargs) super(Trash, self).__init__(*args, **kwargs)
@ -904,12 +888,14 @@ class Trash(Screen):
for item in trash_data: for item in trash_data:
meny = ThreeLineAvatarIconListItem( meny = ThreeLineAvatarIconListItem(
text=item[1], text=item[1],
secondary_text=item[2][:50] + '........' if len(item[2]) >= 50 else (item[2] + ',' + item[3].replace('\n', ''))[0:50] + '........', secondary_text=item[2][:50] + '........' if len(
item[2]) >= 50 else (
item[2] + ',' + item[3].replace('\n', ''))[0:50] + '........',
theme_text_color='Custom', theme_text_color='Custom',
text_color=NavigateApp().theme_cls.primary_color) text_color=NavigateApp().theme_cls.primary_color)
img_latter = './images/text_images/{}.png'.format( img_latter = './images/text_images/{}.png'.format(
item[2][0].upper() if (item[2][0].upper() >= 'A' and item[ item[2][0].upper() if (item[2][0].upper() >= 'A' and item[
2][0].upper() <= 'Z') else '!') 2][0].upper() <= 'Z') else '!')
meny.add_widget(AvatarSampleWidget(source=img_latter)) meny.add_widget(AvatarSampleWidget(source=img_latter))
carousel = Carousel(direction='right') carousel = Carousel(direction='right')
if platform == 'android': if platform == 'android':
@ -948,15 +934,12 @@ class Trash(Screen):
class Page(Screen): class Page(Screen):
"""Page Screen show widgets of page.""" """Page Screen show widgets of page."""
# pylint: disable=too-few-public-methods
pass pass
class Create(Screen): class Create(Screen):
"""Creates the screen widgets.""" """Creates the screen widgets."""
# pylint: disable=too-few-public-methods
def __init__(self, **kwargs): def __init__(self, **kwargs):
"""Getting Labels and address from addressbook.""" """Getting Labels and address from addressbook."""
super(Create, self).__init__(**kwargs) super(Create, self).__init__(**kwargs)
@ -971,11 +954,10 @@ class Create(Screen):
class Setting(Screen): class Setting(Screen):
"""Setting the Screen components.""" """Setting the Screen components."""
# pylint: disable=too-few-public-methods
pass pass
class NavigateApp(App): class NavigateApp(App): # pylint: disable=too-many-public-methods
"""Navigation Layout of class.""" """Navigation Layout of class."""
theme_cls = ThemeManager() theme_cls = ThemeManager()
@ -1103,15 +1085,18 @@ class NavigateApp(App):
return BMConfigParser().addresses()[0] return BMConfigParser().addresses()[0]
return 'Select Address' return 'Select Address'
def createFolder(self, directory): @staticmethod
def createFolder(directory):
"""This method is used to create the directory when app starts""" """This method is used to create the directory when app starts"""
try: try:
if not os.path.exists(directory): if not os.path.exists(directory):
os.makedirs(directory) os.makedirs(directory)
except OSError: except OSError:
print ('Error: Creating directory. ' + directory) print 'Error: Creating directory. ' + directory
def get_default_image(self): @staticmethod
def get_default_image():
"""Getting default image on address"""
if BMConfigParser().addresses(): if BMConfigParser().addresses():
# BMConfigParser().addresses()[0] # BMConfigParser().addresses()[0]
return './images/default_identicon/{}.png'.format(BMConfigParser().addresses()[0]) return './images/default_identicon/{}.png'.format(BMConfigParser().addresses()[0])
@ -1308,7 +1293,9 @@ class NavigateApp(App):
img.x = 5 img.x = 5
self.root.children[2].children[0].ids.btn.add_widget(img) self.root.children[2].children[0].ids.btn.add_widget(img)
def address_identicon(self): @staticmethod
def address_identicon():
"""Address identicon"""
return './images/drawer_logo1.png' return './images/drawer_logo1.png'
@ -1373,6 +1360,7 @@ class GrashofPopup(Popup):
toast('Canceled') toast('Canceled')
def checkAddress_valid(self, instance): def checkAddress_valid(self, instance):
"""Checking is address is valid or not"""
my_addresses = self.parent.children[1].children[2].children[0].ids.btn.values my_addresses = self.parent.children[1].children[2].children[0].ids.btn.values
add_book = [addr[1] for addr in kivy_helper_search.search_sql( add_book = [addr[1] for addr in kivy_helper_search.search_sql(
folder="addressbook")] folder="addressbook")]
@ -1400,21 +1388,18 @@ class GrashofPopup(Popup):
class AvatarSampleWidget(ILeftBody, Image): class AvatarSampleWidget(ILeftBody, Image):
"""Avatar Sample Widget.""" """Avatar Sample Widget."""
# pylint: disable=too-few-public-methods
pass pass
class IconLeftSampleWidget(ILeftBodyTouch, MDIconButton): class IconLeftSampleWidget(ILeftBodyTouch, MDIconButton):
"""Left icon sample widget.""" """Left icon sample widget."""
# pylint: disable=too-few-public-methods
pass pass
class IconRightSampleWidget(IRightBodyTouch, MDCheckbox): class IconRightSampleWidget(IRightBodyTouch, MDCheckbox):
"""Right icon sample widget.""" """Right icon sample widget."""
# pylint: disable=too-few-public-methods
pass pass
@ -1552,7 +1537,8 @@ class MailDetail(Screen):
self.parent.parent.current = 'create' self.parent.parent.current = 'create'
navApp.set_navbar_for_composer() navApp.set_navbar_for_composer()
def copy_composer_text(self, instance, *args): @staticmethod
def copy_composer_text(instance, *args):
"""This method is used for copying the data from mail detail page""" """This method is used for copying the data from mail detail page"""
if len(instance.parent.text.split(':')) > 1: if len(instance.parent.text.split(':')) > 1:
cpy_text = instance.parent.text.split(':')[1].strip() cpy_text = instance.parent.text.split(':')[1].strip()
@ -1651,8 +1637,6 @@ class AddbookDetailPopup(Popup):
class ShowQRCode(Screen): class ShowQRCode(Screen):
"""ShowQRCode Screen uses to show the detail of mails.""" """ShowQRCode Screen uses to show the detail of mails."""
# pylint: disable=too-few-public-methods
def qrdisplay(self): def qrdisplay(self):
"""Method used for showing QR Code.""" """Method used for showing QR Code."""
self.manager.parent.parent.parent.ids.search_bar.clear_widgets() self.manager.parent.parent.parent.ids.search_bar.clear_widgets()
@ -1774,7 +1758,7 @@ class Draft(Screen):
# msg_count_objs.allmail_cnt.badge_text = str( # msg_count_objs.allmail_cnt.badge_text = str(
# int(state.all_count) - 1) # int(state.all_count) - 1)
# msg_count_objs.trash_cnt.badge_text = str( # msg_count_objs.trash_cnt.badge_text = str(
# int(state.trash_count) + 1) # int(state.trash_count) + 1)
state.draft_count = str(int(state.draft_count) - 1) state.draft_count = str(int(state.draft_count) - 1)
# state.all_count = str(int(state.all_count) - 1) # state.all_count = str(int(state.all_count) - 1)
# state.trash_count = str(int(state.trash_count) + 1) # state.trash_count = str(int(state.trash_count) + 1)
@ -1836,8 +1820,6 @@ class Draft(Screen):
class CustomSpinner(Spinner): class CustomSpinner(Spinner):
"""This class is used for setting spinner size.""" """This class is used for setting spinner size."""
# pylint: disable=too-few-public-methods
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
"""Method used for setting size of spinner.""" """Method used for setting size of spinner."""
super(CustomSpinner, self).__init__(*args, **kwargs) super(CustomSpinner, self).__init__(*args, **kwargs)
@ -1893,11 +1875,14 @@ class Allmails(Screen):
for item in all_mails: for item in all_mails:
meny = ThreeLineAvatarIconListItem( meny = ThreeLineAvatarIconListItem(
text=item[1], text=item[1],
secondary_text=item[2][:50] + '........' if len(item[2]) >= 50 else (item[2] + ',' + item[3].replace('\n', ''))[0:50] + '........', secondary_text=item[2][:50] + '........' if len(
item[2]) >= 50 else (
item[2] + ',' + item[3].replace('\n', ''))[0:50] + '........',
theme_text_color='Custom', theme_text_color='Custom',
text_color=NavigateApp().theme_cls.primary_color) text_color=NavigateApp().theme_cls.primary_color)
meny.add_widget(AvatarSampleWidget( meny.add_widget(AvatarSampleWidget(
source='./images/text_images/{}.png'.format(avatarImageFirstLetter(item[2].strip())))) source='./images/text_images/{}.png'.format(
avatarImageFirstLetter(item[2].strip()))))
meny.bind(on_press=partial( meny.bind(on_press=partial(
self.mail_detail, item[5], item[4])) self.mail_detail, item[5], item[4]))
carousel = Carousel(direction='right') carousel = Carousel(direction='right')
@ -2011,4 +1996,4 @@ def avatarImageFirstLetter(letter_string):
else: else:
img_latter = '!' img_latter = '!'
return img_latter return img_latter