Skip to content

Commit

Permalink
Merge pull request #32 from GGF/bignumbers
Browse files Browse the repository at this point in the history
Big number clock added
  • Loading branch information
brunobraga committed Oct 4, 2018
2 parents df40682 + 8f9cc68 commit 49b953b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 16 deletions.
57 changes: 45 additions & 12 deletions termsaverlib/screen/clock.py
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
###############################################################################
#
# file: clock.py
Expand Down Expand Up @@ -68,6 +69,11 @@ class ClockScreen(ScreenBase, PositionHelperBase):
Defines the format of the datetime to be displayed.
"""

big = False
"""
Defines the format of the datetime to be displayed.
"""

cseparator = ":"
"""
Do not change this (if you do, change also its ASCII representation)
Expand All @@ -78,6 +84,8 @@ class ClockScreen(ScreenBase, PositionHelperBase):
Defines if the clock separator should be displayed
"""

lineindigimap = 6

digmap = {
'0': ' ___ \n / _ \ \n| | | |\n| |_| |\n \___/ \n \n',
'1': ' _ \n / | \n | | \n | | \n |_| \n \n',
Expand Down Expand Up @@ -107,6 +115,23 @@ class ClockScreen(ScreenBase, PositionHelperBase):
Extracted from standard font of Figlet (http://www.figlet.org/)
"""
digimapbig = {
'1' : ' ███ \n ███ \n ███ \n██████ \n██████ \n██████ \n ███ \n ███ \n ███ \n ███ \n ███ \n ███ \n█████████ \n█████████ \n█████████ \n',
'2' : '█████████ \n█████████ \n█████████ \n ███ \n ███ \n ███ \n█████████ \n█████████ \n█████████ \n███ \n███ \n███ \n█████████ \n█████████ \n█████████ \n',
'3' : '█████████ \n█████████ \n█████████ \n ███ \n ███ \n ███ \n ██████ \n ██████ \n ██████ \n ███ \n ███ \n ███ \n█████████ \n█████████ \n█████████ \n',
'4' : '███ ███ \n███ ███ \n███ ███ \n███ ███ \n███ ███ \n███ ███ \n█████████ \n█████████ \n█████████ \n ███ \n ███ \n ███ \n ███ \n ███ \n ███ \n',
'5' : '█████████ \n█████████ \n█████████ \n███ \n███ \n███ \n█████████ \n█████████ \n█████████ \n ███ \n ███ \n ███ \n█████████ \n█████████ \n█████████ \n',
'6' : '█████████ \n█████████ \n█████████ \n███ \n███ \n███ \n█████████ \n█████████ \n█████████ \n███ ███ \n███ ███ \n███ ███ \n█████████ \n█████████ \n█████████ \n',
'7' : '█████████ \n█████████ \n█████████ \n ███ \n ███ \n ███ \n ███ \n ███ \n ███ \n ███ \n ███ \n ███ \n ███ \n ███ \n ███ \n',
'8' : '█████████ \n█████████ \n█████████ \n███ ███ \n███ ███ \n███ ███ \n█████████ \n█████████ \n█████████ \n███ ███ \n███ ███ \n███ ███ \n█████████ \n█████████ \n█████████ \n',
'9' : '█████████ \n█████████ \n█████████ \n███ ███ \n███ ███ \n███ ███ \n█████████ \n█████████ \n█████████ \n ███ \n ███ \n ███ \n█████████ \n█████████ \n█████████ \n',
'0' : '█████████ \n█████████ \n█████████ \n███ ███ \n███ ███ \n███ ███ \n███ ███ \n███ ███ \n███ ███ \n███ ███ \n███ ███ \n███ ███ \n█████████ \n█████████ \n█████████ \n',
':' : ' \n \n \n███ \n███ \n███ \n \n \n \n███ \n███ \n███ \n \n \n \n',
'a' : ' \n \n \n \n \n \n \n \n \n \n ██ \n█ █ \n█ █ \n ███ \n \n',
'm' : ' \n \n \n \n \n \n \n \n \n \n \n█████ \n█ █ █ \n█ █ █ \n \n',
'p' : ' \n \n \n \n \n \n \n \n \n \n \n███ \n█ █ \n███ \n\n',
' ' : ' \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n',
}

def __init__(self):
"""
Expand All @@ -115,7 +140,7 @@ def __init__(self):
ScreenBase.__init__(self,
"clock",
_("displays a digital clock on screen"),
{'opts': 'hm', 'long_opts': ['help', 'ampm']},
{'opts': 'hmb', 'long_opts': ['help', 'ampm', "big"]},
)
self.cleanup_per_cycle = True

Expand Down Expand Up @@ -166,6 +191,8 @@ def _usage_options_example(self):
-h, --help Displays this help message
-m, --ampm Shows the clock in am/pm 12-hour format, without seconds.
-b, --big Shows the clock big number format, without seconds.
""")
Expand All @@ -189,6 +216,10 @@ def _parse_args(self, prepared_args):
self.screen_exit()
elif o in ("-m", "--ampm"):
self.ampm = True
elif o in ("-b", "--big"):
self.big = True
self.lineindigimap = 15
self.digmap = self.digimapbig
else:
# this should never happen!
raise Exception(_("Unhandled option. See --help for details."))
Expand All @@ -198,6 +229,16 @@ def get_ascii_time(self, date_time):
Returns the ASCII representation of a date.
"""

# shows/hides separator for a blinking effect
# Moved here so as not to duplicate in big number. Default used self.cseparator
separator = ""
if self.show_separator:
separator = self.cseparator
self.show_separator = False
else:
separator = " "
self.show_separator = True

# define clock string based on options (12/24)
if self.ampm:
hour = int(date_time.strftime('%H'))
Expand All @@ -211,17 +252,9 @@ def get_ascii_time(self, date_time):
# fix the zero hour value
if hour == 0:
hour = 12

# shows/hides separator for a blinking effect
separator = ""
if self.show_separator:
separator = self.cseparator
self.show_separator = False
else:
separator = " "
self.show_separator = True

clock = "%s%s%s%s" % (hour, separator, date_time.strftime('%M'), suffix)
elif self.big:
clock = date_time.strftime('%H' + separator + '%M')
else:
# 24hs format includes seconds
clock = date_time.strftime('%H' + self.cseparator + '%M' + self.cseparator + '%S')
Expand All @@ -230,7 +263,7 @@ def get_ascii_time(self, date_time):
for c in clock:
items.append(self.digmap[c])
output = ''
for i in range(6): # loop lines of chars - Increased to six for extra font line
for i in range(self.lineindigimap): # loop lines of chars - Increased to six for extra font line
temp = ''
for item in items:
temp += item.split('\n')[i]
Expand Down
Binary file not shown.
10 changes: 6 additions & 4 deletions termsaverlib/screen/helper/position.py
Expand Up @@ -133,13 +133,15 @@ def fix_text_wrap(self, text):
return text

temp = text.split("\n")
longest_line = max([len(x) for x in temp])
longest_line = max([len(x.decode('utf-8')) for x in temp])
new_text = []
for l in temp:
t = "\n".join(textwrap.wrap(l, width=self.geometry['x']))
# if utf string thwn width must be bigger
overlen = len(l)-len(l.decode('utf-8)'))
t = "\n".join(textwrap.wrap(l, width=self.geometry['x']+overlen))

# fill in trailing blanks
t += " " * (min(longest_line, self.geometry['x']) - min(len(t), self.geometry['x']))
t += " " * (min(longest_line, self.geometry['x']) - min(len(t.decode('utf-8')), self.geometry['x']))
new_text.append(t)
return "\n".join(new_text)

Expand Down Expand Up @@ -172,7 +174,7 @@ def center_text_horizontally(self, text):
new_text = ""
for t in temp:
self.position['x'] = int(math.ceil(
(self.geometry['x'] - len(t)) / 2))
(self.geometry['x'] - len(t.decode('utf-8'))) / 2))
new_text += " " * self.position['x'] + t
if len(temp) > 1:
new_text += "\n"
Expand Down

0 comments on commit 49b953b

Please sign in to comment.