Skip to content
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea/
build/
crud/
23 changes: 14 additions & 9 deletions indicator-doom-cpu
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env python
#!/usr/bin/env python3
APP_LICENCE = '''
Copyright (C) 2014 Edward G. Bruck <ed.bruck1@gmail.com>
Copyright (C) 2017 Andrea Brancaleoni <miwaxe@gmail.com>
Copyright (C) 2019 Andrew Rogers <tuxlovesyou@gmail.com>

This program is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License version 3, as published
Expand All @@ -24,7 +25,10 @@ APP_AUTHORS = [a[10:] for a in str.splitlines(APP_LICENCE) if a.startswith("Copy
import os
import time

from gi.repository import Gtk, GObject, GdkPixbuf
from gi import require_version
require_version('Gtk', '3.0')

from gi.repository import Gtk, GLib, GObject, GdkPixbuf

try:
from gi.repository import AppIndicator3 as AppIndicator
Expand All @@ -49,7 +53,7 @@ class CPUsage:
self.result = self.compute()

def get_time(self):
stat_file = file('/proc/stat', 'r')
stat_file = open('/proc/stat', 'r')
time_list = stat_file.readline().split(' ')[2:6]
stat_file.close()
for i in range(len(time_list)):
Expand Down Expand Up @@ -95,7 +99,7 @@ class AboutDialog(Gtk.AboutDialog):
class AbstractDOOMCPUIndicator(object):
def __init__(self):
global APP_IMAGES
GObject.timeout_add(1000, self.on_update_timer)
GLib.timeout_add(1000, self.on_update_timer)

self.menu_item = None
self.cpu_load_menu_item = None
Expand Down Expand Up @@ -126,10 +130,10 @@ class AbstractDOOMCPUIndicator(object):
def on_update_timer(self):
global APP_IMAGES, APP_NUM_IMAGES
cpu_load = int(CPUsage(interval=0.2).result)
image_idx = cpu_load / (100/(APP_NUM_IMAGES-1))
image_idx = int(cpu_load / (100/(APP_NUM_IMAGES-1)))

if image_idx != self.previous_image_idx:
self.set_icon(APP_IMAGES[image_idx])
self.set_icon(APP_IMAGES[image_idx])

if cpu_load != self.previous_cpu_load:
self.cpu_load_menu_item.set_label('CPU: %d%%' % int(cpu_load))
Expand All @@ -145,7 +149,7 @@ class AbstractDOOMCPUIndicator(object):
AboutDialog()

def set_icon(self, icon):
pass
pass

def run(self):
Gtk.main()
Expand All @@ -162,8 +166,8 @@ class DOOMCPUIndicator(AbstractDOOMCPUIndicator):
self.app_indicator.set_menu(self.menu)

def set_icon(self, icon):
super(DOOMCPUIndicator, self).set_icon(icon)
self.app_indicator.set_icon(icon)
super(DOOMCPUIndicator, self).set_icon(icon)
self.app_indicator.set_icon(icon)


class DOOMCPUStatusIcon(AbstractDOOMCPUIndicator):
Expand All @@ -176,6 +180,7 @@ class DOOMCPUStatusIcon(AbstractDOOMCPUIndicator):

def set_icon(self, icon):
super(DOOMCPUStatusIcon, self).set_icon(icon)
self.icon_indicator = Gtk.StatusIcon() # Werks
self.icon_indicator.set_from_file(icon)

if __name__ == '__main__':
Expand Down