Added images, added cpu monitor, and updated layout

This commit is contained in:
Maxim Stewart 2020-04-17 14:28:19 -05:00
parent 56627de333
commit 4929d71a29
21 changed files with 244 additions and 12 deletions

Binary file not shown.

BIN
images/pic1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

View File

@ -1,5 +1,10 @@
#!/usr/bin/python3
# Python imports
import inspect
from setproctitle import setproctitle
# Gtk imports
import gi, faulthandler, signal
gi.require_version('Gtk', '3.0')
@ -8,14 +13,9 @@ from gi.repository import Gtk as gtk
from gi.repository import Gdk as gdk
from gi.repository import GLib
# Python imports
import inspect
from setproctitle import setproctitle
# Application imports
from utils import Settings
from signal_classes import CrossClassSignals, GridSignals, TaskbarSignals
from signal_classes import CrossClassSignals, GridSignals, TaskbarSignals, DrawSignals
class Main:
@ -58,7 +58,8 @@ class Main:
# Then, builder connects to any signals it needs.
classes = [CrossClassSignals(settings),
GridSignals(settings),
TaskbarSignals(settings)]
TaskbarSignals(settings),
DrawSignals(settings)]
handlers = {}
for c in classes:

View File

@ -7,6 +7,14 @@
<mime-type>inode/directory</mime-type>
</mime-types>
</object>
<object class="GtkAdjustment" id="brushSizeProp">
<property name="lower">1</property>
<property name="upper">100</property>
<property name="value">1</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
<signal name="value-changed" handler="onBrushSizeChange" swapped="no"/>
</object>
<object class="GtkWindow" id="Window">
<property name="can_focus">False</property>
<property name="default_width">800</property>
@ -76,14 +84,15 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkScrolledWindow">
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkViewport">
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="can_focus">True</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkIconView" id="Desktop">
<property name="visible">True</property>
@ -93,6 +102,63 @@
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkColorButton" id="brushColorProp">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_alpha">True</property>
<property name="rgba">rgb(138,226,52)</property>
<signal name="color-set" handler="onColorSet" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkDrawingArea" id="drawArea">
<property name="height_request">60</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<signal name="configure-event" handler="onConfigure" swapped="no"/>
<signal name="draw" handler="onDraw" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkSpinButton">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="adjustment">brushSizeProp</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>

View File

@ -0,0 +1,164 @@
#!/usr/bin/python3
# Python Imports
from __future__ import division
import cairo, psutil
# GTK Imports
from gi.repository import GObject
from gi.repository import GLib
class DrawSignals:
def __init__(self, settings):
self.settings = settings
self.builder = self.settings.returnBuilder()
self.drawArea = self.builder.get_object("drawArea")
self.brushSizeProp = self.builder.get_object("brushSizeProp")
self.brushColorProp = self.builder.get_object("brushColorProp")
self.messageWidget = self.builder.get_object("messageWidget")
self.messageLabel = self.builder.get_object("messageLabel")
self.cpu_percents = []
self.doDrawBackground = False
self.isDrawing = False
self.surface = None
self.aw = None # Draw area width
self.ah = None # Draw area height
self.xStep = None # For x-axis 60 sec steps
self.yStep = None # For y-axis %s
rgba = self.brushColorProp.get_rgba()
self.brushColorVal = [rgba.red, rgba.green, rgba.blue, rgba.alpha]
self.brushSizeVal = self.brushSizeProp.get_value()
self.updateSpeed = 100 # 1 sec = 1000ms
self.success = "#88cc27"
self.warning = "#ffa800"
self.error = "#ff0000"
self.good = [0.53, 0.8, 0.15, 1.0]
self.warning = [1.0, 0.66, 0.0, 1.0]
self.danger = [1.0, 0.0, 0.0, 1.0]
# Note: y-axis on draw area goes from top to bottom when increasing.
# Need to do the math such that you subtract from max height to start from bottom to go up
# self.linePoints.append([1 * xStep, ah - (23 * yStep)]) # 23%
# self.linePoints.append([2 * xStep, ah - (60 * yStep)]) # 60%
# self.drawPointLine()
# del self.linePoints[0:1]
# self.linePoints.append([3 * xStep, ah - (44 * yStep)]) # 44%
def updateCPUPoints(self):
# Clears screen when enough points exist and unshifts the
# first point to keep fixed range
self.drawBackground(self.brush, self.aw, self.ah)
del self.cpu_percents[0:1]
precent = psutil.cpu_percent()
self.cpu_percents.append(precent)
self.drawPointLine() # Will re-draw every point
self.drawArea.queue_draw()
return True
def drawPointLine(self):
self.brush.set_line_width(self.brushSizeVal)
self.brush.set_line_cap(1) # 0 = BUTT, 1 = ROUND, 2 = SQUARE
oldX = 0.0
oldP = 0.0
i = 1
for p in self.cpu_percents:
# set color depending on usage...
rgba = self.brushColorVal
if p > 50.0:
rgba = self.warning
if p > 85.0:
rgba = self.danger
self.brush.set_source_rgba(rgba[0], rgba[1], rgba[2], rgba[3])
# Movbe to prev. point if any
if oldP is not 0.0 and oldX is not 0.0:
x = oldX
y = float(self.ah) - (oldP * self.yStep)
self.brush.move_to(x, y)
# Draw line to the new point from old point
x2 = i * self.xStep
y2 = float(self.ah) - (p * self.yStep)
self.brush.line_to(x2, y2)
self.brush.stroke()
# Collect info to use as prev. pint
oldX = x2
oldP = p
i += 1
def onConfigure(self, area, eve, data = None):
aw = area.get_allocated_width()
ah = area.get_allocated_height()
self.aw = aw
self.ah = ah
self.xStep = aw / 200 # For x-axis
self.yStep = ah / 100 # For y-axis %s
self.surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, aw, ah)
self.brush = cairo.Context(self.surface)
self.drawBackground(self.brush, aw, ah)
if not self.isDrawing:
self.fillCPUPercents()
self.startCPUGraph()
self.isDrawing = True
return False
# Fill with y bank with 50%s
def fillCPUPercents(self):
self.cpu_percents = [50.0] * 198
# Draw background white
def drawBackground(self, brush, aw, ah):
brush.rectangle(0, 0, aw, ah) # x, y, width, height
brush.set_source_rgba(1, 1, 1, 1.0) # x, y, width, height
if not self.doDrawBackground: # If transparent or white
self.brush.set_operator(0);
brush.fill()
self.brush.set_operator(1); # reset the brush after filling bg...
# Starting graph generation
def startCPUGraph(self):
GObject.timeout_add(self.updateSpeed, self.updateCPUPoints)
def onDraw(self, area, brush):
if self.surface is not None:
brush.set_source_surface(self.surface, 0.0, 0.0)
brush.paint()
else:
print("No surface info...")
return False
def onColorSet(self, widget):
rgba = widget.get_rgba()
self.brushColorVal = [rgba.red, rgba.green, rgba.blue, rgba.alpha]
def onBrushSizeChange(self, widget):
self.brushSizeVal = self.brushSizeProp.get_value()

View File

@ -1,3 +1,4 @@
from signal_classes.CrossClassSignals import CrossClassSignals
from signal_classes.DrawSignals import DrawSignals
from signal_classes.GridSignals import GridSignals
from signal_classes.TaskbarSignals import TaskbarSignals

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.