Exemplo n.º 1
0
    def __call__(self, num_cols):
        self.row = settings.current_row_idx
        self.col = settings.current_col_idx
        self.num_cols = num_cols
        if len(settings.contents[0]
               ) + 1 >= settings.grid_total_w // settings.cell_w:
            check_grid_resize(0, 1)

        for a in range(0, num_cols):
            for row in settings.contents:
                row.insert(settings.current_col_idx, '')
        if not settings.passed_commands:
            settings.grid.erase()
Exemplo n.º 2
0
def handle_basic_navigation(key):
    if key == key_mappings.UP and settings.current_row_idx > 0:
        settings.current_row_idx -= 1
        if settings.current_row_idx < settings.h_holder:
            settings.h_holder -= 1
    elif key == key_mappings.DOWN:
        # need to check that we are not at the height boundary
        if settings.current_row_idx + 1 != settings.grid_h_cap:
            settings.current_row_idx += 1
            if settings.current_row_idx >= settings.h_holder + settings.grid_h:
                settings.h_holder += 1
                check_grid_resize(1, 0)
            elif settings.current_row_idx >= settings.grid_total_h:
                check_grid_resize(1, 0)
            # settings.stdscr.addstr(1, 0, str(settings.grid_total_h))
    elif key == key_mappings.LEFT and settings.current_col_idx > 0:
        settings.current_col_idx -= 1
        if settings.current_col_idx * settings.cell_w + settings.dist_from_wall <= settings.w_holder:
            settings.w_holder -= settings.cell_w
    elif key == key_mappings.RIGHT:
        # need to check that we are not at the width boundary
        if (settings.current_col_idx +
                1) * settings.cell_w < settings.grid_w_cap:
            settings.current_col_idx += 1
            if settings.current_col_idx * settings.cell_w + settings.dist_from_wall >= settings.w_holder + settings.grid_w // settings.cell_w * settings.cell_w:  # divide and multiply by cell_w to truncate and make grid_w a multiple of cell_w
                settings.w_holder += settings.cell_w
                check_grid_resize(0, 1)
            elif settings.current_col_idx * settings.cell_w >= settings.grid_total_w:
                check_grid_resize(0, 1)
Exemplo n.º 3
0
    def __call__(self, num_rows):
        self.row = settings.current_row_idx
        self.col = settings.current_col_idx
        self.num_rows = num_rows
        if len(settings.contents) + 1 >= settings.grid_total_h:
            check_grid_resize(1, 0)

        row_len = len(settings.contents[0])
        # settings.grid.addstr(21,2,"B4: "+str(settings.contents))
        for a in range(0, num_rows):
            row = []
            for comma in range(0, row_len):
                row.append('')
            settings.contents.insert(settings.current_row_idx, row)
        # pad_data_with_commas()
        if not settings.passed_commands:
            settings.grid.erase()
Exemplo n.º 4
0
def go_to(y, x):
    if y > 0 and x > 0:
        # make off by 1 variable to keep track of off by 1 because the indices we use start from 0 but the user starts counting from 1
        off_by_1 = 1
        # account for the off by 1
        y -= off_by_1
        x -= off_by_1

        # if user  tries to go out of max dimensions, just go to the bottom
        if y >= settings.grid_h_cap:
            y = settings.grid_h_cap - 1
        if x >= settings.grid_w_cap // settings.cell_w:
            x = settings.grid_w_cap // settings.cell_w - 1

        # make scaled_x variable for comparing to total width and settings settings.w_holder
        scaled_x = x * settings.cell_w

        if not settings.passed_commands:
            # resize the grid if necessary
            while y >= settings.grid_total_h:
                # settings.stdscr.addstr(1,0,"grid_total_h: "+str(settings.grid_total_h))
                check_grid_resize(y - settings.h_holder, 0)
            while scaled_x >= settings.grid_total_w:
                check_grid_resize(0, scaled_x - settings.w_holder)

        # move the user
        settings.current_row_idx = y
        settings.current_col_idx = x

        # check if go_to went to the height boundary
        dist_from_bottom = settings.grid_h_cap - y
        if dist_from_bottom < settings.grid_h:
            # settings.stdscr.addstr(1,0,str(settings.h)+" vs: "+str(settings.grid_h))
            settings.h_holder = settings.grid_h_cap - settings.grid_h
        else:
            settings.h_holder = y

        # check if go_to went to the width boundary
        dist_from_rightmost = settings.grid_w_cap - scaled_x
        if dist_from_rightmost < settings.grid_w:
            rounded_w = settings.grid_w // settings.cell_w * settings.cell_w
            settings.w_holder = settings.grid_w_cap - rounded_w
        else:
            settings.w_holder = scaled_x
Exemplo n.º 5
0
def quick_scroll(direction):
    h, w = get_dimensions()
    if direction == 'w':
        # if user is at top of screen
        if settings.current_row_idx == settings.h_holder:
            if settings.current_row_idx - h <= 0:
                # scroll all the way up since we scroll less than screen height
                settings.current_row_idx = 0
                settings.h_holder = 0
            else:
                # scroll up by screen height
                settings.current_row_idx = settings.current_row_idx - h
                settings.h_holder = settings.h_holder - h
        else:
            # go to the top of the screen
            settings.current_row_idx = settings.h_holder
    elif direction == 'a':
        if settings.current_col_idx == settings.w_holder // settings.cell_w:
            if settings.current_col_idx - w // settings.cell_w <= 0:
                # scroll all the way left since we scroll less than screen width
                settings.current_col_idx = 0
                settings.w_holder = 0
            else:
                # scroll left by screen width
                settings.current_col_idx = settings.current_col_idx - w // settings.cell_w
                settings.w_holder = settings.w_holder - w // settings.cell_w * settings.cell_w  # divide and multiply to truncate so that w is a multiple of cell_w
        else:
            settings.current_col_idx = settings.w_holder // settings.cell_w
    elif direction == 's':
        check_grid_resize(h, 0)
        if settings.current_row_idx == settings.h_holder + h - 1:
            # check if we are at the boundary
            if settings.current_row_idx != settings.grid_h_cap:
                if settings.current_row_idx + h > settings.grid_h_cap:
                    # check_grid_resize(h,0)
                    settings.current_row_idx = settings.grid_h_cap - 1
                    settings.h_holder = settings.current_row_idx - h + 1
                else:
                    # scroll down by screen height
                    settings.current_row_idx = settings.current_row_idx + h
                    settings.h_holder = settings.h_holder + h
        else:
            # settings.stdscr.addstr(1,0,"IN ELSE")
            # check if quick scroll will reach the height boundary
            if settings.h_holder + h - 1 >= settings.grid_total_h:
                # check_grid_resize(h,0)
                settings.current_row_idx = settings.grid_total_h - 1
            else:
                # scroll to the bottom of screen
                settings.current_row_idx = settings.h_holder + h - 1
    else:  # the character is 'd'
        rounded_w = w // settings.cell_w * settings.cell_w  # divide and multiply to truncate so that w is a multiple of cell_w
        check_grid_resize(0, rounded_w)
        if settings.current_col_idx == (
                settings.w_holder + rounded_w - settings.cell_w
        ) // settings.cell_w:  # we subtract settings.cell_w because we want to scroll one cell less than the full width of the screen otherwise we will go out of bounds
            # check if we are at the boundary
            if settings.current_col_idx * settings.cell_w + w > settings.grid_w_cap:
                # check_grid_resize(0,w)
                settings.current_col_idx = (settings.grid_w_cap -
                                            1) // settings.cell_w
                settings.w_holder = settings.current_col_idx * settings.cell_w - rounded_w + settings.cell_w
            else:
                # scroll right by screen width
                settings.current_col_idx = settings.current_col_idx + w // settings.cell_w
                settings.w_holder = settings.w_holder + rounded_w
        else:
            # check if quick scroll will reach the width boundary
            if settings.w_holder + rounded_w - settings.cell_w > settings.grid_total_w:
                # settings.stdscr.addstr(1,0,"IN FURTHER")
                # check_grid_resize(0,w)
                settings.current_col_idx = (
                    settings.grid_total_w) // settings.cell_w
                # settings.current_col_idx = (settings.grid_total_w - settings.cell_w) // settings.cell_w
            else:
                # scroll all the way to the right of the screen
                settings.current_col_idx = (settings.w_holder + rounded_w -
                                            settings.cell_w) // settings.cell_w
                # settings.current_col_idx = (settings.w_holder + rounded_w - settings.cell_w) // settings.cell_w
            # check that we aren't out of bounds
            if settings.current_col_idx * settings.cell_w >= settings.grid_total_w:
                settings.current_col_idx = settings.grid_total_w // settings.cell_w - 1
Exemplo n.º 6
0
def main(stdscr):
    settings.stdscr = stdscr
    settings.c_manager = command_manager()
    settings.file_name = sys.argv[1]
    # set the format that the program will use (either normal CSV with commas or my own with coordinates)
    # settings.format = "my_format"
    settings.format = "CSV"
    read_data()

    # check if file exceeds max boundaries
    if settings.grid_h_cap < len(
            settings.contents) or settings.grid_w_cap < len(
                settings.contents[0] * settings.cell_w):
        sys.exit("The file you tried to open was too large")

    # determine if we are opening the program or just executing commands and then closing
    # If there are more than 2 arguments, the user is sending in commands to be done on the file
    if len(sys.argv) > 2:
        # set bool to true so when calling big commands, we can pass in commands and it will know to parse them
        settings.passed_commands = True
        testing = sys.argv[2] is "testing"

        if testing:
            # start iterating at the 4th argument and go through all system arguments
            for arg in sys.argv[3:]:
                big_commands(arg)
                save_data(sys.argv[-1])
        else:
            # start iterating at the 3rd argument and go through all system arguments
            for arg in sys.argv[2:]:
                big_commands(arg)
                save_data(sys.argv[1])
    # Otherwise, open the program normally with the specified file
    else:
        # set bool to true so when calling big commands, it parses user inputted command when program is running
        settings.passed_commands = False
        # create color schemes for the top and bottom margins
        curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_WHITE)

        # get dimensions
        settings.h, settings.w = settings.stdscr.getmaxyx()
        settings.grid_h, settings.grid_w = get_dimensions()

        # initial drawing of grid
        create_without_grid_lines()

        # we might need to resize initial grid
        if settings.grid_total_h < len(settings.contents):
            check_grid_resize(
                len(settings.contents) - settings.grid_total_h, 0)
        if settings.grid_total_w < len(settings.contents[0] * settings.cell_w):
            check_grid_resize(
                0,
                len(settings.contents[0]) * settings.cell_w -
                settings.grid_total_w)

        refresh_grid()

        # main loop
        while settings.user_exited == False:
            # read in user input
            key = settings.stdscr.getch()
            handle_visual_mode(key)
            handle_basic_navigation(key)
            handle_resize(key)
            if not settings.visual_mode:
                handle_help_menu(key)
                handle_inserting(key)
                handle_commands(key)
            handle_big_commands(key)
            handle_grid_update(key)