1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
3
# Copyright (C) 2010 Артём Попов <artfwo@gmail.com>
4
# This program is free software: you can redistribute it and/or modify it
5
# under the terms of the GNU General Public License version 3, as published
6
# by the Free Software Foundation.
8
# This program is distributed in the hope that it will be useful, but
9
# WITHOUT ANY WARRANTY; without even the implied warranties of
10
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11
# PURPOSE. See the GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License along
14
# with this program. If not, see <http://www.gnu.org/licenses/>.
18
# import multiprocessing
19
# multiprocessing.cpu_count()
28
from indicator_cpufreq import cpufreq
29
from indicator_cpufreq.indicator_cpufreqconfig import get_data_file
32
from gettext import gettext as _
33
#gettext.textdomain('indicator-cpufreq')
35
# FIXME: replace value with user-selectable unit
38
def readable_frequency(f):
39
return _("%s GHz") % locale.format(_("%.2f"), f / 1.0e6)
42
'conservative': _("Conservative"),
43
'ondemand': _("Ondemand"),
44
#'userspace': _("Userspace"),
45
'powersave': _("Powersave"),
46
'performance': _("Performance"),
49
def readable_governor(g):
50
if governor_names.has_key(g):
51
return governor_names[g]
55
class MyIndicator(appindicator.Indicator):
57
appindicator.Indicator.__init__(self, "indicator-cpufreq",
59
appindicator.CATEGORY_HARDWARE)
60
self.set_status(appindicator.STATUS_ACTIVE)
61
self.set_icon(get_data_file('media', 'indicator-cpufreq.png'))
64
self.select_items = {}
67
# frequency menu items
68
freqs = cpufreq.get_available_frequencies(FIXME_CPU)
70
menu_item = gtk.RadioMenuItem(group, readable_frequency(freq))
73
menu.append(menu_item)
74
menu_item.connect("activate", self.select_activated, 'frequency', freq)
75
self.select_items[freq] = menu_item
77
menu.append(gtk.SeparatorMenuItem())
80
governors = cpufreq.get_available_governors(FIXME_CPU)
81
for governor in governors:
82
if governor == 'userspace':
84
menu_item = gtk.RadioMenuItem(group, readable_governor(governor))
85
menu.append(menu_item)
86
menu_item.connect('activate', self.select_activated, 'governor', governor)
87
self.select_items[governor] = menu_item
93
gobject.timeout_add(1500, self.poll_timeout)
95
def poll_timeout(self):
100
for i in self.select_items.values():
101
i.handler_block_by_func(self.select_activated)
103
fmin, fmax, governor = cpufreq.get_policy(FIXME_CPU)
104
freq = cpufreq.get_freq_kernel(FIXME_CPU)
106
ratio = min([25, 50, 75, 100], key=lambda x: abs(x - (float(freq) / fmax * 100)))
107
if freq < fmax and ratio == 100:
110
self.set_icon(get_data_file('media', 'indicator-cpufreq-%d.png' % ratio))
112
if governor == 'userspace':
113
self.select_items[freq].set_active(True)
115
self.select_items[governor].set_active(True)
117
for i in self.select_items.values():
118
i.handler_unblock_by_func(self.select_activated)
120
#self.props.label = readable_frequency(freq)
122
def select_activated(self, menuitem, select, value):
124
bus = dbus.SystemBus()
125
proxy = bus.get_object("org.gnome.CPUFreqSelector",
126
"/org/gnome/cpufreq_selector/selector",
128
if select == 'frequency':
129
proxy.SetFrequency(dbus.UInt32(FIXME_CPU), dbus.UInt32(value),
130
dbus_interface='org.gnome.CPUFreqSelector')
132
proxy.SetGovernor(dbus.UInt32(FIXME_CPU), value,
133
dbus_interface='org.gnome.CPUFreqSelector')
138
gobject.type_register(MyIndicator)
140
if __name__ == "__main__":