Skip to content

Instantly share code, notes, and snippets.

View nzjrs's full-sized avatar

John nzjrs

View GitHub Profile
@nzjrs
nzjrs / gtk-theme-swatch.py
Created January 21, 2009 01:25
PyGtk widget that displays color swatches according you your Gtk theme
#!/usr/bin/env python
# gtk-theme-swatch: A PyGtk widget that displays the color swatches of all
# gtk.Styles, in all states. Useful for designing themes
# author: John Stowers <[email protected]>
import gtk
class ThemeSwatch(gtk.DrawingArea):
SWATCH_SIZE = 50 #swatch size
@nzjrs
nzjrs / FooThread.py
Created January 25, 2009 04:43
PyGtk threading example
# Demo application showing how once can combine the python
# threading module with GObject signals to make a simple thread
# manager class which can be used to stop horrible blocking GUIs.
#
# (c) 2008, John Stowers <[email protected]>
#
# This program serves as an example, and can be freely used, copied, derived
# and redistributed by anyone. No warranty is implied or given.
import gtk
import gobject
@nzjrs
nzjrs / emit.py
Created February 2, 2009 04:05
Python example demonstrating when callbacks are run in a threaded environment
#!/usr/bin/env python
# Python example demonstrating when callbacks are run in a threaded environment
# John Stowers
import threading
import thread
import time
import gobject
import gtk
@nzjrs
nzjrs / mem_usage.py
Created February 5, 2009 11:07
Prints the memory usage (including private and dirty) for a given PID
#!/usr/bin/env python
# Prints the memory usage (including private and dirty) for a given PID
#
import sys
import re
def permute(args):
ret = []
if args:
@nzjrs
nzjrs / animated-status-icon.py
Created June 27, 2009 04:55
Animated Gtk+ StatusIcon
#!/usr/bin/env python
"""
Animated Gtk+ StatusIcon
Given an icon name or path, animates the icon in a number of ways, rotating,
shrinking, saturating it, etc.
Inspiration from:
http://groups.google.com/group/sage-devel/browse_thread/thread/f9aeba22ac171082
"""
@nzjrs
nzjrs / gtk-curve-test.py
Created June 30, 2009 22:25
Demo for testing gtk.Curve
#!/usr/bin/env python
# Demo for testing gtk.Curve
# John Stowers 2009
import random
import gtk
class UI:
TYPES = (gtk.CURVE_TYPE_LINEAR, gtk.CURVE_TYPE_SPLINE, gtk.CURVE_TYPE_FREE)
@nzjrs
nzjrs / test-rtgraph.py
Created July 12, 2009 11:11
python rtgraph demo
#!/usr/bin/env python
# A simple example of using multiple rtgraph HScrollLineGraph widgets
# Micah Dowty <[email protected]>, John Stowers
#
import gtk
import time, math, re
import gs.ui.rtgraph as rtgraph
windows = []
@nzjrs
nzjrs / curses-demo.py
Created August 8, 2009 03:26
Helper for using curses from python
#!/usr/bin/env python
# This module provides a 'with' for using curses in Python.
# from: http://www.finalcog.com/python-with-curses-with_curses
from __future__ import with_statement
import curses
class WithCurses(object):
"""
@nzjrs
nzjrs / datedifference.py
Created October 11, 2009 11:38
Humanize date differences
#!/usr/bin/env python
# This function prints the difference between two python datetime objects
# in a more human readable form
#
# Adapted from: http://www.chimeric.de/blog/2008/0711_smart_dates_in_python
def humanize_date_difference(now, otherdate=None, offset=None):
if otherdate:
dt = otherdate - now
offset = dt.seconds + (dt.days * 60*60*24)
@nzjrs
nzjrs / fix-update-copyright-headers.py
Created October 13, 2009 11:36
Update or add copyright headers to source files.