Skip to content

Instantly share code, notes, and snippets.

@oglops
oglops / QTableView_with_QStandardItemModel.py
Created February 15, 2016 01:40
QTableView + QStandardItemModel
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class Window(QMainWindow):
'This time I try to put the table populating code in main ui'
def __init__(self, parent=None):
@oglops
oglops / QListView_with_QStandardItemModel.py
Created February 15, 2016 01:42
QListView + QStandardItemModel
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
data = ['row1', 'row2', 'row3']
class MyList(QListView):
def __init__(self, data, parent=None):
@oglops
oglops / QTableView_with_QAbstractTableModel.py
Created February 15, 2016 02:10
QTableView + QAbstractTableModel
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys
my_array = [['00', '01', '02'],
['10', '11', '12'],
['20', '21', '22']]
def main():
@oglops
oglops / elidedbutton.py
Created February 15, 2016 07:01
PySide/PyQt truncate text in QLabel based on minimumSize
# http://stackoverflow.com/questions/11446478/pyside-pyqt-truncate-text-in-qlabel-based-on-minimumsize/11764662#11764662
from PyQt4.QtCore import Qt
from PyQt4.QtGui import QApplication,\
QLabel,\
QFontMetrics,\
QPainter
from PyQt4 import QtGui, QtCore
@oglops
oglops / promote.ui
Created February 16, 2016 05:57
ui file for promoted widget demo
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>264</width>
<height>117</height>
@oglops
oglops / promote.py
Last active February 16, 2016 06:32
promoted widget demo
import os
import sys
from PyQt4 import QtGui, QtCore, uic
import sip
uiFile = os.path.join(os.path.dirname(__file__), 'promote.ui')
# Load the ui file, and create my class
form_class, base_class = uic.loadUiType(uiFile)
@oglops
oglops / script_editor_font.py
Created February 16, 2016 08:46
set script editor font for maya
# You can put this inside your userSetup.py
# import maya.utils as mu
# import script_editor_font as SE
# mu.executeDeferred(SE.launchFromCmdWndIcon)
from PyQt4 import QtGui, QtCore
from maya import cmds, mel
import maya.OpenMayaUI as apiUI
import sip
@oglops
oglops / img2base64.py
Created February 28, 2016 10:17
convert image file to base64 string
#!/usr/bin/env python
import sys
import base64
with open(sys.argv[1], "rb") as imageFile:
img_str = base64.b64encode(imageFile.read())
print img_str
@oglops
oglops / yaml_OrderedDict.py
Last active January 25, 2023 11:08
write to and load from yaml file with OrderedDict
#!/usr/bin/env python
try:
# for python newer than 2.7
from collections import OrderedDict
except ImportError:
# use backport from pypi
from ordereddict import OrderedDict
import yaml
@oglops
oglops / py.py
Created March 6, 2016 02:55
package python 2.7.11 x64
#!/usr/bin/python
#
# This is a small stub that is intended to be built into an executable with a
# setup.py file using "python setup.py py2exe". This results in an executable
# called py.exe. This can be used to run an arbitrary python script on Windows
# (XP and later) via py.exe (name of script).
#
# Changes:
# 2.7.4.1:
# * initial release