Skip to content

Commit 0bded4a

Browse files
author
surbhi
committed
code-quality: Update code quality
- kivy/baseclass/network - kivy/baseclass/payment -kivy/baseclass/popup
1 parent 7e1cdef commit 0bded4a

File tree

3 files changed

+74
-81
lines changed

3 files changed

+74
-81
lines changed

src/bitmessagekivy/baseclass/network.py

+22-33
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# pylint: disable=no-name-in-module, too-few-public-methods
33

44
"""
5-
Network status
5+
Network status
66
"""
77

88
import os
@@ -16,39 +16,28 @@
1616
if os.environ.get('INSTALL_TESTS', False) and not state.backend_py3_compatible:
1717
from pybitmessage.mockbm import kivy_main
1818
stats = kivy_main.network.stats
19-
objectracker = kivy_main.network.objectracker
19+
object_tracker = kivy_main.network.objectracker
2020
else:
21-
from pybitmessage.network import stats, objectracker
21+
from pybitmessage.network import stats, objectracker as object_tracker
2222

2323

2424
class NetworkStat(Screen):
25-
"""NetworkStat class for kivy Ui"""
26-
27-
text_variable_1 = StringProperty(
28-
'{0}::{1}'.format('Total Connections', '0'))
29-
text_variable_2 = StringProperty(
30-
'Processed {0} per-to-per messages'.format('0'))
31-
text_variable_3 = StringProperty(
32-
'Processed {0} brodcast messages'.format('0'))
33-
text_variable_4 = StringProperty(
34-
'Processed {0} public keys'.format('0'))
35-
text_variable_5 = StringProperty(
36-
'Processed {0} object to be synced'.format('0'))
37-
38-
def __init__(self, *args, **kwargs):
39-
"""Init method for network stat"""
40-
super(NetworkStat, self).__init__(*args, **kwargs)
41-
Clock.schedule_interval(self.init_ui, 1)
42-
43-
def init_ui(self, dt=0):
44-
"""Clock Schdule for method networkstat screen"""
45-
self.text_variable_1 = '{0} :: {1}'.format(
46-
'Total Connections', str(len(stats.connectedHostsList())))
47-
self.text_variable_2 = 'Processed {0} per-to-per messages'.format(
48-
str(state.numberOfMessagesProcessed))
49-
self.text_variable_3 = 'Processed {0} brodcast messages'.format(
50-
str(state.numberOfBroadcastsProcessed))
51-
self.text_variable_4 = 'Processed {0} public keys'.format(
52-
str(state.numberOfPubkeysProcessed))
53-
self.text_variable_5 = '{0} object to be synced'.format(
54-
len(objectracker.missingObjects))
25+
"""NetworkStat class for Kivy UI"""
26+
27+
text_variable_1 = StringProperty(f'Total Connections::0')
28+
text_variable_2 = StringProperty(f'Processed 0 peer-to-peer messages')
29+
text_variable_3 = StringProperty(f'Processed 0 broadcast messages')
30+
text_variable_4 = StringProperty(f'Processed 0 public keys')
31+
text_variable_5 = StringProperty(f'Processed 0 objects to be synced')
32+
33+
def __init__(self, **kwargs):
34+
super().__init__(**kwargs) # pylint: disable=missing-super-argument
35+
Clock.schedule_interval(self.update_stats, 1)
36+
37+
def update_stats(self, dt):
38+
"""Update network statistics"""
39+
self.text_variable_1 = f'Total Connections::{len(stats.connectedHostsList())}'
40+
self.text_variable_2 = f'Processed {state.numberOfMessagesProcessed} peer-to-peer messages'
41+
self.text_variable_3 = f'Processed {state.numberOfBroadcastsProcessed} broadcast messages'
42+
self.text_variable_4 = f'Processed {state.numberOfPubkeysProcessed} public keys'
43+
self.text_variable_5 = f'Processed {object_tracker.missingObjects} objects'

src/bitmessagekivy/baseclass/payment.py

+8-13
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,31 @@
11
# pylint: disable=import-error, no-name-in-module, too-few-public-methods, too-many-ancestors
22

3-
'''
4-
Payment/subscription frontend
5-
'''
3+
"""
4+
Payment/subscription frontend
5+
"""
66

77
from kivy.uix.boxlayout import BoxLayout
88
from kivy.uix.screenmanager import Screen
99
from kivy.app import App
1010

1111
from kivymd.uix.behaviors.elevation import RectangularElevationBehavior
1212
from kivymd.uix.label import MDLabel
13-
from kivymd.uix.list import (
14-
IRightBodyTouch,
15-
OneLineAvatarIconListItem
16-
)
13+
from kivymd.uix.list import IRightBodyTouch, OneLineAvatarIconListItem
1714

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

2017

2118
class Payment(Screen):
22-
"""Payment Screen class for kivy Ui"""
19+
"""Payment Screen class for Kivy UI"""
2320

2421
def __init__(self, *args, **kwargs):
25-
"""Instantiate kivy state variable"""
26-
super(Payment, self).__init__(*args, **kwargs)
22+
"""Instantiate Kivy state variable"""
23+
super().__init__(*args, **kwargs) # pylint: disable=missing-super-argument
2724
self.kivy_state = kivy_state_variables()
2825

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

4641

4742
class Category(BoxLayout, RectangularElevationBehavior):

src/bitmessagekivy/baseclass/popup.py

+44-35
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
# pylint: disable=no-member, no-name-in-module, unused-argument, too-few-public-methods
33

44
"""
5-
All the popup are managed here.
6-
5+
All the popups are managed here.
76
"""
7+
88
import logging
99
from datetime import datetime
1010

@@ -17,34 +17,34 @@
1717

1818
from pybitmessage.bitmessagekivy import kivy_helper_search
1919
from pybitmessage.bitmessagekivy.get_platform import platform
20-
2120
from pybitmessage.bitmessagekivy.baseclass.common import toast
22-
2321
from pybitmessage.addresses import decodeAddress
2422

2523
logger = logging.getLogger('default')
2624

2725

2826
class AddressChangingLoader(Popup):
29-
"""Run a Screen Loader when changing the Identity for kivy UI"""
27+
"""Run a Screen Loader when changing the Identity for Kivy UI"""
3028

3129
def __init__(self, **kwargs):
32-
super(AddressChangingLoader, self).__init__(**kwargs)
30+
super().__init__(**kwargs) # pylint: disable=missing-super-argument
3331
Clock.schedule_once(self.dismiss_popup, 0.5)
3432

3533
def dismiss_popup(self, dt):
36-
"""Dismiss popups"""
34+
"""Dismiss popup"""
3735
self.dismiss()
3836

3937

4038
class AddAddressPopup(BoxLayout):
41-
"""Popup for adding new address to addressbook"""
39+
"""Popup for adding new address to address book"""
4240

4341
validation_dict = {
44-
"missingbm": "The address should start with ''BM-''",
42+
"missingbm": "The address should start with 'BM-'",
4543
"checksumfailed": "The address is not typed or copied correctly",
46-
"versiontoohigh": "The version number of this address is higher than this"
47-
" software can support. Please upgrade Bitmessage.",
44+
"versiontoohigh": (
45+
"The version number of this address is higher than this "
46+
"software can support. Please upgrade Bitmessage."
47+
),
4848
"invalidcharacters": "The address contains invalid characters.",
4949
"ripetooshort": "Some data encoded in the address is too short.",
5050
"ripetoolong": "Some data encoded in the address is too long.",
@@ -53,19 +53,19 @@ class AddAddressPopup(BoxLayout):
5353
valid = False
5454

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

5858
def checkAddress_valid(self, instance):
59-
"""Checking address is valid or not"""
59+
"""Check if the address is valid or not"""
6060
my_addresses = (
6161
App.get_running_app().root.ids.content_drawer.ids.identity_dropdown.values)
6262
add_book = [addr[1] for addr in kivy_helper_search.search_sql(
6363
folder="addressbook")]
6464
entered_text = str(instance.text).strip()
6565
if entered_text in add_book:
66-
text = 'Address is already in the addressbook.'
66+
text = 'Address is already in the address book.'
6767
elif entered_text in my_addresses:
68-
text = 'You can not save your own address.'
68+
text = 'You cannot save your own address.'
6969
elif entered_text:
7070
text = self.addressChanged(entered_text)
7171

@@ -82,7 +82,7 @@ def checkAddress_valid(self, instance):
8282
self.ids.address.helper_text = 'This field is required'
8383

8484
def checkLabel_valid(self, instance):
85-
"""Checking address label is unique or not"""
85+
"""Check if the address label is unique or not"""
8686
entered_label = instance.text.strip()
8787
addr_labels = [labels[0] for labels in kivy_helper_search.search_sql(
8888
folder="addressbook")]
@@ -112,25 +112,25 @@ def addressChanged(self, addr):
112112

113113

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

117117
address_label = StringProperty()
118118
address = StringProperty()
119119

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

124124
def checkLabel_valid(self, instance):
125-
"""Checking address label is unique of not"""
125+
"""Check if the address label is unique or not"""
126126
entered_label = str(instance.text.strip())
127127
address_list = kivy_helper_search.search_sql(folder="addressbook")
128128
addr_labels = [labels[0] for labels in address_list]
129129
add_dict = dict(address_list)
130130
if self.address and entered_label in addr_labels \
131131
and self.address != add_dict[entered_label]:
132132
self.ids.add_label.error = True
133-
self.ids.add_label.helper_text = 'label name already exists.'
133+
self.ids.add_label.helper_text = 'Label name already exists.'
134134
elif entered_label:
135135
self.ids.add_label.error = False
136136
else:
@@ -139,17 +139,17 @@ def checkLabel_valid(self, instance):
139139

140140

141141
class MyaddDetailPopup(BoxLayout):
142-
"""MyaddDetailPopup class for kivy Ui"""
142+
"""Popup for my address details for Kivy UI"""
143143

144144
address_label = StringProperty()
145145
address = StringProperty()
146146

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

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

163163
def close_pop(self):
164-
"""Pop is Cancelled"""
164+
"""Cancel the popup"""
165165
self.parent.parent.parent.dismiss()
166166
toast('Cancelled')
167167

168168

169169
class AppClosingPopup(Popup):
170-
"""AppClosingPopup class for kivy Ui"""
170+
"""Popup for closing the application for Kivy UI"""
171171

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

175175
def closingAction(self, text):
176176
"""Action on closing window"""
@@ -185,22 +185,30 @@ def closingAction(self, text):
185185

186186

187187
class SenderDetailPopup(Popup):
188-
"""SenderDetailPopup class for kivy Ui"""
188+
"""Popup for sender details for Kivy UI"""
189189

190190
to_addr = StringProperty()
191191
from_addr = StringProperty()
192192
time_tag = StringProperty()
193193

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

198198
def assignDetail(self, to_addr, from_addr, timeinseconds):
199-
"""Detailes assigned"""
199+
"""Assign details to the popup"""
200200
self.to_addr = to_addr
201201
self.from_addr = from_addr
202+
self.time_tag = self.format_time(timeinseconds)
203+
self.adjust_popup_height(to_addr)
204+
205+
def format_time(self, timeinseconds):
206+
"""Format the timestamp into a readable string"""
202207
time_obj = datetime.fromtimestamp(int(timeinseconds))
203-
self.time_tag = time_obj.strftime("%d %b %Y, %I:%M %p")
208+
return time_obj.strftime("%d %b %Y, %I:%M %p")
209+
210+
def adjust_popup_height(self, to_addr):
211+
"""Adjust the height of the popup based on the address length"""
204212
device_type = 2 if platform == 'android' else 1.5
205213
pop_height = 1.2 * device_type * (self.ids.sd_label.height + self.ids.dismiss_btn.height)
206214
if len(to_addr) > 3:
@@ -219,13 +227,14 @@ def assignDetail(self, to_addr, from_addr, timeinseconds):
219227

220228

221229
class ToAddrBoxlayout(BoxLayout):
222-
"""ToAddrBoxlayout class for kivy Ui"""
230+
"""BoxLayout for displaying the to address"""
231+
223232
to_addr = StringProperty()
224233

225234
def set_toAddress(self, to_addr):
226-
"""This method is use to set to address"""
235+
"""Set the to address"""
227236
self.to_addr = to_addr
228237

229238

230239
class ToAddressTitle(BoxLayout):
231-
"""ToAddressTitle class for BoxLayout behaviour"""
240+
"""BoxLayout for displaying the to address title"""

0 commit comments

Comments
 (0)