Browse Source

Fixes bug that made it impossible to search for things containing any of
[-_=+<>].

Caleb Fangmeier 6 years ago
parent
commit
537170ee59
1 changed files with 104 additions and 101 deletions
  1. 104 101
      tuijam

+ 104 - 101
tuijam

@@ -16,99 +16,6 @@ def sec_to_min_sec(sec_tot):
         return min_, sec
 
 
-class PlayBar(urwid.ProgressBar):
-    # Class stolen from: https://github.com/and3rson/clay/blob/master/clay/playbar.py
-    vol_inds = [' ', '▁', '▂', '▃', '▄', '▅', '▆', '▇', '█']
-
-    def __init__(self, app, *args, **kwargs):
-        super(PlayBar, self).__init__(*args, **kwargs)
-        self.app = app
-
-    def get_prog_tot(self):
-        curr_time_s = self.app.player.time_pos
-        rem_time_s = self.app.player.time_remaining
-        if curr_time_s is None or rem_time_s is None:
-            return 0, 0
-        else:
-            progress = int(curr_time_s)
-            total = int(curr_time_s + rem_time_s)
-            return progress, total
-
-    def get_text(self):
-        if self.app.current_song is None:
-            return 'Idle'
-        progress, total = self.get_prog_tot()
-        # return [u' \u25B6 ' if self.app.play_state == 'play' else u' \u25A0 ',
-        #         ('np_artist', self.app.current_song.artist),
-        #         ' - ',
-        #         ('np_song', self.app.current_song.title),
-        #         '  [{:02d}:{:02d} / {:02d}:{:02d}]'.format(progress // 60,
-        #                                                    progress % 60,
-        #                                                    total // 60,
-        #                                                    total % 60)
-        #         ]
-        return ' {} {} - {} [{:02d}:{:02d} / {:02d}:{:02d}] {}'.format(
-            '▶' if self.app.play_state == 'play' else '■',
-            self.app.current_song.artist,
-            self.app.current_song.title,
-            progress // 60,
-            progress % 60,
-            total // 60,
-            total % 60,
-            self.vol_inds[self.app.volume]
-        )
-
-    def update(self):
-        self._invalidate()
-
-        progress, total = self.get_prog_tot()
-        if progress >= 0 and total > 0:
-            percent = progress / total * 100
-            self.set_completion(percent)
-        else:
-            self.set_completion(0)
-
-    def render(self, size, focus=False):
-        """
-        Render the progress bar - fixed implementation.
-        For details see https://github.com/urwid/urwid/pull/261
-        """
-        (maxcol,) = size
-        txt = urwid.Text(self.get_text(), self.text_align, urwid.widget.CLIP)
-        c = txt.render((maxcol,))
-
-        cf = float(self.current) * maxcol / self.done
-        ccol_dirty = int(cf)
-        ccol = len(c._text[0][:ccol_dirty].decode(
-            'utf-8', 'ignore'
-        ).encode(
-            'utf-8'
-        ))
-        cs = 0
-        if self.satt is not None:
-            cs = int((cf - ccol) * 8)
-        if ccol < 0 or (ccol == 0 and cs == 0):
-            c._attr = [[(self.normal, maxcol)]]
-        elif ccol >= maxcol:
-            c._attr = [[(self.complete, maxcol)]]
-        elif cs and c._text[0][ccol] == " ":
-            t = c._text[0]
-            cenc = self.eighths[cs].encode("utf-8")
-            c._text[0] = t[:ccol] + cenc + t[ccol + 1:]
-            a = []
-            if ccol > 0:
-                a.append((self.complete, ccol))
-            a.append((self.satt, len(cenc)))
-            if maxcol - ccol - 1 > 0:
-                a.append((self.normal, maxcol - ccol - 1))
-            c._attr = [a]
-            c._cs = [[(None, len(c._text[0]))]]
-        else:
-            c._attr = [[(self.complete, ccol),
-                        (self.normal, maxcol - ccol)]]
-        return c
-
-
 class MusicObject:
 
     @staticmethod
@@ -344,6 +251,99 @@ class SearchPanel(urwid.ListBox):
             return None
 
 
+class PlayBar(urwid.ProgressBar):
+    # Class stolen from: https://github.com/and3rson/clay/blob/master/clay/playbar.py
+    vol_inds = [' ', '▁', '▂', '▃', '▄', '▅', '▆', '▇', '█']
+
+    def __init__(self, app, *args, **kwargs):
+        super(PlayBar, self).__init__(*args, **kwargs)
+        self.app = app
+
+    def get_prog_tot(self):
+        curr_time_s = self.app.player.time_pos
+        rem_time_s = self.app.player.time_remaining
+        if curr_time_s is None or rem_time_s is None:
+            return 0, 0
+        else:
+            progress = int(curr_time_s)
+            total = int(curr_time_s + rem_time_s)
+            return progress, total
+
+    def get_text(self):
+        if self.app.current_song is None:
+            return 'Idle'
+        progress, total = self.get_prog_tot()
+        # return [u' \u25B6 ' if self.app.play_state == 'play' else u' \u25A0 ',
+        #         ('np_artist', self.app.current_song.artist),
+        #         ' - ',
+        #         ('np_song', self.app.current_song.title),
+        #         '  [{:02d}:{:02d} / {:02d}:{:02d}]'.format(progress // 60,
+        #                                                    progress % 60,
+        #                                                    total // 60,
+        #                                                    total % 60)
+        #         ]
+        return ' {} {} - {} [{:02d}:{:02d} / {:02d}:{:02d}] {}'.format(
+            '▶' if self.app.play_state == 'play' else '■',
+            self.app.current_song.artist,
+            self.app.current_song.title,
+            progress // 60,
+            progress % 60,
+            total // 60,
+            total % 60,
+            self.vol_inds[self.app.volume]
+        )
+
+    def update(self):
+        self._invalidate()
+
+        progress, total = self.get_prog_tot()
+        if progress >= 0 and total > 0:
+            percent = progress / total * 100
+            self.set_completion(percent)
+        else:
+            self.set_completion(0)
+
+    def render(self, size, focus=False):
+        """
+        Render the progress bar - fixed implementation.
+        For details see https://github.com/urwid/urwid/pull/261
+        """
+        (maxcol,) = size
+        txt = urwid.Text(self.get_text(), self.text_align, urwid.widget.CLIP)
+        c = txt.render((maxcol,))
+
+        cf = float(self.current) * maxcol / self.done
+        ccol_dirty = int(cf)
+        ccol = len(c._text[0][:ccol_dirty].decode(
+            'utf-8', 'ignore'
+        ).encode(
+            'utf-8'
+        ))
+        cs = 0
+        if self.satt is not None:
+            cs = int((cf - ccol) * 8)
+        if ccol < 0 or (ccol == 0 and cs == 0):
+            c._attr = [[(self.normal, maxcol)]]
+        elif ccol >= maxcol:
+            c._attr = [[(self.complete, maxcol)]]
+        elif cs and c._text[0][ccol] == " ":
+            t = c._text[0]
+            cenc = self.eighths[cs].encode("utf-8")
+            c._text[0] = t[:ccol] + cenc + t[ccol + 1:]
+            a = []
+            if ccol > 0:
+                a.append((self.complete, ccol))
+            a.append((self.satt, len(cenc)))
+            if maxcol - ccol - 1 > 0:
+                a.append((self.normal, maxcol - ccol - 1))
+            c._attr = [a]
+            c._cs = [[(None, len(c._text[0]))]]
+        else:
+            c._attr = [[(self.complete, ccol),
+                        (self.normal, maxcol - ccol)]]
+        return c
+
+
 class QueuePanel(urwid.ListBox):
     def __init__(self, app):
         self.app = app
@@ -580,20 +580,23 @@ class App(urwid.Pile):
             self.toggle_play()
         elif key == 'ctrl q':
             self.stop()
-        elif key == '>':
-            self.seek(10)
-        elif key == '<':
-            self.seek(-10)
         elif key == 'ctrl n':
             self.queue_panel.play_next()
         elif key == 'ctrl r':
             self.search_panel.update_search_results(self.history, [], [])
         elif key == 'ctrl s':
             self.queue_panel.shuffle()
-        elif key in '-_':
-            self.volume_down()
-        elif key in '+=':
-            self.volume_up()
+        elif self.focus != self.search_input:
+            if key == '>':
+                self.seek(10)
+            elif key == '<':
+                self.seek(-10)
+            elif key in '-_':
+                self.volume_down()
+            elif key in '+=':
+                self.volume_up()
+            else:
+                return self.focus.keypress(size, key)
         else:
             return self.focus.keypress(size, key)