Adding autostart in Ubuntu
This commit is contained in:
parent
b925f1a130
commit
5cb2e7f027
17
README.md
17
README.md
|
@ -3,12 +3,13 @@ Pinger.py
|
||||||
A ping tool that sits in your system tray
|
A ping tool that sits in your system tray
|
||||||
---------
|
---------
|
||||||
|
|
||||||
- Currently for Ubuntu only
|
|
||||||
- (Requires Python, GTK, and AppIndicator3)
|
|
||||||
- **Contributions welcome to expand to other OSes!**
|
|
||||||
- Saves your sanity when the wifi sucks
|
- Saves your sanity when the wifi sucks
|
||||||
- Doesn't clutter up your screen with ping windows
|
- Doesn't clutter up your screen with ping windows
|
||||||
- Lets you know when pings fail instead of silently failing
|
- 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):**
|
**Usage (in Ubuntu):**
|
||||||
|
|
||||||
|
@ -16,14 +17,8 @@ Open the Terminal program and enter the following commands:
|
||||||
|
|
||||||
cd ~
|
cd ~
|
||||||
git clone https://github.com/zyphlar/pinger.git
|
git clone https://github.com/zyphlar/pinger.git
|
||||||
|
python pinger/pinger.py &
|
||||||
|
|
||||||
Open the Startup Applications program and click Add.
|
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.
|
||||||
|
|
||||||
Name: Pinger
|
|
||||||
Command: python ~/pinger/pinger.py
|
|
||||||
|
|
||||||
Click Save, and Close.
|
|
||||||
|
|
||||||
Pinger should now start automatically in your system tray when you login next. (It just says "xx.x ms"). You can test it manually by typing `python ~/pinger/pinger.py` in your terminal and pressing Enter.
|
|
||||||
|
|
||||||
Report bugs or feature requests at https://github.com/zyphlar/pinger/issues
|
Report bugs or feature requests at https://github.com/zyphlar/pinger/issues
|
||||||
|
|
36
pinger.py
36
pinger.py
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
#
|
#
|
||||||
# Pinger.py -- A ping tool that sits in your system tray
|
# Pinger.py -- A ping tool that sits in your system tray
|
||||||
# Copyright 2013 Will Bradley
|
# Copyright 2013 Will Bradley
|
||||||
|
@ -43,6 +44,14 @@ import subprocess
|
||||||
import re
|
import re
|
||||||
# Ctrl-c
|
# Ctrl-c
|
||||||
import signal
|
import signal
|
||||||
|
# File paths
|
||||||
|
import os
|
||||||
|
|
||||||
|
# Vars
|
||||||
|
startup_active_label = "✓ Start Automatically"
|
||||||
|
startup_inactive_label = "Start Automatically"
|
||||||
|
home_path = os.path.expanduser("~")
|
||||||
|
startup_path = home_path+'/.config/autostart/pinger.desktop'
|
||||||
|
|
||||||
#
|
#
|
||||||
# Main Class
|
# Main Class
|
||||||
|
@ -71,11 +80,34 @@ class Pinger:
|
||||||
self.menu.append(menu_item)
|
self.menu.append(menu_item)
|
||||||
menu_item.connect("activate", callback, text)
|
menu_item.connect("activate", callback, text)
|
||||||
menu_item.show()
|
menu_item.show()
|
||||||
|
return menu_item
|
||||||
|
|
||||||
def destroy(self, widget, data=None):
|
def destroy(self, widget, data=None):
|
||||||
print "destroy signal occurred"
|
print "Quitting..."
|
||||||
Gtk.main_quit()
|
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.set_label(startup_active_label)
|
||||||
|
self.startup_menu.connect("activate", self.remove_autostart, startup_active_label)
|
||||||
|
else:
|
||||||
|
self.startup_menu.set_label(startup_inactive_label)
|
||||||
|
self.startup_menu.connect("activate", self.create_autostart, startup_inactive_label)
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# Handle ctrl-c
|
# Handle ctrl-c
|
||||||
signal.signal(signal.SIGINT, self.destroy)
|
signal.signal(signal.SIGINT, self.destroy)
|
||||||
|
@ -90,6 +122,8 @@ class Pinger:
|
||||||
|
|
||||||
# create a menu
|
# create a menu
|
||||||
self.menu = Gtk.Menu()
|
self.menu = Gtk.Menu()
|
||||||
|
self.startup_menu = self.create_menu_item(startup_inactive_label, self.create_autostart)
|
||||||
|
self.update_startup_menu()
|
||||||
self.create_menu_item("Exit", self.destroy)
|
self.create_menu_item("Exit", self.destroy)
|
||||||
self.ind.set_menu(self.menu)
|
self.ind.set_menu(self.menu)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user