Skip to content

Instantly share code, notes, and snippets.

John Stowers nzjrs

View GitHub Profile
@nzjrs
nzjrs / gtkcolorbutton.py
Created Feb 24, 2013
A PyGObject / GTK implementation of a solid color GtkButton
View gtkcolorbutton.py
import numpy
import cairo
from math import pi
from gi.repository import Gtk,Gdk
def draw_rounded(cr, area, radius):
a,b,c,d=area
cr.arc(a + radius, c + radius, radius, 2*(pi/2), 3*(pi/2))
cr.arc(b - radius, c + radius, radius, 3*(pi/2), 4*(pi/2))
@nzjrs
nzjrs / gtkmodebutton.py
Last active Dec 11, 2015
A PyGObject / GTK implementation of a ModeButton / ModeButtonBox
View gtkmodebutton.py
from gi.repository import Gtk
class _ButtonBoxMixin(object):
def add(self, widget):
self.pack_start(widget)
def pack_start(self, widget, *args, **kwargs):
if type(widget) is Gtk.RadioButton:
widget.props.draw_indicator = False
@nzjrs
nzjrs / bomb.py
Created Sep 28, 2012
Macgyver Bomb
View bomb.py
import threading
import time
import serial
from gi.repository import Gtk, Gdk, GObject
GObject.threads_init()
Gdk.threads_init()
@nzjrs
nzjrs / denumpy.py
Created Sep 19, 2012
Recursively convert dicts containg np types into primitive equivs
View denumpy.py
import numpy as np
def fix(d):
#d = d.copy()
for k,v in d.items():
if type(v) == dict:
d[k] = fix(v)
elif isinstance(v,np.floating):
d[k] = float(v)
elif isinstance(v,np.integer):
@nzjrs
nzjrs / caironumpy.py
Last active Oct 10, 2016
Mixing Cairo, Gtk, and numpy
View caironumpy.py
# http://stackoverflow.com/a/10031877
import numpy
import cairo
import math
from gi.repository import Gtk,Gdk
data = numpy.zeros((200, 200, 4), dtype=numpy.uint8)
surface = cairo.ImageSurface.create_for_data(
@nzjrs
nzjrs / .gitmodules
Created Mar 29, 2012
University of Canterbury Thesis Template
View .gitmodules
[submodule "documents/latex-makefile"]
path = documents/latex-makefile
url = git://gist.github.com/503886.git
@nzjrs
nzjrs / Makefile
Created Feb 11, 2012
Testing ORC - The Oil Runtime Compiler
View Makefile
all: testc testorc
clean:
rm -f testc testorc out.c out.h
testc: out.c test.c
$(CC) -DDISABLE_ORC=1 -o $@ $^
testorc: out.c test.c
$(CC) -o $@ $^ `pkg-config --cflags --libs orc-0.4`
@nzjrs
nzjrs / dotdict.py
Created Sep 7, 2011
Namespaced foo.bar.baz dict wrapper
View dotdict.py
import UserDict
class DotDict(UserDict.IterableUserDict):
def __init__(self):
UserDict.IterableUserDict.__init__(self)
def __setitem__(self, key, val):
bits = key.split(".")
if bits[0] not in self.data:
@nzjrs
nzjrs / skype-notify.py
Created Jun 3, 2011
Python script to make Skype co-operate with GNOME3 notifications
View skype-notify.py
#!/usr/bin/env python
# Python script to make Skype co-operate with GNOME3 notifications.
#
#
# Copyright (c) 2011, John Stowers
#
# Adapted from skype-notify.py
# Copyright (c) 2009, Lightbreeze
#
#
@nzjrs
nzjrs / Makefile
Created May 25, 2011
Python ctypes example
View Makefile
all: test libtest.so testmodule
libtest.so: libtest.c
$(CC) -Wall -g -fPIC -shared -o $@ $? -lc
test: test_main.c libtest.o
$(CC) -o $@ $?
testmodule: testmodule.c
python setup.py build
You can’t perform that action at this time.