diff --git a/pywmdatetime/__init__.py b/pywmdatetime/__init__.py new file mode 100644 index 0000000..bcdd476 --- /dev/null +++ b/pywmdatetime/__init__.py @@ -0,0 +1 @@ +from pywmdatetime import * diff --git a/pywmdatetime/pywmdatetime.py b/pywmdatetime/pywmdatetime.py index 0a61699..ed8373f 100755 --- a/pywmdatetime/pywmdatetime.py +++ b/pywmdatetime/pywmdatetime.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -'''pywmdatetime.py +"""pywmdatetime.py WindowMaker dockapp that displays time, date, weekday and week number. @@ -25,8 +25,8 @@ Added event handling for graceful shutdown 2003-06-16 Kristoffer Erlandsson First workingish version -''' -usage = '''pywmdatetime.py [options] +""" +usage = """pywmdatetime.py [options] Available options are: -h, --help print this help -f, --foreground set the foreground color @@ -40,14 +40,14 @@ Available options are: The formats are the same as Python's strftime() accept. See the sample rc-file for more information about this. -''' +""" import sys import time import getopt import os -import pywmhelpers +from pywmgeneral import pywmhelpers width = 64 height = 64 diff --git a/pywmgeneral/__init__.py b/pywmgeneral/__init__.py new file mode 100644 index 0000000..48f6c63 --- /dev/null +++ b/pywmgeneral/__init__.py @@ -0,0 +1 @@ +from pywmhelpers import * diff --git a/pywmgeneric/__init__.py b/pywmgeneric/__init__.py new file mode 100644 index 0000000..0251d58 --- /dev/null +++ b/pywmgeneric/__init__.py @@ -0,0 +1 @@ +from pywmgeneric import * diff --git a/pywmgeneric/pywmgeneric.py b/pywmgeneric/pywmgeneric.py index bed9cf3..d152d23 100755 --- a/pywmgeneric/pywmgeneric.py +++ b/pywmgeneric/pywmgeneric.py @@ -1,5 +1,5 @@ #!/usr/bin/env python - +# -*- coding: utf-8 -*- '''pywmgeneric.py WindowMaker dockapp to display the output from an external program, or the @@ -40,10 +40,10 @@ import ConfigParser import getopt import popen2 -import pywmhelpers +from pywmgeneral import pywmhelpers class UserMethods: - '''Put methods that should be called when the action is method=... here. + """Put methods that should be called when the action is method=... here. The action methods should return a function, which in turn returns the string to be displayed (if no 'display =' exists) and stored @@ -57,15 +57,43 @@ class UserMethods: THE METHODS ALLREADY HERE ARE JUST SAMPLES AND WILL PROBABLY NOT WORK WITH YOUR SYSTEM. - ''' + """ + + userTicks = sysTicks = niceTicks = idleTicks = 0 + def getCpuTemp(self): - try: - f = file('/proc/sys/dev/sensors/w83697hf-isa-0290/temp2', 'r') - except IOError: - return lambda: 'error' - temp = f.readline().split()[2] - f.close() - return lambda: 'cpu: %s' % temp + def result(): + try: + f = file('/proc/stat', 'r') + except IOError: + return lambda: 'error' + + import re + cpuinfo = re.compile(r'^cpu.* (?P[0-9]+) +(?P[0-9]+)' + r'+(?P[0-9]+) +(?P[0-9]+)') + match = dict([(k, int(v)) + for (k,v) in cpuinfo.match(f.readline()).groupdict().items()]) + totalTicks = ((match['user'] - self.userTicks) + + (match['sys'] - self.sysTicks) + + (match['nice'] - self.niceTicks) + + (match['idle'] - self.idleTicks)); + + if (totalTicks > 0): + user = (100. * (match['user'] - self.userTicks)) / totalTicks; + sys = (100. * (match['sys'] - self.sysTicks)) / totalTicks; + nice = (100. * (match['nice'] - self.niceTicks)) / totalTicks; + idle = (100. - (user + sys + nice)); + else: + user = sys = nice = idle = 0; + + self.userTicks = match['user'] + self.sysTicks = match['sys'] + self.niceTicks = match['nice'] + self.idleTicks = match['idle'] + + f.close() + return '%02.f/%02.f/%02.f' % (user, nice, sys) + return result def getSysTemp(self): try: @@ -118,7 +146,7 @@ digits = '0123456789:/-%. ' maxChars = 9 defaultConfigFile = '~/.pywmgenericrc' -defaultRGBFiles = ('/usr/lib/X11/rgb.txt', '/usr/X11R6/lib/X11/rgb.txt') +defaultRGBFiles = ('/usr/share/X11/rgb.txt', '/usr/X11R6/lib/X11/rgb.txt') err = sys.stderr.write @@ -143,10 +171,10 @@ def getXY(line): return 0, line * (letterHeight + 3) + 1 def isTrue(s): - '''Return true if the string s can be interpreted as a true value. + """Return true if the string s can be interpreted as a true value. Raises ValueError if we get a string we don't like. - ''' + """ trueThings = ['on', 'yes', '1', 'true'] falseThings = ['off', 'no', '0', 'false'] if s in trueThings: @@ -345,13 +373,13 @@ class Entry: pass def translateText(self, text): - '''Translate chars that can't be painted in the app to something nicer. + """Translate chars that can't be painted in the app to something nicer. Or nothing if we can't come up with something good. Could be nice to extend this function with chars more fitting for your language. - ''' - fromChars = 'åäöèü' - toChars = 'aaoeu' + """ + fromChars = 'áéíóúàèìòùâêîôûäëïöü' + toChars = 'aeiouaeiouaeiouaeiou' deleteChars = [] for c in text.lower(): if not (c in letters or c in digits or c in fromChars): @@ -484,15 +512,15 @@ class PywmGeneric: while 1: counter += 1 self._checkForEvents() - if counter % 3 == 0: + if counter % 2 == 0: [e.tick1() for e in self._entrys if not e is None] - if counter % 100 == 0: + if counter % 20 == 0: [e.tick2() for e in self._entrys if not e is None] if counter == 999999: counter = -1 pywmhelpers.redraw() - time.sleep(0.1) + time.sleep(0.5) def parseCommandLine(argv): '''Parse the commandline. Return a dictionary with options and values.''' diff --git a/pywmhdmon/__init__.py b/pywmhdmon/__init__.py new file mode 100644 index 0000000..a14ea61 --- /dev/null +++ b/pywmhdmon/__init__.py @@ -0,0 +1 @@ +from pywmhdmon import * diff --git a/pywmhdmon/pywmhdmon.py b/pywmhdmon/pywmhdmon.py index e8a29fb..ccacb4a 100755 --- a/pywmhdmon/pywmhdmon.py +++ b/pywmhdmon/pywmhdmon.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python2.3 """pywmhdmon.py @@ -55,7 +55,7 @@ import time import getopt import os -import pywmhelpers +from pywmgeneral import pywmhelpers width = 64 height = 64 diff --git a/pywmseti/__init__.py b/pywmseti/__init__.py new file mode 100644 index 0000000..e0d0e8c --- /dev/null +++ b/pywmseti/__init__.py @@ -0,0 +1 @@ +from pywmseti import * diff --git a/pywmseti/pywmseti.py b/pywmseti/pywmseti.py index fb58455..e4a8e38 100755 --- a/pywmseti/pywmseti.py +++ b/pywmseti/pywmseti.py @@ -37,7 +37,7 @@ import time import getopt import os -import pywmhelpers +from pywmgeneral import pywmhelpers width = 64 height = 64 diff --git a/pywmsysmon/__init__.py b/pywmsysmon/__init__.py new file mode 100644 index 0000000..60763cd --- /dev/null +++ b/pywmsysmon/__init__.py @@ -0,0 +1 @@ +from pywmsysmon import * diff --git a/pywmsysmon/pywmsysmon.py b/pywmsysmon/pywmsysmon.py index 16385ee..3cc4d47 100755 --- a/pywmsysmon/pywmsysmon.py +++ b/pywmsysmon/pywmsysmon.py @@ -36,7 +36,7 @@ import time import getopt import os -import pywmhelpers +from pywmgeneral import pywmhelpers width = 64 height = 64 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..044701d --- /dev/null +++ b/setup.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Set these so they match your system. +XLibDir = '/usr/X11R6/lib' +XIncludes = '/usr/X11R6/include' + +from distutils.core import setup, Extension + +module1 = Extension('pywmgeneral', + libraries = ['Xpm', 'Xext', 'X11'], + library_dirs = [XLibDir], + include_dirs = [XIncludes], + sources = ['pywmgeneral/pywmgeneral.c']) + +setup(name="pywmdockapps", + version = "$Revision$"[11:-2], + + description=''' + read the whole story at http://pywmdockapps.sourceforge.net/''', + + author="Kristoffer Erlandsson & al.", + author_email="mfrasca@zonnet.nl", + url="http://ibo.sourceforge.net", + license="(L)GPL", + py_modules=['pywmdatetime.pywmdatetime', + 'pywmgeneral.pywmhelpers', + 'pywmgeneric.pywmgeneric', + 'pywmhdmon.pywmhdmon', + 'pywmseti.pywmseti', + 'pywmsysmon.pywmsysmon', + ], + ext_modules = [module1])