-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First track CpuFreqDisplay
- Loading branch information
0 parents
commit e072c2e
Showing
4 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*~ | ||
*.swp | ||
*.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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~ .* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |