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:
@@ -47,7 +47,7 @@ import time
|
|||||||
import getopt
|
import getopt
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from pywmgeneral import pywmhelpers
|
import wmdocklib
|
||||||
|
|
||||||
width = 64
|
width = 64
|
||||||
height = 64
|
height = 64
|
||||||
@@ -79,7 +79,7 @@ maxCharsPerLine = 9
|
|||||||
|
|
||||||
def addString(s, x, y):
|
def addString(s, x, y):
|
||||||
try:
|
try:
|
||||||
pywmhelpers.addString(s, x, y, letterWidth, letterHeight, lettersStartX,
|
wmdocklib.addString(s, x, y, letterWidth, letterHeight, lettersStartX,
|
||||||
lettersStartY, letters, digitWidth, digitHeight,
|
lettersStartY, letters, digitWidth, digitHeight,
|
||||||
digitsStartX, digitsStartY, digits, xOffset, yOffset,
|
digitsStartX, digitsStartY, digits, xOffset, yOffset,
|
||||||
width, height)
|
width, height)
|
||||||
@@ -89,14 +89,14 @@ def addString(s, x, y):
|
|||||||
|
|
||||||
def clearLine(y):
|
def clearLine(y):
|
||||||
'''Clear a line of text at position 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)
|
xOffset, y + yOffset)
|
||||||
|
|
||||||
def getCenterStartPos(s):
|
def getCenterStartPos(s):
|
||||||
return pywmhelpers.getCenterStartPos(s, letterWidth, width, xOffset)
|
return wmdocklib.getCenterStartPos(s, letterWidth, width, xOffset)
|
||||||
|
|
||||||
def getVertSpacing(numLines, margin):
|
def getVertSpacing(numLines, margin):
|
||||||
return pywmhelpers.getVertSpacing(numLines, margin, height, letterHeight,
|
return wmdocklib.getVertSpacing(numLines, margin, height, letterHeight,
|
||||||
yOffset)
|
yOffset)
|
||||||
|
|
||||||
def calculateWeek(localTime):
|
def calculateWeek(localTime):
|
||||||
@@ -147,11 +147,11 @@ def parseCommandLine(argv):
|
|||||||
return d
|
return d
|
||||||
|
|
||||||
def checkForEvents():
|
def checkForEvents():
|
||||||
event = pywmhelpers.getEvent()
|
event = wmdocklib.getEvent()
|
||||||
while not event is None:
|
while not event is None:
|
||||||
if event['type'] == 'destroynotify':
|
if event['type'] == 'destroynotify':
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
event = pywmhelpers.getEvent()
|
event = wmdocklib.getEvent()
|
||||||
|
|
||||||
def mainLoop(timeFmt, dateFmt, dayFmt, weekFmt):
|
def mainLoop(timeFmt, dateFmt, dayFmt, weekFmt):
|
||||||
recalcWeek = weekFmt.find('%q') + 1 # True if we found %q.
|
recalcWeek = weekFmt.find('%q') + 1 # True if we found %q.
|
||||||
@@ -197,7 +197,7 @@ def mainLoop(timeFmt, dateFmt, dayFmt, weekFmt):
|
|||||||
lastStrs[3] = weekStr
|
lastStrs[3] = weekStr
|
||||||
if counter == 999999:
|
if counter == 999999:
|
||||||
counter = -1
|
counter = -1
|
||||||
pywmhelpers.redraw()
|
wmdocklib.redraw()
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
def parseColors(defaultRGBFileNames, config, xpm):
|
def parseColors(defaultRGBFileNames, config, xpm):
|
||||||
@@ -221,17 +221,17 @@ def parseColors(defaultRGBFileNames, config, xpm):
|
|||||||
for key, value in colors:
|
for key, value in colors:
|
||||||
col = config.get(key)
|
col = config.get(key)
|
||||||
if not col is None:
|
if not col is None:
|
||||||
code = pywmhelpers.getColorCode(col, rgbFileName)
|
code = wmdocklib.getColorCode(col, rgbFileName)
|
||||||
if code is None:
|
if code is None:
|
||||||
sys.stderr.write('Bad colorcode for %s, ignoring.\n' % key)
|
sys.stderr.write('Bad colorcode for %s, ignoring.\n' % key)
|
||||||
else:
|
else:
|
||||||
pywmhelpers.setColor(xpm, value, code)
|
wmdocklib.setColor(xpm, value, code)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
clConfig = parseCommandLine(sys.argv)
|
clConfig = parseCommandLine(sys.argv)
|
||||||
configFile = clConfig.get('configfile', defaultConfigFile)
|
configFile = clConfig.get('configfile', defaultConfigFile)
|
||||||
configFile = os.path.expanduser(configFile)
|
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
|
# Merge the two configs, let the commandline options overwrite those in the
|
||||||
# configuration file.
|
# configuration file.
|
||||||
config = fileConfig
|
config = fileConfig
|
||||||
@@ -239,7 +239,7 @@ def main():
|
|||||||
config[i[0]] = i[1]
|
config[i[0]] = i[1]
|
||||||
|
|
||||||
parseColors(defaultRGBFiles, config, xpm)
|
parseColors(defaultRGBFiles, config, xpm)
|
||||||
pywmhelpers.setDefaultPixmap(xpm)
|
wmdocklib.setDefaultPixmap(xpm)
|
||||||
timeFmt = config.get('timeformat', timeDefaultFormat)
|
timeFmt = config.get('timeformat', timeDefaultFormat)
|
||||||
dateFmt = config.get('dateformat', dateDefaultFormat)
|
dateFmt = config.get('dateformat', dateDefaultFormat)
|
||||||
dayFmt = config.get('weekdayformat', dayDefaultFormat)
|
dayFmt = config.get('weekdayformat', dayDefaultFormat)
|
||||||
@@ -252,7 +252,7 @@ def main():
|
|||||||
except IndexError: # Should only happen when using the interpreter.
|
except IndexError: # Should only happen when using the interpreter.
|
||||||
programName = ''
|
programName = ''
|
||||||
sys.argv[0] = programName
|
sys.argv[0] = programName
|
||||||
pywmhelpers.openXwindow(sys.argv, width, height)
|
wmdocklib.openXwindow(sys.argv, width, height)
|
||||||
mainLoop(timeFmt, dateFmt, dayFmt, weekFmt)
|
mainLoop(timeFmt, dateFmt, dayFmt, weekFmt)
|
||||||
|
|
||||||
xpm = \
|
xpm = \
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ import ConfigParser
|
|||||||
import getopt
|
import getopt
|
||||||
import popen2
|
import popen2
|
||||||
|
|
||||||
from pywmgeneral import pywmhelpers
|
import wmdocklib
|
||||||
|
|
||||||
prevStat = {'user':0,
|
prevStat = {'user':0,
|
||||||
'nice':0,
|
'nice':0,
|
||||||
@@ -160,7 +160,7 @@ err = sys.stderr.write
|
|||||||
def addString(s, x, y):
|
def addString(s, x, y):
|
||||||
'''Convenience function around pwymhelpers.addString.'''
|
'''Convenience function around pwymhelpers.addString.'''
|
||||||
try:
|
try:
|
||||||
pywmhelpers.addString(s, x, y, letterWidth, letterHeight, lettersStartX,
|
wmdocklib.addString(s, x, y, letterWidth, letterHeight, lettersStartX,
|
||||||
lettersStartY, letters, digitWidth, digitHeight,
|
lettersStartY, letters, digitWidth, digitHeight,
|
||||||
digitsStartX, digitsStartY, digits, xOffset, yOffset,
|
digitsStartX, digitsStartY, digits, xOffset, yOffset,
|
||||||
width, height)
|
width, height)
|
||||||
@@ -170,7 +170,7 @@ def addString(s, x, y):
|
|||||||
|
|
||||||
def clearLine(y):
|
def clearLine(y):
|
||||||
'''Clear a line of text at position 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)
|
xOffset, y + yOffset)
|
||||||
|
|
||||||
def getXY(line):
|
def getXY(line):
|
||||||
@@ -482,7 +482,7 @@ class PywmGeneric:
|
|||||||
for i in range(5):
|
for i in range(5):
|
||||||
x, y = getXY(i)
|
x, y = getXY(i)
|
||||||
if not self._entrys[i] is None:
|
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)
|
width - 2 * xOffset, y + yOffset + letterHeight)
|
||||||
|
|
||||||
def parseTimeStr(self, timeStr):
|
def parseTimeStr(self, timeStr):
|
||||||
@@ -502,17 +502,17 @@ class PywmGeneric:
|
|||||||
raise ValueError, 'Invalid literal'
|
raise ValueError, 'Invalid literal'
|
||||||
|
|
||||||
def _checkForEvents(self):
|
def _checkForEvents(self):
|
||||||
event = pywmhelpers.getEvent()
|
event = wmdocklib.getEvent()
|
||||||
while not event is None:
|
while not event is None:
|
||||||
if event['type'] == 'destroynotify':
|
if event['type'] == 'destroynotify':
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
elif event['type'] == 'buttonrelease':
|
elif event['type'] == 'buttonrelease':
|
||||||
region = pywmhelpers.checkMouseRegion(event['x'], event['y'])
|
region = wmdocklib.checkMouseRegion(event['x'], event['y'])
|
||||||
button = event['button']
|
button = event['button']
|
||||||
if region != -1:
|
if region != -1:
|
||||||
if not self._entrys[region] is None:
|
if not self._entrys[region] is None:
|
||||||
self._entrys[region].mouseClicked(button)
|
self._entrys[region].mouseClicked(button)
|
||||||
event = pywmhelpers.getEvent()
|
event = wmdocklib.getEvent()
|
||||||
|
|
||||||
def mainLoop(self):
|
def mainLoop(self):
|
||||||
counter = -1
|
counter = -1
|
||||||
@@ -526,7 +526,7 @@ class PywmGeneric:
|
|||||||
|
|
||||||
if counter == 999999:
|
if counter == 999999:
|
||||||
counter = -1
|
counter = -1
|
||||||
pywmhelpers.redraw()
|
wmdocklib.redraw()
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
|
|
||||||
def parseCommandLine(argv):
|
def parseCommandLine(argv):
|
||||||
@@ -577,11 +577,11 @@ def parseColors(defaultRGBFileList, config, xpm):
|
|||||||
for key, value in colors:
|
for key, value in colors:
|
||||||
col = config.get(key)
|
col = config.get(key)
|
||||||
if not col is None:
|
if not col is None:
|
||||||
code = pywmhelpers.getColorCode(col, rgbFileName)
|
code = wmdocklib.getColorCode(col, rgbFileName)
|
||||||
if code is None:
|
if code is None:
|
||||||
err('Bad colorcode for %s, ignoring.\n' % key)
|
err('Bad colorcode for %s, ignoring.\n' % key)
|
||||||
else:
|
else:
|
||||||
pywmhelpers.setColor(xpm, value, code)
|
wmdocklib.setColor(xpm, value, code)
|
||||||
|
|
||||||
def readConfigFile(fileName):
|
def readConfigFile(fileName):
|
||||||
'''Read the config file.
|
'''Read the config file.
|
||||||
@@ -622,8 +622,8 @@ def main():
|
|||||||
except IndexError:
|
except IndexError:
|
||||||
programName = ''
|
programName = ''
|
||||||
sys.argv[0] = programName
|
sys.argv[0] = programName
|
||||||
pywmhelpers.setDefaultPixmap(xpm)
|
wmdocklib.setDefaultPixmap(xpm)
|
||||||
pywmhelpers.openXwindow(sys.argv, width, height)
|
wmdocklib.openXwindow(sys.argv, width, height)
|
||||||
pywmgeneric = PywmGeneric(config)
|
pywmgeneric = PywmGeneric(config)
|
||||||
pywmgeneric.mainLoop()
|
pywmgeneric.mainLoop()
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ import time
|
|||||||
import getopt
|
import getopt
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from pywmgeneral import pywmhelpers
|
import wmdocklib
|
||||||
|
|
||||||
width = 64
|
width = 64
|
||||||
height = 64
|
height = 64
|
||||||
@@ -96,7 +96,7 @@ class PywmSeti:
|
|||||||
|
|
||||||
def addString(self, s, x, y):
|
def addString(self, s, x, y):
|
||||||
try:
|
try:
|
||||||
pywmhelpers.addString(s, x, y, letterWidth, letterHeight,
|
wmdocklib.addString(s, x, y, letterWidth, letterHeight,
|
||||||
lettersStartX, lettersStartY, letters, digitWidth,
|
lettersStartX, lettersStartY, letters, digitWidth,
|
||||||
digitHeight, digitsStartX, digitsStartY, digits,
|
digitHeight, digitsStartX, digitsStartY, digits,
|
||||||
xOffset, yOffset, width, height)
|
xOffset, yOffset, width, height)
|
||||||
@@ -105,10 +105,10 @@ class PywmSeti:
|
|||||||
sys.exit(3)
|
sys.exit(3)
|
||||||
|
|
||||||
def getCenterStartPos(self, s):
|
def getCenterStartPos(self, s):
|
||||||
return pywmhelpers.getCenterStartPos(s, letterWidth, width, xOffset)
|
return wmdocklib.getCenterStartPos(s, letterWidth, width, xOffset)
|
||||||
|
|
||||||
def getVertSpacing(self, numLines, margin):
|
def getVertSpacing(self, numLines, margin):
|
||||||
return pywmhelpers.getVertSpacing(numLines, margin, height,
|
return wmdocklib.getVertSpacing(numLines, margin, height,
|
||||||
letterHeight, yOffset)
|
letterHeight, yOffset)
|
||||||
|
|
||||||
def getProgress(self, lines):
|
def getProgress(self, lines):
|
||||||
@@ -178,7 +178,7 @@ class PywmSeti:
|
|||||||
h = runningIndHeight
|
h = runningIndHeight
|
||||||
targX = width - xOffset - w - 5
|
targX = width - xOffset - w - 5
|
||||||
targY = yOffset + 5
|
targY = yOffset + 5
|
||||||
pywmhelpers.copyXPMArea(indX, indY, w, h, targX, targY)
|
wmdocklib.copyXPMArea(indX, indY, w, h, targX, targY)
|
||||||
|
|
||||||
def updateRunning(self):
|
def updateRunning(self):
|
||||||
'''Update the information regarding if we got seti@home running or not.
|
'''Update the information regarding if we got seti@home running or not.
|
||||||
@@ -233,10 +233,10 @@ class PywmSeti:
|
|||||||
self._progress = progress
|
self._progress = progress
|
||||||
percent = int(progress * 100.0)
|
percent = int(progress * 100.0)
|
||||||
graphSize = int(round(progress * graphLength))
|
graphSize = int(round(progress * graphLength))
|
||||||
pywmhelpers.copyXPMArea(
|
wmdocklib.copyXPMArea(
|
||||||
graphLineStartX, graphLineStartY, graphSize, graphHeight,
|
graphLineStartX, graphLineStartY, graphSize, graphHeight,
|
||||||
graphStartX, graphStartY)
|
graphStartX, graphStartY)
|
||||||
pywmhelpers.copyXPMArea(
|
wmdocklib.copyXPMArea(
|
||||||
graphBgStartX, graphBgStartY, graphLength - graphSize, graphHeight,
|
graphBgStartX, graphBgStartY, graphLength - graphSize, graphHeight,
|
||||||
graphStartX + graphSize, graphStartY)
|
graphStartX + graphSize, graphStartY)
|
||||||
self.addString((str(percent) + '%').ljust(4), 4, 32)
|
self.addString((str(percent) + '%').ljust(4), 4, 32)
|
||||||
@@ -289,15 +289,15 @@ class PywmSeti:
|
|||||||
|
|
||||||
def _checkForEvents(self):
|
def _checkForEvents(self):
|
||||||
'''Check for, and handle, X events.'''
|
'''Check for, and handle, X events.'''
|
||||||
event = pywmhelpers.getEvent()
|
event = wmdocklib.getEvent()
|
||||||
while not event is None:
|
while not event is None:
|
||||||
if event['type'] == 'buttonrelease':
|
if event['type'] == 'buttonrelease':
|
||||||
region = pywmhelpers.checkMouseRegion(event['x'],
|
region = wmdocklib.checkMouseRegion(event['x'],
|
||||||
event['y'])
|
event['y'])
|
||||||
self.handleMouseClick(region)
|
self.handleMouseClick(region)
|
||||||
elif event['type'] == 'destroynotify':
|
elif event['type'] == 'destroynotify':
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
event = pywmhelpers.getEvent()
|
event = wmdocklib.getEvent()
|
||||||
|
|
||||||
def mainLoop(self):
|
def mainLoop(self):
|
||||||
counter = -1
|
counter = -1
|
||||||
@@ -313,7 +313,7 @@ class PywmSeti:
|
|||||||
self.updateTime()
|
self.updateTime()
|
||||||
if counter == 999999:
|
if counter == 999999:
|
||||||
counter = -1
|
counter = -1
|
||||||
pywmhelpers.redraw()
|
wmdocklib.redraw()
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
|
||||||
@@ -378,17 +378,17 @@ def parseColors(defaultRGBFileNames, config, xpm):
|
|||||||
for key, value in colors:
|
for key, value in colors:
|
||||||
col = config.get(key)
|
col = config.get(key)
|
||||||
if not col is None:
|
if not col is None:
|
||||||
code = pywmhelpers.getColorCode(col, rgbFileName)
|
code = wmdocklib.getColorCode(col, rgbFileName)
|
||||||
if code is None:
|
if code is None:
|
||||||
sys.stderr.write('Bad colorcode for %s, ignoring.\n' % key)
|
sys.stderr.write('Bad colorcode for %s, ignoring.\n' % key)
|
||||||
else:
|
else:
|
||||||
pywmhelpers.setColor(xpm, value, code)
|
wmdocklib.setColor(xpm, value, code)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
clConfig = parseCommandLine(sys.argv)
|
clConfig = parseCommandLine(sys.argv)
|
||||||
configFile = clConfig.get('configfile', defaultConfigFile)
|
configFile = clConfig.get('configfile', defaultConfigFile)
|
||||||
configFile = os.path.expanduser(configFile)
|
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
|
# Merge the two configs, let the commandline options overwrite those in the
|
||||||
# configuration file.
|
# configuration file.
|
||||||
config = fileConfig
|
config = fileConfig
|
||||||
@@ -423,9 +423,9 @@ def main():
|
|||||||
except IndexError:
|
except IndexError:
|
||||||
programName = ''
|
programName = ''
|
||||||
sys.argv[0] = programName
|
sys.argv[0] = programName
|
||||||
pywmhelpers.setDefaultPixmap(xpm)
|
wmdocklib.setDefaultPixmap(xpm)
|
||||||
pywmhelpers.openXwindow(sys.argv, width, height)
|
wmdocklib.openXwindow(sys.argv, width, height)
|
||||||
pywmhelpers.addMouseRegion(0, xOffset, yOffset, width - 2 * xOffset,
|
wmdocklib.addMouseRegion(0, xOffset, yOffset, width - 2 * xOffset,
|
||||||
height - 2 * yOffset)
|
height - 2 * yOffset)
|
||||||
pwms = PywmSeti(statePath, uinfoPath, pidPath, execCmd)
|
pwms = PywmSeti(statePath, uinfoPath, pidPath, execCmd)
|
||||||
pwms.mainLoop()
|
pwms.mainLoop()
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#! /usr/bin/env python
|
#! /usr/bin/env python
|
||||||
|
|
||||||
'''pywmsysmon.py
|
"""pywmsysmon.py
|
||||||
|
|
||||||
WindowMaker system monitor dockapp written in Python. It displays your CPU
|
WindowMaker system monitor dockapp written in Python. It displays your CPU
|
||||||
usage and your available/used memory.
|
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
|
2003-06-24 Kristoffer Erlandsson
|
||||||
First working version
|
First working version
|
||||||
'''
|
"""
|
||||||
usage='''pywmsysmon.py [options]
|
usage="""pywmsysmon.py [options]
|
||||||
Available options are:
|
Available options are:
|
||||||
-h, --help print this help
|
-h, --help print this help
|
||||||
-f, --barfgcolor <color> set the foreground color of the memory bar
|
-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
|
-m, --procmeminfo <file> set the location of /proc/meminfo
|
||||||
-i, --ignorenice ignore nice valued cpu usage
|
-i, --ignorenice ignore nice valued cpu usage
|
||||||
-u, --updatedelay <value> delay (in seconds) between cpu graph updates
|
-u, --updatedelay <value> delay (in seconds) between cpu graph updates
|
||||||
'''
|
"""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import getopt
|
import getopt
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from pywmgeneral import pywmhelpers
|
from pywmgeneral import wmdocklib
|
||||||
|
|
||||||
width = 64
|
width = 64
|
||||||
height = 64
|
height = 64
|
||||||
@@ -103,10 +103,10 @@ class PywmSysMon:
|
|||||||
self._usageHistory.append(cpuUsage)
|
self._usageHistory.append(cpuUsage)
|
||||||
|
|
||||||
def getMemInfo(self):
|
def getMemInfo(self):
|
||||||
'''Get memory information.
|
"""Get memory information.
|
||||||
|
|
||||||
Return a tuple with (total_mem, used_mem, buffered_mem, cached_mem).
|
Return a tuple with (total_mem, used_mem, buffered_mem, cached_mem).
|
||||||
'''
|
"""
|
||||||
try:
|
try:
|
||||||
meminfoFile = file(self._procMeminfo, 'r')
|
meminfoFile = file(self._procMeminfo, 'r')
|
||||||
except IOError, e:
|
except IOError, e:
|
||||||
@@ -125,19 +125,19 @@ class PywmSysMon:
|
|||||||
return (total, used, buffers, cached)
|
return (total, used, buffers, cached)
|
||||||
|
|
||||||
def freeMem(self, memData):
|
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
|
total, used, buffers, cached = memData
|
||||||
reallyUsed = used - buffers - cached
|
reallyUsed = used - buffers - cached
|
||||||
free = total - reallyUsed
|
free = total - reallyUsed
|
||||||
return free
|
return free
|
||||||
|
|
||||||
def getCPUUsage(self):
|
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
|
Only works for systems where this can be found in a /proc/stat like
|
||||||
file. Return the usage in percent.
|
file. Return the usage in percent.
|
||||||
'''
|
"""
|
||||||
try:
|
try:
|
||||||
statFile = file(self._procStat, 'r')
|
statFile = file(self._procStat, 'r')
|
||||||
except IOError, e:
|
except IOError, e:
|
||||||
@@ -161,7 +161,7 @@ class PywmSysMon:
|
|||||||
|
|
||||||
def addString(self, s, x, y):
|
def addString(self, s, x, y):
|
||||||
try:
|
try:
|
||||||
pywmhelpers.addString(s, x, y, letterWidth, letterHeight,
|
wmdocklib.addString(s, x, y, letterWidth, letterHeight,
|
||||||
lettersStartX, lettersStartY, letters, digitWidth,
|
lettersStartX, lettersStartY, letters, digitWidth,
|
||||||
digitHeight, digitsStartX, digitsStartY, digits,
|
digitHeight, digitsStartX, digitsStartY, digits,
|
||||||
xOffset, yOffset, width, height)
|
xOffset, yOffset, width, height)
|
||||||
@@ -170,29 +170,29 @@ class PywmSysMon:
|
|||||||
sys.exit(3)
|
sys.exit(3)
|
||||||
|
|
||||||
def paintGraph(self, percentFilled, x, y, w):
|
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.
|
Paint at position x, y and with width w.
|
||||||
'''
|
"""
|
||||||
paintWidth = int(round(percentFilled/100.0 * w))
|
paintWidth = int(round(percentFilled/100.0 * w))
|
||||||
if paintWidth > 0:
|
if paintWidth > 0:
|
||||||
pywmhelpers.copyXPMArea(
|
wmdocklib.copyXPMArea(
|
||||||
hGraphLineStartX, hGraphLineStartY, paintWidth, hGraphHeight,
|
hGraphLineStartX, hGraphLineStartY, paintWidth, hGraphHeight,
|
||||||
x, y)
|
x, y)
|
||||||
if w - paintWidth > 0:
|
if w - paintWidth > 0:
|
||||||
pywmhelpers.copyXPMArea(
|
wmdocklib.copyXPMArea(
|
||||||
hGraphBgStartX, hGraphBgStartY, w - paintWidth, hGraphHeight,
|
hGraphBgStartX, hGraphBgStartY, w - paintWidth, hGraphHeight,
|
||||||
x + paintWidth, y)
|
x + paintWidth, y)
|
||||||
|
|
||||||
def drawVertLine(self, sourceX, sourceY, targX, targY, length):
|
def drawVertLine(self, sourceX, sourceY, targX, targY, length):
|
||||||
'''Draw a vertical line.
|
"""Draw a vertical line.
|
||||||
'''
|
"""
|
||||||
if length > 0:
|
if length > 0:
|
||||||
pywmhelpers.copyXPMArea(sourceX, sourceY, 1, length, targX, targY)
|
wmdocklib.copyXPMArea(sourceX, sourceY, 1, length, targX, targY)
|
||||||
|
|
||||||
def drawCPUUsageHistory(self):
|
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
|
count = 0
|
||||||
for histItem in self._usageHistory:
|
for histItem in self._usageHistory:
|
||||||
lengthFilled = int(round(vGraphHeight * (histItem/100.0)))
|
lengthFilled = int(round(vGraphHeight * (histItem/100.0)))
|
||||||
@@ -206,13 +206,13 @@ class PywmSysMon:
|
|||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
def updateCPUInfo(self):
|
def updateCPUInfo(self):
|
||||||
'''Update the current cpu usage graph.'''
|
"""Update the current cpu usage graph."""
|
||||||
currentUsage = self.getCPUUsage()
|
currentUsage = self.getCPUUsage()
|
||||||
self.addUsageToHist(currentUsage)
|
self.addUsageToHist(currentUsage)
|
||||||
self.drawCPUUsageHistory()
|
self.drawCPUUsageHistory()
|
||||||
|
|
||||||
def updateMemInfo(self):
|
def updateMemInfo(self):
|
||||||
'''Update the current memory usage graph.'''
|
"""Update the current memory usage graph."""
|
||||||
memInfo = self.getMemInfo()
|
memInfo = self.getMemInfo()
|
||||||
total = memInfo[0]
|
total = memInfo[0]
|
||||||
free = self.freeMem(memInfo)
|
free = self.freeMem(memInfo)
|
||||||
@@ -220,11 +220,11 @@ class PywmSysMon:
|
|||||||
self.paintGraph(percentUsed, hGraphStartX, hGraphStartY, hGraphWidth)
|
self.paintGraph(percentUsed, hGraphStartX, hGraphStartY, hGraphWidth)
|
||||||
|
|
||||||
def _checkForEvents(self):
|
def _checkForEvents(self):
|
||||||
event = pywmhelpers.getEvent()
|
event = wmdocklib.getEvent()
|
||||||
while not event is None:
|
while not event is None:
|
||||||
if event['type'] == 'destroynotify':
|
if event['type'] == 'destroynotify':
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
event = pywmhelpers.getEvent()
|
event = wmdocklib.getEvent()
|
||||||
|
|
||||||
def mainLoop(self):
|
def mainLoop(self):
|
||||||
counter = -1
|
counter = -1
|
||||||
@@ -237,11 +237,11 @@ class PywmSysMon:
|
|||||||
self.updateMemInfo()
|
self.updateMemInfo()
|
||||||
if counter == 999999:
|
if counter == 999999:
|
||||||
counter = -1
|
counter = -1
|
||||||
pywmhelpers.redraw()
|
wmdocklib.redraw()
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
def parseCommandLine(argv):
|
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:'
|
shorts = 'hf:g:b:p:a:r:s:m:iu:'
|
||||||
longs = ['help=', 'barbgcolor=', 'barfgcolor=', 'background=',
|
longs = ['help=', 'barbgcolor=', 'barfgcolor=', 'background=',
|
||||||
'graphforeground=', 'graphbackground=', 'rgbfile=', 'procstat=',
|
'graphforeground=', 'graphbackground=', 'rgbfile=', 'procstat=',
|
||||||
@@ -308,11 +308,11 @@ def parseColors(defaultRGBFileList, config, xpm):
|
|||||||
for key, value in colors:
|
for key, value in colors:
|
||||||
col = config.get(key)
|
col = config.get(key)
|
||||||
if not col is None:
|
if not col is None:
|
||||||
code = pywmhelpers.getColorCode(col, rgbFileName)
|
code = wmdocklib.getColorCode(col, rgbFileName)
|
||||||
if code is None:
|
if code is None:
|
||||||
sys.stderr.write('Bad colorcode for %s, ignoring.\n' % key)
|
sys.stderr.write('Bad colorcode for %s, ignoring.\n' % key)
|
||||||
else:
|
else:
|
||||||
pywmhelpers.setColor(xpm, value, code)
|
wmdocklib.setColor(xpm, value, code)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -336,8 +336,8 @@ def main():
|
|||||||
except IndexError:
|
except IndexError:
|
||||||
programName = ''
|
programName = ''
|
||||||
sys.argv[0] = programName
|
sys.argv[0] = programName
|
||||||
pywmhelpers.setDefaultPixmap(xpm)
|
wmdocklib.setDefaultPixmap(xpm)
|
||||||
pywmhelpers.openXwindow(sys.argv, width, height)
|
wmdocklib.openXwindow(sys.argv, width, height)
|
||||||
pywmsysmon = PywmSysMon(procMeminfo, procStat, ignoreNice, updateDelay)
|
pywmsysmon = PywmSysMon(procMeminfo, procStat, ignoreNice, updateDelay)
|
||||||
pywmsysmon.mainLoop()
|
pywmsysmon.mainLoop()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user