Skip to content

Commit

Permalink
Merge pull request #2 from jeffchannell/1.0.2
Browse files Browse the repository at this point in the history
1.0.2
  • Loading branch information
jeffchannell authored Jan 4, 2017
2 parents 8b9c665 + 0191c7b commit 18fb41e
Showing 1 changed file with 152 additions and 10 deletions.
162 changes: 152 additions & 10 deletions nvindicator.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
#!/usr/bin/env python3

"""nvindicator.py: An nvidia GPU indicator applet"""
"""nvindicator.py: An NVIDIA GPU indicator applet"""

__author__ = "Jeff Channell"
__copyright__ = "Copyright 2017, Jeff Channell"
__credits__ = ["Jeff Channell"]
__license__ = "GPL"
__version__ = "1.0.1"
__version__ = "1.0.2"
__maintainer__ = "Jeff Channell"
__email__ = "[email protected]"
__status__ = "Prototype"

import gi
import signal
import subprocess
import sys

gi.require_version("Gtk", "3.0")
gi.require_version("AppIndicator3", "0.1")

from gi.repository import Gtk
from gi.repository import AppIndicator3 as appindicator
from gi.repository import GLib
Expand All @@ -29,34 +34,109 @@ def __init__(self):
universal_newlines=True
)

# about window init
self.about = None

# track menus
self.menus = []

# track gpus
self.gpus = []
xml = self.read_nvidia()

# all menus display the driver version
driver = str(xml.driver_version[0])

for gpu in xml.gpu:
items = []

# create a new indicator
ind = appindicator.Indicator.new(
"NvIndicator",
"nvidia-settings",
appindicator.IndicatorCategory.APPLICATION_STATUS
appindicator.IndicatorCategory.HARDWARE
)
ind.set_status(appindicator.IndicatorStatus.ACTIVE)
self.gpus.append(ind)
menu = Gtk.Menu()

# add an nvidia-settings menu item
item = Gtk.MenuItem()
item.set_label("Open NVIDIA Settings")
item.connect("activate", self.run_nvidia_settings)
menu.append(item)

# sep
item = Gtk.SeparatorMenuItem()
menu.append(item)

# gpu name
item = Gtk.MenuItem()
item.set_label(str(gpu.product_name[0]))
item.connect("activate", self.do_nothing)
menu.append(item)

# add an nvidia-settings menu item
# driver version
item = Gtk.MenuItem()
item.set_label("NVIDIA Settings")
item.connect("activate", self.run_nvidia_settings)
item.set_label("Driver\tv{}".format(driver))
item.connect("activate", self.do_nothing)
menu.append(item)

# memory usage - update 0
item = Gtk.MenuItem()
item.set_label(
"Using {} of {}".format(
str(gpu.fb_memory_usage[0].used[0]),
str(gpu.fb_memory_usage[0].total[0])
)
)
item.connect("activate", self.do_nothing)
items.append(item)
menu.append(item)

# temperature - update 1
item = Gtk.MenuItem()
item.set_label(
"Temperature\t\t{}".format(
str(gpu.temperature[0].gpu_temp[0])
)
)
item.get_children()[0].set_justify(Gtk.Justification.FILL)
item.connect("activate", self.do_nothing)
items.append(item)
menu.append(item)

# power draw - update 2
item = Gtk.MenuItem()
item.set_label(
"Power Draw\t\t{}".format(
str(gpu.power_readings[0].power_draw[0])
)
)
item.get_children()[0].set_justify(Gtk.Justification.FILL)
item.connect("activate", self.do_nothing)
items.append(item)
menu.append(item)

# processes - update 3
item = Gtk.MenuItem()
item.set_label(
"Processes\t\t\t{}".format(
str(len(gpu.processes))
)
)
item.get_children()[0].set_justify(Gtk.Justification.FILL)
item.connect("activate", self.do_nothing)
items.append(item)
menu.append(item)

# sep
item = Gtk.SeparatorMenuItem()
menu.append(item)

# about me
item = Gtk.MenuItem()
item.set_label("About")
item.connect("activate", self.show_about)
menu.append(item)

# add a quit menu item
Expand All @@ -68,11 +148,35 @@ def __init__(self):
# set the menu
menu.show_all()
ind.set_menu(menu)
self.menus.append(menu)
self.menus.append(items)

self.gpus.append(ind)

def add_about_window_contents(self):
text = Gtk.Label()
text.set_markup(
"<b>About NvIndicator</b>\n\n{}\n\n"
"An NVIDIA GPU indicator applet\n\n"
"<a href=\"https://github.com/jeffchannell/nvindicator\">"
"https://github.com/jeffchannell/nvindicator</a>\n\n"
"<small>"
"© 2017 Jeff Channell\n\n"
"This program comes with absolutely no warranty.\n"
"See the GNU General Public License, version 3 or later for details."
"</small>".format(__version__)
)
text.set_line_wrap(True)
text.set_justify(Gtk.Justification.CENTER)

self.about.add(text)

def clear(self):
for gpu in self.gpus:
gpu.set_status(appindicator.IndicatorStatus.ACTIVE)

def destroy_about(self, widget, something):
self.about = None
return False

def do_nothing(self, widget):
pass
Expand Down Expand Up @@ -105,14 +209,52 @@ def run_loop(self):
def run_nvidia_settings(self, widget):
run(["nvidia-settings"])

def show_about(self, widget):
if None == self.about:
self.about = Gtk.Window()
self.about.set_title("About NvInidicator")
self.about.set_keep_above(True)
self.about.connect("delete-event", self.destroy_about)
self.add_about_window_contents()

self.about.set_position(Gtk.WindowPosition.CENTER)
self.about.set_size_request(400, 200)
self.about.show_all()


def update_gpu(self, idx, gpu):
self.gpus[idx].set_label(
"GPU: {}% MEM: {}%".format(
str(gpu.utilization[0].gpu_util[0]).split()[0],
str(gpu.utilization[0].memory_util[0]).split()[0]
str(gpu.utilization[0].gpu_util[0]).split()[0].rjust(3),
str(gpu.utilization[0].memory_util[0]).split()[0].rjust(3)
),
"NvInidicatorUsage"
)

self.menus[idx][0].set_label(
"Using {} of {}".format(
str(gpu.fb_memory_usage[0].used[0]),
str(gpu.fb_memory_usage[0].total[0])
)
)

self.menus[idx][1].set_label(
"Temperature\t\t{}".format(
str(gpu.temperature[0].gpu_temp[0])
)
)

self.menus[idx][2].set_label(
"Power Draw\t\t{}".format(
str(gpu.power_readings[0].power_draw[0])
)
)

self.menus[idx][3].set_label(
"Processes\t\t\t{}".format(
str(len(gpu.processes))
)
)

def main():
# allow app to be killed using ctrl+c
Expand Down

0 comments on commit 18fb41e

Please sign in to comment.