aboutsummaryrefslogblamecommitdiffstats
path: root/xpybar/config/mysun.py
blob: cfd1d5c7b7709aa92ff68f239ad27c8c16962da6 (plain) (tree)










































                                                                                    
# -*- python -*-
from common import *

class MySun(Entry):
    def __init__(self, *args, clock = None, **kwargs):
        self.text = '...'
        self.clock = clock
        Entry.__init__(self, *args, **kwargs)
        xasync(self.wait, name = 'solar')
    
    def wait(self):
        palette = None
        while palette is None:
            try:
                palette = G.bar.palette
            except:
                time.sleep(0.1)
        twilight_12 = colour_interpol(palette[1], palette[3], 1 / 3)
        twilight_6 = colour_interpol(palette[1], palette[3], 2 / 3)
        command = pdeath('HUP', 'blueshift', '-c', HOME + '/.config/xpybar/bin/sun')
        while True:
            try:
                text = 'Sun: %s' % spawn_read(*command)
                if self.clock is not None:
                    elevation = float(text.split(' ')[3][:-1])
                    if   elevation <= -18:  self.clock.twilight = '31'
                    elif elevation <= -12:  self.clock.twilight = twilight_12
                    elif elevation <=  -6:  self.clock.twilight = twilight_6
                    elif elevation <=   0:  self.clock.twilight = '33'
                    elif elevation <=   6:  self.clock.twilight = '39'
                    else:                   self.clock.twilight = '34'
                    self.clock.invalidate()
            except:
                text = '¿Cannot get solar information?'
                if self.clock is not None:
                    self.clock.twilight = '39'
                    self.clock.invalidate()
            self.text = text
            self.invalidate()
            time.sleep(20)
    
    def function(self):
        return self.text