New update, now it supports one battery and more.
Thanks to mynameisfiber [https://github.com/mynameisfiber]
]]>https://aur.archlinux.org/packages/dualtidy/
Hope you guys like it
]]>I had a problem where this script would crash after suspending my laptop due to the output of acpi not matching the desired result
I had the same problem, and I fixed it before reading the page to the end and finding your solution.
My solution is just a bit different (I've added new icon if output of 'acpi' command can't be parsed):
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
import gtk
import gobject
import subprocess
ACPI_CMD = 'acpi'
TIMEOUT = 2
class MainApp:
def __init__(self):
self.icon = gtk.StatusIcon()
self.update_icon()
gobject.timeout_add_seconds(TIMEOUT,self.update_icon)
def get_battery_info(self):
text = subprocess.check_output(ACPI_CMD).strip('\n')
if not 'Battery' in text:
return {'state':"Unknown",
'percentage':0,
'tooltip':""
}
data = text.split(',')
return {'state':data[0].split(':')[1].strip(' '),
'percentage':int(data[1].strip(' %')),
'tooltip': text.split(':',1)[1][1:]
}
def get_icon_name(self, state, percentage):
if state == 'Discharging':
if percentage < 10:
return 'battery_empty'
elif percentage < 20:
return 'battery_caution'
elif percentage < 40:
return 'battery_low'
elif percentage < 60:
return 'battery_two_thirds'
elif percentage < 75:
return 'battery_third_fouth'
else:
return 'battery_full'
elif state == 'Charged':
return 'battery_charged'
elif state == 'Unknown':
return 'dialog-question'
else:
return 'battery_plugged'
def update_icon(self):
info = self.get_battery_info()
icon_name = self.get_icon_name(info['state'],info['percentage'])
self.icon.set_from_icon_name(icon_name)
self.icon.set_tooltip_text(info['tooltip'])
return True
if __name__ == "__main__":
try:
MainApp()
gtk.main()
except KeyboardInterrupt:
pass
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
import gtk
import gobject
import subprocess
import re
ACPI_CMD = 'acpi'
TIMEOUT = 2
class MainApp:
def __init__(self):
self.icon = gtk.StatusIcon()
self.update_icon()
gobject.timeout_add_seconds(TIMEOUT,self.update_icon)
def get_battery_info(self):
text = subprocess.check_output(ACPI_CMD).strip('\n')
if(re.match("[^:]+:[^,]+,.+",text)):
data = text.split(',')
return {'state':data[0].split(':')[1].strip(' '),
'percentage':int(data[1].strip(' %')),
'tooltip': text.split(':',1)[1][1:]
}
def get_icon_name(self, state, percentage):
if state == 'Discharging':
if percentage < 10:
return 'xfce4-battery-critical'
elif percentage < 40:
return 'xfce4-battery-low'
elif percentage < 75:
return 'xfce4-battery-ok'
else:
return 'xfce4-battery-full'
else:
if percentage < 10:
return 'xfce4-battery-critical-charging'
elif percentage < 40:
return 'xfce4-battery-low-charging'
elif percentage < 75:
return 'xfce4-battery-ok-charging'
else:
return 'xfce4-battery-full-charging'
def update_icon(self):
info = self.get_battery_info()
icon_name = self.get_icon_name(info['state'],info['percentage'])
self.icon.set_from_icon_name(icon_name)
self.icon.set_tooltip_text(info['tooltip'])
return True
if __name__ == "__main__":
try:
MainApp()
gtk.main()
except KeyboardInterrupt:
pass
One solution is to copy all status icons from Faenza Dark to your icon theme of choice. Of course, that will destroy all nice status icons in that icon theme. In Faenza Dark the png's are called 'gpm-battery-xxx-xxx.png' and 'gpm-primary-xxx-xxx.png', or the like. You could also copy each and every one of them manually for all sizes and scalable too. That would preserve your present status icons and just add the necessary ones.
Trying this solution, but it's not yet working for me. I have openbox and Clearlooks is my default theme. After I copied all Faenza-Dark png's from status/16 to /usr/share/themes/Clearlooks same red cross persists. Thanks for any tips!
]]>unknown, 97%
This script is just polling an acpi status from "acpi -i" output.
So, if you got an Unknown status in acpi -i output and you have ThinkPad, it possibly means "Charging".
This is fantastic.
I've been mad at xfce4-power-manager for a while now because while its interface is pretty much the same as this (which is what I want), it likes to not realize that i've removed the power adaptor, or plugged it back in, and so on. So I sat there wondering why there didn't seem to be a battery monitor that just polled acpi periodically, and ended up just writing a shell script that just outputs the %
...but this is much, much nicer It's people like you that make me miss my Arch days.
]]>I am excited to use this script. I have built it from AUR, it starts and reports battery information properly, however, I do not have a proper icon (there is a red 'x' with some themes, other themes are just blank).
Same here with Openbox and Tint2. Tidybattery shows just a white "paper"-icon with a red cross on it. The icon shows an on-mouse-over effect that says in my case:
unknown, 97%
Any hint on how to get a proper icon would be appreciated
]]>