aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-03-03 23:40:59 +0100
committerMattias Andrée <maandree@operamail.com>2014-03-03 23:40:59 +0100
commitcf19015c665fa067034e94be1fdc315e94bb2b04 (patch)
tree706f660a60243100b282437c77cc8b1e56e46250 /src
parentadd chase (diff)
downloadxpybar-cf19015c665fa067034e94be1fdc315e94bb2b04.tar.gz
xpybar-cf19015c665fa067034e94be1fdc315e94bb2b04.tar.bz2
xpybar-cf19015c665fa067034e94be1fdc315e94bb2b04.tar.xz
add solar information
Signed-off-by: Mattias Andrée <maandree@operamail.com>
Diffstat (limited to 'src')
-rwxr-xr-xsrc/__main__.py10
-rw-r--r--src/plugins/solar.py39
-rw-r--r--src/util.py2
3 files changed, 48 insertions, 3 deletions
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):
'''