Skip to content

Instantly share code, notes, and snippets.

Avatar

Justin Israel justinfx

View GitHub Profile
@justinfx
justinfx / list_edit.py
Created April 21, 2023 22:26
Qt examples of tracking QListWidget item text edits
View list_edit.py
"""
"Connect rename command in QListWidget item edit"
https://groups.google.com/g/python_inside_maya/c/lPoWGuXyFsg/m/sLiWOaJgBAAJ
"""
from PySide2 import QtCore, QtGui, QtWidgets
class MyListWidget(QtWidgets.QListWidget):
@justinfx
justinfx / read_proto_desc.py
Created July 14, 2019 06:15
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 / flash_text.py
Last active December 19, 2022 01:53
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 / enc_dec_test.py
Last active October 16, 2022 13:28
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 / qlistwidgetitem_click.py
Created September 20, 2016 10:23
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 / modelPanelPyQt4.py
Last active July 7, 2022 10:31
Mixing PyQt4 and Maya UI objects
View modelPanelPyQt4.py
from PyQt4 import QtCore, QtGui
import maya.cmds as cmds
import maya.OpenMayaUI as mui
import sip
class MyDialog(QtGui.QDialog):
@justinfx
justinfx / file_model_filters.py
Created November 8, 2016 10:07
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 / repeat.py
Created May 25, 2015 10:40
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 July 12, 2012 02:17
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 / docking_dockables.py
Created March 25, 2013 22:24
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: