Example #1
0
def start():
    arguments = docopt.docopt(__doc__, version=lyrics.__version__)
    debug.use_debugging = arguments['--debug']
    debug.debug('started with', arguments)

    state.playlist = playlist.Playlist.from_path(arguments['<path>'])
    main_app.start()
Example #2
0
def search():
    state.search_mode = True
    state.search = ''
    state.search_list.append('')
    state.search_index = len(state.search_list) - 1
    state.search_cursor = 0
    state.playlist = state.playlist.search('')
    debug.debug('base', state.playlist, state.playlist.search('').parent)
    _search_update()
Example #3
0
    def move_cursor(self, x, y):
        """ x can always be ignored, it's just about the y movement """
        num_lines = self.get_num_lines()
        self.cursor_at += y
        self.cursor_at = min(max(self.cursor_at, 0), num_lines - 1)
        debug.debug('cursor', state.current_window, self.cursor_at, y,
                                self.view_at)

        max_view_bottom = self.view_at + self.real_height - self.scroll_off
        if self.cursor_at < self.view_at + self.scroll_off:
            self.view_at = max(0, self.cursor_at - self.scroll_off)
        elif self.cursor_at > max_view_bottom - 1:
            self.view_at = min(num_lines - self.real_height,
                    self.cursor_at - self.real_height + 1 + self.scroll_off)
Example #4
0
    def add_str(self, x, y, string, col=None, align='left'):
        x, y = self.clean_position(x, y)
        if align == 'right':
            x = max(0, x - len(string))

        # check for strings that are being written in the wrong place.
        if y >= self.height:
            debug.debug('cannot write here: y=%s' % y)
            return False
        result = True
        if x + len(string) >= self.width:
            debug.debug('cannot write here: x=%s, len=%s' % (x, len(string)))
            string = string[:self.width - x - 1]
            result = False

        string = string.replace('\0', '')
        self.win_curses.addstr(y, x, string.encode('UTF-8'), col)
        return result
Example #5
0
def event_handler(key_str):
    debug.debug('key pressed', repr(key_str))

    # strip ctrl
    #key_chr = curses.ascii.ctrl(key_chr)

    try:
        key_str = curses_mapping[key_str]
    except KeyError:
        if len(key_str) > 1 and key_str[0] == '^':
            key_str = '<C-%s>' % key_str[1:]
        # TODO catch control keys

    debug.debug('key resolved as', key_str)

    if state.search_mode:
        if key_str == '<SPACE>':
            key_str = ' '
        allowed = r'-_ +*/%$&!"\'\?!@`,.;:<>^|#[](){}~='
        if key_str.isalnum() or key_str in allowed:
            _search_write(key_str)
        else:
            try:
                registered_events['search'][key_str]()
            except KeyError:
                pass

    else:
        if state.last_command:
            # cleanup
            state.last_command = ''
            state.keyboard_repeat = ''

        if re.match('\d', key_str):
            state.keyboard_repeat += key_str
        else:
            execute_key_command(key_str, state.keyboard_repeat)

            state.last_command = key_str

    app.main_app.draw()
Example #6
0
    def from_path(cls, paths, recursive=True):
        if not paths:
            return cls.from_library()

        def is_sound(path):
            return path[-4:] in ('.mp3', '.wav', '.ogg', '.wmv', 'm3u') \
                or path[-5:] == '.flac'

        debug.debug('load from', paths)
        new_paths = []
        for path in paths:
            path = path.decode('UTF-8')
            path = abspath(expandvars(expanduser(path)))
            for root, dirs, files in os.walk(path):
                for name in files:
                    p = join(root, name)
                    if is_sound(p):
                        new_paths.append(p)
                if recursive is False:
                    break
        #debug.debug('song paths', paths)
        return cls([Song(p) for p in new_paths])
Example #7
0
    def draw(self):
        self.win_curses.noutrefresh()
        self.win_curses.erase()
        #self.win_curses.box()

        length, max_display = self.clean_position(-2, -2)

        lines = self.lines
        self.win_curses.bkgd(' ')
        debug.debug('t', self.visible_in_window())
        for i, line_nr in enumerate(range(*self.visible_in_window())):
            col = color.DEFAULT
            if state.current_window == self and self.cursor_at == line_nr:
                col = color.BG_MAGENTA
                self.win_curses.hline(i + 1, 1, ' ', length, col)
            try:
                self.add_str(1, i + 1, lines[line_nr], col)
            except IndexError:
                # thread problems
                break

        self.win_curses.refresh()
Example #8
0
 def visible_in_window(self):
     """ return the two coordinates of the start and the end window """
     debug.debug('v', self.view_at, self.view_at + self.real_height)
     return self.view_at, min(self.view_at + self.real_height,
                                 self.get_num_lines())
Example #9
0
 def get_num_lines(self):
     debug.debug('asdf', len(state.playlist.songs))
     return len(state.playlist.songs)