GraphIcons: Extend and deprecate previous pixmaps (#1534)
* GraphPixmaps: deprecate pixmaps * Deprecation print * More doc strings and deprecation warning
|
@ -5,7 +5,7 @@ import weakref
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import os
|
import os
|
||||||
from ...Qt import QtGui, QtCore, QT_LIB
|
from ...Qt import QtGui, QtCore, QT_LIB
|
||||||
from ... import pixmaps
|
from ... import icons
|
||||||
from ... import functions as fn
|
from ... import functions as fn
|
||||||
from ...widgets.FileDialog import FileDialog
|
from ...widgets.FileDialog import FileDialog
|
||||||
from .. PlotDataItem import PlotDataItem
|
from .. PlotDataItem import PlotDataItem
|
||||||
|
@ -120,7 +120,7 @@ class PlotItem(GraphicsWidget):
|
||||||
|
|
||||||
## Set up control buttons
|
## Set up control buttons
|
||||||
path = os.path.dirname(__file__)
|
path = os.path.dirname(__file__)
|
||||||
self.autoBtn = ButtonItem(pixmaps.getPixmap('auto'), 14, self)
|
self.autoBtn = ButtonItem(icons.getGraphPixmap('auto'), 14, self)
|
||||||
self.autoBtn.mode = 'auto'
|
self.autoBtn.mode = 'auto'
|
||||||
self.autoBtn.clicked.connect(self.autoBtnClicked)
|
self.autoBtn.clicked.connect(self.autoBtnClicked)
|
||||||
self.buttonsHidden = False ## whether the user has requested buttons to be hidden
|
self.buttonsHidden = False ## whether the user has requested buttons to be hidden
|
||||||
|
|
|
@ -1,25 +1,43 @@
|
||||||
import os.path as op
|
import os.path as op
|
||||||
|
import warnings
|
||||||
|
|
||||||
from ..Qt import QtGui
|
from ..Qt import QtGui
|
||||||
|
|
||||||
__all__ = ['getGraphIcon']
|
__all__ = ['getGraphIcon', 'getGraphPixmap']
|
||||||
|
|
||||||
_ICON_REGISTRY = {}
|
_ICON_REGISTRY = {}
|
||||||
|
|
||||||
|
|
||||||
class GraphIcon:
|
class GraphIcon:
|
||||||
"""An icon place holder for lazy loading of QIcons"""
|
"""An icon place holder for lazy loading of QIcons
|
||||||
|
|
||||||
|
The icon must reside in the icons folder and the path refers to the full
|
||||||
|
name including suffix of the icon file, e.g.:
|
||||||
|
|
||||||
|
tiny = GraphIcon("tiny.png")
|
||||||
|
|
||||||
|
Icons can be later retrieved via the function `getGraphIcon` and providing
|
||||||
|
the name:
|
||||||
|
|
||||||
|
tiny = getGraphIcon("tiny")
|
||||||
|
"""
|
||||||
|
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
self._path = path
|
self._path = path
|
||||||
self._icon = None
|
|
||||||
name = path.split('.')[0]
|
name = path.split('.')[0]
|
||||||
_ICON_REGISTRY[name] = self
|
_ICON_REGISTRY[name] = self
|
||||||
|
self._icon = None
|
||||||
|
|
||||||
|
def _build_qicon(self):
|
||||||
|
icon = QtGui.QIcon(op.join(op.dirname(__file__), self._path))
|
||||||
|
name = self._path.split('.')[0]
|
||||||
|
_ICON_REGISTRY[name] = icon
|
||||||
|
self._icon = icon
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def qicon(self):
|
def qicon(self):
|
||||||
if self._icon is None:
|
if self._icon is None:
|
||||||
self._icon = QtGui.QIcon(op.join(op.dirname(__file__), self._path))
|
self._build_qicon()
|
||||||
|
|
||||||
return self._icon
|
return self._icon
|
||||||
|
|
||||||
|
@ -34,5 +52,28 @@ def getGraphIcon(name):
|
||||||
return icon
|
return icon
|
||||||
|
|
||||||
|
|
||||||
|
def getGraphPixmap(name, size=(20, 20)):
|
||||||
|
"""Return a `QPixmap` from the registry by `name`"""
|
||||||
|
icon = getGraphIcon(name)
|
||||||
|
|
||||||
|
return icon.pixmap(*size)
|
||||||
|
|
||||||
|
|
||||||
|
def getPixmap(name, size=(20, 20)):
|
||||||
|
"""Historic `getPixmap` function
|
||||||
|
|
||||||
|
(eg. getPixmap('auto') loads pyqtgraph/icons/auto.png)
|
||||||
|
"""
|
||||||
|
warnings.warn(
|
||||||
|
"'getPixmap' is deprecated and will be removed soon, "
|
||||||
|
"please use `getGraphPixmap` in the future",
|
||||||
|
DeprecationWarning, stacklevel=2)
|
||||||
|
return getGraphPixmap(name, size=size)
|
||||||
|
|
||||||
|
|
||||||
# Note: List all graph icons here ...
|
# Note: List all graph icons here ...
|
||||||
|
auto = GraphIcon("auto.png")
|
||||||
|
ctrl = GraphIcon("ctrl.png")
|
||||||
|
default = GraphIcon("default.png")
|
||||||
invisibleEye = GraphIcon("invisibleEye.svg")
|
invisibleEye = GraphIcon("invisibleEye.svg")
|
||||||
|
lock = GraphIcon("lock.png")
|
||||||
|
|
Before Width: | Height: | Size: 1022 B After Width: | Height: | Size: 1022 B |
Before Width: | Height: | Size: 934 B After Width: | Height: | Size: 934 B |
Before Width: | Height: | Size: 810 B After Width: | Height: | Size: 810 B |
Before Width: | Height: | Size: 6.2 KiB After Width: | Height: | Size: 6.2 KiB |
Before Width: | Height: | Size: 913 B After Width: | Height: | Size: 913 B |
|
@ -6,7 +6,7 @@ from .ParameterItem import ParameterItem
|
||||||
from ..widgets.SpinBox import SpinBox
|
from ..widgets.SpinBox import SpinBox
|
||||||
from ..widgets.ColorButton import ColorButton
|
from ..widgets.ColorButton import ColorButton
|
||||||
from ..colormap import ColorMap
|
from ..colormap import ColorMap
|
||||||
from .. import pixmaps as pixmaps
|
from .. import icons as icons
|
||||||
from .. import functions as fn
|
from .. import functions as fn
|
||||||
from ..pgcollections import OrderedDict
|
from ..pgcollections import OrderedDict
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ class WidgetParameterItem(ParameterItem):
|
||||||
self.defaultBtn.setFixedWidth(20)
|
self.defaultBtn.setFixedWidth(20)
|
||||||
self.defaultBtn.setFixedHeight(20)
|
self.defaultBtn.setFixedHeight(20)
|
||||||
modDir = os.path.dirname(__file__)
|
modDir = os.path.dirname(__file__)
|
||||||
self.defaultBtn.setIcon(QtGui.QIcon(pixmaps.getPixmap('default')))
|
self.defaultBtn.setIcon(icons.getGraphIcon('default'))
|
||||||
self.defaultBtn.clicked.connect(self.defaultClicked)
|
self.defaultBtn.clicked.connect(self.defaultClicked)
|
||||||
|
|
||||||
self.displayLabel = QtGui.QLabel()
|
self.displayLabel = QtGui.QLabel()
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
"""
|
|
||||||
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
|
|
||||||
from ..python2_3 import basestring
|
|
||||||
if sys.version_info[0] == 2:
|
|
||||||
from . import pixmapData_2 as pixmapData
|
|
||||||
else:
|
|
||||||
from . import pixmapData_3 as 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) or isinstance(data, bytes):
|
|
||||||
pixmapData.pixmapData[key] = pickle.loads(data)
|
|
||||||
arr = pixmapData.pixmapData[key]
|
|
||||||
return QtGui.QPixmap(makeQImage(arr, alpha=True))
|
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
import numpy as np
|
|
||||||
from PyQt4 import QtGui
|
|
||||||
import os, pickle, sys
|
|
||||||
|
|
||||||
path = os.path.abspath(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)
|
|
||||||
ver = sys.version_info[0]
|
|
||||||
with open(os.path.join(path, 'pixmapData_%d.py' % (ver, )), 'w') as fh:
|
|
||||||
fh.write("import numpy as np; pixmapData=%s" % (repr(pixmaps), ))
|
|