def draw_clock(cols, lines): """ Draw clock """ if cols < 25 or lines < 25: print('Too little columns/lines for print out the clock!') exit() # prepare chars single_line_border_chars = ('.', '-', '.', '|', ' ', '|', '`', '-', "'") second_hand_char = '.' minute_hand_char = 'o' hour_hand_char = 'O' mark_char = '`' if os.name == 'nt': single_line_border_chars = ('.', '-', '.', '|', ' ', '|', '`', '-', "'") # ('\xDA', '\xC4', '\xBF', '\xB3', '\x20', '\xB3', '\xC0', '\xC4', '\xD9') second_hand_char = '.' # '\xFA' minute_hand_char = 'o' # '\xF9' hour_hand_char = 'O' # 'o' mark_char = '`' # '\xF9' # create ascii canvas for clock and eval vars ascii_canvas = AsciiCanvas(cols, lines) center_x = int(math.ceil(cols / 2.0)) center_y = int(math.ceil(lines / 2.0)) radius = center_y - 5 second_hand_length = int(radius / 1.17) minute_hand_length = int(radius / 1.25) hour_hand_length = int(radius / 1.95) # add clock region and clock face ascii_canvas.add_rect(5, 3, int(math.floor(cols / 2.0)) * 2 - 9, int(math.floor(lines / 2.0)) * 2 - 5) draw_clock_face(ascii_canvas, radius, mark_char) now = datetime.datetime.now() # add regions with weekday and day if possible if center_x > 25: left_pos = int(radius * x_scale_ratio) / 2 - 4 ascii_canvas.add_nine_patch_rect(int(center_x + left_pos), int(center_y - 1), 5, 3, single_line_border_chars) ascii_canvas.add_text(int(center_x + left_pos + 1), int(center_y), now.strftime('%a')) ascii_canvas.add_nine_patch_rect(int(center_x + left_pos + 5), int(center_y - 1), 4, 3, single_line_border_chars) ascii_canvas.add_text(int(center_x + left_pos + 1 + 5), int(center_y), now.strftime('%d')) # add clock hands draw_second_hand(ascii_canvas, now.second, second_hand_length, fill_char=second_hand_char) draw_minute_hand(ascii_canvas, now.minute, minute_hand_length, fill_char=minute_hand_char) draw_hour_hand(ascii_canvas, now.hour, now.minute, hour_hand_length, fill_char=hour_hand_char) # print out canvas ascii_canvas.print_out()
def draw_clock(cols, lines): """ Draw clock """ if cols < 25 or lines < 25: print('Too little columns/lines for print out the clock!') exit() # prepare chars single_line_border_chars = ('.', '-', '.', '|', ' ', '|', '`', '-', "'") second_hand_char = '.' minute_hand_char = '#' hour_hand_char = '+' mark_char = '`' if os.name == 'nt': single_line_border_chars = ( '.', '-', '.', '|', ' ', '|', '`', '-', "'" ) # ('\xDA', '\xC4', '\xBF', '\xB3', '\x20', '\xB3', '\xC0', '\xC4', '\xD9') second_hand_char = '.' # '\xFA' minute_hand_char = '#' # '\xF9' hour_hand_char = '+' # 'o' mark_char = '`' # '\xF9' # create ascii canvas for clock and eval vars ascii_canvas = AsciiCanvas(cols * 2, lines) center_x = int(math.ceil(cols / 4.0)) center_y = int(math.ceil(lines / 2.0)) radius = center_y - 5 second_hand_length = int(radius / 1.17) minute_hand_length = int(radius / 1.25) hour_hand_length = int(radius / 1.95) # add clock region and clock face ascii_canvas.add_rect(5, 3, int(math.floor(cols / 2.0)) * 2 - 9, int(math.floor(lines / 2.0)) * 2 - 5) draw_clock_face(ascii_canvas, radius, mark_char) now = datetime.datetime.now() # add regions with weekday and day if possible if center_x > 25: left_pos = int(radius * x_scale_ratio) / 2 - 4 ascii_canvas.add_nine_patch_rect(int(center_x + left_pos), int(center_y - 1), 5, 3, single_line_border_chars) ascii_canvas.add_text(int(center_x + left_pos + 1), int(center_y), now.strftime('%a')) ascii_canvas.add_nine_patch_rect(int(center_x + left_pos + 5), int(center_y - 1), 4, 3, single_line_border_chars) ascii_canvas.add_text(int(center_x + left_pos + 1 + 5), int(center_y), now.strftime('%d')) # add clock hands draw_second_hand(ascii_canvas, now.second, second_hand_length, fill_char=second_hand_char) draw_minute_hand(ascii_canvas, now.minute, minute_hand_length, fill_char=minute_hand_char) draw_hour_hand(ascii_canvas, now.hour, now.minute, hour_hand_length, fill_char=hour_hand_char) # draw weather global location global temperature y = 6 ascii_canvas.add_text( 70, y + 0, 'oooooooooooooooooooooooooooooooooooooooooooooooooooooo') ascii_canvas.add_text( 70, y + 1, 'o o') ascii_canvas.add_text(70, y + 2, 'o' + location + ' ' + temperature + '\"o') ascii_canvas.add_text( 70, y + 3, 'o o') ascii_canvas.add_text( 70, y + 4, 'oooooooooooooooooooooooooooooooooooooooooooooooooooooo') # draw calendar global todays global lastday global startday global Y global M startday, lastday = calendar.calendar(Y, M) draw_calendar(ascii_canvas, startday, lastday, todays) #draw info y = 25 ascii_canvas.add_text(70, y, '<Infomation>') ascii_canvas.add_text(70, y + 2, ' [ key: year - 1') ascii_canvas.add_text(70, y + 4, ' ] key: year + 1') ascii_canvas.add_text(70, y + 6, ' < key: month - 1') ascii_canvas.add_text(70, y + 8, ' > key: month + 1') ascii_canvas.add_text(70, y + 10, 'enter key: go memo') ascii_canvas.add_text(92, y + 2, '|') ascii_canvas.add_text(92, y + 3, '|') ascii_canvas.add_text(92, y + 4, '|') ascii_canvas.add_text(92, y + 5, '|') ascii_canvas.add_text(92, y + 6, '|') ascii_canvas.add_text(92, y + 7, '|') ascii_canvas.add_text(92, y + 8, '|') ascii_canvas.add_text(92, y + 9, '|') ascii_canvas.add_text(92, y + 10, '|') ascii_canvas.add_text(94, y + 2, ' → key: day + 1') ascii_canvas.add_text(94, y + 4, ' ← key: day - 1') ascii_canvas.add_text(94, y + 6, ' ↑ key: day - 7') ascii_canvas.add_text(94, y + 8, ' ↓ key: day + 7') ascii_canvas.add_text(94, y + 10, 'slash key: change clock') #draw change mode x, y = 70, 4 ascii_canvas.add_text( x, y, Style.BRIGHT + Fore.YELLOW + '[v] Analog' + Style.DIM) x, y = 100, 4 ascii_canvas.add_text(x, y, '[ ] Digital') # print out canvas ascii_canvas.print_out()