Moved CPU drawing to mixin

This commit is contained in:
Maxim Stewart 2020-05-08 22:31:29 -05:00
parent 88d836ac06
commit 3a04b2c8e8
6 changed files with 55 additions and 63 deletions

View File

@ -15,7 +15,7 @@ from gi.repository import GLib
# Application imports # Application imports
from utils import Settings from utils import Settings
from signal_classes import CrossClassSignals, GridSignals, TaskbarSignals, DrawSignals from signal_classes import CrossClassSignals, GridSignals
class Main: class Main:
@ -57,9 +57,7 @@ class Main:
# Gets the methods from the classes and sets to handler. # Gets the methods from the classes and sets to handler.
# Then, builder connects to any signals it needs. # Then, builder connects to any signals it needs.
classes = [CrossClassSignals(settings), classes = [CrossClassSignals(settings),
GridSignals(settings), GridSignals(settings)]
TaskbarSignals(settings),
DrawSignals(settings)]
handlers = {} handlers = {}
for c in classes: for c in classes:

View File

@ -5,16 +5,51 @@ from datetime import datetime
from gi.repository import GObject from gi.repository import GObject
# Application imports # Application imports
from mixins import CPUDrawMixin, TaskbarMixin
class CrossClassSignals: class CrossClassSignals(CPUDrawMixin, TaskbarMixin):
def __init__(self, settings): def __init__(self, settings):
self.settings = settings self.settings = settings
self.builder = self.settings.returnBuilder() self.builder = self.settings.returnBuilder()
self.timeLabel = self.builder.get_object("timeLabel") self.timeLabel = self.builder.get_object("timeLabel")
self.drawArea = self.builder.get_object("drawArea")
self.brushSizeProp = self.builder.get_object("brushSizeProp")
self.brushColorProp = self.builder.get_object("brushColorProp")
# Menu bar setup
self.orientation = 1 # 0 = horizontal, 1 = vertical
# Must be before setting clock
self.setPagerWidget()
self.setTasklistWidget()
# Must be after pager and task list inits
self.displayclock() self.displayclock()
self.startClock() self.startClock()
# CPUDrawMixin Parts
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.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]
# Displays Timer # Displays Timer
def displayclock(self): def displayclock(self):

View File

@ -1,4 +1,4 @@
from signal_classes.CrossClassSignals import CrossClassSignals from mixins import CPUDrawMixin
from signal_classes.DrawSignals import DrawSignals from mixins import TaskbarMixin
from signal_classes.GridSignals import GridSignals from signal_classes.GridSignals import GridSignals
from signal_classes.TaskbarSignals import TaskbarSignals from signal_classes.CrossClassSignals import CrossClassSignals

View File

@ -14,39 +14,7 @@ from gi.repository import GLib
class DrawSignals: class CPUDrawMixin:
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. # 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 # 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([1 * xStep, ah - (23 * yStep)]) # 23%
@ -54,9 +22,6 @@ class DrawSignals:
# self.drawPointLine() # self.drawPointLine()
# del self.linePoints[0:1] # del self.linePoints[0:1]
# self.linePoints.append([3 * xStep, ah - (44 * yStep)]) # 44% # self.linePoints.append([3 * xStep, ah - (44 * yStep)]) # 44%
def updateCPUPoints(self): def updateCPUPoints(self):
# Clears screen when enough points exist and unshifts the # Clears screen when enough points exist and unshifts the
# first point to keep fixed range # first point to keep fixed range

View File

@ -23,15 +23,7 @@ class MouseButton:
RIGHT_BUTTON = 3 RIGHT_BUTTON = 3
class TaskbarSignals: class TaskbarMixin:
def __init__(self, settings):
self.settings = settings
self.builder = self.settings.returnBuilder()
self.orientation = 1 # 0 = horizontal, 1 = vertical
self.setPagerWidget()
self.setTasklistWidget()
def toggleCalPopover(self, widget, eve): def toggleCalPopover(self, widget, eve):
calendarPopup = self.builder.get_object('calendarPopup') calendarPopup = self.builder.get_object('calendarPopup')
if (calendarPopup.get_visible() == False): if (calendarPopup.get_visible() == False):

View File

@ -0,0 +1,2 @@
from .TaskbarMixin import TaskbarMixin
from .CPUDrawMixin import CPUDrawMixin