Skip to content

Instantly share code, notes, and snippets.

View justinfx's full-sized avatar

Justin Israel justinfx

View GitHub Profile
@justinfx
justinfx / blocking.py
Created October 24, 2012 23:46
PyQt UI Development for Maya - Chapter 03 - blocking/non-blocking operations
#!/usr/bin/env python
"""
Copyright (c) 2012, Justin Israel (justinisrael@gmail.com)
All rights reserved.
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 notice,
@justinfx
justinfx / button_shift_click.py
Created December 3, 2012 18:59
A QPushButton that checks for the shift key modifier
"""
Record various key press states from a custom QPushButton
"""
from PyQt4 import QtGui, QtCore
class Button(QtGui.QPushButton):
def __init__(self, *args, **kwargs):
@justinfx
justinfx / maya_script_editor.py
Last active March 8, 2024 18:33
An example of how to use multiprocessing from within Maya, by actually running it as a subprocess and communicating back the results.
"""
This code can be run from a Maya script editor
"""
import subprocess
import cPickle
print 'This value below should be a 1000:'
p = subprocess.Popen(["/path/to/multi_test.py", "-po"], stdout=subprocess.PIPE)
result = cPickle.load(p.stdout)
@justinfx
justinfx / read_qt_process.py
Last active July 11, 2019 11:02
2 different examples of reading the progressive output of a process in PyQt. 1) Using a QProcess 2) Using subprocess [https://groups.google.com/d/msg/python_inside_maya/x9COZGNPGEU/gD4xpbs3S08J]
from functools import partial
from subprocess import Popen, PIPE
from PyQt4 import QtCore, QtGui
## testProgram.sh
"""
#!/bin/bash
@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…
#!/usr/bin/env python
"""
Playing around with QMainWindow's nested within each other
as dock widgets.
"""
from random import randint
try:
@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.
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 / trace_stack.py
Created April 17, 2013 22:00
python snippet for dumping a call stack at any point in code
import inspect
def trace():
frames = (str(f[1:4]) for f in inspect.getouterframes(inspect.currentframe())[1:])
print "\n".join(frames)
print '\n'
// Preferences.sublime-settings
{
// ...
"auto_complete_triggers": [{"selector": "source.python", "characters": "."}],
"auto_complete_selector": "-"
}
@justinfx
justinfx / mm_pushbutton.py
Created June 14, 2013 00:28
Attaching a Maya Marking Menu to the right click of a PyQt QPushButton widget
from PyQt4 import QtCore, QtGui
import maya.cmds as cmds
import maya.OpenMayaUI as mui
import sip
def getMayaWindow():
ptr = mui.MQtUtil.mainWindow()
return sip.wrapinstance(long(ptr), QtCore.QObject)
widget = QtGui.QDialog(getMayaWindow())
@justinfx
justinfx / colordialog.py
Created June 16, 2013 20:26
Example of having QColorDialog remember the last color selection Corrected from: http://pastebin.com/L9ge14k0
from PyQt4 import QtCore, QtGui
class ColorBox(QtGui.QFrame):
def __init__(self,parent=None):
super(ColorBox,self).__init__(parent)
self.bgColor = QtCore.Qt.white
self.setFixedHeight(20)
self.setFrameStyle(1)