def update(self): with self._lock: if self._geom.is_sane(): (filename,position,duration) = self._audiobook.position() if filename == None: filename = "" if self._audiobook.playing: state = "Playing" elif self._audiobook.eob: state = "End" else: state = "Paused" with self._curseslock: prefix = "File: " maxchars = self._geom.w - len(prefix) - 1 first = prefix + filename[-maxchars:] second = "{position} / {duration} [{state}]".format( position=ns_to_str(position), duration=ns_to_str(duration), state=state) self._window.erase() if self._geom.h>=1: self._window.addnstr(0,0,first,self._geom.w-1) if self._geom.h>=2: self._window.addnstr(1,0,second,self._geom.w-1) self._window.refresh()
def draw(self): with self._lock: if self._geom.is_sane(): with self._curseslock: self._window.erase() playlog = self._audiobook.playlog # Make sure the focus index is valid. self._focus = calc_focus( length = len(playlog), focus = self._focus) num = min(self._geom.h, len(playlog)) focus = self._focus if focus==None: start = max(0, len(playlog)-num) else: start = max(0, min(len(playlog)-num, focus - num/2)) for i in xrange(0, num): # Position in playlog logi = i + start # Check if this is the currently selected line if logi == focus: mark = "-> " attr = curses.A_REVERSE else: mark = " " attr = curses.A_NORMAL walltime = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(playlog[logi].walltime)) event = playlog[logi].event[:self._conf.event_len] event += " " * (self._conf.event_len - len(event)) # Format all stuff before filename part0 = "{mark}{walltime} {event} ".format( mark = mark, walltime = walltime, event = event) # Format all stuff after filename position = ns_to_str(playlog[logi].position) duration = ns_to_str(playlog[logi].duration) part2 = " {position} / {duration}".format( position=position, duration=duration) # Compute maximum length of filename part1len = max(0, self._geom.w - 1 - len(part0) - len(part2)) # Take the end of filename, if it is too long. part1 = playlog[logi].filename[-part1len:] # Combine into complete line. pad = " " * (part1len - len(part1)) line = part0 + part1 + pad + part2 if self._geom.h>=1: self._window.addnstr(i, 0, line, self._geom.w-1,attr) self._window.refresh()