<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<atom:link href="http://forum.ubuntu-fr.org/extern.php?action=feed&amp;tid=1064941&amp;type=rss" rel="self" type="application/rss+xml" />
		<title><![CDATA[Forum Ubuntu-fr.org / [résolu]Affichage pourcentage batterie]]></title>
		<link>http://forum.ubuntu-fr.org/viewtopic.php?id=1064941</link>
		<description><![CDATA[Les sujets les plus récents dans [résolu]Affichage pourcentage batterie.]]></description>
		<lastBuildDate>Mon, 15 Oct 2012 22:43:09 +0000</lastBuildDate>
		<generator>FluxBB</generator>
		<item>
			<title><![CDATA[Réponse à&#160;:  [résolu]Affichage pourcentage batterie]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=11136351#p11136351</link>
			<description><![CDATA[<p>de rien <img src="http://forum.ubuntu-fr.org/img/smilies/wink.png" width="15" height="15" alt="wink" /></p><p>un p&#039;tit [résolu] ?</p>]]></description>
			<author><![CDATA[dummy@example.com (nesthib)]]></author>
			<pubDate>Mon, 15 Oct 2012 22:43:09 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=11136351#p11136351</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  [résolu]Affichage pourcentage batterie]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=11133481#p11133481</link>
			<description><![CDATA[<p>Salut !</p><p>Oui je me doutais qu&#039;il existait des outils, mais je ne connais pas du tout python alors j&#039;ai bricolé comme j&#039;ai pu <img src="http://forum.ubuntu-fr.org/img/smilies/tongue.png" width="15" height="15" alt="tongue" /></p><p>C&#039;est parfait maintenant :</p><div class="codebox"><pre><code>#!/usr/bin/python
import sys
import pynotify
import subprocess
import re

s=subprocess.check_output(&quot;upower -i /org/freedesktop/UPower/devices/battery_BAT0&quot;, shell=True)
j=(&#039;%s%%&#039; % re.findall(&#039;percentage: *([0-9]+\.?[0-9]?)&#039;, s)[0])

#s=subprocess.check_output(&#039;./battery.sh&#039;, shell=True)

if __name__ == &quot;__main__&quot;:
    if not pynotify.init(&quot;icon-summary-body&quot;):
        sys.exit(1)
 
    n = pynotify.Notification(&quot;Batterie :&quot;,
	j)
    n.show()</code></pre></div><p>Je trouve que c&#039;est une très bonne alternative à l&#039;affichage du pourcentage de la batterie comme indicateur<br />Merci pour ta contribution !</p>]]></description>
			<author><![CDATA[dummy@example.com (Vicolaships)]]></author>
			<pubDate>Mon, 15 Oct 2012 19:15:04 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=11133481#p11133481</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  [résolu]Affichage pourcentage batterie]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=11092461#p11092461</link>
			<description><![CDATA[<div class="quotebox"><cite>Vicolaships a écrit&#160;:</cite><blockquote><div><p>J&#039;ai une suite de sed qui me permet de ne garder que le premier chiffre après la virgule d&#039;un nombre dans une chaine de caractères :</p><div class="codebox"><pre><code>echo &quot;percentage : 95.8342%&quot; | sed &#039;s/[^0-9,.]*//g&#039; | sed &#039;s/\(\.[0-9]\).*$/\1/g&#039;
&gt;95.8</code></pre></div></div></blockquote></div><div class="codebox"><pre><code>echo &quot;percentage : 95.8342%&quot; | sed &#039;s/[^0-9]*\([0-9]\+\.\?[0-9]\?\).*/\1/&#039;</code></pre></div><p>après, franchement, tu utilises python… pourquoi ne pas profiter de sa puissance ?</p><div class="codebox"><pre><code>import re
import subprocess

s=subprocess.check_output(&quot;upower -i /org/freedesktop/UPower/devices/battery_BAT0&quot;, shell=True)
print(&#039;Batterie:\n%s%%&#039; % re.findall(&#039;percentage: *([0-9]+\.?[0-9]?)&#039;, s)[0])</code></pre></div>]]></description>
			<author><![CDATA[dummy@example.com (nesthib)]]></author>
			<pubDate>Fri, 12 Oct 2012 00:30:00 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=11092461#p11092461</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  [résolu]Affichage pourcentage batterie]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=11085361#p11085361</link>
			<description><![CDATA[<p>Bon j&#039;ai quelque chose qui me convient :</p><p>battery.sh</p><div class="codebox"><pre><code>echo $((100*$(sed -n &quot;s/remaining capacity: *\(.*\) m[AW]h/\1/p&quot; /proc/acpi/battery/BAT0/state)/$(sed -n &quot;s/last full capacity: *\(.*\) m[AW]h/\1/p&quot; /proc/acpi/battery/BAT0/info)))%</code></pre></div><p>battery-percentage</p><div class="codebox"><pre><code>#!/usr/bin/python
import sys
import pynotify
import subprocess

s=subprocess.check_output(&#039;./battery.sh&#039;, shell=True)

if __name__ == &quot;__main__&quot;:
    if not pynotify.init(&quot;icon-summary-body&quot;):
        sys.exit(1)
 
    n = pynotify.Notification(&quot;Batterie :&quot;,
	s,&quot;%&quot;)
    n.show()</code></pre></div><p>On copie les scripts pour pouvoir les executer partout : </p><div class="codebox"><pre><code>sudo cp battery.sh /usr/bin &amp;&amp; sudo battery-percentage /usr/bin &amp;&amp; battery-percentage</code></pre></div><p>Dans Compiz on peut créer un raccourci qui lance la commande &quot;battery-percentage&quot;.<br />Chez moi Super+B donne :</p><p><span class="postimg"><img src="http://data.imagup.com/11/1164629346.png" alt="1164629346.png" /></span></p>]]></description>
			<author><![CDATA[dummy@example.com (Vicolaships)]]></author>
			<pubDate>Thu, 11 Oct 2012 13:54:18 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=11085361#p11085361</guid>
		</item>
		<item>
			<title><![CDATA[Réponse à&#160;:  [résolu]Affichage pourcentage batterie]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=11084841#p11084841</link>
			<description><![CDATA[<p>Maintenant j&#039;ai :</p><div class="codebox"><pre><code>#!/usr/bin/python
import sys
import pynotify
import subprocess

# sed &#039;s/[^0-9,.]*//g&#039;
# sed &#039;s/\(\.[0-9]\).*$/\1/g&#039;
s=subprocess.check_output(&quot;upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep percentage | sed &#039;s/[^0-9,.]*//g&#039;&quot;, shell=True)

if __name__ == &quot;__main__&quot;:
    if not pynotify.init(&quot;icon-summary-body&quot;):
        sys.exit(1)
 
    n = pynotify.Notification(&quot;Batterie :&quot;,
	s,&quot;%&quot;)
    n.show()</code></pre></div><p>C&#039;est beaucoup mieux, mais c&#039;est dommage car je n&#039;arrive pas à mettre l&#039;autre sed pour tronquer la valeur. La &quot;%&quot; ne s&#039;affiche pas, et quand j&#039;arrive à l&#039;afficher il est sur la ligne suivante.</p><p>Un petit peu d&#039;aide ? <img src="http://forum.ubuntu-fr.org/img/smilies/smile.png" width="15" height="15" alt="smile" /></p>]]></description>
			<author><![CDATA[dummy@example.com (Vicolaships)]]></author>
			<pubDate>Thu, 11 Oct 2012 13:11:08 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=11084841#p11084841</guid>
		</item>
		<item>
			<title><![CDATA[[résolu]Affichage pourcentage batterie]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=11084271#p11084271</link>
			<description><![CDATA[<p>Salut, sous Ubuntu 12.04 j&#039;aimerai un affichage du pourcentage de la batterie avec un raccourci.<br />Je créé donc un script python qui va générer une notification en utilisant&#160; python-notify (sudo apt-get install python-notify)</p><p>Par contre j&#039;arrive pas à afficher proprement la valeur du pourcentage; voilà le script :</p><div class="codebox"><pre><code>#!/usr/bin/python
import sys
import pynotify
import subprocess

s=subprocess.check_output([&quot;upower&quot;, &quot;-i&quot;, &quot;/org/freedesktop/UPower/devices/battery_BAT0&quot;, &quot;|&quot;, &quot;grep&quot;, &quot;alpha&quot;])
 
if __name__ == &quot;__main__&quot;:
    if not pynotify.init(&quot;icon-summary-body&quot;):
        sys.exit(1)
 
    n = pynotify.Notification(&quot;Batterie :&quot;,
	s+&quot;%&quot;)
    n.show()</code></pre></div><p>Le <em>| grep &quot;alpha&quot;</em> n&#039;est pas pris en compte. </p><p>J&#039;ai une suite de sed qui me permet de ne garder que le premier chiffre après la virgule d&#039;un nombre dans une chaine de caractères :</p><div class="codebox"><pre><code>echo &quot;percentage : 95.8342%&quot; | sed &#039;s/[^0-9,.]*//g&#039; | sed &#039;s/\(\.[0-9]\).*$/\1/g&#039;
&gt;95.8</code></pre></div><p>L&#039;affichage idéal serait donc :</p><div class="codebox"><pre><code>Batterie :
98.9%</code></pre></div><p>Un petit peu d&#039;aide serait bienvenue pour assembler tout ça <img src="http://forum.ubuntu-fr.org/img/smilies/smile.png" width="15" height="15" alt="smile" /></p>]]></description>
			<author><![CDATA[dummy@example.com (Vicolaships)]]></author>
			<pubDate>Thu, 11 Oct 2012 12:12:02 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=11084271#p11084271</guid>
		</item>
	</channel>
</rss>
