Added Pause option, fixed bug with accumulating event triggers
Pause option added. So you can easily toggle whether pings are going out without having to fully kill pinger. Fixed a bug where toggling the autostart option would cumulatively add new event handlers, eventually making the program unresponsive after several toggles.
This commit is contained in:
parent
f09333305b
commit
fc6f5bdbcf
23
pinger.py
23
pinger.py
|
@ -50,6 +50,8 @@ import sys
|
||||||
# Vars
|
# Vars
|
||||||
startup_active_label = "✓ Start Automatically"
|
startup_active_label = "✓ Start Automatically"
|
||||||
startup_inactive_label = "Start Automatically"
|
startup_inactive_label = "Start Automatically"
|
||||||
|
pause_label = "Pause"
|
||||||
|
play_label = "Resume"
|
||||||
home_path = os.path.expanduser("~")
|
home_path = os.path.expanduser("~")
|
||||||
startup_path = home_path+'/.config/autostart/pinger.desktop'
|
startup_path = home_path+'/.config/autostart/pinger.desktop'
|
||||||
startup_dir = home_path+'/.config/autostart/'
|
startup_dir = home_path+'/.config/autostart/'
|
||||||
|
@ -96,8 +98,10 @@ else:
|
||||||
|
|
||||||
class Pinger:
|
class Pinger:
|
||||||
ping_log = []
|
ping_log = []
|
||||||
|
paused = False
|
||||||
|
|
||||||
def ping(self, widget=None, data=None):
|
def ping(self, widget=None, data=None):
|
||||||
|
if not self.paused:
|
||||||
ping = subprocess.Popen(
|
ping = subprocess.Popen(
|
||||||
["ping", "-c", "1", host],
|
["ping", "-c", "1", host],
|
||||||
stdout = subprocess.PIPE,
|
stdout = subprocess.PIPE,
|
||||||
|
@ -150,14 +154,26 @@ class Pinger:
|
||||||
def remove_autostart(self, widget, data=None):
|
def remove_autostart(self, widget, data=None):
|
||||||
os.remove(startup_path)
|
os.remove(startup_path)
|
||||||
self.update_startup_menu()
|
self.update_startup_menu()
|
||||||
|
print "Removed"
|
||||||
|
|
||||||
|
def toggle_pause(self, widget, data=None):
|
||||||
|
if self.paused:
|
||||||
|
self.paused = False
|
||||||
|
else:
|
||||||
|
self.paused = True
|
||||||
|
self.update_pause_menu()
|
||||||
|
|
||||||
def update_startup_menu(self):
|
def update_startup_menu(self):
|
||||||
if os.path.exists(startup_path):
|
if os.path.exists(startup_path):
|
||||||
self.startup_menu.set_label(startup_active_label)
|
self.startup_menu.set_label(startup_active_label)
|
||||||
self.startup_menu.connect("activate", self.remove_autostart, startup_active_label)
|
|
||||||
else:
|
else:
|
||||||
self.startup_menu.set_label(startup_inactive_label)
|
self.startup_menu.set_label(startup_inactive_label)
|
||||||
self.startup_menu.connect("activate", self.create_autostart, startup_inactive_label)
|
|
||||||
|
def update_pause_menu(self):
|
||||||
|
if self.paused:
|
||||||
|
self.pause_menu.set_label(play_label)
|
||||||
|
else:
|
||||||
|
self.pause_menu.set_label(pause_label)
|
||||||
|
|
||||||
def update_log_menu(self):
|
def update_log_menu(self):
|
||||||
graph = ""
|
graph = ""
|
||||||
|
@ -192,6 +208,9 @@ class Pinger:
|
||||||
|
|
||||||
# create a menu
|
# create a menu
|
||||||
self.menu = Gtk.Menu()
|
self.menu = Gtk.Menu()
|
||||||
|
# with pause option
|
||||||
|
self.pause_menu = self.create_menu_item(pause_label, self.toggle_pause)
|
||||||
|
self.update_pause_menu()
|
||||||
# with autostart option
|
# with autostart option
|
||||||
self.startup_menu = self.create_menu_item(startup_inactive_label, self.create_autostart)
|
self.startup_menu = self.create_menu_item(startup_inactive_label, self.create_autostart)
|
||||||
self.update_startup_menu()
|
self.update_startup_menu()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user