Skip to content

Commit 763f48e

Browse files
author
surbhi
committed
Define magic numbers
1 parent a150fc2 commit 763f48e

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

src/bitmessageqt/__init__.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@
6767

6868
is_windows = sys.platform.startswith('win')
6969

70+
HOUR = 60 * 60
71+
SLIDER_SCALING_EXPONENT = 3.199
72+
DAY = 24 * HOUR
73+
HOURS_48 = 48
74+
MONTH = 28 * DAY
75+
7076

7177
# TODO: rewrite
7278
def powQueueSize():
@@ -834,11 +840,11 @@ def __init__(self, parent=None):
834840

835841
# Put the TTL slider in the correct spot
836842
TTL = config.getint('bitmessagesettings', 'ttl')
837-
if TTL < 3600: # an hour
838-
TTL = 3600
839-
elif TTL > 28*24*60*60: # 28 days
840-
TTL = 28*24*60*60
841-
self.ui.horizontalSliderTTL.setSliderPosition((TTL - 3600) ** (1/3.199))
843+
if TTL < HOUR:
844+
TTL = HOUR
845+
elif TTL > MONTH:
846+
TTL = MONTH
847+
self.ui.horizontalSliderTTL.setSliderPosition((TTL - HOUR) ** (1 / SLIDER_SCALING_EXPONENT))
842848
self.updateHumanFriendlyTTLDescription(TTL)
843849

844850
QtCore.QObject.connect(self.ui.horizontalSliderTTL, QtCore.SIGNAL(
@@ -891,34 +897,32 @@ def updateStartOnLogon(self):
891897
except (NameError, TypeError):
892898
self.desktop = False
893899

894-
def updateTTL(self, sliderPosition):
895-
TTL = int(sliderPosition ** 3.199 + 3600)
896-
self.updateHumanFriendlyTTLDescription(TTL)
897-
config.set('bitmessagesettings', 'ttl', str(TTL))
900+
def updateTTL(self, slider_position):
901+
ttl = int(slider_position ** SLIDER_SCALING_EXPONENT + HOUR)
902+
self.updateHumanFriendlyTTLDescription(ttl)
903+
config.set('bitmessagesettings', 'ttl', str(ttl))
898904
config.save()
899905

900-
def updateHumanFriendlyTTLDescription(self, TTL):
901-
numberOfHours = int(round(TTL / (60*60)))
906+
def updateHumanFriendlyTTLDescription(self, ttl):
902907
font = QtGui.QFont()
903908
stylesheet = ""
904909

905-
if numberOfHours < 48:
910+
if ttl < (2 * DAY):
906911
self.ui.labelHumanFriendlyTTLDescription.setText(
907-
_translate("MainWindow", "%n hour(s)", None, QtCore.QCoreApplication.CodecForTr, numberOfHours) +
912+
_translate("MainWindow", "%n hour(s)", None, QtCore.QCoreApplication.CodecForTr, int(round(ttl / HOUR))) +
908913
", " +
909914
_translate("MainWindow", "not recommended for chans", None, QtCore.QCoreApplication.CodecForTr)
910915
)
911916
stylesheet = "QLabel { color : red; }"
912917
font.setBold(True)
913918
else:
914-
numberOfDays = int(round(TTL / (24*60*60)))
915919
self.ui.labelHumanFriendlyTTLDescription.setText(
916920
_translate(
917921
"MainWindow",
918922
"%n day(s)",
919923
None,
920924
QtCore.QCoreApplication.CodecForTr,
921-
numberOfDays))
925+
int(round(ttl / DAY))))
922926
font.setBold(False)
923927
self.ui.labelHumanFriendlyTTLDescription.setStyleSheet(stylesheet)
924928
self.ui.labelHumanFriendlyTTLDescription.setFont(font)

0 commit comments

Comments
 (0)