Exemple #1
0
    def handle_resize(self):
        self.dim = self.parent.dim - Point(2, 3)

        if self.max.x < self.dim.x:
            self.resize(Point(self.max.y, self.dim.x))

        self.SCROLLBAR.resize(self.dim.y)
        if self.list: self.list.reshape_list()

        self.refresh()
Exemple #2
0
	def handle_resize(self):
		self.dim = Point(1, self.parent.dim.x)
		self.start = Point(self.parent.dim.y - 1, 0)

		self.STATUSBAR.resize(*self.dim)
		self.STATUSBAR.mvwin(*self.start)

		self.write([], extra = self.content)
		self.update_count([None] * self.count)
		self.refresh()
Exemple #3
0
    def safe_print(self, string, attr=curses.A_NORMAL, curs_pos=Point(None)):
        curs_pos = curs_pos.assign_if_none(Point(self.PAD.getyx()))

        while 1:
            try:
                self.PAD.addstr(*curs_pos, string, attr)
                break

            except curses.error:
                self.resize(Point(self.max.y + 20, self.max.x))
Exemple #4
0
    def refresh(self, scroll=Point(), offset=None, refresh_scrollbar=True):
        scroll = scroll.assign_if_none(Point(self.scroll_pos, 0))
        offset = offset or self.start

        self.PAD.refresh(*scroll, *offset, *(self.dim + (offset - 1)))

        if refresh_scrollbar:
            self.SCROLLBAR.update_scroll_pos()
            self.SCROLLBAR.scroll()
            self.SCROLLBAR.refresh()
Exemple #5
0
    def resize(self, new_ylen=None):
        new_ylen = new_ylen or self.parent.dim.y

        try:
            self.WIN.resize(new_ylen, self.dim.x)

            pos = Point(self.parent.start) + Point(0, self.parent.dim.x)
            self.WIN.mvwin(*pos)

        except curses.error:
            exit("could not resize scrollwin")

        self.dim.y = new_ylen
Exemple #6
0
    def _enumerate2d(self):
        temp = []
        for x, row in enumerate(self.list_1d):
            for y, element in enumerate(row):
                temp += [[Point(y, x), element]]

        return temp
Exemple #7
0
    def print_help():
        pad.erase()
        for section in sections:
            section.erase()

        pad.safe_print("Console Media Library", COLOR_DICT['LRED_BLACK'])
        pad.safe_print("  v" + VERSION_NO + " - 2020\n" +
                       "Developed by Anchith Acharya U. and Adhish N.\n" +
                       "Github link: ")
        pad.safe_print("https://github.com/anchithAcharya/Camel\n\n",
                       COLOR_DICT['LRED_BLACK'])

        for i in (0, 1):
            for key, action in zip(keys[i], actions[i]):
                sections[i].safe_print(key, COLOR_DICT['LRED_BLACK'])

                if action:
                    if action == actions[i][-1]:
                        sections[i].PAD.insstr(' : ' + action)
                    else:
                        sections[i].safe_print(' : ' + action)

        pad.safe_print("\nPress Esc key to close this menu.\n\n",
                       COLOR_DICT['LRED_BLACK'],
                       curs_pos=Point(sections[0].start.y + sections[0].dim.y,
                                      0))
Exemple #8
0
    def __init__(self, parent):
        self.WIN = curses.newwin(1, 1)
        self.parent = parent

        self.WIN.leaveok(1)

        self.scroll_pos = 0
        self.dim = Point(0, 1)
Exemple #9
0
    def __init__(self, size: Point, parent):
        self.PAD = curses.newpad(1, 1)
        self.parent = parent
        parent.pad = self

        self.SCROLLBAR = Scrollwin(self)

        self.scroll_pos = 0
        self.max_used_space = None

        self.max = Point()
        self.dim = self.parent.dim - Point(2, 3)

        self.start = Point(parent.WIN.getparyx()) + 1

        self.list = None

        self.resize(size)
Exemple #10
0
    def __init__(self, window):
        self.WIN = window
        self.dim = Point(self.WIN.getmaxyx())

        self.sub = None
        self.statusbar = None

        self.WIN.clear()
        self.refresh()
Exemple #11
0
    def safe_print(self, str, method="addstr", curs_pos=Point(), attr=None):
        curs_pos = curs_pos.assign_if_none(Point(self.WIN.getyx()))

        if attr: self.WIN.attron(attr)

        while 1:
            try:
                if method == "border":
                    getattr(self.WIN, method)()

                else:
                    getattr(self.WIN, method)(*curs_pos, str)
                break

            except curses.error:
                self.resize(self.max_y + 20, self.max_x)

        if attr: self.WIN.attroff(attr)
Exemple #12
0
    def change_list(self, new_list1d: list, process_settings=(False, True)):
        self.list_1d.clear()
        self.selected_items.clear()

        self._process_list(new_list1d, *process_settings)

        self.dim = Point(len(self.LIST), len(self.LIST[0]))
        self._calculate_indices()

        self.pad.max_used_space = len(self.LIST)
        self.cursor = self.LIST[0][0]
Exemple #13
0
    def handle_resize(self):
        self.dim = Point(self.WIN.getmaxyx())

        if self.dim < 8:
            exit("window size too small")

        self.WIN.clear()
        self.refresh()

        self.sub.handle_resize()
        self.statusbar.handle_resize()
Exemple #14
0
	def __init__(self, parent: Window, attr):
		self.STATUSBAR = parent.WIN.subwin(1,1, 0,0)
		self.dim = Point(1, parent.dim.x)
		
		self.parent = parent
		parent.statusbar = self

		self.attr = attr
		self.content = []
		self.count = 0

		self.handle_resize()
Exemple #15
0
    def __init__(self, parent, dim: Point, start=Point(0, 0)):
        try:
            self.PAD = parent.PAD.subpad(*dim, *start)

        except curses.error:
            exit("could not create subwindow.")

        self.parent = parent

        self.dim = dim
        self.start = start

        self.subpad = self.resize = self.handle_resize = None
Exemple #16
0
    def __init__(self, parent, dir_list=[]):
        self.cursor = None
        self.selected_items = []

        self.dim = Point(0, 1)
        self.pad = parent

        self.max_list_width = max(
            int(self.pad.dim.x /
                (self.max_strlen + len(self.column_seperator))), 1)

        self.list_1d = []
        self.LIST = [[]]

        self.change_list(dir_list)
Exemple #17
0
    def __init__(self, parent, dim: Point, start=Point(0, 0)):
        try:
            sub = parent.WIN.subwin(*dim, *start)

        except curses.error:
            exit("could not create subwindow.")

        super().__init__(sub)
        del self.sub, self.statusbar
        self.subwin = None

        self.parent = parent

        self.start = start
        self.pad = None

        self.refresh()
Exemple #18
0
    def __init__(self, name="", file_type=""):
        self.name = name
        self.type = file_type

        self.index = Point()

        if len(self.name) <= Marquee.max_strlen:
            self.disp_str = self.name + ' ' * (Marquee.max_strlen -
                                               len(self.name))
            self.show_ellipsis = False

        else:
            self.disp_str = self.name[:Marquee.max_strlen - 3]
            self.show_ellipsis = True

        self.hscroll_index = 0
        self.hscroll_delay = 0
Exemple #19
0
def show_help(pad, statusbar, handle_resize):
    scroll = Point(0)

    sections = []
    for i, start in enumerate(section_start):
        sections.append(
            pad.subpad(
                Point(len(keys[i]), (max_key_len[i] + 3 + max_value_len[i])),
                start))

    refresh_screen = True
    manage_resize = 0

    pad.SCROLLBAR.WIN.erase()
    pad.SCROLLBAR.refresh()

    def print_help():
        pad.erase()
        for section in sections:
            section.erase()

        pad.safe_print("Console Media Library", COLOR_DICT['LRED_BLACK'])
        pad.safe_print("  v" + VERSION_NO + " - 2020\n" +
                       "Developed by Anchith Acharya U. and Adhish N.\n" +
                       "Github link: ")
        pad.safe_print("https://github.com/anchithAcharya/Camel\n\n",
                       COLOR_DICT['LRED_BLACK'])

        for i in (0, 1):
            for key, action in zip(keys[i], actions[i]):
                sections[i].safe_print(key, COLOR_DICT['LRED_BLACK'])

                if action:
                    if action == actions[i][-1]:
                        sections[i].PAD.insstr(' : ' + action)
                    else:
                        sections[i].safe_print(' : ' + action)

        pad.safe_print("\nPress Esc key to close this menu.\n\n",
                       COLOR_DICT['LRED_BLACK'],
                       curs_pos=Point(sections[0].start.y + sections[0].dim.y,
                                      0))

    statusbar.write(
        ('Scroll up', 'Scroll down', 'Scroll left', 'Scroll right'),
        extra=[('Esc', "Close help")])

    print_help()

    def equals(ch, action):
        return any(ch in keybind for keybind in KEYBINDS[action])

    while 1:
        if refresh_screen:
            pad.refresh(scroll, refresh_scrollbar=False)
            refresh_screen = False

        ch = pad.PAD.getch()

        if ch == curses.KEY_RESIZE:
            manage_resize = 1

        elif equals(ch, "Scroll up"):
            if scroll.y > 0:
                scroll.y -= 1

            refresh_screen = True

        elif equals(ch, "Scroll down"):
            if scroll.y < (SCROLL_LIMIT.y - (pad.dim.y - 1)):
                scroll.y += 1

            refresh_screen = True

        elif equals(ch, "Scroll left"):
            if scroll.x > 0:
                scroll.x = max(scroll.x - 2, 0)

            refresh_screen = True

        elif equals(ch, "Scroll right"):
            if scroll.x < (SCROLL_LIMIT.x - (pad.dim.x - 1)):
                scroll.x = min(scroll.x + 2,
                               (SCROLL_LIMIT.x - (pad.dim.x - 1)))

            refresh_screen = True

        elif equals(ch, "Quit"):
            curses.ungetch(curses.KEY_F10)
            break

        elif ch == KEY_VALUES["Esc"]:
            break

        if manage_resize == 2:
            handle_resize()
            # print_statusbar(('^PgUp','^PgDn','F10'), extra={'Esc':"Close help"})

            curses.curs_set(1)
            curses.curs_set(0)

            manage_resize = 0
            refresh_screen = True

        if manage_resize != 0: manage_resize = 2

    statusbar.write(('Help', 'Reverse sort order', 'Quit'))
Exemple #20
0
    return lyst, max_len


keys = [keybind[0][1] for keybind in KEYBINDS.values()]
actions = KEYBINDS.keys()

keys, max_key_len = process_list(keys, '\n')
actions, max_value_len = process_list(actions, '')

keys = [[(' ' * (max_len - len(item)) + item) for item in x]
        for x, max_len in zip(keys, max_key_len)]
actions = [[(item + ' ' * (max_len - len(item))) if item else '' for item in x]
           for x, max_len in zip(actions, max_value_len)]

section_start = [
    Point(4, 3),
    Point(4, 3 + (max_key_len[0] + 3 + max_value_len[0]) + 5)
]
SCROLL_LIMIT = Point(len(keys[0]) + 5, 91)


def show_help(pad, statusbar, handle_resize):
    scroll = Point(0)

    sections = []
    for i, start in enumerate(section_start):
        sections.append(
            pad.subpad(
                Point(len(keys[i]), (max_key_len[i] + 3 + max_value_len[i])),
                start))
Exemple #21
0
def main(screen):
	curses.curs_set(0)
	init_colors()

	screen = Window(screen)
	frame = screen.subwin(screen.dim - Point(3,2), Point(1))
	frame.decorate()
	frame.refresh()

	statusbar = Statusbar(screen, COLOR_DICT["RED_BLACK"])
	statusbar.write(('Help', 'Reverse sort order', 'Quit'))

	pad = Pad(Point(settings.MIN_DIMS), frame)

	pad.PAD.keypad(1)
	pad.PAD.nodelay(1)
	pad.PAD.timeout(300)

	dir_list = List(pad, [settings.ROOT])
	pad.list = dir_list

	manage_resize = 0		# 0: static screen    1: screen is being resized, wait    2: handle resize
	screen.handle_resize()

	dir_list.cursor = dir_list.list_1d[1]
	curses.ungetch(KEYBINDS["Open file/directory under cursor"][0][0])


	qs = ""
	qs_timeout = -1
	refresh_screen = False
	dirHistory = Stack_pointer()

	def set_scroll():
		nonlocal refresh_screen

		if dir_list.cursor.index.y not in range(pad.scroll_pos, (pad.scroll_pos + pad.dim.y)):
			if dir_list.cursor.index.y < pad.dim.y:
				pad.scroll_pos = 0
		
			elif dir_list.cursor.index.y >= (len(dir_list.LIST) - pad.dim.y):
					pad.scroll_pos = (len(dir_list.LIST) - pad.dim.y)
				
			else: pad.scroll_pos = dir_list.cursor.index.y

		refresh_screen = True

	def change_list(path = dir_list.cursor.name, group_open = False, rev = False, add_to_history = True):
		if rev:
			dir_list.reshape_list(rev = rev)

			set_scroll()
			return
		
		if group_open: file_type = "multiple"
		else: file_type = dir_list.cursor.type

		if file_type == "folder":
			this_dir = os.getcwd()

			os.chdir(path)

			if add_to_history:
				dirHistory.append(os.getcwd())

			dir_list.change_list(os.listdir(), (settings.SHOW_HIDDEN_FILES, settings.SHOW_ONLY_MEDIA_FILES))

			if path == '..' and settings.SELECT_PREV_DIR_ON_CD_UP:
				this_dir = os.path.basename(this_dir)
				
				for file in dir_list.list_1d:
					if file.name == this_dir:
						dir_list.cursor = file
			
			statusbar.update_count(dir_list.selected_items)
			set_scroll()

		elif file_type == "audio" or file_type == "video" or group_open:
			if group_open:
				path = ""

				for item in (dir_list.selected_items or [dir_list.cursor]):
					path += '"{}" '.format(item.name)
			
			else:
				path = '"{}"'.format(path)

			subprocess.call(settings.MEDIA_PLAYER_PATH + ' ' + path + '  vlc://quit &', shell = True,
							stdout = subprocess.DEVNULL, stderr = subprocess.DEVNULL)

	def equals(ch, action):
		return any(ch in keybind for keybind in KEYBINDS[action])

	while 1:

		if refresh_screen or (manage_resize == 0 and dir_list.cursor.show_ellipsis):
			dir_list.display()
			refresh_screen = False
		
		ch = pad.PAD.getch()

		if ch == curses.KEY_RESIZE:
			manage_resize = 1

		elif equals(ch, "Navigate up"):
			index = dir_list.cursor.index
			up = dir_list.atIndex(index - Point(1,0))

			if up:
				dir_list.cursor = up

				if up.index.y < pad.scroll_pos and pad.scroll_pos > 0:
					pad.scroll_pos -= 1

				set_scroll()

		elif equals(ch, "Navigate down"):
			index = dir_list.cursor.index
			down = dir_list.atIndex(index + Point(1,0))

			if down:
				dir_list.cursor = down

				if down.index.y > (pad.scroll_pos + pad.dim.y) - 1:
					pad.scroll_pos += 1

				set_scroll()
		
		elif equals(ch, "Navigate left"):
			index = dir_list.cursor.index
			left = dir_list.atIndex(index - Point(0,1))

			if left:
				dir_list.cursor = left
				set_scroll()

		elif equals(ch, "Navigate right"):
			index = dir_list.cursor.index
			right = dir_list.atIndex(index + Point(0,1))

			if right:
				dir_list.cursor = right
				set_scroll()

		elif equals(ch, "Navigate to first item"):
			dir_list.cursor = dir_list.list_1d[0]
			pad.scroll_pos = 0

			refresh_screen = True

		elif equals(ch, "Navigate to bottom-most item"):
			if settings.END_SELECTS_LAST_ITEM:
				dir_list.cursor = dir_list.list_1d[-1]
			
			else:
				dir_list.cursor = dir_list.LIST[-1][-1]
			
			set_scroll()

		elif equals(ch, "Move up by one directory"):
			if dir_list.list_1d[0].name == "..":
				dir_list.cursor = dir_list.list_1d[0]
				curses.ungetch(KEYBINDS["Open file/directory under cursor"][0][0])
			
			refresh_screen = True
		
		elif equals(ch, "Back"):
			path = dirHistory.up()

			if path:
				change_list(path, add_to_history = False)
		
		elif equals(ch, "Forward"):
			path = dirHistory.down()

			if path:
				change_list(path, add_to_history = False)

		elif equals(ch, "Scroll up"):
			if pad.scroll_pos > 0:
				pad.scroll_pos -= 1
		
			refresh_screen = True
		
		elif equals(ch, "Scroll down"):
			if pad.scroll_pos < (pad.max_used_space - pad.dim.y):
				pad.scroll_pos += 1
			
			refresh_screen = True

		elif equals(ch, "Page up"):
			pad.scroll_pos = max(pad.scroll_pos - (pad.dim.y - 1), 0)
			refresh_screen = True
		
		elif equals(ch, "Page down"):
			pad.scroll_pos = min(pad.scroll_pos + (pad.dim.y - 1), max(pad.max_used_space - pad.dim.y, 0))
			refresh_screen = True

		elif equals(ch, "Select/deselect item under cursor"):
			if dir_list.cursor not in dir_list.selected_items:
				if dir_list.cursor.name != "..":
					dir_list.selected_items.append(dir_list.cursor)
			
			else:
				dir_list.selected_items.remove(dir_list.cursor)

			statusbar.update_count(dir_list.selected_items)

			refresh_screen = True

		elif equals(ch, "Group select"):
			if dir_list.selected_items == []: continue

			last_selected = dir_list.selected_items[-1]

			if dir_list.cursor == last_selected or dir_list.cursor == dir_list.list_1d[0]: continue

			select = False

			for file in dir_list.list_1d[1:]:
				if not select and (file == dir_list.cursor or file == last_selected):
					select = True

					if file not in dir_list.selected_items:
						dir_list.selected_items.append(file)
					
					continue
				
				if select:
					if file not in dir_list.selected_items:
						dir_list.selected_items.append(file)
				
					if file == dir_list.cursor or file == last_selected:
						break
			
			statusbar.update_count(dir_list.selected_items)

			refresh_screen = True

		elif equals(ch, "Select all items"):
			if not dir_list.selected_items == dir_list.list_1d[1:]:
				dir_list.selected_items = dir_list.list_1d[1:]
				statusbar.update_count(dir_list.selected_items)

				refresh_screen = True
			
			else: curses.ungetch(KEYBINDS["Deselect all items"][0][0])
		
		elif equals(ch, "Deselect all items"):
			dir_list.selected_items = []

			statusbar.update_count(dir_list.selected_items)
			refresh_screen = True

		elif equals(ch, "Group open all selected items directly"):
			if not (dir_list.selected_items == [] and dir_list.cursor.name == ".."):
				change_list(group_open = True)
		
		elif equals(ch, "Open file/directory under cursor"):
			change_list(dir_list.cursor.name)

		elif equals(ch, "Help"):
			help_section.show_help(pad, screen.statusbar, screen.handle_resize)
			refresh_screen = True

		elif equals(ch, "Reverse sort order"):
			change_list(rev = True)

		elif equals(ch, "Quit"): break

		elif ch > 0 and chr(ch).isalnum():
			qs += chr(ch)

			for file in dir_list.list_1d:
				if file.name.lower().startswith(qs):
					dir_list.cursor = file

					set_scroll()
					break

			qs_timeout = 3

		elif ch == -1:
			if qs_timeout >= 0:
				qs_timeout -= 1

				if qs_timeout == 0:
					qs_timeout = -1
					qs = ""

		if manage_resize == 2:
			screen.handle_resize()

			curses.curs_set(1)
			curses.curs_set(0)

			manage_resize = 0
			refresh_screen = True
		
		if manage_resize != 0: manage_resize = 2
Exemple #22
0
 def decorate(self):
     self.safe_print(None, "border", attr=COLOR_DICT["RED_BLACK"])
     self.safe_print(" CML ", curs_pos=Point(0, 5))
Exemple #23
0
    def handle_resize(self):
        self.resize(self.parent.dim - Point(3, 2))
        self.decorate()

        self.pad.handle_resize()
        self.refresh()
Exemple #24
0
    def _calculate_indices(self):
        length, width = self.dim

        for i in self.LIST:
            for j in i:
                j.set_index(Point(self.LIST.index(i), i.index(j)))
Exemple #25
0
    def subwin(self, dim: Point, start=Point(0, 0)):
        self.sub = Subwindow(self, dim, start)

        return self.sub