Пример #1
0
def main(stdscr):
    test = Window(30, 30, 0, 0)
    while True:
        test.clear()
        test.add_str(0, 0,
                     "Lines: {} Colums: {}".format(curses.LINES, curses.COLS))
        test.add_str(1, 0, "{}".format(stdscr.getmaxyx()))
        stdscr.getkey()
Пример #2
0
def main(stdscr):
    test = Window(10, 10, 0, 0)

    stdscr.getkey()

    for i in range(test.y):
        test.add_str(i, 0, "+" * test.x)

    test.refresh()

    stdscr.getkey()
    test.clear()
    test.offset_x = 15
    test.clear()
    for i in range(test.y):
        test.add_str(i, 0, "+" * test.x)
    test.refresh()

    stdscr.getkey()
Пример #3
0
class Hero():
    def __init__(self, stdscr):
        curses.curs_set(0)
        curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_MAGENTA)

        self.clipbord = None
        self.tab_manager = Tab_manager(
            os.path.dirname(os.path.abspath(__file__)))
        self.stdscr = Window(curses.LINES, curses.COLS, 0, 0)
        self.stdscr.window = stdscr

        self.stdscr.refresh()
        self.parent_dir_widged = File_viewer(
            self.stdscr.x - 3,
            round(config.parent_dir_width * self.stdscr.y / 100), 1, 0,
            self.tab_manager.selected_tab.current_file.parent_dir,
            self.tab_manager.selected_tab.current_file)
        self.current_dir_widged = File_viewer(
            self.stdscr.x - 3,
            round(config.current_dir_width * self.stdscr.y / 100), 1,
            self.parent_dir_widged.y,
            self.tab_manager.selected_tab.current_file,
            self.tab_manager.selected_tab.selected_file, True)
        self.preview_widged = File_viewer(
            self.stdscr.x - 3, self.stdscr.y - self.parent_dir_widged.y -
            self.current_dir_widged.y - 1, 1,
            self.stdscr.y - (self.stdscr.y - self.parent_dir_widged.y -
                             self.current_dir_widged.y - 1),
            self.tab_manager.selected_tab.selected_file)
        self.statusbar = Statusbar(
            1, self.stdscr.y, 0, 0, getpass.getuser(), socket.gethostname(),
            self.tab_manager.selected_tab.current_file.path,
            self.tab_manager.tab_list)
        self.window_command = Window(1, self.stdscr.y, self.stdscr.x - 1, 0)
        self.window_info = Window(1, self.stdscr.y, self.stdscr.x - 2, 0)
        self.stdscr.refresh()

        #self.resize()
        self.stdscr.refresh()
        self.mainloop()

    def resize(self):
        self.stdscr.x = curses.LINES
        self.stdscr.y = curses.COLS
        return None
        self.parent_dir_widged.x = curses.LINES - 3
        self.parent_dir_widged.y = round(config.parent_dir_width *
                                         curses.COLS / 100)
        self.parent_dir_widged.offset_x = 1
        self.parent_dir_widged.offset_y = 0

        self.current_dir_widged.x = curses.LINES - 3
        self.current_dir_widged.y = round(config.current_dir_width *
                                          curses.COLS / 100)
        self.current_dir_widged.offset_x = 1
        self.current_dir_widged.offset_y = self.parent_dir_widged.y + 1

        self.preview_widged.x = curses.LINES - 1
        self.preview_widged.y = round(config.parent_dir_width * curses.COLS /
                                      100)
        self.preview_widged.offset_x = 1
        self.preview_widged.offset_y = curses.COLS - (
            self.current_dir_widged.y + self.current_dir_widged.offset_y + 1)

        self.statusbar.x = 1
        self.statusbar.y = curses.COLS
        self.statusbar.offset_x = 0
        self.statusbar.offset_y = 0

        self.window_command.x = 1
        self.window_command.y = curses.COLS
        self.window_command.offset_x = curses.LINES - 1
        self.window_command.offset_y = 0

        self.window_info.x = 1
        self.window_info.y = curses.COLS
        self.window_info.offset_x = curses.LINES - 2
        self.window_info.offset_y = 0

        self.redraw()

    def mainloop(self):

        while True:
            # Get last keypress
            key = self.get_next_keypress()
            self.window_command.clear()
            self.window_info.add_str(0, 0, str(key))
            self.window_info.refresh()
            # End Programm
            if key in config.K_QUIT:
                curses.endwin()
                break

            elif key in [str(i) for i in range(1, 10)]:
                self.tab_manager.switch_tab(int(key))
                self.statusbar.tab_list = self.tab_manager.tab_list
                self.statusbar.draw()

            elif key in config.K_UP:
                self.tab_manager.selected_tab.selected_file_index -= 1
                self.current_dir_widged.selected_file = self.tab_manager.selected_tab.selected_file
                self.current_dir_widged.draw()

                self.preview_widged.current_file = self.tab_manager.selected_tab.selected_file
                self.preview_widged.draw()

            elif key in config.K_DOWN:
                self.tab_manager.selected_tab.selected_file_index += 1

                self.current_dir_widged.selected_file = self.tab_manager.selected_tab.selected_file
                self.current_dir_widged.draw()

                self.preview_widged.current_file = self.tab_manager.selected_tab.selected_file
                self.preview_widged.draw()

            elif key in config.K_LEFT:
                if self.tab_manager.selected_tab.current_file.parent_dir:
                    self.tab_manager.selected_tab.current_file = self.tab_manager.selected_tab.current_file.parent_dir

                    self.parent_dir_widged.current_file = self.tab_manager.selected_tab.current_file.parent_dir
                    self.parent_dir_widged.selected_file = self.tab_manager.selected_tab.current_file
                    self.parent_dir_widged.draw()

                    self.current_dir_widged.current_file = self.tab_manager.selected_tab.current_file
                    self.current_dir_widged.selected_file = self.tab_manager.selected_tab.selected_file
                    self.current_dir_widged.draw()

                    self.preview_widged.current_file = self.tab_manager.selected_tab.selected_file
                    self.preview_widged.draw()

            elif key in config.K_RIGHT:
                if self.tab_manager.selected_tab.selected_file:
                    if self.tab_manager.selected_tab.selected_file.is_dir:
                        self.tab_manager.selected_tab.current_file = self.tab_manager.selected_tab.selected_file

                        self.parent_dir_widged.current_file = self.tab_manager.selected_tab.current_file.parent_dir
                        self.parent_dir_widged.selected_file = self.tab_manager.selected_tab.current_file
                        self.parent_dir_widged.draw()

                        self.current_dir_widged.current_file = self.tab_manager.selected_tab.current_file
                        self.current_dir_widged.selected_file = self.tab_manager.selected_tab.selected_file
                        self.current_dir_widged.draw()

                        self.preview_widged.current_file = self.tab_manager.selected_tab.selected_file
                        self.preview_widged.draw()

            # Actiones
            elif key in config.K_RELOADE:
                self.redraw()

            elif key in config.K_COPY:
                if self.tab_manager.selected_tab.selected_file:
                    self.clipbord = self.tab_manager.selected_tab.selected_file
                    self.window_command.add_str(0, 0, 'Copied to clipbord',
                                                True)
                    self.window_command.refresh()
                else:
                    self.window_command.add_str(0, 0, 'No location selected',
                                                True)
                    self.window_command.refresh()

            elif key in config.K_PASTE:
                if self.clipbord:
                    if not os.path.exists(
                            os.path.join(
                                self.tab_manager.selected_tab.selected_file.
                                path, self.clipbord.full_name)):
                        if os.path.exists(self.clipbord.path):
                            shutil.copy2(
                                self.clipbord.path, self.tab_manager.
                                selected_tab.current_file.path)
                            self.window_command.add_str(0, 0, 'Pasted', True)
                            #self.tab_manager.selected_tab.selected_file = self.tab_manager.selected_tab.selected_dir.index( os.path.basename(os.path.normpath(self.clipbord)))
                        else:
                            self.window_command.add_str(
                                0, 0, 'Item no longer exists', True)
                            self.clipbord = None
                    else:
                        self.window_command.add_str(0, 0,
                                                    'Item already exists',
                                                    True)
                else:
                    self.window_command.add_str(0, 0, 'No path in clipbord',
                                                True)
                self.window_command.refresh()
                self.current_dir_widged.draw()
                self.preview_widged.draw()

            elif key in config.K_DELETE:
                # change selected item then deleate it
                if self.tab_manager.selected_tab.selected_file:
                    if self.tab_manager.selected_tab.selected_file_index > 0:
                        self.tab_manager.selected_tab.selected_file_index -= 1

                    if len(self.tab_manager.selected_tab.current_file.content
                           ) == 1:
                        self.tab_manager.selected_tab.selected_file_index = None

                    self.window_command.add_str(
                        0, 0, 'Confirm deletion of {} (y/n)'.format(
                            self.tab_manager.selected_tab.selected_file.
                            full_name), True)
                    self.window_command.refresh()
                    key = self.get_next_keypress()
                    if key == 'y':
                        if self.tab_manager.selected_tab.selected_file.is_dir:
                            shutil.rmtree(self.tab_manager.selected_tab.
                                          selected_file.path)
                        else:
                            os.remove(self.tab_manager.selected_tab.
                                      selected_file.path)

                        self.current_dir_width.draw()
                        self.preview_widged.draw()
                        self.parent_dir_widged.draw()

                        self.window_command.clear()
                        self.window_command.add_str(0, 0, 'Item deleated',
                                                    True)
                        self.window_command.refresh()

                    else:
                        self.window_command.clear()

            elif key in config.K_RENAME:
                pass

            elif key in config.K_CREATE:
                pass

    def init_colors(sefl):
        curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_MAGENTA)

    def reload_dir_from_tab(self):
        self.parent_dir_widged.current_file = self.tab_manager.selected_tab.current_file.parent_dir
        self.parent_dir_widged.selected_file = self.tab_manager.selected_tab.current_file
        self.parent_dir_widged.draw()

        self.current_dir_widged.current_file = self.tab_manager.selected_tab.current_file
        self.current_dir_widged.selected_file = self.tab_manager.selected_tab.selected_file
        self.current_dir_widged.draw()

        self.preview_widged.current_file = self.tab_manager.selected_tab.selected_file
        self.preview_widged.draw()

    def redraw(self):
        self.parent_dir_widged.draw()
        self.current_dir_widged.draw()
        self.preview_widged.draw()
        self.statusbar.draw()
        self.window_command.refresh()
        self.window_info.refresh()

    def get_next_keypress(self):
        while True:
            keypress = self.stdscr.window.getkey()
            self.window_info.add_str(0, 0, 0, 0, str(keypress))
            if keypress == curses.KEY_RESIZE:
                self.resize()
            else:
                return keypress