Skip to content

Commit 0170abc

Browse files
authored
Merge pull request Bitmessage#1 from cis-navjot-g/codequalitykivy
flake8 fixes part1
2 parents 3edfc98 + e940463 commit 0170abc

File tree

1 file changed

+83
-50
lines changed

1 file changed

+83
-50
lines changed

src/bitmessagekivy/mpybit.py

Lines changed: 83 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,30 @@
1-
# -*- coding: utf-8 -*-
1+
"""Coding: utf-8."""
22
from kivy.app import App
33
from kivy.lang import Builder
44
from kivy.metrics import dp
55
from kivy.properties import ObjectProperty
66
from kivy.uix.image import Image
7-
from kivy.uix.screenmanager import Screen, NoTransition
8-
from kivymd.bottomsheet import MDListBottomSheet, MDGridBottomSheet
7+
from kivy.uix.screenmanager import Screen
98
from kivymd.button import MDIconButton
10-
from kivymd.date_picker import MDDatePicker
119
from kivymd.dialog import MDDialog
1210
from kivymd.label import MDLabel
13-
from kivymd.list import ILeftBody, ILeftBodyTouch, IRightBodyTouch, BaseListItem
14-
from kivymd.material_resources import DEVICE_TYPE
11+
from kivymd.list import ILeftBody, ILeftBodyTouch, IRightBodyTouch
1512
from kivymd.navigationdrawer import MDNavigationDrawer, NavigationDrawerHeaderBase
1613
from kivymd.selectioncontrols import MDCheckbox
17-
from kivymd.snackbar import Snackbar
1814
from kivymd.theming import ThemeManager
19-
from kivymd.time_picker import MDTimePicker
2015
from kivymd.list import ThreeLineAvatarIconListItem, TwoLineAvatarIconListItem, TwoLineListItem
2116
from kivy.properties import ListProperty, StringProperty, BooleanProperty
2217
from kivy.clock import Clock
2318
from bmconfigparser import BMConfigParser
2419
import state
2520
import queues
2621
from kivy.uix.popup import Popup
27-
from helper_sql import *
28-
from kivy.uix.gridlayout import GridLayout
29-
from kivy.app import App
22+
from helper_sql import sqlQuery, sqlExecute
3023
from kivy.uix.textinput import TextInput
31-
from kivy.lang import Builder
3224
from kivy.uix.boxlayout import BoxLayout
3325
from kivy.uix.floatlayout import FloatLayout
34-
from kivy.properties import NumericProperty, ListProperty, BooleanProperty, ObjectProperty
26+
from kivy.properties import NumericProperty
3527
from kivy.uix.recycleview import RecycleView
36-
from kivy.uix.recyclegridlayout import RecycleGridLayout
3728
from kivy.uix.recycleview.views import RecycleDataViewBehavior
3829
from kivy.uix.label import Label
3930
from kivy.uix.recycleboxlayout import RecycleBoxLayout
@@ -50,17 +41,22 @@
5041
from kivy.utils import platform
5142
from kivy.uix.spinner import Spinner
5243

44+
5345
class Navigatorss(MDNavigationDrawer):
46+
"""Navigators class contains image, title and logo."""
47+
5448
image_source = StringProperty('images/qidenticon_two.png')
5549
title = StringProperty('Navigation')
5650
drawer_logo = StringProperty()
5751

5852

5953
class Inbox(Screen):
6054
"""Inbox Screen uses screen to show widgets of screens."""
55+
6156
data = ListProperty()
6257

6358
def __init__(self, *args, **kwargs):
59+
"""Method Parsing the address."""
6460
super(Inbox, self).__init__(*args, **kwargs)
6561
if state.association == '':
6662
if BMConfigParser().addresses():
@@ -89,16 +85,31 @@ def loadMessagelist(self, account, where="", what=""):
8985
if queryreturn:
9086
for mail in queryreturn:
9187
third_text = mail[3].replace('\n', ' ')
92-
data.append({'text': mail[4].strip(), 'secondary_text': mail[5][:10] + '...........' if len(mail[3]) > 10 else mail[3] + '\n' + " " + (third_text[:25] + '...!') if len(third_text) > 25 else third_text, 'receivedTime': mail[6] })
88+
data.append({
89+
'text': mail[4].strip(),
90+
'secondary_text': mail[5][:10] + '...........' if len(
91+
mail[3]) > 10 else mail[3] + '\n' + " " + (
92+
third_text[:25] + '...!') if len(
93+
third_text) > 25 else third_text,
94+
'receivedTime': mail[6]})
9395
for item in data:
94-
meny = ThreeLineAvatarIconListItem(text=item['text'], secondary_text=item['secondary_text'], theme_text_color= 'Custom', text_color=NavigateApp().theme_cls.primary_color)
95-
meny.add_widget(AvatarSampleWidget(source='./images/text_images/{}.png'.format(item['secondary_text'][0].upper() if (item['secondary_text'][0].upper() >= 'A' and item['secondary_text'][0].upper() <= 'Z') else '!')))
96-
meny.bind(on_press = partial(self.inbox_detail, item['receivedTime']))
96+
meny = ThreeLineAvatarIconListItem(
97+
text=item['text'],
98+
secondary_text=item['secondary_text'],
99+
theme_text_color='Custom',
100+
text_color=NavigateApp().theme_cls.primary_color)
101+
meny.add_widget(
102+
AvatarSampleWidget(
103+
source='./images/text_images/{}.png'.format(
104+
item['secondary_text'][0].upper() if (
105+
item['secondary_text'][0].upper() >= 'A' and item[
106+
'secondary_text'][0].upper() <= 'Z') else '!')))
107+
meny.bind(on_press=partial(self.inbox_detail, item['receivedTime']))
97108
carousel = Carousel(direction='right')
98109
if platform == 'android':
99110
carousel.height = 150
100111
elif platform == 'linux':
101-
carousel.height = meny.height - 10
112+
carousel.height = meny.height - 10
102113
carousel.size_hint_y = None
103114
carousel.ignore_perpendicular_swipes = True
104115
carousel.data_index = 0
@@ -110,7 +121,7 @@ def loadMessagelist(self, account, where="", what=""):
110121
carousel.add_widget(del_btn)
111122
carousel.add_widget(meny)
112123
ach_btn = Button(text='Achieve')
113-
ach_btn.background_color = (0,1,0,1)
124+
ach_btn.background_color = (0, 1, 0, 1)
114125
ach_btn.bind(on_press=partial(self.archive, item['receivedTime']))
115126
carousel.add_widget(ach_btn)
116127
carousel.index = 1
@@ -126,7 +137,7 @@ def loadMessagelist(self, account, where="", what=""):
126137
self.ids.ml.add_widget(content)
127138

128139
def inbox_detail(self, receivedTime, *args):
129-
"""Load inbox page details"""
140+
"""Load inbox page details."""
130141
state.detailPageType = 'inbox'
131142
state.sentMailTime = receivedTime
132143
if self.manager:
@@ -140,7 +151,7 @@ def inbox_detail(self, receivedTime, *args):
140151
src_mng_obj.current = 'mailDetail'
141152

142153
def delete(self, data_index, instance, *args):
143-
"""Delete inbox mail from inbox listing"""
154+
"""Delete inbox mail from inbox listing."""
144155
sqlExecute("UPDATE inbox SET folder = 'trash' WHERE received = {};".format(data_index))
145156
msg_count_objs = self.parent.parent.parent.parent.children[2].children[0].ids
146157
if int(state.inbox_count) > 0:
@@ -152,13 +163,13 @@ def delete(self, data_index, instance, *args):
152163
self.update_trash()
153164

154165
def archive(self, data_index, instance, *args):
155-
"""Archive inbox mail from inbox listing"""
166+
"""Archive inbox mail from inbox listing."""
156167
sqlExecute("UPDATE inbox SET folder = 'trash' WHERE received = {};".format(data_index))
157168
self.ids.ml.remove_widget(instance.parent.parent)
158169
self.update_trash()
159170

160171
def update_trash(self):
161-
"""Update trash screen mails which is deleted from inbox"""
172+
"""Update trash screen mails which is deleted from inbox."""
162173
try:
163174
self.parent.screens[4].clear_widgets()
164175
self.parent.screens[4].add_widget(Trash())
@@ -167,11 +178,9 @@ def update_trash(self):
167178
self.parent.parent.screens[4].add_widget(Trash())
168179

169180
def refresh_callback(self, *args):
170-
"""A method that updates the state of your application
171-
while the spinner remains on the screen."""
172-
181+
"""A method that updates the state of your application while the spinner remains on the screen."""
173182
def refresh_callback(interval):
174-
"""This methods is used for loading the inbox screen data"""
183+
"""Method used for loading the inbox screen data."""
175184
self.ids.ml.clear_widgets()
176185
self.remove_widget(self.children[1])
177186
try:
@@ -187,7 +196,9 @@ def refresh_callback(interval):
187196

188197
class MyAddress(Screen):
189198
"""MyAddress Screen uses screen to show widgets of screens."""
199+
190200
def __init__(self, *args, **kwargs):
201+
"""Clock Schdule for method inbox accounts."""
191202
super(MyAddress, self).__init__(*args, **kwargs)
192203
Clock.schedule_once(self.init_ui, 0)
193204

@@ -198,8 +209,15 @@ def init_ui(self, dt=0):
198209
for address in state.kivyapp.variable_1:
199210
data.append({'text': BMConfigParser().get(address, 'label'), 'secondary_text': address})
200211
for item in data:
201-
meny = TwoLineAvatarIconListItem(text=item['text'], secondary_text=item['secondary_text'], theme_text_color= 'Custom',text_color=NavigateApp().theme_cls.primary_color)
202-
meny.add_widget(AvatarSampleWidget(source='./images/text_images/{}.png'.format(item['text'][0].upper() if (item['text'][0].upper() >= 'A' and item['text'][0].upper() <= 'Z') else '!')))
212+
meny = TwoLineAvatarIconListItem(
213+
text=item['text'],
214+
secondary_text=item['secondary_text'],
215+
theme_text_color='Custom',
216+
text_color=NavigateApp().theme_cls.primary_color)
217+
meny.add_widget(AvatarSampleWidget(
218+
source='./images/text_images/{}.png'.format(
219+
item['text'][0].upper() if (item['text'][0].upper() >= 'A' and item[
220+
'text'][0].upper() <= 'Z') else '!')))
203221
meny.bind(on_press=partial(self.myadd_detail, item['secondary_text'], item['text']))
204222
self.ids.ml.add_widget(meny)
205223
else:
@@ -217,16 +235,15 @@ def init_ui(self, dt=0):
217235
pass
218236

219237
def myadd_detail(self, fromaddress, label, *args):
238+
"""Myaddress Details."""
220239
p = MyaddDetailPopup()
221240
p.open()
222241
p.set_address(fromaddress, label)
223242

224243
def refresh_callback(self, *args):
225-
"""A method that updates the state of your application
226-
while the spinner remains on the screen."""
227-
244+
"""A method that updates the state of your application while the spinner remains on the screen."""
228245
def refresh_callback(interval):
229-
"""This methods is used for loading the myaddress screen data"""
246+
"""Method used for loading the myaddress screen data."""
230247
self.ids.ml.clear_widgets()
231248
self.remove_widget(self.children[1])
232249
try:
@@ -242,7 +259,9 @@ def refresh_callback(interval):
242259

243260
class AddressBook(Screen):
244261
"""AddressBook Screen uses screen to show widgets of screens."""
262+
245263
def __init__(self, *args, **kwargs):
264+
"""Getting AddressBook Details."""
246265
super(AddressBook, self).__init__(*args, **kwargs)
247266
Clock.schedule_once(self.init_ui, 0)
248267

@@ -251,9 +270,15 @@ def init_ui(self, dt=0):
251270
data = sqlQuery("SELECT label, address from addressbook")
252271
if data:
253272
for item in data:
254-
meny = TwoLineAvatarIconListItem(text=item[0], secondary_text=item[1], theme_text_color='Custom',text_color=NavigateApp().theme_cls.primary_color)
255-
meny.add_widget(AvatarSampleWidget(source='./images/text_images/{}.png'.format(item[0][0].upper() if (item[0][0].upper() >= 'A' and item[0][0].upper() <= 'Z') else '!')))
256-
meny.bind(on_press = partial(self.addBook_detail, item[1], item[0]))
273+
meny = TwoLineAvatarIconListItem(
274+
text=item[0],
275+
secondary_text=item[1],
276+
theme_text_color='Custom',
277+
text_color=NavigateApp().theme_cls.primary_color)
278+
meny.add_widget(AvatarSampleWidget(
279+
source='./images/text_images/{}.png'.format(
280+
item[0][0].upper() if (item[0][0].upper() >= 'A' and item[0][0].upper() <= 'Z') else '!')))
281+
meny.bind(on_press=partial(self.addBook_detail, item[1], item[0]))
257282
carousel = Carousel(direction='right')
258283
if platform == 'android':
259284
carousel.height = 140
@@ -269,7 +294,7 @@ def init_ui(self, dt=0):
269294
del_btn.bind(on_press=partial(self.delete_address, item[1]))
270295
carousel.add_widget(del_btn)
271296
carousel.add_widget(meny)
272-
carousel.index=1
297+
carousel.index = 1
273298
self.ids.ml.add_widget(carousel)
274299
else:
275300
content = MDLabel(font_style='Body1',
@@ -282,59 +307,69 @@ def init_ui(self, dt=0):
282307
self.ids.ml.add_widget(content)
283308

284309
def refreshs(self, *args):
310+
"""Refresh the Widget."""
285311
state.navinstance.ids.sc11.clear_widgets()
286312
state.navinstance.ids.sc11.add_widget(AddressBook())
287313

288314
def addBook_detail(self, address, label, *args):
315+
"""Addressbook Details."""
289316
p = AddbookDetailPopup()
290317
p.open()
291318
p.set_addbook_data(address, label)
292319

293320
def delete_address(self, address, instance, *args):
294-
"""Delete inbox mail from inbox listing"""
321+
"""Delete inbox mail from inbox listing."""
295322
self.ids.ml.remove_widget(instance.parent.parent)
296323
sqlExecute("DELETE FROM addressbook WHERE address = '{}';".format(address))
297324

298325

299326
class SelectableRecycleBoxLayout(FocusBehavior, LayoutSelectionBehavior,
300327
RecycleBoxLayout):
301-
''' Adds selection and focus behaviour to the view. '''
328+
"""Adds selection and focus behaviour to the view."""
329+
302330
pass
303331

304332

305333
class SelectableLabel(RecycleDataViewBehavior, Label):
306-
''' Add selection support to the Label '''
334+
"""Add selection support to the Label."""
335+
307336
index = None
308337
selected = BooleanProperty(False)
309338
selectable = BooleanProperty(True)
310339

311340
def refresh_view_attrs(self, rv, index, data):
312-
''' Catch and handle the view changes '''
341+
"""Catch and handle the view changes."""
313342
self.index = index
314343
return super(SelectableLabel, self).refresh_view_attrs(
315344
rv, index, data)
316345

317346
def on_touch_down(self, touch):
318-
''' Add selection on touch down '''
347+
"""Add selection on touch down."""
319348
if super(SelectableLabel, self).on_touch_down(touch):
320349
return True
321350
if self.collide_point(*touch.pos) and self.selectable:
322351
return self.parent.select_with_touch(self.index, touch)
323352

324353
def apply_selection(self, rv, index, is_selected):
325-
''' Respond to the selection of items in the view. '''
354+
"""Respond to the selection of items in the view."""
326355
self.selected = is_selected
327356
if is_selected:
328357
print("selection changed to {0}".format(rv.data[index]))
329-
rv.parent.txt_input.text = rv.parent.txt_input.text.replace(rv.parent.txt_input.text, rv.data[index]['text'])
358+
rv.parent.txt_input.text = rv.parent.txt_input.text.replace(
359+
rv.parent.txt_input.text, rv.data[index]['text'])
330360

331361

332362
class RV(RecycleView):
363+
"""Recycling View."""
364+
333365
def __init__(self, **kwargs):
366+
"""Recycling Method."""
334367
super(RV, self).__init__(**kwargs)
335368

336369

337370
class DropDownWidget(BoxLayout):
371+
"""Adding Dropdown Widget."""
372+
338373
txt_input = ObjectProperty()
339374
rv = ObjectProperty()
340375

@@ -353,7 +388,7 @@ def send(self):
353388
status, addressVersionNumber, streamNumber, ripe = decodeAddress(
354389
toAddress)
355390
if status == 'success':
356-
from addresses import *
391+
from addresses import addBMIfNotPresent
357392
toAddress = addBMIfNotPresent(toAddress)
358393
statusIconColor = 'red'
359394
if addressVersionNumber > 4 or addressVersionNumber <= 1:
@@ -385,9 +420,8 @@ def send(self):
385420
encoding,
386421
BMConfigParser().getint('bitmessagesettings', 'ttl'))
387422
state.check_sent_acc = fromAddress
388-
state.msg_counter_objs = self.parent.parent.parent.parent.parent.parent.children[0].children[2].children[0].ids
389-
# state.msg_counter_objs.send_cnt.badge_text = str(int(state.sent_count) + 1)
390-
# state.sent_count = str(int(state.sent_count) + 1)
423+
state.msg_counter_objs = \
424+
self.parent.parent.parent.parent.parent.parent.children[0].children[2].children[0].ids
391425
self.parent.parent.screens[3].clear_widgets()
392426
self.parent.parent.screens[3].add_widget(Sent())
393427
toLabel = ''
@@ -423,7 +457,6 @@ def address_error_message(self, msg):
423457
self.main_pop = Popup(title="Error", content=self.box,
424458
size_hint=(None, None), size=(550, 400), auto_dismiss=False, title_size=30)
425459
self.but.bind(on_press=self.main_pop.dismiss)
426-
# self.main_pop.background = './images/popup.jpeg'
427460
self.main_pop.open()
428461

429462

0 commit comments

Comments
 (0)