Skip to content

Commit a4df181

Browse files
author
surbhi
committed
Define magic numbers
1 parent f99b2bb commit a4df181

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

src/bitmessageqt/__init__.py

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

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

70+
HOUR = 60 * 60
71+
SLIDER_SCALING_EXPONENT = 3.199
72+
DAY = 24 * HOUR
73+
MONTH = 28 * DAY
74+
7075

7176
# TODO: rewrite
7277
def powQueueSize():
@@ -834,11 +839,11 @@ def __init__(self, parent=None):
834839

835840
# Put the TTL slider in the correct spot
836841
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))
842+
if TTL < HOUR:
843+
TTL = HOUR
844+
elif TTL > MONTH:
845+
TTL = MONTH
846+
self.ui.horizontalSliderTTL.setSliderPosition((TTL - HOUR) ** (1 / SLIDER_SCALING_EXPONENT))
842847
self.updateHumanFriendlyTTLDescription(TTL)
843848

844849
QtCore.QObject.connect(self.ui.horizontalSliderTTL, QtCore.SIGNAL(
@@ -891,34 +896,32 @@ def updateStartOnLogon(self):
891896
except (NameError, TypeError):
892897
self.desktop = False
893898

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

900-
def updateHumanFriendlyTTLDescription(self, TTL):
901-
numberOfHours = int(round(TTL / (60*60)))
905+
def updateHumanFriendlyTTLDescription(self, ttl):
902906
font = QtGui.QFont()
903907
stylesheet = ""
904908

905-
if numberOfHours < 48:
909+
if ttl < (2 * DAY):
906910
self.ui.labelHumanFriendlyTTLDescription.setText(
907-
_translate("MainWindow", "%n hour(s)", None, QtCore.QCoreApplication.CodecForTr, numberOfHours) +
911+
_translate("MainWindow", "%n hour(s)", None, QtCore.QCoreApplication.CodecForTr, int(round(ttl / HOUR))) +
908912
", " +
909913
_translate("MainWindow", "not recommended for chans", None, QtCore.QCoreApplication.CodecForTr)
910914
)
911915
stylesheet = "QLabel { color : red; }"
912916
font.setBold(True)
913917
else:
914-
numberOfDays = int(round(TTL / (24*60*60)))
915918
self.ui.labelHumanFriendlyTTLDescription.setText(
916919
_translate(
917920
"MainWindow",
918921
"%n day(s)",
919922
None,
920923
QtCore.QCoreApplication.CodecForTr,
921-
numberOfDays))
924+
int(round(ttl / DAY))))
922925
font.setBold(False)
923926
self.ui.labelHumanFriendlyTTLDescription.setStyleSheet(stylesheet)
924927
self.ui.labelHumanFriendlyTTLDescription.setFont(font)

0 commit comments

Comments
 (0)