Skip to content

kivy-code-quality-8 #2286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: v0.6
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 22 additions & 33 deletions src/bitmessagekivy/baseclass/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# pylint: disable=no-name-in-module, too-few-public-methods

"""
Network status
Network status
"""

import os
Expand All @@ -16,39 +16,28 @@
if os.environ.get('INSTALL_TESTS', False) and not state.backend_py3_compatible:
from pybitmessage.mockbm import kivy_main
stats = kivy_main.network.stats
objectracker = kivy_main.network.objectracker
object_tracker = kivy_main.network.objectracker
else:
from pybitmessage.network import stats, objectracker
from pybitmessage.network import stats, objectracker as object_tracker


class NetworkStat(Screen):
"""NetworkStat class for kivy Ui"""

text_variable_1 = StringProperty(
'{0}::{1}'.format('Total Connections', '0'))
text_variable_2 = StringProperty(
'Processed {0} per-to-per messages'.format('0'))
text_variable_3 = StringProperty(
'Processed {0} brodcast messages'.format('0'))
text_variable_4 = StringProperty(
'Processed {0} public keys'.format('0'))
text_variable_5 = StringProperty(
'Processed {0} object to be synced'.format('0'))

def __init__(self, *args, **kwargs):
"""Init method for network stat"""
super(NetworkStat, self).__init__(*args, **kwargs)
Clock.schedule_interval(self.init_ui, 1)

def init_ui(self, dt=0):
"""Clock Schdule for method networkstat screen"""
self.text_variable_1 = '{0} :: {1}'.format(
'Total Connections', str(len(stats.connectedHostsList())))
self.text_variable_2 = 'Processed {0} per-to-per messages'.format(
str(state.numberOfMessagesProcessed))
self.text_variable_3 = 'Processed {0} brodcast messages'.format(
str(state.numberOfBroadcastsProcessed))
self.text_variable_4 = 'Processed {0} public keys'.format(
str(state.numberOfPubkeysProcessed))
self.text_variable_5 = '{0} object to be synced'.format(
len(objectracker.missingObjects))
"""NetworkStat class for Kivy UI"""

text_variable_1 = StringProperty(f'Total Connections::0')

Check failure on line 27 in src/bitmessagekivy/baseclass/network.py

View check run for this annotation

PyBitmessage Code Quality Checks / Code Quality - flake8

E999

SyntaxError: invalid syntax
text_variable_2 = StringProperty(f'Processed 0 peer-to-peer messages')
text_variable_3 = StringProperty(f'Processed 0 broadcast messages')
text_variable_4 = StringProperty(f'Processed 0 public keys')
text_variable_5 = StringProperty(f'Processed 0 objects to be synced')

def __init__(self, **kwargs):
super().__init__(**kwargs) # pylint: disable=missing-super-argument
Clock.schedule_interval(self.update_stats, 1)

def update_stats(self, dt):
"""Update network statistics"""
self.text_variable_1 = f'Total Connections::{len(stats.connectedHostsList())}'
self.text_variable_2 = f'Processed {state.numberOfMessagesProcessed} peer-to-peer messages'
self.text_variable_3 = f'Processed {state.numberOfBroadcastsProcessed} broadcast messages'
self.text_variable_4 = f'Processed {state.numberOfPubkeysProcessed} public keys'
self.text_variable_5 = f'Processed {object_tracker.missingObjects} objects'
21 changes: 8 additions & 13 deletions src/bitmessagekivy/baseclass/payment.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,31 @@
# pylint: disable=import-error, no-name-in-module, too-few-public-methods, too-many-ancestors

'''
Payment/subscription frontend
'''
"""
Payment/subscription frontend
"""

from kivy.uix.boxlayout import BoxLayout
from kivy.uix.screenmanager import Screen
from kivy.app import App

from kivymd.uix.behaviors.elevation import RectangularElevationBehavior
from kivymd.uix.label import MDLabel
from kivymd.uix.list import (
IRightBodyTouch,
OneLineAvatarIconListItem
)
from kivymd.uix.list import IRightBodyTouch, OneLineAvatarIconListItem

from pybitmessage.bitmessagekivy.baseclass.common import toast, kivy_state_variables


class Payment(Screen):
"""Payment Screen class for kivy Ui"""
"""Payment Screen class for Kivy UI"""

def __init__(self, *args, **kwargs):
"""Instantiate kivy state variable"""
super(Payment, self).__init__(*args, **kwargs)
"""Instantiate Kivy state variable"""
super().__init__(*args, **kwargs) # pylint: disable=missing-super-argument
self.kivy_state = kivy_state_variables()

# TODO: get_free_credits() is not used anywhere, will be used later for Payment/subscription.
def get_free_credits(self, instance): # pylint: disable=unused-argument
"""Get the available credits"""
# pylint: disable=no-self-use
self.kivy_state.available_credit = 0
existing_credits = 0
if existing_credits > 0:
Expand All @@ -40,8 +36,7 @@
toast('Credit added to your account!')
# TODO: There is no sc18 screen id is available,
# need to create sc18 for Credits screen inside main.kv
App.get_running_app().root.ids.sc18.ids.cred.text = '{0}'.format(
self.kivy_state.available_credit)
App.get_running_app().root.ids.sc18.ids.cred.text = f'{self.kivy_state.available_credit}'

Check failure on line 39 in src/bitmessagekivy/baseclass/payment.py

View check run for this annotation

PyBitmessage Code Quality Checks / Code Quality - flake8

E999

SyntaxError: invalid syntax


class Category(BoxLayout, RectangularElevationBehavior):
Expand Down
79 changes: 44 additions & 35 deletions src/bitmessagekivy/baseclass/popup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# pylint: disable=no-member, no-name-in-module, unused-argument, too-few-public-methods

"""
All the popup are managed here.

All the popups are managed here.
"""

import logging
from datetime import datetime

Expand All @@ -17,34 +17,34 @@

from pybitmessage.bitmessagekivy import kivy_helper_search
from pybitmessage.bitmessagekivy.get_platform import platform

from pybitmessage.bitmessagekivy.baseclass.common import toast

from pybitmessage.addresses import decodeAddress

logger = logging.getLogger('default')


class AddressChangingLoader(Popup):
"""Run a Screen Loader when changing the Identity for kivy UI"""
"""Run a Screen Loader when changing the Identity for Kivy UI"""

def __init__(self, **kwargs):
super(AddressChangingLoader, self).__init__(**kwargs)
super().__init__(**kwargs) # pylint: disable=missing-super-argument
Clock.schedule_once(self.dismiss_popup, 0.5)

def dismiss_popup(self, dt):
"""Dismiss popups"""
"""Dismiss popup"""
self.dismiss()


class AddAddressPopup(BoxLayout):
"""Popup for adding new address to addressbook"""
"""Popup for adding new address to address book"""

validation_dict = {
"missingbm": "The address should start with ''BM-''",
"missingbm": "The address should start with 'BM-'",
"checksumfailed": "The address is not typed or copied correctly",
"versiontoohigh": "The version number of this address is higher than this"
" software can support. Please upgrade Bitmessage.",
"versiontoohigh": (
"The version number of this address is higher than this "
"software can support. Please upgrade Bitmessage."
),
"invalidcharacters": "The address contains invalid characters.",
"ripetooshort": "Some data encoded in the address is too short.",
"ripetoolong": "Some data encoded in the address is too long.",
Expand All @@ -53,19 +53,19 @@
valid = False

def __init__(self, **kwargs):
super(AddAddressPopup, self).__init__(**kwargs)
super().__init__(**kwargs) # pylint: disable=missing-super-argument

def checkAddress_valid(self, instance):
"""Checking address is valid or not"""
"""Check if the address is valid or not"""
my_addresses = (
App.get_running_app().root.ids.content_drawer.ids.identity_dropdown.values)
add_book = [addr[1] for addr in kivy_helper_search.search_sql(
folder="addressbook")]
entered_text = str(instance.text).strip()
if entered_text in add_book:
text = 'Address is already in the addressbook.'
text = 'Address is already in the address book.'
elif entered_text in my_addresses:
text = 'You can not save your own address.'
text = 'You cannot save your own address.'
elif entered_text:
text = self.addressChanged(entered_text)

Expand All @@ -82,7 +82,7 @@
self.ids.address.helper_text = 'This field is required'

def checkLabel_valid(self, instance):
"""Checking address label is unique or not"""
"""Check if the address label is unique or not"""
entered_label = instance.text.strip()
addr_labels = [labels[0] for labels in kivy_helper_search.search_sql(
folder="addressbook")]
Expand Down Expand Up @@ -112,25 +112,25 @@


class SavedAddressDetailPopup(BoxLayout):
"""Pop-up for Saved Address details for kivy UI"""
"""Popup for saved address details for Kivy UI"""

address_label = StringProperty()
address = StringProperty()

def __init__(self, **kwargs):
"""Set screen of address detail page"""
super(SavedAddressDetailPopup, self).__init__(**kwargs)
super().__init__(**kwargs) # pylint: disable=missing-super-argument

def checkLabel_valid(self, instance):
"""Checking address label is unique of not"""
"""Check if the address label is unique or not"""
entered_label = str(instance.text.strip())
address_list = kivy_helper_search.search_sql(folder="addressbook")
addr_labels = [labels[0] for labels in address_list]
add_dict = dict(address_list)
if self.address and entered_label in addr_labels \
and self.address != add_dict[entered_label]:
self.ids.add_label.error = True
self.ids.add_label.helper_text = 'label name already exists.'
self.ids.add_label.helper_text = 'Label name already exists.'
elif entered_label:
self.ids.add_label.error = False
else:
Expand All @@ -139,17 +139,17 @@


class MyaddDetailPopup(BoxLayout):
"""MyaddDetailPopup class for kivy Ui"""
"""Popup for my address details for Kivy UI"""

address_label = StringProperty()
address = StringProperty()

def __init__(self, **kwargs):
"""My Address Details screen setting"""
super(MyaddDetailPopup, self).__init__(**kwargs)
"""Set screen of my address details"""
super().__init__(**kwargs) # pylint: disable=missing-super-argument

def send_message_from(self):
"""Method used to fill from address of composer autofield"""
"""Fill from address of composer autofield"""
App.get_running_app().set_navbar_for_composer()
window_obj = App.get_running_app().root.ids
window_obj.id_create.children[1].ids.ti.text = self.address
Expand All @@ -161,16 +161,16 @@
self.parent.parent.parent.dismiss()

def close_pop(self):
"""Pop is Cancelled"""
"""Cancel the popup"""
self.parent.parent.parent.dismiss()
toast('Cancelled')


class AppClosingPopup(Popup):
"""AppClosingPopup class for kivy Ui"""
"""Popup for closing the application for Kivy UI"""

def __init__(self, **kwargs):
super(AppClosingPopup, self).__init__(**kwargs)
super().__init__(**kwargs) # pylint: disable=missing-super-argument

def closingAction(self, text):
"""Action on closing window"""
Expand All @@ -185,22 +185,30 @@


class SenderDetailPopup(Popup):
"""SenderDetailPopup class for kivy Ui"""
"""Popup for sender details for Kivy UI"""

to_addr = StringProperty()
from_addr = StringProperty()
time_tag = StringProperty()

def __init__(self, **kwargs):
"""this metthod initialized the send message detial popup"""
super(SenderDetailPopup, self).__init__(**kwargs)
"""Initialize the send message detail popup"""
super().__init__(**kwargs) # pylint: disable=missing-super-argument

def assignDetail(self, to_addr, from_addr, timeinseconds):
"""Detailes assigned"""
"""Assign details to the popup"""
self.to_addr = to_addr
self.from_addr = from_addr
self.time_tag = self.format_time(timeinseconds)
self.adjust_popup_height(to_addr)

def format_time(self, timeinseconds):

Check notice on line 205 in src/bitmessagekivy/baseclass/popup.py

View check run for this annotation

PyBitmessage Code Quality Checks / Code Quality - pylint

R0201 / no-self-use

Method could be a function
"""Format the timestamp into a readable string"""
time_obj = datetime.fromtimestamp(int(timeinseconds))
self.time_tag = time_obj.strftime("%d %b %Y, %I:%M %p")
return time_obj.strftime("%d %b %Y, %I:%M %p")

def adjust_popup_height(self, to_addr):
"""Adjust the height of the popup based on the address length"""
device_type = 2 if platform == 'android' else 1.5
pop_height = 1.2 * device_type * (self.ids.sd_label.height + self.ids.dismiss_btn.height)
if len(to_addr) > 3:
Expand All @@ -219,13 +227,14 @@


class ToAddrBoxlayout(BoxLayout):
"""ToAddrBoxlayout class for kivy Ui"""
"""BoxLayout for displaying the to address"""

to_addr = StringProperty()

def set_toAddress(self, to_addr):
"""This method is use to set to address"""
"""Set the to address"""
self.to_addr = to_addr


class ToAddressTitle(BoxLayout):
"""ToAddressTitle class for BoxLayout behaviour"""
"""BoxLayout for displaying the to address title"""