def __init__(self): QDialog.__init__(self) self.ui = Ui_BatteryPublisher() self.ui.setupUi(self) self.publisher = PublishSubscribe.QValueSpacePublisher('/power/battery') self.ui.batteryCharge.valueChanged.connect(self.chargeChanged) self.ui.charging.toggled.connect(self.chargingToggled) self.chargeTimer = 0 self.chargeChanged(self.ui.batteryCharge.value())
class BatteryPublisher(QDialog): def __init__(self): QDialog.__init__(self) self.ui = Ui_BatteryPublisher() self.ui.setupUi(self) self.publisher = PublishSubscribe.QValueSpacePublisher('/power/battery') self.ui.batteryCharge.valueChanged.connect(self.chargeChanged) self.ui.charging.toggled.connect(self.chargingToggled) self.chargeTimer = 0 self.chargeChanged(self.ui.batteryCharge.value()) def changeEvent(self, e): QDialog.changeEvent(self, e) if e.type() == QEvent.LanguageChange: self.ui.retranslateUi(self) def timerEvent(self, e): newCharge = self.ui.batteryCharge.value() + 1 self.ui.batteryCharge.setValue(newCharge) if newCharge >= 100: self.ui.charging.setChecked(False) def chargeChanged(self, newCharge): self.publisher.setValue('charge', newCharge) def chargingToggled(self, charging): self.ui.batteryCharge.setEnabled(not charging) self.publisher.setValue('charging', charging) if charging: self.chargeTimer = self.startTimer(2000) else: self.killTimer(self.chargeTimer)