Skip to content

Commit 6b481fc

Browse files
author
surbhi
committed
refactor maildetail.py: replace magic numbers with constants
1 parent 3a2cc27 commit 6b481fc

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/bitmessagekivy/baseclass/maildetail.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# pylint: disable=broad-except
44

55
"""
6-
MailDetail screen for inbox, sent, draft, and trash.
6+
MailDetail screen for inbox, sent, draft and trash.
77
"""
88

99
import os
@@ -27,11 +27,18 @@
2727
from pybitmessage.bitmessagekivy.get_platform import platform
2828
from pybitmessage.helper_sql import sqlQuery
2929

30+
# Define constants for magic numbers
31+
ANDROID_WIDTH = 0.8
32+
OTHER_WIDTH = 0.55
33+
DIALOG_HEIGHT = 0.25
34+
LONG_PRESS_DURATION = 1
35+
DELETE_DELAY = 4
36+
3037

3138
class OneLineListTitle(OneLineListItem):
3239
"""OneLineListTitle class for Kivy UI."""
3340
__events__ = ('on_long_press', )
34-
long_press_time = NumericProperty(1)
41+
long_press_time = NumericProperty(LONG_PRESS_DURATION)
3542

3643
def on_state(self, instance, value):
3744
"""Handle state change for long press."""
@@ -51,10 +58,10 @@ def on_long_press(self, *args):
5158
def copy_message_title(self, title_text):
5259
"""Display dialog box with options to copy the message title."""
5360
self.title_text = title_text
54-
width = 0.8 if platform == 'android' else 0.55
61+
width = ANDROID_WIDTH if platform == 'android' else OTHER_WIDTH
5562
self.dialog_box = MDDialog(
5663
text=title_text,
57-
size_hint=(width, 0.25),
64+
size_hint=(width, DIALOG_HEIGHT),
5865
buttons=[
5966
MDFlatButton(text="Copy", on_release=self.copy_title_callback),
6067
MDFlatButton(text="Cancel", on_release=self.copy_title_callback),
@@ -89,7 +96,7 @@ class MailDetail(Screen): # pylint: disable=too-many-instance-attributes
8996

9097
def __init__(self, *args, **kwargs):
9198
"""Initialize MailDetail screen."""
92-
super().__init__(*args, **kwargs)
99+
super().__init__(*args, **kwargs) # pylint: disable=missing-super-argument
93100
self.kivy_state = kivy_state_variables()
94101
Clock.schedule_once(self.init_ui, 0)
95102

@@ -150,7 +157,7 @@ def delete_mail(self):
150157
if self.page_type != 'draft':
151158
self._update_mail_counts(msg_count_objs)
152159

153-
Clock.schedule_once(self.callback_for_delete, 4)
160+
Clock.schedule_once(self.callback_for_delete, DELETE_DELAY)
154161

155162
def _update_sent_mail(self, msg_count_objs):
156163
"""Update UI for sent mail."""

0 commit comments

Comments
 (0)