From 491d629bf0ab0315f6d1b4858c7c76ae431b97dd Mon Sep 17 00:00:00 2001
From: Anton Sarukhanov <code@ant.sr>
Date: Sun, 8 Feb 2015 17:38:20 +0000
Subject: [PATCH] Added IP address and shutdown button

---
 requirements.txt | 23 ++++++++++++++++-------
 testbox.py       | 25 +++++++++++++++++++++++--
 2 files changed, 39 insertions(+), 9 deletions(-)

diff --git a/requirements.txt b/requirements.txt
index 9f60220..46e280f 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,8 +1,17 @@
-Cython==0.21
-Kivy==1.9.0-dev
+Cython==0.21.2
+docutils==0.12
+Kivy==1.9.0.dev0
 Kivy-Garden==0.1.1
-argparse==1.2.1
-distribute==0.6.24
-pygame==1.9.1release
-requests==2.4.3
-wsgiref==0.1.2
+mcpi==0.1.1
+numpy==1.6.2
+picamera==1.8
+pifacecommon==4.0.0
+pifacedigitalio==3.0.4
+pygame===1.9.1release
+pyglet==1.1.4
+Pygments==2.0.1
+pygobject==3.8.2
+pyserial==2.5
+requests==2.5.1
+RPi.GPIO==0.5.8
+smbus==1.1
diff --git a/testbox.py b/testbox.py
index 54481ac..a864ffe 100644
--- a/testbox.py
+++ b/testbox.py
@@ -1,5 +1,5 @@
-#import kivy
 import os
+import netifaces
 
 os.environ['SDL_VIDEODRIVER'] = 'fbcon'
 os.environ['SDL_FBDEV'] = '/dev/fb1'
@@ -52,6 +52,7 @@ class MyApp(App):
             self.layout.add_widget(self.pb[channel])
         self.meter = Meter(self.channels)
         Clock.schedule_interval(self.measure, 0.01)
+        Clock.schedule_interval(self.get_IP_address, 2)
         return self.layout
     def measure(self, dt):
         measurements = self.meter.measure()
@@ -94,7 +95,27 @@ class MyApp(App):
             # Nothing was found connected
             self.layout.clear_widgets()
             self.layout.add_widget(Label(text="Connect something!", font_size=48))
-
+            poweroff_button = Button(text="[color=ff0000]Shut Down[/color]", font_size=24, markup=True)
+            poweroff_button.bind(on_press=self.poweroff)
+            self.layout.add_widget(poweroff_button)
+            # Display IP address if we have one
+            if hasattr(self, 'ip_address_string') and self.ip_address_string:
+                self.layout.add_widget(Label(
+                    text="[color=3333ff]IP: {0}[/color]"\
+                        .format(self.ip_address_string),
+                    font_size=36,
+                    markup=True
+                    ))
+    def get_IP_address(self, dt):
+        try:
+            gateway_interface = netifaces.gateways()[netifaces.AF_INET][0][1]
+            ip_addresses = netifaces.ifaddresses(gateway_interface)
+            internet_ip_addresses = [addr['addr'] for addr in ip_addresses[netifaces.AF_INET]]
+            self.ip_address_string = ", ".join(internet_ip_addresses)
+        except KeyError:
+            self.ip_address_string = None
+    def poweroff(self, dt):
+        os.system('poweroff')
 
 if __name__ == '__main__':
     MyApp().run()
-- 
GitLab