Commit 64be9c8b authored by Luke Campagnola's avatar Luke Campagnola
Browse files

converted all png files to compiled .py file; this allows easier packaging with py2exe

parent 5081c97a
......@@ -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.
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