Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
First track CpuFreqDisplay
  • Loading branch information
grissiom committed Mar 17, 2009
0 parents commit e072c2e
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*~
*.swp
*.zip
9 changes: 9 additions & 0 deletions CpuFreqDisplay/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

all: uninstall zipfile
plasmapkg -i ../CpuFreqDisplay.zip

uninstall:
plasmapkg -r CpuFreqDisplay

zipfile:metadata.desktop contents/code/main.py
zip -r ../CpuFreqDisplay.zip . -x *~ contents/code/main.py~ .*
69 changes: 69 additions & 0 deletions CpuFreqDisplay/contents/code/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Written by Grissiom chaos.proton@gmail.com

# This script is inspired by ruby-cpufreq plasmoid and released under GPL
# license. It noly goal is to display CPU frequency. If you want to do CPU
# scaling, try PowerDevil.

import subprocess as sp

from PyQt4.QtCore import QTimer, Qt, SIGNAL
#from PyQt4.QtGui import QFont

from PyKDE4.plasma import Plasma
from PyKDE4 import plasmascript

class CpuFreqDisplay(plasmascript.Applet):
def __init__(self, parent, args = None):
plasmascript.Applet.__init__(self, parent)

def init(self):
self.setHasConfigurationInterface(False)
self.setAspectRatioMode(Plasma.IgnoreAspectRatio)

# from plasmaengineexplorer, solidservice seems not working on my box.
# FIXME: What if the box is signal cored or cores with different frequency?
f = sp.Popen(["cat", "/sys/devices/system/cpu/cpu0/cpufreq/scaling_available_frequencies"],
close_fds = True, stdout = sp.PIPE).stdout
afreq = f.readlines()[0].split(' ')[:-1]# the last byte is '\n'
self.afreq = map(int, afreq)
self.afreq.sort()
self.update_freq()

self.timer = QTimer(self)
self.connect(self.timer, SIGNAL('timeout()'), self.update_freq)
self.timer.start(1000)

def update_freq(self):
f = sp.Popen(["cat", "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq"],
close_fds = True, stdout = sp.PIPE).stdout
self.cfreq = int(f.readlines()[0])

def paintInterface(self, p, option, rect):
p.save()
if self.cfreq == self.afreq[0]:
self.color = Qt.green
elif self.cfreq == self.afreq[-1]:
self.color = Qt.red
else:
self.color = Qt.yellow
if self.cfreq > 1000000:
text = "%dGHz" % (self.cfreq / 1000000.0)
else:
text = "%dMHz" % (self.cfreq / 1000.0)

# TODO:optimization should goes here
font = p.font()
ps = font.pixelSize()
p.setFont(font)
while p.boundingRect(rect, Qt.AlignTop | Qt.AlignLeft, text).width() < rect.width()\
and p.boundingRect(rect, Qt.AlignTop | Qt.AlignLeft, text).height() < rect.height():
ps += 1
font.setPixelSize(ps)
p.setFont(font)

p.setPen(self.color)
p.drawText(rect, Qt.AlignTop | Qt.AlignLeft, text)
p.restore()

def CreateApplet(p):
return CpuFreqDisplay(p)
17 changes: 17 additions & 0 deletions CpuFreqDisplay/metadata.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[Desktop Entry]
Encoding=UTF-8
Name=CpuFreqDisplay
Type=Service
ServiceTypes=Plasma/Applet

X-Plasma-API=python
X-Plasma-MainScript=code/main.py
X-KDE-PluginInfo-Author=Grissiom
X-KDE-PluginInfo-Email=chaos.proton@gmail.com
X-KDE-PluginInfo-Name=CpuFreqDisplay
X-KDE-PluginInfo-Version=0.01
X-KDE-PluginInfo-Website=http://plasma.kde.org/
X-KDE-PluginInfo-Category=Examples
X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=true

0 comments on commit e072c2e

Please sign in to comment.