Compare commits
2 Commits
checkmenui
...
gtk-status
| Author | SHA1 | Date | |
|---|---|---|---|
| e6f4038fb5 | |||
| 6fc219338f |
24
README.md
24
README.md
@@ -1,24 +0,0 @@
|
||||
Pinger.py
|
||||
=========
|
||||
A ping tool that sits in your system tray
|
||||
---------
|
||||
|
||||
- Saves your sanity when the wifi sucks
|
||||
- Doesn't clutter up your screen with ping windows
|
||||
- Lets you know when pings fail instead of silently failing
|
||||
- **Currently for Ubuntu only**
|
||||
- (Requires Python, GTK, and AppIndicator3)
|
||||
- Startup Automatically option creates a `~/.config/autostart/pinger.desktop` file
|
||||
- **Contributions welcome to expand to other OSes!**
|
||||
|
||||
**Usage (in Ubuntu):**
|
||||
|
||||
Open the Terminal program and enter the following commands:
|
||||
|
||||
cd ~
|
||||
git clone https://github.com/zyphlar/pinger.git
|
||||
python pinger/pinger.py &
|
||||
|
||||
Pinger should open in your system tray (It just looks like "XX.X ms"). To set Pinger to start automatically (in Ubuntu) click it and choose Start Automatically.
|
||||
|
||||
Report bugs or feature requests at https://github.com/zyphlar/pinger/issues
|
||||
4
README.txt
Normal file
4
README.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
Pinger.py -- A ping tool that sits in your system tray
|
||||
|
||||
+ Saves your sanity when the wifi sucks
|
||||
+ Doesn't clutter up your screen with ping windows
|
||||
BIN
activity.png
Normal file
BIN
activity.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.6 KiB |
114
appindicator.py
Normal file
114
appindicator.py
Normal file
@@ -0,0 +1,114 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2009-2012 Canonical Ltd.
|
||||
#
|
||||
# Authors: Neil Jagdish Patel <neil.patel@canonical.com>
|
||||
# Jono Bacon <jono@ubuntu.com>
|
||||
# David Planella <david.planella@ubuntu.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of either or both of the following licenses:
|
||||
#
|
||||
# 1) the GNU Lesser General Public License version 3, as published by the
|
||||
# Free Software Foundation; and/or
|
||||
# 2) the GNU Lesser General Public License version 2.1, as published by
|
||||
# the Free Software Foundation.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranties of
|
||||
# MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
|
||||
# PURPOSE. See the applicable version of the GNU Lesser General Public
|
||||
# License for more details.
|
||||
#
|
||||
# You should have received a copy of both the GNU Lesser General Public
|
||||
# License version 3 and version 2.1 along with this program. If not, see
|
||||
# <http://www.gnu.org/licenses/>
|
||||
#
|
||||
|
||||
from gi.repository import Gtk
|
||||
|
||||
# Timer
|
||||
from gi.repository import GObject as gobject
|
||||
# Pinging
|
||||
import subprocess
|
||||
# Regex
|
||||
import re
|
||||
|
||||
# Vars
|
||||
host = "www.google.com"
|
||||
|
||||
class HelloWorld:
|
||||
|
||||
def ping(self, widget=None, data=None):
|
||||
ping = subprocess.Popen(
|
||||
["ping", "-c", "1", host],
|
||||
stdout = subprocess.PIPE,
|
||||
stderr = subprocess.PIPE
|
||||
)
|
||||
out, error = ping.communicate()
|
||||
if error:
|
||||
label = "!! FAIL !!"
|
||||
else:
|
||||
m = re.search('time=(.*) ms', out)
|
||||
label = m.group(1)+" ms"
|
||||
#ind.set_label (label, "100.0 ms")
|
||||
status.set_title(label)
|
||||
#self.ping_menu_item.set_label(out)
|
||||
gobject.timeout_add_seconds(self.timeout, self.ping)
|
||||
|
||||
def destroy(self, widget, data=None):
|
||||
print "destroy signal occurred"
|
||||
Gtk.main_quit()
|
||||
|
||||
def __init__(self):
|
||||
# register a periodic timer
|
||||
self.counter = 0
|
||||
self.timeout = 1
|
||||
gobject.timeout_add_seconds(self.timeout, self.ping)
|
||||
|
||||
|
||||
def menuitem_response(w, buf):
|
||||
print buf
|
||||
|
||||
|
||||
def create_menu_item(menu, text, callback):
|
||||
|
||||
menu_items = Gtk.MenuItem(text)
|
||||
|
||||
menu.append(menu_items)
|
||||
|
||||
menu_items.connect("activate", callback, text)
|
||||
|
||||
# show the items
|
||||
menu_items.show()
|
||||
|
||||
return menu_items
|
||||
|
||||
if __name__ == "__main__":
|
||||
status = Gtk.StatusIcon()
|
||||
status.set_title("0.0 ms")
|
||||
status.set_from_stock(Gtk.STOCK_HOME)
|
||||
status.connect("activate",Gtk.Window.present)
|
||||
#ind = appindicator.Indicator.new (
|
||||
# "pinger",
|
||||
# "", #indicator-messages
|
||||
# appindicator.IndicatorCategory.COMMUNICATIONS)
|
||||
#ind.set_status (appindicator.IndicatorStatus.ACTIVE)
|
||||
#ind.set_attention_icon ("indicator-messages-new")
|
||||
#ind.set_label ("0.0 ms", "100.0 ms")
|
||||
|
||||
# create a menu
|
||||
menu = Gtk.Menu()
|
||||
|
||||
# and the app
|
||||
hello = HelloWorld()
|
||||
|
||||
# create menu items
|
||||
#hello.ping_menu_item = create_menu_item(menu, "Ping", hello.ping)
|
||||
create_menu_item(menu, "Exit", hello.destroy)
|
||||
|
||||
# Add the menu to our statusbar
|
||||
#ind.set_menu(menu)
|
||||
|
||||
# Runtime loop
|
||||
Gtk.main()
|
||||
32
new_gtk.py
Normal file
32
new_gtk.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import gtk
|
||||
|
||||
class Main(gtk.Window):
|
||||
|
||||
def __init__(self):
|
||||
super(Main, self).__init__()
|
||||
self.connect('delete-event', self.on_delete_event)
|
||||
self.set_title("Virtual Machine Monitor")
|
||||
self.set_position(gtk.WIN_POS_CENTER)
|
||||
self.set_default_size(640,600)
|
||||
self.set_geometry_hints(min_width=640, min_height=600)
|
||||
self.set_icon_from_file("activity.png")
|
||||
#menubar = self.add_menubar()
|
||||
|
||||
pixbuf = gtk.gdk.pixbuf_new_from_file_at_size("activity.png",25,25)
|
||||
statusicon = gtk.StatusIcon()
|
||||
statusicon.set_title("0.0 ms")
|
||||
statusicon = gtk.status_icon_new_from_pixbuf(pixbuf)
|
||||
statusicon.connect("activate",self.tray_activate)
|
||||
self.show_all()
|
||||
|
||||
def on_delete_event(self, widget, event):
|
||||
self.hide()
|
||||
return True
|
||||
|
||||
def tray_activate(self, widget):
|
||||
self.present()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
Main()
|
||||
gtk.main()
|
||||
152
pinger.py
152
pinger.py
@@ -1,152 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Pinger.py -- A ping tool that sits in your system tray
|
||||
# Copyright 2013 Will Bradley
|
||||
#
|
||||
# Authors: Will Bradley <bradley.will@gmail.com>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of either or both of the following licenses:
|
||||
#
|
||||
# 1) the GNU Lesser General Public License version 3, as published by the
|
||||
# Free Software Foundation; and/or
|
||||
# 2) the GNU Lesser General Public License version 2.1, as published by
|
||||
# the Free Software Foundation.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranties of
|
||||
# MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
|
||||
# PURPOSE. See the applicable version of the GNU Lesser General Public
|
||||
# License for more details.
|
||||
#
|
||||
# You should have received a copy of both the GNU Lesser General Public
|
||||
# License version 3 and version 2.1 along with this program. If not, see
|
||||
# <http://www.gnu.org/licenses/>
|
||||
#
|
||||
|
||||
# User-editable variables
|
||||
host = "4.2.2.2" # IP or hostname
|
||||
ping_frequency = 5 # in seconds
|
||||
|
||||
#
|
||||
# Dependencies
|
||||
#
|
||||
|
||||
# System Tray Icon
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import AppIndicator3 as appindicator
|
||||
# Timer
|
||||
from gi.repository import GObject as gobject
|
||||
# Pinging
|
||||
import subprocess
|
||||
# Regex
|
||||
import re
|
||||
# Ctrl-c
|
||||
import signal
|
||||
# File paths
|
||||
import os
|
||||
|
||||
# Vars
|
||||
startup_label = "Start Automatically"
|
||||
home_path = os.path.expanduser("~")
|
||||
startup_path = home_path+'/.config/autostart/pinger.desktop'
|
||||
|
||||
#
|
||||
# Main Class
|
||||
#
|
||||
|
||||
class Pinger:
|
||||
|
||||
def ping(self, widget=None, data=None):
|
||||
ping = subprocess.Popen(
|
||||
["ping", "-c", "1", host],
|
||||
stdout = subprocess.PIPE,
|
||||
stderr = subprocess.PIPE
|
||||
)
|
||||
out, error = ping.communicate()
|
||||
m = re.search('time=(.*) ms', out)
|
||||
if error or m == None:
|
||||
label = "PING FAIL"
|
||||
else:
|
||||
label = m.group(1)+" ms"
|
||||
self.ind.set_label (label, "100.0 ms")
|
||||
#self.ping_menu_item.set_label(out)
|
||||
gobject.timeout_add_seconds(self.timeout, self.ping)
|
||||
|
||||
def create_menu_item(self, menu_type, text, callback):
|
||||
if menu_type == "check":
|
||||
menu_item = Gtk.CheckMenuItem(text)
|
||||
menu_item.set_active(True)
|
||||
else:
|
||||
menu_item = Gtk.MenuItem(text)
|
||||
self.menu.append(menu_item)
|
||||
menu_item.connect("activate", callback, text)
|
||||
menu_item.show()
|
||||
return menu_item
|
||||
|
||||
def destroy(self, widget, data=None):
|
||||
print "Quitting..."
|
||||
Gtk.main_quit()
|
||||
|
||||
def create_autostart(self, widget, data=None):
|
||||
with open(startup_path,'w') as f:
|
||||
f.write("[Desktop Entry]\r\n"
|
||||
"Type=Application\r\n"
|
||||
"Exec=python "+os.path.abspath( __file__ )+"\r\n"
|
||||
"X-GNOME-Autostart-enabled=true\r\n"
|
||||
"Name=Pinger\r\n"
|
||||
"Comment=Pings the internet every few seconds")
|
||||
self.update_startup_menu()
|
||||
|
||||
def remove_autostart(self, widget, data=None):
|
||||
os.remove(startup_path)
|
||||
self.update_startup_menu()
|
||||
|
||||
def update_startup_menu(self):
|
||||
if os.path.exists(startup_path):
|
||||
self.startup_menu.connect("activate", self.remove_autostart, startup_label)
|
||||
self.startup_menu.set_active(False)
|
||||
else:
|
||||
self.startup_menu.connect("activate", self.create_autostart, startup_label)
|
||||
self.startup_menu.set_active(True)
|
||||
|
||||
def __init__(self):
|
||||
# Handle ctrl-c
|
||||
signal.signal(signal.SIGINT, self.destroy)
|
||||
|
||||
# Print welcome message
|
||||
print "Starting Pinger..."
|
||||
|
||||
# Create systray icon
|
||||
self.ind = appindicator.Indicator.new (
|
||||
"pinger",
|
||||
"", # no icon
|
||||
appindicator.IndicatorCategory.COMMUNICATIONS)
|
||||
self.ind.set_status (appindicator.IndicatorStatus.ACTIVE)
|
||||
self.ind.set_label ("Pinger Loading...", "Pinger Loading...")
|
||||
|
||||
# create a menu
|
||||
self.menu = Gtk.Menu()
|
||||
|
||||
self.startup_menu = self.create_menu_item("check",startup_label, self.remove_autostart)
|
||||
#self.update_startup_menu()
|
||||
self.create_menu_item(None, "Exit", self.destroy)
|
||||
self.ind.set_menu(self.menu)
|
||||
|
||||
# start the ping process
|
||||
self.counter = 0
|
||||
self.timeout = ping_frequency
|
||||
self.ping()
|
||||
|
||||
# Print started message
|
||||
print "Started."
|
||||
|
||||
# Begin runtime loop
|
||||
Gtk.main()
|
||||
|
||||
#
|
||||
# Runtime
|
||||
#
|
||||
|
||||
if __name__ == "__main__":
|
||||
pinger = Pinger()
|
||||
Reference in New Issue
Block a user