1
0
mirror of https://github.com/gryf/wmdocklib.git synced 2025-12-19 12:28:10 +01:00

1569327 release 1.1 is broken

finalizing cleaning up things.

all example scripts include and use wmdocklib (was pywmhelpers from pywmdockapps)
This commit is contained in:
mfrasca
2006-10-03 08:10:30 +00:00
parent 5320092e59
commit d1c1618277
4 changed files with 73 additions and 73 deletions

View File

@@ -47,7 +47,7 @@ import time
import getopt
import os
from pywmgeneral import pywmhelpers
import wmdocklib
width = 64
height = 64
@@ -79,7 +79,7 @@ maxCharsPerLine = 9
def addString(s, x, y):
try:
pywmhelpers.addString(s, x, y, letterWidth, letterHeight, lettersStartX,
wmdocklib.addString(s, x, y, letterWidth, letterHeight, lettersStartX,
lettersStartY, letters, digitWidth, digitHeight,
digitsStartX, digitsStartY, digits, xOffset, yOffset,
width, height)
@@ -89,14 +89,14 @@ def addString(s, x, y):
def clearLine(y):
'''Clear a line of text at position y.'''
pywmhelpers.copyXPMArea(73, yOffset, width - 2 * xOffset, letterHeight,
wmdocklib.copyXPMArea(73, yOffset, width - 2 * xOffset, letterHeight,
xOffset, y + yOffset)
def getCenterStartPos(s):
return pywmhelpers.getCenterStartPos(s, letterWidth, width, xOffset)
return wmdocklib.getCenterStartPos(s, letterWidth, width, xOffset)
def getVertSpacing(numLines, margin):
return pywmhelpers.getVertSpacing(numLines, margin, height, letterHeight,
return wmdocklib.getVertSpacing(numLines, margin, height, letterHeight,
yOffset)
def calculateWeek(localTime):
@@ -147,11 +147,11 @@ def parseCommandLine(argv):
return d
def checkForEvents():
event = pywmhelpers.getEvent()
event = wmdocklib.getEvent()
while not event is None:
if event['type'] == 'destroynotify':
sys.exit(0)
event = pywmhelpers.getEvent()
event = wmdocklib.getEvent()
def mainLoop(timeFmt, dateFmt, dayFmt, weekFmt):
recalcWeek = weekFmt.find('%q') + 1 # True if we found %q.
@@ -197,7 +197,7 @@ def mainLoop(timeFmt, dateFmt, dayFmt, weekFmt):
lastStrs[3] = weekStr
if counter == 999999:
counter = -1
pywmhelpers.redraw()
wmdocklib.redraw()
time.sleep(0.1)
def parseColors(defaultRGBFileNames, config, xpm):
@@ -221,17 +221,17 @@ def parseColors(defaultRGBFileNames, config, xpm):
for key, value in colors:
col = config.get(key)
if not col is None:
code = pywmhelpers.getColorCode(col, rgbFileName)
code = wmdocklib.getColorCode(col, rgbFileName)
if code is None:
sys.stderr.write('Bad colorcode for %s, ignoring.\n' % key)
else:
pywmhelpers.setColor(xpm, value, code)
wmdocklib.setColor(xpm, value, code)
def main():
clConfig = parseCommandLine(sys.argv)
configFile = clConfig.get('configfile', defaultConfigFile)
configFile = os.path.expanduser(configFile)
fileConfig = pywmhelpers.readConfigFile(configFile, sys.stderr)
fileConfig = wmdocklib.readConfigFile(configFile, sys.stderr)
# Merge the two configs, let the commandline options overwrite those in the
# configuration file.
config = fileConfig
@@ -239,7 +239,7 @@ def main():
config[i[0]] = i[1]
parseColors(defaultRGBFiles, config, xpm)
pywmhelpers.setDefaultPixmap(xpm)
wmdocklib.setDefaultPixmap(xpm)
timeFmt = config.get('timeformat', timeDefaultFormat)
dateFmt = config.get('dateformat', dateDefaultFormat)
dayFmt = config.get('weekdayformat', dayDefaultFormat)
@@ -252,7 +252,7 @@ def main():
except IndexError: # Should only happen when using the interpreter.
programName = ''
sys.argv[0] = programName
pywmhelpers.openXwindow(sys.argv, width, height)
wmdocklib.openXwindow(sys.argv, width, height)
mainLoop(timeFmt, dateFmt, dayFmt, weekFmt)
xpm = \

View File

@@ -40,7 +40,7 @@ import ConfigParser
import getopt
import popen2
from pywmgeneral import pywmhelpers
import wmdocklib
prevStat = {'user':0,
'nice':0,
@@ -160,7 +160,7 @@ err = sys.stderr.write
def addString(s, x, y):
'''Convenience function around pwymhelpers.addString.'''
try:
pywmhelpers.addString(s, x, y, letterWidth, letterHeight, lettersStartX,
wmdocklib.addString(s, x, y, letterWidth, letterHeight, lettersStartX,
lettersStartY, letters, digitWidth, digitHeight,
digitsStartX, digitsStartY, digits, xOffset, yOffset,
width, height)
@@ -170,7 +170,7 @@ def addString(s, x, y):
def clearLine(y):
'''Clear a line of text at position y.'''
pywmhelpers.copyXPMArea(72, yOffset, width - 2 * xOffset, letterHeight,
wmdocklib.copyXPMArea(72, yOffset, width - 2 * xOffset, letterHeight,
xOffset, y + yOffset)
def getXY(line):
@@ -482,7 +482,7 @@ class PywmGeneric:
for i in range(5):
x, y = getXY(i)
if not self._entrys[i] is None:
pywmhelpers.addMouseRegion(i, x + xOffset, y + yOffset,
wmdocklib.addMouseRegion(i, x + xOffset, y + yOffset,
width - 2 * xOffset, y + yOffset + letterHeight)
def parseTimeStr(self, timeStr):
@@ -502,17 +502,17 @@ class PywmGeneric:
raise ValueError, 'Invalid literal'
def _checkForEvents(self):
event = pywmhelpers.getEvent()
event = wmdocklib.getEvent()
while not event is None:
if event['type'] == 'destroynotify':
sys.exit(0)
elif event['type'] == 'buttonrelease':
region = pywmhelpers.checkMouseRegion(event['x'], event['y'])
region = wmdocklib.checkMouseRegion(event['x'], event['y'])
button = event['button']
if region != -1:
if not self._entrys[region] is None:
self._entrys[region].mouseClicked(button)
event = pywmhelpers.getEvent()
event = wmdocklib.getEvent()
def mainLoop(self):
counter = -1
@@ -526,7 +526,7 @@ class PywmGeneric:
if counter == 999999:
counter = -1
pywmhelpers.redraw()
wmdocklib.redraw()
time.sleep(0.5)
def parseCommandLine(argv):
@@ -577,11 +577,11 @@ def parseColors(defaultRGBFileList, config, xpm):
for key, value in colors:
col = config.get(key)
if not col is None:
code = pywmhelpers.getColorCode(col, rgbFileName)
code = wmdocklib.getColorCode(col, rgbFileName)
if code is None:
err('Bad colorcode for %s, ignoring.\n' % key)
else:
pywmhelpers.setColor(xpm, value, code)
wmdocklib.setColor(xpm, value, code)
def readConfigFile(fileName):
'''Read the config file.
@@ -622,8 +622,8 @@ def main():
except IndexError:
programName = ''
sys.argv[0] = programName
pywmhelpers.setDefaultPixmap(xpm)
pywmhelpers.openXwindow(sys.argv, width, height)
wmdocklib.setDefaultPixmap(xpm)
wmdocklib.openXwindow(sys.argv, width, height)
pywmgeneric = PywmGeneric(config)
pywmgeneric.mainLoop()

View File

@@ -37,7 +37,7 @@ import time
import getopt
import os
from pywmgeneral import pywmhelpers
import wmdocklib
width = 64
height = 64
@@ -96,7 +96,7 @@ class PywmSeti:
def addString(self, s, x, y):
try:
pywmhelpers.addString(s, x, y, letterWidth, letterHeight,
wmdocklib.addString(s, x, y, letterWidth, letterHeight,
lettersStartX, lettersStartY, letters, digitWidth,
digitHeight, digitsStartX, digitsStartY, digits,
xOffset, yOffset, width, height)
@@ -105,10 +105,10 @@ class PywmSeti:
sys.exit(3)
def getCenterStartPos(self, s):
return pywmhelpers.getCenterStartPos(s, letterWidth, width, xOffset)
return wmdocklib.getCenterStartPos(s, letterWidth, width, xOffset)
def getVertSpacing(self, numLines, margin):
return pywmhelpers.getVertSpacing(numLines, margin, height,
return wmdocklib.getVertSpacing(numLines, margin, height,
letterHeight, yOffset)
def getProgress(self, lines):
@@ -178,7 +178,7 @@ class PywmSeti:
h = runningIndHeight
targX = width - xOffset - w - 5
targY = yOffset + 5
pywmhelpers.copyXPMArea(indX, indY, w, h, targX, targY)
wmdocklib.copyXPMArea(indX, indY, w, h, targX, targY)
def updateRunning(self):
'''Update the information regarding if we got seti@home running or not.
@@ -233,10 +233,10 @@ class PywmSeti:
self._progress = progress
percent = int(progress * 100.0)
graphSize = int(round(progress * graphLength))
pywmhelpers.copyXPMArea(
wmdocklib.copyXPMArea(
graphLineStartX, graphLineStartY, graphSize, graphHeight,
graphStartX, graphStartY)
pywmhelpers.copyXPMArea(
wmdocklib.copyXPMArea(
graphBgStartX, graphBgStartY, graphLength - graphSize, graphHeight,
graphStartX + graphSize, graphStartY)
self.addString((str(percent) + '%').ljust(4), 4, 32)
@@ -289,15 +289,15 @@ class PywmSeti:
def _checkForEvents(self):
'''Check for, and handle, X events.'''
event = pywmhelpers.getEvent()
event = wmdocklib.getEvent()
while not event is None:
if event['type'] == 'buttonrelease':
region = pywmhelpers.checkMouseRegion(event['x'],
region = wmdocklib.checkMouseRegion(event['x'],
event['y'])
self.handleMouseClick(region)
elif event['type'] == 'destroynotify':
sys.exit(0)
event = pywmhelpers.getEvent()
event = wmdocklib.getEvent()
def mainLoop(self):
counter = -1
@@ -313,7 +313,7 @@ class PywmSeti:
self.updateTime()
if counter == 999999:
counter = -1
pywmhelpers.redraw()
wmdocklib.redraw()
time.sleep(0.1)
@@ -378,17 +378,17 @@ def parseColors(defaultRGBFileNames, config, xpm):
for key, value in colors:
col = config.get(key)
if not col is None:
code = pywmhelpers.getColorCode(col, rgbFileName)
code = wmdocklib.getColorCode(col, rgbFileName)
if code is None:
sys.stderr.write('Bad colorcode for %s, ignoring.\n' % key)
else:
pywmhelpers.setColor(xpm, value, code)
wmdocklib.setColor(xpm, value, code)
def main():
clConfig = parseCommandLine(sys.argv)
configFile = clConfig.get('configfile', defaultConfigFile)
configFile = os.path.expanduser(configFile)
fileConfig = pywmhelpers.readConfigFile(configFile, sys.stderr)
fileConfig = wmdocklib.readConfigFile(configFile, sys.stderr)
# Merge the two configs, let the commandline options overwrite those in the
# configuration file.
config = fileConfig
@@ -423,9 +423,9 @@ def main():
except IndexError:
programName = ''
sys.argv[0] = programName
pywmhelpers.setDefaultPixmap(xpm)
pywmhelpers.openXwindow(sys.argv, width, height)
pywmhelpers.addMouseRegion(0, xOffset, yOffset, width - 2 * xOffset,
wmdocklib.setDefaultPixmap(xpm)
wmdocklib.openXwindow(sys.argv, width, height)
wmdocklib.addMouseRegion(0, xOffset, yOffset, width - 2 * xOffset,
height - 2 * yOffset)
pwms = PywmSeti(statePath, uinfoPath, pidPath, execCmd)
pwms.mainLoop()

View File

@@ -1,6 +1,6 @@
#! /usr/bin/env python
'''pywmsysmon.py
"""pywmsysmon.py
WindowMaker system monitor dockapp written in Python. It displays your CPU
usage and your available/used memory.
@@ -15,8 +15,8 @@ Fixed a bug which caused infinite loop if the mouse was clicked
2003-06-24 Kristoffer Erlandsson
First working version
'''
usage='''pywmsysmon.py [options]
"""
usage="""pywmsysmon.py [options]
Available options are:
-h, --help print this help
-f, --barfgcolor <color> set the foreground color of the memory bar
@@ -29,14 +29,14 @@ Available options are:
-m, --procmeminfo <file> set the location of /proc/meminfo
-i, --ignorenice ignore nice valued cpu usage
-u, --updatedelay <value> delay (in seconds) between cpu graph updates
'''
"""
import sys
import time
import getopt
import os
from pywmgeneral import pywmhelpers
from pywmgeneral import wmdocklib
width = 64
height = 64
@@ -103,10 +103,10 @@ class PywmSysMon:
self._usageHistory.append(cpuUsage)
def getMemInfo(self):
'''Get memory information.
"""Get memory information.
Return a tuple with (total_mem, used_mem, buffered_mem, cached_mem).
'''
"""
try:
meminfoFile = file(self._procMeminfo, 'r')
except IOError, e:
@@ -125,19 +125,19 @@ class PywmSysMon:
return (total, used, buffers, cached)
def freeMem(self, memData):
'''Take a tuple as returned from getMemInfo and return the free mem.
'''
"""Take a tuple as returned from getMemInfo and return the free mem.
"""
total, used, buffers, cached = memData
reallyUsed = used - buffers - cached
free = total - reallyUsed
return free
def getCPUUsage(self):
'''Get the current CPU usage.
"""Get the current CPU usage.
Only works for systems where this can be found in a /proc/stat like
file. Return the usage in percent.
'''
"""
try:
statFile = file(self._procStat, 'r')
except IOError, e:
@@ -161,7 +161,7 @@ class PywmSysMon:
def addString(self, s, x, y):
try:
pywmhelpers.addString(s, x, y, letterWidth, letterHeight,
wmdocklib.addString(s, x, y, letterWidth, letterHeight,
lettersStartX, lettersStartY, letters, digitWidth,
digitHeight, digitsStartX, digitsStartY, digits,
xOffset, yOffset, width, height)
@@ -170,29 +170,29 @@ class PywmSysMon:
sys.exit(3)
def paintGraph(self, percentFilled, x, y, w):
'''Paint a graph with percentFilled percent filled.
"""Paint a graph with percentFilled percent filled.
Paint at position x, y and with width w.
'''
"""
paintWidth = int(round(percentFilled/100.0 * w))
if paintWidth > 0:
pywmhelpers.copyXPMArea(
wmdocklib.copyXPMArea(
hGraphLineStartX, hGraphLineStartY, paintWidth, hGraphHeight,
x, y)
if w - paintWidth > 0:
pywmhelpers.copyXPMArea(
wmdocklib.copyXPMArea(
hGraphBgStartX, hGraphBgStartY, w - paintWidth, hGraphHeight,
x + paintWidth, y)
def drawVertLine(self, sourceX, sourceY, targX, targY, length):
'''Draw a vertical line.
'''
"""Draw a vertical line.
"""
if length > 0:
pywmhelpers.copyXPMArea(sourceX, sourceY, 1, length, targX, targY)
wmdocklib.copyXPMArea(sourceX, sourceY, 1, length, targX, targY)
def drawCPUUsageHistory(self):
'''Draw the complete CPU usage graph according to what's in the history.
'''
"""Draw the complete CPU usage graph according to what's in the history.
"""
count = 0
for histItem in self._usageHistory:
lengthFilled = int(round(vGraphHeight * (histItem/100.0)))
@@ -206,13 +206,13 @@ class PywmSysMon:
count += 1
def updateCPUInfo(self):
'''Update the current cpu usage graph.'''
"""Update the current cpu usage graph."""
currentUsage = self.getCPUUsage()
self.addUsageToHist(currentUsage)
self.drawCPUUsageHistory()
def updateMemInfo(self):
'''Update the current memory usage graph.'''
"""Update the current memory usage graph."""
memInfo = self.getMemInfo()
total = memInfo[0]
free = self.freeMem(memInfo)
@@ -220,11 +220,11 @@ class PywmSysMon:
self.paintGraph(percentUsed, hGraphStartX, hGraphStartY, hGraphWidth)
def _checkForEvents(self):
event = pywmhelpers.getEvent()
event = wmdocklib.getEvent()
while not event is None:
if event['type'] == 'destroynotify':
sys.exit(0)
event = pywmhelpers.getEvent()
event = wmdocklib.getEvent()
def mainLoop(self):
counter = -1
@@ -237,11 +237,11 @@ class PywmSysMon:
self.updateMemInfo()
if counter == 999999:
counter = -1
pywmhelpers.redraw()
wmdocklib.redraw()
time.sleep(0.1)
def parseCommandLine(argv):
'''Parse the commandline. Return a dictionary with options and values.'''
"""Parse the commandline. Return a dictionary with options and values."""
shorts = 'hf:g:b:p:a:r:s:m:iu:'
longs = ['help=', 'barbgcolor=', 'barfgcolor=', 'background=',
'graphforeground=', 'graphbackground=', 'rgbfile=', 'procstat=',
@@ -308,11 +308,11 @@ def parseColors(defaultRGBFileList, config, xpm):
for key, value in colors:
col = config.get(key)
if not col is None:
code = pywmhelpers.getColorCode(col, rgbFileName)
code = wmdocklib.getColorCode(col, rgbFileName)
if code is None:
sys.stderr.write('Bad colorcode for %s, ignoring.\n' % key)
else:
pywmhelpers.setColor(xpm, value, code)
wmdocklib.setColor(xpm, value, code)
@@ -336,8 +336,8 @@ def main():
except IndexError:
programName = ''
sys.argv[0] = programName
pywmhelpers.setDefaultPixmap(xpm)
pywmhelpers.openXwindow(sys.argv, width, height)
wmdocklib.setDefaultPixmap(xpm)
wmdocklib.openXwindow(sys.argv, width, height)
pywmsysmon = PywmSysMon(procMeminfo, procStat, ignoreNice, updateDelay)
pywmsysmon.mainLoop()