Skip to content

Instantly share code, notes, and snippets.

View mottosso's full-sized avatar

Marcus Ottosson mottosso

View GitHub Profile
@mottosso
mottosso / main.py
Created October 22, 2014 07:43
Modo Pyblish
#python
import pyblish.api
pyblish.api.register_plugin_path(r"C:\plugins")
import pyblish.main
pyblish.main.publish()
@mottosso
mottosso / point_and_matrix.py
Created October 29, 2014 13:36
Point and Matrix implementations
import math
class Point(object):
def __init__(self, point=[0.0, 0.0, 0.0]):
self.x, self.y, self.z = point
def __str__(self):
return '(%0.4f, %0.4f, %0.4f)' % (self.x, self.y, self.z)
@mottosso
mottosso / mouse_monitor.py
Last active December 13, 2018 01:07
Monitoring Mouse Clicks
from PyQt5 import QtWidgets
from PyQt5 import QtCore
class Handler(QtCore.QObject):
def eventFilter(self, obj, event):
if event.type() == QtCore.QEvent.MouseButtonPress:
print "Clicked: %s" % obj.text()
return super(Handler, self).eventFilter(obj, event)
@mottosso
mottosso / print_with_lineno.py
Last active August 29, 2015 14:09
Append line-number to print statements
import os
import sys
import inspect
class MyStdout:
def write(self, text):
# Gather information about the program
# at it's location during printing.
frame = inspect.currentframe()
@mottosso
mottosso / application.js
Last active August 29, 2015 14:10
Asynchronous call from QML to Python with callback 1
/*
* This gist registers a custom context property to call upon arbitrary
* Javascript functions from Python. Note that this particular example
* does NOT work.
*
* See here for an alternative (that DOES work)
* https://gist.github.com/mottosso/2b6ae87454fb911414b0
*/
@mottosso
mottosso / application.js
Last active October 16, 2021 14:30
Asynchronous call from QML to Python with callback 3
/*
* This gist registers a custom QObject from Python into QML.
* The QObject is called from QML, whereby Python performs an
* expensive operation which, upon completion, emits a signal
* which is then again handled from QML.
*
* See here for an alternative (that doesn't work)
* https://gist.github.com/mottosso/aee134d71864bc8425e0
*/
@mottosso
mottosso / application.js
Last active August 29, 2015 14:10
Asynchronous call from QML to Python with callback 2
/*
* This gist registers a custom context property to call upon arbitrary
* Javascript functions from Python.
*
* As opposed to example #1, this wraps the callback in a QJSValue
* prior to storing it. Without it, Python would crash. Why?
*
* Example #1: https://gist.github.com/mottosso/aee134d71864bc8425e0
* Example #3: https://gist.github.com/mottosso/2b6ae87454fb911414b0
*/
@mottosso
mottosso / C.sublime-build
Last active January 31, 2022 02:49
Sublime Build System for Clang
// Build System for Sublime Text 3 to compile C using Clang.
//
// Usage:
// Compile and run via CTRL-b or F7
// Compile with CTRL-SHIFT-b
//
// Pre-requisities:
// - A Unix-like OS (for bash)
// - clang must be available on your PATH
//
@mottosso
mottosso / observer.c
Last active August 29, 2015 14:13
Mockup of observer pattern in Python and C
// Observer pattern in C
#include <stdio.h>
// To pass and store functions, we need to define a function pointer
typedef void (*Signal)();
// We can the use this Signal as type for the contents of the `subscribers` array.
// We also keep track of how many subscribers there are currently, so as to
// not overwrite previously added signals.
@mottosso
mottosso / README.md
Last active November 1, 2017 03:27
Developer toolchain for updating the pyqt/python-qt5 repository

The python-qt5 developer toolchain

Helper functions for updating the Python Qt5 repository.