Skip to content

Instantly share code, notes, and snippets.

View nzjrs's full-sized avatar

John nzjrs

View GitHub Profile
@nzjrs
nzjrs / gtkcolorbutton.py
Created February 24, 2013 12:15
A PyGObject / GTK implementation of a solid color GtkButton
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 December 11, 2015 20:59
A PyGObject / GTK implementation of a ModeButton / ModeButtonBox
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 September 28, 2012 09:37
Macgyver Bomb
import threading
import time
import serial
from gi.repository import Gtk, Gdk, GObject
GObject.threads_init()
Gdk.threads_init()
@nzjrs
nzjrs / denumpy.py
Created September 19, 2012 16:48
Recursively convert dicts containg np types into primitive equivs
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 October 10, 2016 04:04
Mixing Cairo, Gtk, and numpy
# 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 March 29, 2012 05:00
University of Canterbury Thesis Template
[submodule "documents/latex-makefile"]
path = documents/latex-makefile
url = git://gist.github.com/503886.git
@nzjrs
nzjrs / Makefile
Created February 11, 2012 23:12
Testing ORC - The Oil Runtime Compiler
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 September 7, 2011 03:12
Namespaced foo.bar.baz dict wrapper
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 June 3, 2011 13:14
Python script to make Skype co-operate with GNOME3 notifications
#!/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 07:09
Python ctypes example
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