[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Perlpanel-devel] New Applet: CPUFreq
From: |
James Mitchell |
Subject: |
[Perlpanel-devel] New Applet: CPUFreq |
Date: |
Wed, 29 Sep 2004 12:09:15 -0500 |
User-agent: |
Mozilla Thunderbird 0.8 (X11/20040913) |
This is a quicky applet to read the CPU Frequency from the Linux 2.6
sysfs interface (other interfaces left as an exercise to those who
care). It's largely lifted from the CPUTemp applet.
--- PerlPanel-0.8.0/lib/PerlPanel/Applet/CPUFreq.pm 1969-12-31
18:00:00.000000000 -0600
+++ PerlPanel-James/lib/PerlPanel/Applet/CPUFreq.pm 2004-09-29
12:04:16.000000000 -0500
@@ -0,0 +1,83 @@
+# PerlPanel is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# PerlPanel is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with PerlPanel; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# Mostly borrowed from CPUTemp.pm
+# Copyright: (C) 2003-2004 Gavin Brown <address@hidden>
+# Changed to Linux 2.6 CPU Frequency interface
+# 2004 James Mitchell <address@hidden>
+#
+package PerlPanel::Applet::CPUFreq;
+use strict;
+
+sub new {
+ my $self = {};
+ $self->{package} = shift;
+ bless($self, $self->{package});
+ return $self;
+}
+
+sub configure {
+ my $self = shift;
+ $self->{config} = PerlPanel::get_config('CPUFreq');
+ $self->{widget} = Gtk2::EventBox->new;
+
+ $self->{label}= Gtk2::Label->new();
+ $self->{widget}->add($self->{label});
+
+ PerlPanel::tips->set_tip($self->{widget}, _('CPU Frequency'));
+ $self->{widget}->set_size_request(84, -1);
+
+ $self->widget->show_all;
+
+ $self->update;
+ Glib::Timeout->add(1000, sub { $self->update });
+ return 1;
+
+}
+
+sub update {
+ my $self = shift;
+ open(LOADAVG, '/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq')
or PerlPanel::error(_("Couldn't open
'/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq': {error}", error =>
$!), sub { exit }) and return undef;
+ chomp(my $data = <LOADAVG>);
+ close(LOADAVG);
+ my $freq = $data/1000;
+ if ($freq > 1000) {
+ $freq = $freq / 1000;
+ $freq = sprintf("%.2f GHZ", $freq);
+ } else {
+ $freq = sprintf("%d MHZ", $freq);
+ }
+ $self->{label}->set_text($freq);
+ return 1;
+}
+
+sub widget {
+ return $_[0]->{widget};
+}
+
+sub expand {
+ return 0;
+}
+
+sub fill {
+ return 0;
+}
+
+sub get_default_config {
+ return {
+ show_icon => 'true',
+ };
+}
+
+1;
--- PerlPanel-0.8.0/share/perlpanel/applet.registry 2004-09-20
11:08:02.000000000 -0500
+++ PerlPanel-James/share/perlpanel/applet.registry 2004-09-29
11:43:18.000000000 -0500
@@ -15,6 +15,7 @@
Commander:A button to show a command dialog.:Launchers
Configurator:A comprehensive configuration dialog.:Utilitiies
CPUTemp:Shows the temperature of your computer's CPU.:System
+CPUFreq:Shows the frequency of your computer's CPU.:System
GnomeMenu:Your GNOME Menu.:Menus
# DEPRECATED IN 0.8.0: IconBar:Shows launcher icons on the panel.:Launchers
Launcher:Shows a single launcher icon on the panel.:Launchers
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Perlpanel-devel] New Applet: CPUFreq,
James Mitchell <=