~jr/guidance/powermanager-kde4

« back to all changes in this revision

Viewing changes to guidance-power-manager.py

  • Committer: Jonathan Riddell
  • Date: 2008-05-01 17:13:05 UTC
  • Revision ID: jriddell@canonical.com-20080501171305-yq8z6w7x5qcctq8m
tidying and copy of brightness methods, not yet implemented

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
 
62
62
        uic.loadUi("guidance-power-manager.ui", self)
63
63
 
64
 
        ##KGlobal.iconLoader().addAppDir("guidance")
65
 
 
66
64
        # The systray icon should show and hide the KDialogBase, not only this widget,
67
65
        # therefore, it gets our parent as parent.
68
66
        self.systray = SystemTrayIcon(parent)
69
67
        self.icon = "battery-charging-100"
70
68
        self.systray.setIcon(QIcon(UserIcon(self.icon)))
71
 
        #self.connect(self.systray, SIGNAL("quitSelected()"), self.quit)
72
69
 
73
 
        # Configuration filename
74
 
        ##self.config = KConfig("power-managerrc")
75
 
        ##config = KConfig("power-managerrc")
76
 
        ##self.config = config.group("General")
 
70
        # Configuration file
77
71
        app = KApplication.kApplication()
78
72
        config = KGlobal.config()
79
73
        self.config = config.group("power-manager")
430
424
 
431
425
        self.config.sync()
432
426
 
433
 
    def quit(self):
434
 
        print "quit"
 
427
    #FIXME add global key bindings for these
 
428
    #def showBrightnessPopup(self):
 
429
    #    if self.powermanager.onBattery():
 
430
    #        value=self.BatteryBrightnessSlider.value()*100/self.BatteryBrightnessSlider.maxValue()
 
431
    #    else:
 
432
    #        value=self.PoweredBrightnessSlider.value()*100/self.PoweredBrightnessSlider.maxValue()
 
433
    #    self.brightnessPopup = KPassivePopup.message('<b>Brightness:</b> '+str(value)+'%', self.systray)
 
434
    #    """pop.setTimeout(3000)"""
 
435
    #    self.brightnessPopup.show()    
 
436
 
 
437
    #def setBrightnessUp(self):
 
438
    #    """Increments slider value by 10%"""
 
439
    #    if self.powermanager.onBattery():
 
440
    #        #self.BatteryBrightnessSlider.setValue(float(self.BatteryBrightnessSlider.value())+max(float(self.BatteryBrightnessSlider.maxValue())/float(10),1))
 
441
    #    else:
 
442
    #        self.PoweredBrightnessSlider.setValue(float(self.PoweredBrightnessSlider.value())+max(float(self.PoweredBrightnessSlider.maxValue())/float(10),1))
 
443
     #   self.showBrightnessPopup()
 
444
            
 
445
    #def setBrightnessDown(self):
 
446
    #    """Decrements slider value by 10%"""
 
447
    #    if self.powermanager.onBattery():
 
448
    #        self.BatteryBrightnessSlider.setValue(float(self.BatteryBrightnessSlider.value())-max(float(self.BatteryBrightnessSlider.maxValue())/float(10),1))
 
449
    #    else:
 
450
    #        self.PoweredBrightnessSlider.setValue(float(self.PoweredBrightnessSlider.value())-max(float(self.PoweredBrightnessSlider.maxValue())/float(10),1))
 
451
    #    self.showBrightnessPopup()
 
452
 
 
453
    #def getBrightness(self):
 
454
    #  """Work with percentages - it's a bit nicer"""
 
455
    #  if self.powermanager.onBattery():
 
456
    #    value=self.BatteryBrightnessSlider.value()*100/self.BatteryBrightnessSlider.maxValue()
 
457
    #  else:
 
458
    #    value=self.PoweredBrightnessSlider.value()*100/self.PoweredBrightnessSlider.maxValue()
 
459
    #  return QString(str(value))
435
460
 
436
461
    def lockScreen(self):
437
462
        """ locks the screen using kdesktop """
593
618
                state, level, remain, rate, current, full = self.powermanager.getBatteryState(batt)
594
619
                self._updateBatteryWidget(batt, state, level, remain, rate)
595
620
 
596
 
                ## notify plugged/unplugged batteries
597
 
                print "poll, batt chck"
 
621
                # notify plugged/unplugged batteries
598
622
                if state == "not present":
599
623
                    if self.powermanager.batteryIsPresent[batt]:
600
624
                        print "been removed"
606
630
                        self.notify(i18n("The battery has been inserted."))
607
631
                        self.powermanager.batteryIsPresent[batt] = True
608
632
 
609
 
                    ## get cumulative charge levels/rate 
 
633
                    # get cumulative charge levels/rate 
610
634
                    self.batt_rate += rate
611
635
                    self.batt_charge += current
612
636
                    self.batt_full += full
613
637
 
614
 
                    ## calculate overall level (average of present batteries)
 
638
                    # calculate overall level (average of present batteries)
615
639
                    self.batt_remain += remain
616
640
                    self.batt_level += level
617
641
                    plugged_num += 1
618
642
 
619
 
                    ## calculate overall state (charging/discharging/charged)
 
643
                    # calculate overall state (charging/discharging/charged)
620
644
                    if state in ("charging","discharging"):
621
645
                        self.batt_state = state
622
646
                    elif not self.batt_state in ("charging, discharging"):
727
751
            self.tooltip.layout().addLayout(self.BattLayout[batt])
728
752
            i += 1
729
753
 
 
754
    def _updateBatteryWidget(self, batt, state, level, remain, rate):
 
755
        """ Retrieve battery information and update the related widgets accordingly. """
 
756
        self.BattProgress[batt].setEnabled(True)
 
757
        self.BattProgress[batt].setMaximum(100)
 
758
        self.BattProgress[batt].setValue(level)
 
759
        if state == "not present":
 
760
            self.BattProgress[batt].setFormat(i18n("not present"))
 
761
        elif state == "charging":
 
762
            self.BattProgress[batt].setFormat(i18n("Charging (%p%)"))
 
763
        elif state == "discharging":
 
764
            if rate > 0:
 
765
                showrate = rate/1000
 
766
                self.BattProgress[batt].setFormat(i18n("Discharging (%p%)") + " - %.d W" % showrate)
 
767
            else:
 
768
                self.BattProgress[batt].setFormat(i18n("Discharging (%p%)"))
 
769
        else:
 
770
            self.BattProgress[batt].setFormat("%p%")
 
771
 
730
772
    def _addCpuWidgets(self):
731
773
        """ Adds progressbars to show CPU frequencies to the tooltip."""
732
774
        if not SHOW_CPUFREQ:
783
825
            index = self.BatteryCriticalCombo.currentIndex()
784
826
        self.CriticalRemainTime.setEnabled(index != 0)
785
827
 
786
 
    def _updateBatteryWidget(self, batt, state, level, remain, rate):
787
 
        """ Retrieve battery information and update the related widgets accordingly. """
788
 
        self.BattProgress[batt].setEnabled(True)
789
 
        self.BattProgress[batt].setMaximum(100)
790
 
        self.BattProgress[batt].setValue(level)
791
 
        if state == "not present":
792
 
            self.BattProgress[batt].setFormat(i18n("not present"))
793
 
        elif state == "charging":
794
 
            self.BattProgress[batt].setFormat(i18n("Charging (%p%)"))
795
 
        elif state == "discharging":
796
 
            if rate > 0:
797
 
                showrate = rate/1000
798
 
                self.BattProgress[batt].setFormat(i18n("Discharging (%p%)") + " - %.d W" % showrate)
799
 
            else:
800
 
                self.BattProgress[batt].setFormat(i18n("Discharging (%p%)"))
801
 
        else:
802
 
            self.BattProgress[batt].setFormat("%p%")
803
 
 
804
828
    def _updateCpuWidgets(self):
805
829
        """ Retrieve CPU freq information and update the related widgets accordingly. """
806
830
        if not SHOW_CPUFREQ:
1019
1043
    def slotUser1(self):
1020
1044
        self.aboutus.show()
1021
1045
 
1022
 
# This class needed because we can't use a widget for a tooltip in Qt 4 (only text)
1023
 
# Also we can't use a KPassivePopup because KSystemTrayIcon is not a QWidget
1024
1046
class SystemTrayIcon(KSystemTrayIcon):
 
1047
    """This class needed because we can't use a widget for a tooltip in Qt 4 (only text)
 
1048
       Also we can't use a KPassivePopup because KSystemTrayIcon is not a QWidget """
1025
1049
 
1026
1050
    def setToolTip(self, toolTip):
 
1051
        """ set the toolTip widget """
1027
1052
        self.toolTip = toolTip
1028
1053
        self.toolTip.setWindowFlags(Qt.ToolTip)
1029
1054
 
1030
1055
    def event(self, event):
 
1056
        """ overloaded to pick up tooltip events and show our widget 
 
1057
            would be nice to hide it when the mouse leaves but systemtrayicons 
 
1058
            don't get that event so use a timer """
1031
1059
        if event.type() == QEvent.ToolTip:
1032
1060
            self.toolTip.show()
1033
1061
            x = self.geometry().x() - self.toolTip.width()