Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.97 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use Gtk2 '-init';
  5.  
  6. sub get_current_status_image
  7. {
  8.   `acpi` =~ /: (\w+)(, (\d+))?\%/;
  9.   my $status = $1;
  10.   my $percent = $3;
  11.  
  12.   my $result = '/usr/share/icons/oxygen/48x48/status/battery';
  13.   if ($status eq "Charging")
  14.   {
  15.     $result .= '-charging';
  16.   }
  17.   if ($status eq "Full")
  18.   {
  19.     $result .= '-100';
  20.   }
  21.  
  22.   if ($percent <= 20)
  23.   {
  24.     $result .= "-caution";
  25.   }
  26.   elsif ($percent <= 40)
  27.   {
  28.     $result .= "-low";
  29.   }
  30.   elsif ($percent <= 60)
  31.   {
  32.     $result .= "-040";
  33.   }
  34.   elsif ($percent <= 80)
  35.   {
  36.     $result .= "-060";
  37.   }
  38.   else
  39.   {
  40.     $result .= "-080";
  41.   }
  42.  
  43.   #print "Status: $status, $percent percent, result $result.png\n";
  44.   return $result . '.png';
  45. }
  46.  
  47. my $tray = Gtk2::StatusIcon->new;
  48.  
  49. $tray->set_from_file(get_current_status_image());
  50. $tray->set_visible(1);
  51.  
  52. Glib::Timeout->add (10 * 1000, sub
  53.   {
  54.     $tray->set_from_file(get_current_status_image());
  55.     return 1;
  56.   });
  57.  
  58. Gtk2->main;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement