~artfwo/indicator-cpufreq/trunk

« back to all changes in this revision

Viewing changes to indicator_cpufreq/indicator.py

  • Committer: Artem Popov
  • Date: 2013-01-25 14:15:03 UTC
  • Revision ID: artfwo@ubuntu.com-20130125141503-wg4wb2x0yowu1gs5
* Finally a working Python3 port.
* Drop remaining stuff from Quickly, use vanilla distutils-extra.
* Bugfixes:
    - LP: #1008438.
    - LP: #1079864.
* Transliterate copyright info.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2
2
#
3
 
# Copyright (C) 2010 Артём Попов <artfwo@gmail.com>
 
3
# Copyright (C) 2010 Artem Popov <artfwo@gmail.com>
4
4
# This program is free software: you can redistribute it and/or modify it 
5
5
# under the terms of the GNU General Public License version 3, as published 
6
6
# by the Free Software Foundation.
24
24
import dbus
25
25
 
26
26
from indicator_cpufreq import cpufreq
27
 
from indicator_cpufreq.indicator_cpufreqconfig import get_data_file, get_icon_path
28
27
 
29
28
import gettext
30
29
from gettext import gettext as _
42
41
}
43
42
 
44
43
def readable_governor(g):
45
 
    if governor_names.has_key(g):
 
44
    if g in governor_names:
46
45
        return governor_names[g]
47
46
    else:
48
47
        return g
69
68
        self.cpus = range(maxcpu)
70
69
        
71
70
        # frequency menu items
72
 
        freqs = cpufreq.get_available_frequencies(self.cpus[0])
 
71
        #freqs = cpufreq.get_available_frequencies(self.cpus[0])
 
72
        freqs = reversed(sorted(set(cpufreq.get_available_frequencies(self.cpus[0]))))
73
73
        for freq in freqs:
74
74
            menu_item = Gtk.RadioMenuItem.new_with_label(group, readable_frequency(freq))
75
75
            group = menu_item.get_group()
84
84
        for governor in governors:
85
85
            if governor == 'userspace':
86
86
                continue
87
 
            menu_item = Gtk.RadioMenuItem.new_with_label(group, readable_governor(governor))
 
87
            menu_item = Gtk.RadioMenuItem.new_with_label(group, str(readable_governor(governor)))
88
88
            group = menu_item.get_group()
89
89
            menu.append(menu_item)
90
90
            menu_item.connect('activate', self.select_activated, 'governor', governor)
107
107
        # use the highest freq among cores for display
108
108
        freq = max([cpufreq.get_freq_kernel(cpu) for cpu in self.cpus])
109
109
        
110
 
        ratio = min([25, 50, 75, 100], key=lambda x: abs(x - (float(freq) / fmax * 100)))
 
110
        ratio = min([25, 50, 75, 100], key=lambda x: abs((fmax - fmin) * x / 100.0 - (freq - fmin)))
111
111
        if freq < fmax and ratio == 100:
112
112
            ratio = 75
113
113