Permalink
Browse files

pulled getPowerDisplay out of the two guis (gtk and dzen) and cleaned…

… it up a bit
  • Loading branch information...
1 parent b398136 commit 7cb8d196d0d1a74053b4d9fc51395a6178a06505 @teleshoes committed May 30, 2012
Showing with 19 additions and 42 deletions.
  1. +16 −0 src/battstatus.py
  2. +1 −21 src/dzenprinter.py
  3. +2 −21 src/gui.py
View
@@ -40,6 +40,22 @@ def getBattInfo(self, batt_id):
return self.batt1
else:
return None
+ def getPowerDisplay(self):
+ disp = self.prefs.display_power_usage.lower()
+ if disp == 'average':
+ p0 = int(self.batt0.power_avg)
+ p1 = int(self.batt1.power_avg)
+ elif disp == 'now':
+ p0 = int(self.batt0.power_now)
+ p1 = int(self.batt1.power_now)
+ else:
+ return ''
+
+ if p0 != 0:
+ p = p0
+ else:
+ p = p1
+ return "%3.1fW" % (p/1000.0)
def update(self, prefs):
if self.last_acpi != self.prefs.use_acpi:
if self.prefs.use_acpi:
View
@@ -101,27 +101,7 @@ def getSeparatorMarkup(self):
return '^fg(' + color + ')|^fg()'
def getPowerMarkup(self):
- disp = self.prefs.display_power_usage.lower()
- if disp == 'average':
- pow0 = int(self.battStatus.batt0.power_avg)
- pow1 = int(self.battStatus.batt1.power_avg)
- if pow0 != 0:
- powavg = pow0
- else:
- powavg = pow1
- powavgW = float(powavg / 100) / 10.0
- return str(powavgW) + 'W'
- elif disp == 'now':
- pow0 = int(self.battStatus.batt0.power_now)
- pow1 = int(self.battStatus.batt1.power_now)
- if pow0 != 0:
- pownow = pow0
- else:
- pownow = pow1
- pownowW = float(pownow / 100) / 10.0
- return str(pownowW) + 'W'
- else:
- return ''
+ return self.battStatus.getPowerDisplay()
def getTopLength(self):
bat0 = self.battStatus.getBattInfo(0).remaining_percent
bat1 = self.battStatus.getBattInfo(1).remaining_percent
View
@@ -183,27 +183,8 @@ def isVertical(self):
return not (orient == gnomeapplet.ORIENT_UP or
orient == gnomeapplet.ORIENT_DOWN)
def getPowerMarkup(self):
- disp = self.prefs.display_power_usage.lower()
- if disp == 'average':
- pow0 = int(self.battStatus.batt0.power_avg)
- pow1 = int(self.battStatus.batt1.power_avg)
- if pow0 != 0:
- powavg = pow0
- else:
- powavg = pow1
- powavgW = float(powavg / 100) / 10.0
- return '\n<span size="xx-small">' + str(powavgW) + 'W</span>'
- elif disp == 'now':
- pow0 = int(self.battStatus.batt0.power_now)
- pow1 = int(self.battStatus.batt1.power_now)
- if pow0 != 0:
- pownow = pow0
- else:
- pownow = pow1
- pownowW = float(pownow / 100) / 10.0
- return '\n<span size="xx-small">' + str(pownowW) + 'W</span>'
- else:
- return ''
+ disp = self.battStatus.getPowerDisplay()
+ return '\n<span size="xx-small">' + disp + '</span>'
def updateLabel(self):
self.label.set_markup(
self.getBattMarkup(0) +

0 comments on commit 7cb8d19

Please sign in to comment.