Skip to content

Instantly share code, notes, and snippets.

@Cilyan
Cilyan / celldatafunc_headers.py
Created March 15, 2015 21:04
This snippet illustrates how to use a CellDataFunc to add heading to each cells.
import pygtk
pygtk.require('2.0')
import gtk
data = [
[('val_a1', 'val_b1', 'val_c1', 'val_d1', 'val_e1'), ('', 'val_x1', 'val_y1', 'val_z1', ''), ('', 'val_x2', 'val_y2', 'val_z2', '')],
[('val_a2', 'val_b2', 'val_c2', 'val_d2', 'val_e2'), ('', 'val_x3', 'val_y3', 'val_z3', '')],
[('val_a3', 'val_b3', 'val_c3', 'val_d3', 'val_e3')],
[('val_a4', 'val_b4', 'val_c4', 'val_d4', 'val_e4'), ('', 'val_x4', 'val_y4', 'val_z4', ''), ('', 'val_x5', 'val_y5', 'val_z5', '')],
]
@Cilyan
Cilyan / treemodel_unevenrows_headers.py
Created March 15, 2015 20:30
This snippet illustrates the creation of a custom GtkTreeModel in PyGTK / Python 2 where column number is different between children and parents, and model generates fake headers in each cell
import pygtk
pygtk.require('2.0')
import gtk
data = [
[('val_a1', 'val_b1', 'val_c1', 'val_d1', 'val_e1'), ('val_x1', 'val_y1', 'val_z1'), ('val_x2', 'val_y2', 'val_z2')],
[('val_a2', 'val_b2', 'val_c2', 'val_d2', 'val_e2'), ('val_x3', 'val_y3', 'val_z3')],
[('val_a3', 'val_b3', 'val_c3', 'val_d3', 'val_e3')],
[('val_a4', 'val_b4', 'val_c4', 'val_d4', 'val_e4'), ('val_x4', 'val_y4', 'val_z4'), ('val_x5', 'val_y5', 'val_z5')],
]
@Cilyan
Cilyan / treemodel_unevenrows1.py
Created March 15, 2015 20:15
This snippet illustrates the creation of a custom GtkTreeModel in PyGTK / Python 2 where column number is different between children and parents.
import pygtk
pygtk.require('2.0')
import gtk
data = [
[('val_a1', 'val_b1', 'val_c1', 'val_d1', 'val_e1'), ('val_x1', 'val_y1', 'val_z1'), ('val_x2', 'val_y2', 'val_z2')],
[('val_a2', 'val_b2', 'val_c2', 'val_d2', 'val_e2'), ('val_x3', 'val_y3', 'val_z3')],
[('val_a3', 'val_b3', 'val_c3', 'val_d3', 'val_e3')],
[('val_a4', 'val_b4', 'val_c4', 'val_d4', 'val_e4'), ('val_x4', 'val_y4', 'val_z4'), ('val_x5', 'val_y5', 'val_z5')],
]
@Cilyan
Cilyan / format.py
Created March 15, 2015 03:30
A formatter that cleans a text's whitespacing around punctuation, quotes, parenthesis, brackets or curly brackets.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re # Oh yeah :)
class WhiteFormater:
"""
A formatter that cleans a text's whitespacing around punctuation,
quotes, parenthesis, brackets or curly brackets. There should be no
spaces before a punctuation or a closing delimiter, but at least a space
@Cilyan
Cilyan / monitor_state.c
Created October 14, 2014 23:54
Monitor Systemd's SystemState to light control led
/*
* simple_dbus.c
*
* Copyright 2014 Cilyan Olowen <gaknar@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
@Cilyan
Cilyan / gtk+-3.10.9-cleanup-def-reference.patch
Created June 22, 2014 16:47
This is a patch against Gtk+-3.10.9 that removes references to the yet obsolete gdk.def and gtk.def files for Win32 build/cross build
--- gdk/Makefile.am 2014-06-22 18:37:26.077172331 +0200
+++ gdk/Makefile.am 2014-06-22 18:38:34.244019623 +0200
@@ -179,8 +179,8 @@
if USE_WIN32
libgdk_3_la_SOURCES += gdkkeynames.c
libgdk_3_la_LIBADD += win32/libgdk-win32.la
-libgdk_3_la_DEPENDENCIES = win32/libgdk-win32.la win32/rc/gdk-win32-res.o gdk.def
-libgdk_3_la_LDFLAGS += -Wl,win32/rc/gdk-win32-res.o -export-symbols $(srcdir)/gdk.def
+libgdk_3_la_DEPENDENCIES = win32/libgdk-win32.la win32/rc/gdk-win32-res.o
+libgdk_3_la_LDFLAGS += -Wl,win32/rc/gdk-win32-res.o
@Cilyan
Cilyan / soundtrack.py
Last active December 19, 2021 11:39
Draws the envelop (waveform) of a track on a Gtk.DrawingArea (vertically), uses PyGI and GStreamer
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Sources:
#
# https://stackoverflow.com/questions/9344888/getting-max-amplitude-for-an-audio-file-per-second
# https://git.gnome.org/browse/pitivi/tree/pitivi/timeline/previewers.py
# http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-base-plugins/html/gst-plugins-base-plugins-audioconvert.html
# http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-good-plugins/html/gst-plugins-good-plugins-level.html
# https://git.gnome.org/browse/pitivi/tree/pitivi/coptimizations/renderer.c
@Cilyan
Cilyan / fnv64basedhash.py
Last active May 23, 2022 15:39
Pure Python implementation of FNV64 and a custom hash suitable for urls. The hash prepends a salt in from of the data, then computes the FNV64 hash and encode the data in base64. Remember however that the FNV64 is not a cryptographic hash.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2014 Cilyan Olowen <gaknar@gmail.com>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
@Cilyan
Cilyan / parsesegment.py
Created February 11, 2014 13:33
Simple lex/parse pattern with one state machine in lexer and another in parser
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
class ParseSegment:
# Dictionary of patterns per state
# Tuples are (token name, pattern, state change command)
_regexes = {
"out": [
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from PyQt4 import QtGui, QtCore
import time
import sys
import random
class WorkerThread(QtCore.QThread):
# Worker Thread