Commit b96a0f1b authored by Luke Campagnola's avatar Luke Campagnola
Browse files

Added example scripts used for bundling with py2exe

parents ad7645c9 083ee002
......@@ -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):
......
......@@ -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)
......
......@@ -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()
......
"""
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))
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))
This diff is collapsed.
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
"""
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"]}}
)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment