Skip to content

Instantly share code, notes, and snippets.

Avatar

Justin Israel justinfx

View GitHub Profile
@justinfx
justinfx / file_model_filters.py
Created Nov 8, 2016
Using proxy model to apply custom file extension filtering to a QFileSystemModel
View file_model_filters.py
"""
Example of using a proxy model to apply custom
filtering to a QFileSystemModel
RE: https://groups.google.com/d/topic/python_inside_maya/a2QM_KvgfeI/discussion
Justin Israel
justinisrael@gmail.com
"""
from PySide import QtCore, QtGui
@justinfx
justinfx / read_proto_desc.py
Created Jul 14, 2019
Dynamically reading a Protobuf FileDescriptorSet file into Python message classes
View read_proto_desc.py
#!/usr/bin/env python
"""
Read a serialized Protobuf FileDescriptorSet that was
generated from the protoc tool, and dynamically generate
the python classes for each message.
"""
import sys
from google.protobuf import descriptor_pb2
from google.protobuf import reflection
@justinfx
justinfx / enc_dec_test.py
Last active Feb 3, 2022
Speed test of common serializers on python 2.7.2 (pickle, cPickle, ujson, cjson, simplejson, json, yajl, msgpack)
View enc_dec_test.py
"""
Dependencies:
pip install tabulate simplejson ujson yajl msgpack
"""
from timeit import timeit
from tabulate import tabulate
setup = '''d = {
'words': """
@justinfx
justinfx / repeat.py
Created May 25, 2015
Example of a repeatable command decorate, for Maya (maya.cmds)
View repeat.py
"""
Original example reformatted from:
http://blog.3dkris.com/2011/08/python-in-maya-how-to-make-commands.html
python_inside_maya discussion:
https://groups.google.com/d/topic/python_inside_maya/xfuCYBO6aLg/discussion
"""
import maya.cmds as cmds
@justinfx
justinfx / cache_generics.py
Created Jul 12, 2012
forwards generic relations
View cache_generics.py
'''
Cache the generic relation field of all the objects
in the queryset, using larger bulk queries ahead of time.
Improved from original by Daniel Roseman:
http://blog.roseman.org.uk/2010/02/22/django-patterns-part-4-forwards-generic-relations/
'''
def cache_generics(queryset):
@justinfx
justinfx / flash_text.py
Created Apr 5, 2013
An example of how to flash the color of the text of a QLabel in PySide or PyQt4. Uses QPropertyAnimation with a custom setColor property.
View flash_text.py
from PySide import QtCore, QtGui
class Widget(QtGui.QWidget):
def __init__(self):
super(Widget, self).__init__()
self.resize(300,200)
layout = QtGui.QVBoxLayout(self)
@justinfx
justinfx / docking_dockables.py
Created Mar 25, 2013
Playing around with QMainWindow's nested within each other as dock widgets. The main app window has a couple dock widgets added to each of the 4 dock locations around the central widget. These dock widgets are QMainWindows. When enabled, each dock widget will have its own dock widgets populated that can do their own private docking within that c…
View docking_dockables.py
#!/usr/bin/env python
"""
Playing around with QMainWindow's nested within each other
as dock widgets.
"""
from random import randint
try:
View Preferences.sublime-settings
// Preferences.sublime-settings
{
// ...
"auto_complete_triggers": [{"selector": "source.python", "characters": "."}],
"auto_complete_selector": "-"
}
@justinfx
justinfx / qlistwidgetitem_click.py
Created Sep 20, 2016
Qt Example: Double clicking a QListWidgetItem and toggling the background color
View qlistwidgetitem_click.py
"""
https://groups.google.com/d/topic/python_inside_maya/eZOCjK2jewY/discussion
How to create a QListWidget, and toggle the background color of items
when they are double clicked
"""
from PySide import QtCore, QtGui
class List(QtGui.QDialog):
@justinfx
justinfx / MImage_to_QImage.py
Created Jan 28, 2016
Passing pixel pointer from a Maya MImage to Qt's QImage
View MImage_to_QImage.py
"""
Simplified version of original forum post:
http://tech-artists.org/forum/showthread.php?4547-Passing-uchar-pointer-with-PySide-in-Maya
"""
import ctypes
import maya.OpenMaya as om
from PySide import QtCore, QtGui
# Build a test MImage