Skip to content

Commit

Permalink
Start/Stop/Disconnect works; State change requires gksudo
Browse files Browse the repository at this point in the history
  • Loading branch information
I Heart Engineering committed Jul 26, 2012
1 parent 64a5a24 commit a8d84c1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
7 changes: 7 additions & 0 deletions debian/changelog
@@ -1,3 +1,10 @@
turtlebot-indicator (0.0.2) precise; urgency=low

* Start/Stop/Disconnect works
* State change requires gksudo

-- I Heart Engineering <code@iheartengineering.com> Thu, 26 Jul 2012 18:04:31 -0400

turtlebot-indicator (0.0.1) precise; urgency=low

* Basic status working
Expand Down
38 changes: 31 additions & 7 deletions turtlebot-indicator
Expand Up @@ -37,6 +37,7 @@ import sys
import gobject
import gtk
import appindicator
import subprocess
import rosgraph.masterapi

class TurtleBotIndicator:
Expand All @@ -56,6 +57,14 @@ class TurtleBotIndicator:
self._subs = {} # Subscribers keyed by topic

def update(self):
p = subprocess.Popen(['turtlebot-network','interface'], stdout=subprocess.PIPE)
output = p.communicate()[0].strip()
p.wait()
if output != "lo":
self._network_online = True
else:
self._network_online = False

if not self._master_online and self._master.is_online():
self._master_update = True
self._master_online = True
Expand Down Expand Up @@ -104,15 +113,30 @@ class TurtleBotIndicator:
self._turtlebot_online = True
#self._nodes = list(set(self._pubs.values() + self._subs.values()))

def menuitem_shutdown (self,item):
os.system('gksudo "initctl stop turtlebot"')

def menuitem_startup (self,item):
os.system('gksudo "initctl start turtlebot"')

def build_menu(self):
self._menu = gtk.Menu()

if self._turtlebot_online:
self._ind.set_icon ("turtlebot-panel")
topic_item = gtk.MenuItem("Online")
topic_item.set_sensitive(False)
topic_item.show()
self._menu.append(topic_item)
if self._network_online:
if self._turtlebot_online:
self._ind.set_icon ("turtlebot-panel")
topic_item = gtk.MenuItem("Stop TurtleBot")
topic_item.set_sensitive(True)
topic_item.show()
topic_item.connect("activate",self.menuitem_shutdown)
self._menu.append(topic_item)
else:
self._ind.set_icon ("turtlebot-idle")
topic_item = gtk.MenuItem("Start TurtleBot")
topic_item.set_sensitive(True)
topic_item.show()
topic_item.connect("activate",self.menuitem_startup)
self._menu.append(topic_item)
else:
self._ind.set_icon ("turtlebot-idle")
disconnect_item = gtk.MenuItem("disconnected")
Expand All @@ -124,7 +148,7 @@ class TurtleBotIndicator:
def run(self):
self.update()
if not self._exit:
source_id = gobject.timeout_add(1000, self.run)
source_id = gobject.timeout_add(2000, self.run)

def start(self):
self.run()
Expand Down

0 comments on commit a8d84c1

Please sign in to comment.