Skip to content

Commit

Permalink
Fix multiple small mistakes, add CPU/GPU names
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexIII committed Oct 16, 2024
1 parent a00de74 commit b623034
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 17 deletions.
16 changes: 15 additions & 1 deletion src/Backend/AWCCThermal.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def __init__(self, awcc: Optional[AWCCWmiWrapper] = None) -> None:
self._fanIdsAndRelatedSensorsIds = self._awcc.GetFanIdsAndRelatedSensorsIds()
self._fanIds = [ id for id, _ in self._fanIdsAndRelatedSensorsIds ]
self._sensorIds = [ id for _, ids in self._fanIdsAndRelatedSensorsIds for id in ids ]
self._wmi = wmi.WMI()

def getAllTemp(self) -> list[Optional[int]]:
return [ self._awcc.GetSensorTemperature(sensorId) for sensorId in self._sensorIds ]
Expand Down Expand Up @@ -63,4 +64,17 @@ def setFanSpeed(self, fanIdx: int, speed: int) -> bool:
return self._awcc.SetAddonSpeedPercent(self._fanIdsAndRelatedSensorsIds[fanIdx][0], speed)

def setMode(self, mode: ModeType) -> bool:
return self._awcc.ApplyThermalMode(mode)
return self._awcc.ApplyThermalMode(mode)


def getHardwareName(self, fanIdx: int) -> Optional[str]:
if fanIdx == 0:
wmiClass = self._wmi.Win32_Processor
wmiInst = wmiClass()[0]
return wmiInst.Name if hasattr(wmiInst, 'Name') else None
elif fanIdx == 1:
wmiClass = self._wmi.Win32_VideoController
wmiInst = wmiClass()[0]
return wmiInst.Name if hasattr(wmiInst, 'Name') else None
else:
return None
24 changes: 16 additions & 8 deletions src/GUI/AppGUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def __init__(self, awcc: AWCCThermal):
self._awcc = awcc

self.settings = QtCore.QSettings(self.APP_URL, "AWCC")
print(self.settings.fileName())
print(f'Settings location: {self.settings.fileName()}')

# Set main window props
self.setFixedSize(600, 0)
Expand Down Expand Up @@ -173,8 +173,8 @@ def onTrayIconActivated(trigger):
self.setObjectName('QMainWindow')
self.setWindowTitle(self.APP_NAME)

self._thermalGPU = ThermalUnitWidget(self, 'GPU', tempMinMax= (0, 95), tempColorLimits= self.GPU_COLOR_LIMITS, fanMinMax= (0, 5500), sliderMaxAndTick= (120, 20))
self._thermalCPU = ThermalUnitWidget(self, 'CPU', tempMinMax= (0, 110), tempColorLimits= self.CPU_COLOR_LIMITS, fanMinMax= (0, 5500), sliderMaxAndTick= (120, 20))
self._thermalGPU = ThermalUnitWidget(self, self._awcc.getHardwareName(self._awcc.GPUFanIdx) or 'GPU', tempMinMax= (0, 95), tempColorLimits= self.GPU_COLOR_LIMITS, fanMinMax= (0, 5500), sliderMaxAndTick= (120, 20))
self._thermalCPU = ThermalUnitWidget(self, self._awcc.getHardwareName(self._awcc.CPUFanIdx) or 'CPU', tempMinMax= (0, 110), tempColorLimits= self.CPU_COLOR_LIMITS, fanMinMax= (0, 5500), sliderMaxAndTick= (120, 20))

lTherm = QtWidgets.QHBoxLayout()
lTherm.addWidget(self._thermalGPU)
Expand Down Expand Up @@ -249,6 +249,9 @@ def onFailsafeCB():
mainLayout.setContentsMargins(10, 0, 10, 0)

# Glue GUI to backend
self.gModeHotKey = None
self._updateGaugesTask = None

def setFanSpeed(fan: Literal['GPU', 'CPU'], speed: int) -> None:
res = self._awcc.setFanSpeed(self._awcc.GPUFanIdx if fan == 'GPU' else self._awcc.CPUFanIdx, speed)
print(f'Set {fan} fan speed to {speed}: ' + ('ok' if res else 'fail'))
Expand Down Expand Up @@ -340,6 +343,9 @@ def updateAppState():

def closeEvent(self, event):
minimizeOnClose = self.settings.value(SettingsKey.MinimizeOnCloseFlag.value)
if minimizeOnClose is not None:
minimizeOnClose = str(minimizeOnClose).lower() == 'true'

if minimizeOnClose is None:
# minimizeOnClose is not set, prompt user
(toExit, dontAskAgain) = confirm("Exit", "Do you want to exit or minimize to tray?", ("Exit", "Minimize"), True)
Expand Down Expand Up @@ -370,9 +376,11 @@ def _errorExit(self, message: str, message2: Optional[str] = None) -> None:
errorExit(message, message2)

def _destroy(self):
self.gModeHotKey.stop()
self.gModeHotKey.wait()
self._updateGaugesTask.stop()
if self.gModeHotKey is not None:
self.gModeHotKey.stop()
self.gModeHotKey.wait()
if self.gModeHotKey is not None:
self._updateGaugesTask.stop()
print('Cleanup: done')

def _onGModeHotKeyPressed(self):
Expand Down Expand Up @@ -432,8 +440,8 @@ def _loadAppSettings(self):
self._limitTempCPU.setCurrentText(str(savedTemp))
savedTemp = self.settings.value(SettingsKey.GPUThresholdTemp.value) or 85
self._limitTempGPU.setCurrentText(str(savedTemp))
savedFailsafe = self.settings.value(SettingsKey.FailSafeIsOnFlag.value) or 'True'
self._failsafeCB.setChecked(not (savedFailsafe == 'False'))
savedFailsafe = self.settings.value(SettingsKey.FailSafeIsOnFlag.value) or 'true'
self._failsafeCB.setChecked(str(savedFailsafe).lower() == 'true')

def clearAppSettings(self):
(isYes, _) = confirm("Reset to Default", "Do you want to reset all settings to default?", ("Reset", "Cancel"))
Expand Down
3 changes: 3 additions & 0 deletions src/GUI/HotKey.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def __init__(self, key: int, keyPressedSignal: Signal):
super(HotKey, self).__init__()
self.keyPressedSignal = keyPressedSignal
self.key = key
self.nativeThreadId = None

def run(self):
self.nativeThreadId = threading.get_native_id()
Expand All @@ -31,4 +32,6 @@ def run(self):
user32.UnregisterHotKey(None, 1)

def stop(self):
if self.nativeThreadId is None:
return
windll.user32.PostThreadMessageW(self.nativeThreadId, win32con.WM_USER, _STOP_SIGNAL_CODE, 0)
19 changes: 11 additions & 8 deletions src/GUI/ThermalUnitWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
from PySide6 import QtCore, QtWidgets
from GUI.QGauge import QGauge
from GUI.AppColors import Colors
import inspect

class ThermalUnitWidget(QtWidgets.QWidget):
def __init__(self, parent: Optional[QtWidgets.QWidget], title: str, tempMinMax: Tuple[int,int], tempColorLimits: Optional[Tuple[int,int]], fanMinMax: Tuple[int,int], sliderMaxAndTick: Tuple[int,int]):
super().__init__(parent)

self._title = QtWidgets.QLabel(title)
self._title = QtWidgets.QLabel(title, )
self._title.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse)
self._title.setToolTip("Triple left-click and Crtl+C to copy")

self._tempBar, _tempBarLabel = self._makeGaugeWithLabel(tempMinMax, ' °C', tempColorLimits)

Expand All @@ -26,13 +29,13 @@ def __init__(self, parent: Optional[QtWidgets.QWidget], title: str, tempMinMax:
self._speedSlider.valueChanged.connect(lambda: self._speedSliderDebounce.start())

grid = QtWidgets.QGridLayout() # type: QtWidgets.QWidget
grid.addWidget(self._title, 0, 0, QtCore.Qt.AlignCenter)
grid.addWidget(self._tempBar, 1, 0, QtCore.Qt.AlignTop)
grid.addWidget(_tempBarLabel, 1, 1, QtCore.Qt.AlignLeft)
grid.addWidget(self._fanBar, 2, 0, QtCore.Qt.AlignTop)
grid.addWidget(_fanBarLabel, 2, 1, QtCore.Qt.AlignLeft)
grid.addWidget(self._speedSlider, 3, 0, QtCore.Qt.AlignTop)
grid.addWidget(_speedSliderLabel, 3, 1, QtCore.Qt.AlignLeft)
grid.addWidget(self._title, 0, 0, 1, 2, QtCore.Qt.AlignCenter if len(title) < 10 else QtCore.Qt.AlignLeft)
grid.addWidget(self._tempBar, 1, 0, QtCore.Qt.AlignTop)
grid.addWidget(_tempBarLabel, 1, 1, QtCore.Qt.AlignLeft)
grid.addWidget(self._fanBar, 2, 0, QtCore.Qt.AlignTop)
grid.addWidget(_fanBarLabel, 2, 1, QtCore.Qt.AlignLeft)
grid.addWidget(self._speedSlider, 3, 0, QtCore.Qt.AlignTop)
grid.addWidget(_speedSliderLabel, 3, 1, QtCore.Qt.AlignLeft)
grid.setColumnStretch(0, 1)
grid.setColumnStretch(1, 0)
self.setLayout(grid)
Expand Down

0 comments on commit b623034

Please sign in to comment.