aboutsummaryrefslogblamecommitdiffstats
path: root/xpybar/config/mymoc.py
blob: da16ece4a474434afd16979ba2d8a4b854447b7e (plain) (tree)





































































                                                                                   
# -*- python -*-
from plugins.moc import MOC

from common import *

class MyMOC(Entry):
    def __init__(self, *args, ignore = None, **kwargs):
        self.show_state = False
        self.display = 0
        self.function_display = Sometimes(self.function_display_, 4)
        Entry.__init__(self, *args, **kwargs)
    
    def invalidate(self):
        self.function_display.counter = 0
        Entry.invalidate(self)
    
    def action(self, col, button, x, y):
        if button == RIGHT_BUTTON:
            self.show_state = not self.show_state
            self.invalidate()
        elif self.show_state:
            if button == LEFT_BUTTON:
               self.invalidate()
            elif button == SCROLL_UP:
               n = self.display + 1
               if n >= 6:
                   return
               self.display = n
               self.invalidate()
            elif button == SCROLL_DOWN:
               n = self.display - 1
               if n < 0:
                   return
               self.display = n
               self.invalidate()
        else:
            moc = MOC()
            if moc.state == MOC.NOT_RUNNING:
                return
            elif button == LEFT_BUTTON:
                if col < 5:
                    return
                col -= 5
                if col % 3 == 2:
                    return
                col //= 3
                if   col == 0:           xasync(lambda : moc.play().wait())
                elif col == 1:           xasync(lambda : moc.toggle_pause().wait())
                elif col == 2:           xasync(lambda : moc.stop().wait())
                elif col == 3:           xasync(lambda : moc.previous().wait())
                elif col == 4:           xasync(lambda : moc.next().wait())
            elif button == SCROLL_UP:    xasync(lambda : moc.seek(+5).wait())
            elif button == SCROLL_DOWN:  xasync(lambda : moc.seek(-5).wait())
    
    def function_display_(self):
        moc = MOC()
        display = self.display
        if display == 0 or moc.state in (MOC.NOT_RUNNING, MOC.STOPPED):
            return 'Moc: %s' % { MOC.NOT_RUNNING : 'not running'
                               , MOC.STOPPED     : 'stopped'
                               , MOC.PAUSED      : 'paused'
                               , MOC.PLAYING     : 'playing'}[moc.state]
        key = ['SongTitle', 'Album', 'Artist', 'Title', 'File'][display -  1]
        label = key.lower() if display != 1 else 'song'
        return 'Moc(%s): %s' % (label, moc[key])
    
    def function(self):
        if not self.show_state:
            return 'Moc: |> || [] |< >|'
        return self.function_display()