Skip to content

Instantly share code, notes, and snippets.

@tcrowson
tcrowson / qt_ClearTreeWidget.py
Last active October 17, 2020 18:51
For PyQt/PySide. A simple function for clearing the contents of a QTreeWidget/QTreeView, since these classes lack convenient clear() or clearContents() methods. Takes a QTreeWidget or QTreeView object as an argument.
import PySide
from PySide import QtGui
def clearQTreeWidget(tree):
iterator = QtGui.QTreeWidgetItemIterator(tree, QtGui.QTreeWidgetItemIterator.All)
while iterator.value():
iterator.value().takeChildren()
iterator +=1
i = tree.topLevelItemCount()
while i > -1:
@tcrowson
tcrowson / softimage_RunAnnotationAsPython.py
Last active April 14, 2021 18:29
For Softimage. A quick snippet for running the text in an Annotation property as Python code. This allows you to store Python code in an Annotation property, as part of a scene or model, and run in later. Running this will drop you into a pick session, asking you to choose an Annotation property. No special error handling for now, it's brute-for…
# Puts the user into a pick-session, asking you to select an Annotation property
# whose text it will then run as Python code.
from win32com.client import constants
annotation = Application.PickElement(constants.siPropertyFilter,'Choose an Annotation Property','Choose an Annotation Property')[2]
exec annotation.Text.Value
@tcrowson
tcrowson / softimage_GatherFramebuffers.py
Last active April 14, 2021 18:31
For Softimage. Searches for 'Store_Color_In_Channel' nodes and adds their channels to the scene channel list.
# loop through shader nodes in the scene, identify 'store_color_in_channel' nodes,
# and add them to the scene globals. Avoid duplicate channnels.
for x in Application.FindObjects("", "{6495C5C1-FD18-474E-9703-AEA66631F7A7}" ):
if str(x.ProgID) == "Softimage.sib_color_storeinchannel.1.0":
chanName = Application.GetValue(x.Channel)
addChan = Application.CreateRenderChannel("%s"%(chanName), "siRenderChannelColorType", "")
newChan = (addChan[-1])
if newChan.isdigit():
Application.RemoveRenderChannel(addChan)
@tcrowson
tcrowson / loadUI_example.py
Last active April 12, 2023 17:55
Dynamically Load UI file from QtDesigner
from PySide.QtGui import *
from PySide.QtCore import *
from PySide.QtUiTools import QUiLoader
uiFile = "path\to\my\UI\file.ui"
class UiLoader(QUiLoader):
'''
Convenience class for dynamically loading QtDesigner '.ui' files,