Skip to content

Instantly share code, notes, and snippets.

@philayres
Created October 24, 2011 19:21
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save philayres/1309895 to your computer and use it in GitHub Desktop.
Save philayres/1309895 to your computer and use it in GitHub Desktop.
Unity indicator for simple clock and date display
#!/usr/bin/env python
# Unity indicator for evolution-less clock and date display
# author: phil ayres
# 24 Oct 2011
import gobject
import gtk
import appindicator
import os, sys
import time
from time import gmtime, strftime
if __name__ == "__main__":
#def on_left_click(widget,data=None):
# Placeholder for later
def on_timer(args=None):
ind.set_label(strftime("%H:%M",time.localtime()))
item.set_label(strftime("%a, %d %b %Y - %H:%M",time.localtime()))
return True
ind = appindicator.Indicator ("simple-clock-client", "clock", appindicator.CATEGORY_APPLICATION_STATUS)
ind.set_status (appindicator.STATUS_ACTIVE)
ind.set_label(strftime("%H:%M",time.localtime()));
menu = gtk.Menu()
item = gtk.MenuItem(strftime("%a, %d %b %Y",time.localtime()))
#item.connect("activate", on_left_click)
item.show()
menu.append(item)
ind.set_menu(menu)
gtk.timeout_add(1000, on_timer)
gtk.main()
@philayres
Copy link
Author

Very simple indicator which I hacked together. I wanted date and time on my indicator panel, without the Evolution resource hogs that are dependencies of the standard Ubuntu 11.10 clock indicator. Since Evolution calendar has (had?) a memory leak in 11.04 I stopped using Evolution and found the clock was impossible to use because of this.

Inspired by Mark Bokil (via http://www.webupd8.org/2011/10/show-desktop-indicator-for-ubuntu-quick.html#more )

You'll need to install wmctrl first, then run the .py file (which I chmod'ed and added to started applications)
sudo apt-get install wmctrl

@philayres
Copy link
Author

Step by step details for installing the indicator:

Download the Gist using the download button above.
Extract the file from the archive file then find the file using the file browser, right click and select Extract Here (or use the command line tar -zxvf gist1309895-43a546ee21b5c650b81ab41e04a887775c2cf16d.tar.gz if you prefer)

Go to your Home directory, and create a new directory called Scripts
Move the extracted file to this new directory.

Hit Ctrl-Alt-T to open a terminal (or through the Unity Dash type Terminal in the search box).
At the prompt, type the following and enter your password when prompted:

sudo apt-get install wmctrl

Follow any prompts to install the package.

Then, we need to make the indicator script executable. In the terminal, type:

chmod 755 ~/Scripts/display-indicator.py

Now, to add the date time indicator to run automatically at startup, search for "Startup Applications" in Dash, click "Add", under "Name" enter "Date Time" and under "Command" click "Browse" and select "desktop-indicator.py" from your Scripts directory.

You may log-off and log in to get the indicator to display, or just run the following from the terminal:

~/Scripts/display-indicator.py &

That's all. Please feel free to Star this gist so others can find it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment