diff options
| -rw-r--r-- | TODO | 1 | ||||
| -rw-r--r-- | examples/moderate | 11 | ||||
| -rwxr-xr-x | src/__main__.py | 10 | ||||
| -rw-r--r-- | src/plugins/solar.py | 39 | ||||
| -rw-r--r-- | src/util.py | 2 | 
5 files changed, 58 insertions, 5 deletions
@@ -2,7 +2,6 @@ List of plugins to implement:       iostat [-x] [-d] [-N] -zk [-p | <devices>...] <interval>       SMART monitoring -     Solar position       Xmonad       Battery       Volume control diff --git a/examples/moderate b/examples/moderate index e7407e5..5a2cfab 100644 --- a/examples/moderate +++ b/examples/moderate @@ -2,6 +2,7 @@  # A moderate xpybar configuration example that has a few monitors that are updates continuously +import os  import time  from plugins.clock import Clock @@ -13,6 +14,7 @@ from plugins.pacman import Pacman  from plugins.uname import Uname  from plugins.weather import Weather  from plugins.chase import Chase +from plugins.solar import Solar  OUTPUT, YPOS, TOP = 0, 24, True @@ -191,18 +193,25 @@ def chase():      return '\033[%smChase\033[0m' % status +solar_ = os.environ['HOME'] + '/.xpybar.sun' +def sun(): +    try: +        return Solar(solar_).output +    except: +        return '¿Cannot get solar information?'  functions = [ Sometimes(lambda : clock_.read(), 1 * 2),                lambda : time.time() % 1,                Sometimes(users, 1 * 2),                weather,                chase, +              Sometimes(sun, 1 * 2),                cpu,                memory,                network,                Sometimes(uname, 30 * 60 * 2),              ] -pattern = [ '%s │ %.2f │ %s │ %s │ %s }{ %s │ %s │ %s │ %s' +pattern = [ '%s │ %.2f │ %s │ %s │ %s │ %s }{ %s │ %s │ %s │ %s'            ] diff --git a/src/__main__.py b/src/__main__.py index ace57f9..5c9f831 100755 --- a/src/__main__.py +++ b/src/__main__.py @@ -16,6 +16,7 @@ GNU General Public License for more details.  You should have received a copy of the GNU General Public License  along with this program.  If not, see <http://www.gnu.org/licenses/>.  ''' +import Xlib.threaded # IMPORTANT (threading do not work otherwise, see XInitThreads)  import Xlib.display, Xlib.Xatom, Xlib.ext.randr, Xlib.X  from argparser import * @@ -93,6 +94,7 @@ class Bar:      @variable  font_height:int   The height of the default font      @variable  font_width:int    The width of an 'X' with the default font      @variable  palette           A 16-array of standard colours +    @variable  cmap_cache        Custom colour map cache      '''      def __init__(self, output, height, ypos, top, font, background, foreground): @@ -115,6 +117,7 @@ class Bar:          self.gc = self.window.create_gc()          self.cmap = self.window.get_attributes().colormap          ## Graphics variables +        self.cmap_cache = {}          self.background = self.create_colour(*background)          self.foreground = self.create_colour(*foreground)          (self.font, self.font_metrics, self.font_height) = self.create_font(font) @@ -311,7 +314,12 @@ class Bar:          @param   blue:int   The blue component [0, 255]          @return             The colour          ''' -        return self.cmap.alloc_color(red * 257, green * 257, blue * 257).pixel +        cid = (red << 16) | (green << 8) | blue +        if cid in self.cmap_cache: +            return self.cmap_cache[cid] +        rc = self.cmap.alloc_color(red * 257, green * 257, blue * 257).pixel +        self.cmap_cache[cid] = rc +        return rc      def create_font(self, font):          ''' diff --git a/src/plugins/solar.py b/src/plugins/solar.py new file mode 100644 index 0000000..3b772cf --- /dev/null +++ b/src/plugins/solar.py @@ -0,0 +1,39 @@ +# -*- python -*- +''' +xpybar – xmobar replacement written in python +Copyright © 2014  Mattias Andrée (maandree@member.fsf.org) + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program.  If not, see <http://www.gnu.org/licenses/>. +''' + +from util import * + + +class Solar: +    ''' +    Solar information using Blueshift +     +    @variable  output:str  The output of blueshift +    ''' +     +     +    def __init__(self, configuration_file): +        ''' +        Constructor +         +        @param  configuration_file:str  Blueshift configuration file that prints the information, +                                        you can base it on `/usr/share/doc/blueshift/examples/` +        ''' +        self.output = spawn_read('blueshift', '-c', configuration_file) + diff --git a/src/util.py b/src/util.py index d9fc5e5..4d229ef 100644 --- a/src/util.py +++ b/src/util.py @@ -21,8 +21,6 @@ import time  import threading  import subprocess -import Xlib.threaded -  def async(target, name = None, group = None):      '''  | 
