Exemplo n.º 1
0
	def update(self):
		self.beginResetModel()
		
		if self._mode == 'smart':
			newFanLevel = Settings.LEVELS[FanModel.LEVEL_TEMPS[bisect.bisect_left(FanModel.LEVEL_TEMPS, self._tempsModel.maxTemp()[1]) - 1]]
			Fan.setLevel(newFanLevel)
		
		elif self._mode == 'manual':
			self._fanStatus = Fan.read()
			# Reset the watchdog timer
			Fan.setLevel(self._fanStatus.level)
		
		self._fanStatus = Fan.read()
		
		self.endResetModel()
Exemplo n.º 2
0
	def __init__(self, parent=None):
		super().__init__(parent)
		self.setupUi(self)
		
		self._tempsModel = TemperaturesModel(self)
		
		self._fanModel = FanModel(self._tempsModel, self)
		
		# Connect the temperatures table to the temperatures model
		self.tempsTable.setModel(self._tempsModel)
		self.tempsTable.verticalHeader().setSectionResizeMode(QHeaderView.ResizeToContents)
		
		# Update the icons when the temperatures change
		self._tempsModel.modelReset.connect(self.updateTemperatureIcons)
		
		# Connect the fan speed and level labels to the fan model.
		self._fanModel.modelReset.connect(self.updateFanLabels)
		
		self.activeButton.toggled.connect(self.toggleTempSensorsVisibility)
		self.toggleTempSensorsVisibility()
		
		self.biosModeButton.toggled.connect(self.enableBIOSMode)
		self.smartModeButton.toggled.connect(self.enableSmartMode)
		self.manualModeButton.toggled.connect(self.enableManualMode)
		
		for speed in sorted(Fan.FIRMWARE_TO_HWMON):
			self.manualModeCombo.addItem(FanModel.LEVEL_DISPLAY_STRINGS[speed], speed)
		self.manualModeCombo.addItem(FanModel.LEVEL_DISPLAY_STRINGS['full-speed'], 'full-speed')
		self.manualModeCombo.setCurrentIndex(len(Fan.FIRMWARE_TO_HWMON))
		# Changing the selected level changes the fan level immediately if manual mode is enabled
		self.manualModeCombo.currentIndexChanged.connect(self.enableManualMode)
		
		# Start off the application in smart mode
		if Fan.isWritable():
			self.smartModeButton.setChecked(True)
		else:
			self.biosModeButton.setChecked(True)
		
		self.show()
		
		# The icon engine and icon object
		self._iconEngine = TPFCIconEngine(self._tempsModel)
		icon = QIcon(self._iconEngine)
		
		# The system tray icon
		self._systemTrayIcon = QSystemTrayIcon(icon, self)
		self._systemTrayIcon.activated.connect(self.systemTrayIconActivated)
		self._systemTrayIcon.setVisible(True)
		
		# The window icon
		self.setWindowIcon(icon)
		
		# The context menu for the system tray icon
		trayIconMenu = QMenu(self)
		self._systemTrayIcon.setContextMenu(trayIconMenu)
		# The first entry in the context menu hides or shows the main window
		self._restoreHideAction = QAction('Hide', self, triggered=self.toggleVisibility)
		trayIconMenu.addAction(self._restoreHideAction)
		# The second entry in the context menu resets the system tray icon
		trayIconMenu.addAction(QAction('Reset icon', self, triggered=self.resetSystemTrayIcon))
		# The third entry in the context menu quits the program
		trayIconMenu.addAction(QAction('Quit', self, triggered=self.quit))
		
		# If the fan level is not modificable, show a warning notification balloon from the system tray icon and disable the fan level controls
		if not Fan.isWritable():
			title = 'Warning'
			message = 'PyTPFanControl does not have write access to the ACPI interface. Fan speed will be read-only.'
			
			dbusAvailable = True
			try:
				import dbus
				try:
					notifications = dbus.SessionBus().get_object("org.freedesktop.Notifications", '/org/freedesktop/Notifications')
					notifications.Notify('PyTPFanControl', dbus.UInt32(0), 'dialog-warning', title, message, dbus.Array(signature='s'), dbus.Dictionary(signature='sv'), 0)
				except dbus.exceptions.DBusException:
					dbusAvailable = False
			except ImportError:
				dbusAvailable = False
			
			if not dbusAvailable:
				QTimer.singleShot(1000, lambda: self._systemTrayIcon.showMessage(title, message, QSystemTrayIcon.Warning))
			
			for control in (self.biosModeButton, self.smartModeButton, self.manualModeButton, self.manualModeCombo):
				control.setEnabled(False)
Exemplo n.º 3
0
	def setManualMode(self, level):
		self._mode = 'manual'
		Fan.setLevel(level)
		self.update()
Exemplo n.º 4
0
	def setBIOSMode(self):
		self._mode = 'auto'
		Fan.setLevel('auto')
		self.update()