예제 #1
0
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()
예제 #2
0
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()
예제 #3
0
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()
예제 #4
0
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()
예제 #5
0
def main(cols, lines, Y, M, D):
    global check
    global choose
    global memo_x, memo_y
    global ascii_canvas_memo

    ascii_canvas_memo = AsciiCanvas(cols * 2, lines, fill_char='\0')

    specificDate = str(Y) + '-' + str(M).rjust(2, '0') + '-' + str(D).rjust(
        2, '0')

    while True:

        # elif keyboard.is_pressed('left arrow'):
        #     todays = todays - 1
        #     if todays < 1:
        #         todays = 1
        #     time.sleep(0.1)

        # elif keyboard.is_pressed('right arrow'):
        #     todays = todays + 1
        #     if lastday < todays:
        #         todays = lastday
        #     time.sleep(0.1)
        if check == 2:
            for key in keys:
                if keyboard.is_pressed(key):
                    # print(keyboard.key_to_scan_codes(key))
                    # print(f"{key} pressed")
                    if choose != 0:
                        if key == 'backspace':
                            ascii_canvas_memo.add_text(memo_x, memo_y, ' ')
                            memo_x = memo_x - 1
                            if memo_x < 0:
                                memo_y = memo_y - 1
                                memo_x = enter_line[memo_y]
                        elif key == 'space':
                            memo_x = memo_x + 1
                        elif key == 'enter':
                            enter_line[memo_y] = memo_x
                            memo_y = memo_y + 1
                            memo_x = 0
                        elif key == 'ctrl+s':
                            f = open(specificDate + ".txt", 'w')
                            f.write(ascii_canvas_memo.get_canvas_as_str())
                            f.close()
                            check = 0
                            print('save_success')
                            time.sleep(2.0)
                        elif key == 'esc':
                            check = 0
                        elif 'a' <= key and key <= 'z':
                            if ascii_canvas_memo.cols < memo_x:
                                enter_line[memo_y] = memo_x
                                memo_x = 0
                                memo_y = memo_y + 1
                            ascii_canvas_memo.add_text(memo_x, memo_y, key)
                            memo_x = memo_x + 1
                        elif '0' <= key and key <= '9':
                            if ascii_canvas_memo.cols < memo_x:
                                enter_line[memo_y] = memo_x
                                memo_x = 0
                                memo_y = memo_y + 1
                            ascii_canvas_memo.add_text(memo_x, memo_y, key)
                            memo_x = memo_x + 1
                    else:
                        if key == 'esc':
                            check = 0
        else:
            if keyboard.is_pressed('esc'):
                break

            elif keyboard.is_pressed('up arrow'):
                choose = choose - 1
                if choose < 0:
                    choose = 0
                time.sleep(0.1)

            elif keyboard.is_pressed('down arrow'):
                choose = choose + 1
                if 3 < choose:
                    choose = 3
                time.sleep(0.1)

            elif keyboard.is_pressed('enter'):
                check = 1

        # elif keyboard.is_pressed('<'):
        #     M = M - 1
        #     time.sleep(0.1)

        # elif keyboard.is_pressed('>'):
        #     M = M + 1
        #     time.sleep(0.1)

        # elif keyboard.is_pressed('['):
        #     Y = Y - 1
        #     time.sleep(0.1)

        # elif keyboard.is_pressed(']'):
        #     Y = Y + 1
        #     time.sleep(0.1)

        # elif keyboard.is_pressed('/'):
        #     if check == 1:
        #         check = 0
        #     else:
        #         check = 1

        # elif keyboard.is_pressed('enter'):
        #     if check != 2:
        #         savecheck = check
        #         check = 2
        #     elif check == 2:
        #         if choose == 0:
        #             # 보기
        #             draw_memo_read()
        #         elif choose == 1:
        #             # 수정
        #             draw_memo_modify()
        #         elif choose == 2:
        #             # 삽입
        #             draw_memo_insert()
        #         elif choose == 3:
        #             # 삭제
        #             draw_memo_remove()
        #     time.sleep(0.1)

        os.system('cls' if os.name == 'nt' else 'clear')

        draw_memo(cols, lines, 40, 3, specificDate)

        # k = keyboard.read_key()  # in my python interpreter, this captures "enter up"
        # k = keyboard.read_key()  # so repeat the line if in the python interpreter

        # print('k: ' + k)
        # time.sleep(1.1)

        time.sleep(0.1)
예제 #6
0
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()