Added example scripts used for bundling with py2exe

This commit is contained in:
Luke Campagnola 2012-10-11 11:57:51 -04:00
commit b96a0f1b39
13 changed files with 94 additions and 7 deletions

View File

@ -7,10 +7,14 @@ class ButtonItem(GraphicsObject):
clicked = QtCore.Signal(object)
def __init__(self, imageFile, width=None, parentItem=None):
def __init__(self, imageFile=None, width=None, parentItem=None, pixmap=None):
self.enabled = True
GraphicsObject.__init__(self)
self.setImageFile(imageFile)
if imageFile is not None:
self.setImageFile(imageFile)
elif pixmap is not None:
self.setPixmap(pixmap)
if width is not None:
s = float(width) / self.pixmap.width()
self.scale(s, s)
@ -19,7 +23,10 @@ class ButtonItem(GraphicsObject):
self.setOpacity(0.7)
def setImageFile(self, imageFile):
self.pixmap = QtGui.QPixmap(imageFile)
self.setPixmap(QtGui.QPixmap(imageFile))
def setPixmap(self, pixmap):
self.pixmap = pixmap
self.update()
def mouseClickEvent(self, ev):

View File

@ -17,6 +17,7 @@ This class is very heavily featured:
display, power spectrum, svg/png export, plot linking, and more.
"""
from pyqtgraph.Qt import QtGui, QtCore, QtSvg, USE_PYSIDE
import pyqtgraph.pixmaps
if USE_PYSIDE:
from .plotConfigTemplate_pyside import *
@ -124,9 +125,9 @@ class PlotItem(GraphicsWidget):
## Set up control buttons
path = os.path.dirname(__file__)
self.autoImageFile = os.path.join(path, 'auto.png')
self.lockImageFile = os.path.join(path, 'lock.png')
self.autoBtn = ButtonItem(self.autoImageFile, 14, self)
#self.autoImageFile = os.path.join(path, 'auto.png')
#self.lockImageFile = os.path.join(path, 'lock.png')
self.autoBtn = ButtonItem(pyqtgraph.pixmaps.getPixmap('auto'), 14, self)
self.autoBtn.mode = 'auto'
self.autoBtn.clicked.connect(self.autoBtnClicked)

View File

@ -5,6 +5,7 @@ from .ParameterItem import ParameterItem
from pyqtgraph.widgets.SpinBox import SpinBox
from pyqtgraph.widgets.ColorButton import ColorButton
import pyqtgraph as pg
import pyqtgraph.pixmaps as pixmaps
import os
from pyqtgraph.pgcollections import OrderedDict
@ -39,7 +40,7 @@ class WidgetParameterItem(ParameterItem):
self.defaultBtn.setFixedWidth(20)
self.defaultBtn.setFixedHeight(20)
modDir = os.path.dirname(__file__)
self.defaultBtn.setIcon(QtGui.QIcon(os.path.join(modDir, 'default.png')))
self.defaultBtn.setIcon(QtGui.QIcon(pixmaps.getPixmap('default')))
self.defaultBtn.clicked.connect(self.defaultClicked)
self.displayLabel = QtGui.QLabel()

23
pixmaps/__init__.py Normal file
View File

@ -0,0 +1,23 @@
"""
Allows easy loading of pixmaps used in UI elements.
Provides support for frozen environments as well.
"""
import os, sys, pickle
from ..functions import makeQImage
from ..Qt import QtGui
import pixmapData
def getPixmap(name):
"""
Return a QPixmap corresponding to the image file with the given name.
(eg. getPixmap('auto') loads pyqtgraph/pixmaps/auto.png)
"""
key = name+'.png'
data = pixmapData.pixmapData[key]
if isinstance(data, basestring):
pixmapData.pixmapData[key] = pickle.loads(data)
arr = pixmapData.pixmapData[key]
return QtGui.QPixmap(makeQImage(arr, alpha=True))

View File

Before

Width:  |  Height:  |  Size: 1022 B

After

Width:  |  Height:  |  Size: 1022 B

18
pixmaps/compile.py Normal file
View File

@ -0,0 +1,18 @@
import numpy as np
from PyQt4 import QtGui
import os, pickle
path = os.path.split(__file__)[0]
pixmaps = {}
for f in os.listdir(path):
if not f.endswith('.png'):
continue
print f
img = QtGui.QImage(os.path.join(path, f))
ptr = img.bits()
ptr.setsize(img.byteCount())
arr = np.asarray(ptr).reshape(img.height(), img.width(), 4).transpose(1,0,2)
pixmaps[f] = pickle.dumps(arr)
fh = open(os.path.join(path, 'pixmapData.py'), 'w')
fh.write("import numpy as np; pixmapData=%s" % repr(pixmaps))

View File

Before

Width:  |  Height:  |  Size: 934 B

After

Width:  |  Height:  |  Size: 934 B

View File

Before

Width:  |  Height:  |  Size: 810 B

After

Width:  |  Height:  |  Size: 810 B

View File

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 6.2 KiB

View File

Before

Width:  |  Height:  |  Size: 913 B

After

Width:  |  Height:  |  Size: 913 B

1
pixmaps/pixmapData.py Normal file

File diff suppressed because one or more lines are too long

10
tools/py2exe.bat Normal file
View File

@ -0,0 +1,10 @@
rem
rem This is a simple windows batch file containing the commands needed to package
rem a program with pyqtgraph and py2exe. See the packaging tutorial at
rem http://luke.campagnola.me/code/pyqtgraph for more information.
rem
rmdir /S /Q dist
rmdir /S /Q build
python .\py2exeSetupWindows.py py2exe --includes sip
pause

View File

@ -0,0 +1,26 @@
"""
Example distutils setup script for packaging a program with
pyqtgraph and py2exe. See the packaging tutorial at
http://luke.campagnola.me/code/pyqtgraph for more information.
"""
from distutils.core import setup
from glob import glob
import py2exe
import sys
## This path must contain msvcm90.dll, msvcp90.dll, msvcr90.dll, and Microsoft.VC90.CRT.manifest
## (see http://www.py2exe.org/index.cgi/Tutorial)
dllpath = r'C:\Windows\WinSxS\x86_Microsoft.VC90.CRT...'
sys.path.append(dllpath)
data_files = [
## Instruct setup to copy the needed DLL files into the build directory
("Microsoft.VC90.CRT", glob(dllpath + r'\*.*')),
]
setup(
data_files=data_files,
windows=['main.py'] ,
options={"py2exe": {"excludes":["Tkconstants", "Tkinter", "tcl"]}}
)