aboutsummaryrefslogtreecommitdiffstats
path: root/xpybar/config/mymoc.py
blob: da16ece4a474434afd16979ba2d8a4b854447b7e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# -*- 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()