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()
def draw_digital_clock(cols, lines): """ Draw clock """ if cols < 25 or lines < 25: print('Too little columns/lines for print out the clock!') exit() # create ascii canvas for clock and eval vars ascii_canvas = AsciiCanvas(cols * 2, lines) # add clock region and clock face now = datetime.datetime.now() ascii_canvas.add_rect(27, 2, 86, 15) # add clock hands x, y = int(math.ceil(ascii_canvas.cols / 4.0)) - 4, 5 draw_digital_hour_hand(ascii_canvas, x, y, now.hour) x = x + 25 draw_digital_minute_hand(ascii_canvas, x, y, now.minute) x = x + 25 draw_digital_second_hand(ascii_canvas, x, y, now.second) # draw weather global location global temperature ascii_canvas.add_text( 25, 18, 'ooooooooooooooooooooooooooooooooooooooooooooooooooooooo') ascii_canvas.add_text( 25, 19, 'o o') ascii_canvas.add_text(25, 20, 'o' + location + ' ' + temperature + '\" o') ascii_canvas.add_text( 25, 21, 'o o') ascii_canvas.add_text( 25, 22, 'ooooooooooooooooooooooooooooooooooooooooooooooooooooooo') # draw calendar global todays global lastday global startday global Y global M startday, lastday = calendar.calendar(Y, M) draw_digital_calendar(ascii_canvas, startday, lastday, todays) #draw info y = 24 ascii_canvas.add_text(25, y, '<Infomation>') ascii_canvas.add_text(25, y + 2, ' [ key: year - 1') ascii_canvas.add_text(25, y + 4, ' ] key: year + 1') ascii_canvas.add_text(25, y + 6, ' < key: month - 1') ascii_canvas.add_text(25, y + 8, ' > key: month + 1') ascii_canvas.add_text(25, y + 10, 'enter key: go memo') ascii_canvas.add_text(51, y + 2, '|') ascii_canvas.add_text(51, y + 3, '|') ascii_canvas.add_text(51, y + 4, '|') ascii_canvas.add_text(51, y + 5, '|') ascii_canvas.add_text(51, y + 6, '|') ascii_canvas.add_text(51, y + 7, '|') ascii_canvas.add_text(51, y + 8, '|') ascii_canvas.add_text(51, y + 9, '|') ascii_canvas.add_text(51, y + 10, '|') ascii_canvas.add_text(53, y + 2, ' → key: day + 1') ascii_canvas.add_text(53, y + 4, ' ← key: day - 1') ascii_canvas.add_text(53, y + 6, ' ↑ key: day - 7') ascii_canvas.add_text(53, y + 8, ' ↓ key: day + 7') ascii_canvas.add_text(53, y + 10, 'slash key: change clock') #draw change mode x, y = 87, 20 ascii_canvas.add_text(x, y, '[ ] Analog') x, y = 104, 20 ascii_canvas.add_text( x, y, Style.BRIGHT + Fore.YELLOW + '[v] Digital' + Style.DIM) # print out canvas ascii_canvas.print_out()
def draw_memo(cols, lines, x, y, specificDate): global check global choose global ascii_canvas_memo ascii_canvas = AsciiCanvas(cols * 2, lines) ascii_canvas.add_text(0, 0, '[CHECK]: ' + str(check)) if check == 0: if choose == 0: ascii_canvas.add_text(x, y + 0, '[Memo Read ]') else: ascii_canvas.add_text(x, y + 0, ' Memo Read ') if choose == 1: ascii_canvas.add_text(x, y + 2, '[Memo Modify]') else: ascii_canvas.add_text(x, y + 2, ' Memo Modify ') if choose == 2: ascii_canvas.add_text(x, y + 4, '[Memo Insert]') else: ascii_canvas.add_text(x, y + 4, ' Memo Insert ') if choose == 3: ascii_canvas.add_text(x, y + 6, '[Memo Remove]') else: ascii_canvas.add_text(x, y + 6, ' Memo Remove ') # print out canvas ascii_canvas.print_out() elif check == 1: if choose == 0: try: f = open(specificDate + ".txt", 'r') for i in range(lines): line = f.readline() ascii_canvas_memo.add_text(0, i, line) f.close() except: print() check = 2 elif choose == 1: try: f = open(specificDate + ".txt", 'r') for i in range(lines): line = f.readline() ascii_canvas_memo.add_text(0, i, line) f.close() except: print() check = 2 elif choose == 2: ascii_canvas_memo.clear() check = 2 elif choose == 3: f = open(specificDate + ".txt", 'w') f.write('') f.close() check = 0 # print out canvas ascii_canvas.print_out() elif check == 2: # print out canvas ascii_canvas_memo.print_out()