Skip to content
Snippets Groups Projects
Commit b50b9490 authored by Luke Campagnola's avatar Luke Campagnola
Browse files

pyqtgraph, .exporters, and .opengl now use static imports

parent 63f3b0ab
No related branches found
No related tags found
No related merge requests found
......@@ -130,56 +130,119 @@ if __version__ is None and not hasattr(sys, 'frozen') and sys.version_info[0] ==
## Import almost everything to make it available from a single namespace
## don't import the more complex systems--canvas, parametertree, flowchart, dockarea
## these must be imported separately.
from . import frozenSupport
def importModules(path, globals, locals, excludes=()):
"""Import all modules residing within *path*, return a dict of name: module pairs.
#from . import frozenSupport
#def importModules(path, globals, locals, excludes=()):
#"""Import all modules residing within *path*, return a dict of name: module pairs.
Note that *path* MUST be relative to the module doing the import.
"""
d = os.path.join(os.path.split(globals['__file__'])[0], path)
files = set()
for f in frozenSupport.listdir(d):
if frozenSupport.isdir(os.path.join(d, f)) and f not in ['__pycache__', 'tests']:
files.add(f)
elif f[-3:] == '.py' and f != '__init__.py':
files.add(f[:-3])
elif f[-4:] == '.pyc' and f != '__init__.pyc':
files.add(f[:-4])
#Note that *path* MUST be relative to the module doing the import.
#"""
#d = os.path.join(os.path.split(globals['__file__'])[0], path)
#files = set()
#for f in frozenSupport.listdir(d):
#if frozenSupport.isdir(os.path.join(d, f)) and f not in ['__pycache__', 'tests']:
#files.add(f)
#elif f[-3:] == '.py' and f != '__init__.py':
#files.add(f[:-3])
#elif f[-4:] == '.pyc' and f != '__init__.pyc':
#files.add(f[:-4])
mods = {}
path = path.replace(os.sep, '.')
for modName in files:
if modName in excludes:
continue
try:
if len(path) > 0:
modName = path + '.' + modName
#mod = __import__(modName, globals, locals, fromlist=['*'])
mod = __import__(modName, globals, locals, ['*'], 1)
mods[modName] = mod
except:
import traceback
traceback.print_stack()
sys.excepthook(*sys.exc_info())
print("[Error importing module: %s]" % modName)
#mods = {}
#path = path.replace(os.sep, '.')
#for modName in files:
#if modName in excludes:
#continue
#try:
#if len(path) > 0:
#modName = path + '.' + modName
#print( "from .%s import * " % modName)
#mod = __import__(modName, globals, locals, ['*'], 1)
#mods[modName] = mod
#except:
#import traceback
#traceback.print_stack()
#sys.excepthook(*sys.exc_info())
#print("[Error importing module: %s]" % modName)
return mods
def importAll(path, globals, locals, excludes=()):
"""Given a list of modules, import all names from each module into the global namespace."""
mods = importModules(path, globals, locals, excludes)
for mod in mods.values():
if hasattr(mod, '__all__'):
names = mod.__all__
else:
names = [n for n in dir(mod) if n[0] != '_']
for k in names:
if hasattr(mod, k):
globals[k] = getattr(mod, k)
importAll('graphicsItems', globals(), locals())
importAll('widgets', globals(), locals(),
excludes=['MatplotlibWidget', 'RawImageWidget', 'RemoteGraphicsView'])
#return mods
#def importAll(path, globals, locals, excludes=()):
#"""Given a list of modules, import all names from each module into the global namespace."""
#mods = importModules(path, globals, locals, excludes)
#for mod in mods.values():
#if hasattr(mod, '__all__'):
#names = mod.__all__
#else:
#names = [n for n in dir(mod) if n[0] != '_']
#for k in names:
#if hasattr(mod, k):
#globals[k] = getattr(mod, k)
# Dynamic imports are disabled. This causes too many problems.
#importAll('graphicsItems', globals(), locals())
#importAll('widgets', globals(), locals(),
#excludes=['MatplotlibWidget', 'RawImageWidget', 'RemoteGraphicsView'])
from .graphicsItems.VTickGroup import *
from .graphicsItems.GraphicsWidget import *
from .graphicsItems.ScaleBar import *
from .graphicsItems.PlotDataItem import *
from .graphicsItems.GraphItem import *
from .graphicsItems.TextItem import *
from .graphicsItems.GraphicsLayout import *
from .graphicsItems.UIGraphicsItem import *
from .graphicsItems.GraphicsObject import *
from .graphicsItems.PlotItem import *
from .graphicsItems.ROI import *
from .graphicsItems.InfiniteLine import *
from .graphicsItems.HistogramLUTItem import *
from .graphicsItems.GridItem import *
from .graphicsItems.GradientLegend import *
from .graphicsItems.GraphicsItem import *
from .graphicsItems.BarGraphItem import *
from .graphicsItems.ViewBox import *
from .graphicsItems.ArrowItem import *
from .graphicsItems.ImageItem import *
from .graphicsItems.AxisItem import *
from .graphicsItems.LabelItem import *
from .graphicsItems.CurvePoint import *
from .graphicsItems.GraphicsWidgetAnchor import *
from .graphicsItems.PlotCurveItem import *
from .graphicsItems.ButtonItem import *
from .graphicsItems.GradientEditorItem import *
from .graphicsItems.MultiPlotItem import *
from .graphicsItems.ErrorBarItem import *
from .graphicsItems.IsocurveItem import *
from .graphicsItems.LinearRegionItem import *
from .graphicsItems.FillBetweenItem import *
from .graphicsItems.LegendItem import *
from .graphicsItems.ScatterPlotItem import *
from .graphicsItems.ItemGroup import *
from .widgets.MultiPlotWidget import *
from .widgets.ScatterPlotWidget import *
from .widgets.ColorMapWidget import *
from .widgets.FileDialog import *
from .widgets.ValueLabel import *
from .widgets.HistogramLUTWidget import *
from .widgets.CheckTable import *
from .widgets.BusyCursor import *
from .widgets.PlotWidget import *
from .widgets.ComboBox import *
from .widgets.GradientWidget import *
from .widgets.DataFilterWidget import *
from .widgets.SpinBox import *
from .widgets.JoystickButton import *
from .widgets.GraphicsLayoutWidget import *
from .widgets.TreeWidget import *
from .widgets.PathButton import *
from .widgets.VerticalLabel import *
from .widgets.FeedbackButton import *
from .widgets.ColorButton import *
from .widgets.DataTreeWidget import *
from .widgets.GraphicsView import *
from .widgets.LayoutWidget import *
from .widgets.TableWidget import *
from .widgets.ProgressDialog import *
from .imageview import *
from .WidgetGroup import *
......@@ -194,6 +257,7 @@ from .SignalProxy import *
from .colormap import *
from .ptime import time
##############################################################
## PyQt and PySide both are prone to crashing on exit.
## There are two general approaches to dealing with this:
......
......@@ -60,6 +60,6 @@ class CSVExporter(Exporter):
fd.write('\n')
fd.close()
CSVExporter.register()
......@@ -11,6 +11,14 @@ class Exporter(object):
Abstract class used for exporting graphics to file / printer / whatever.
"""
allowCopy = False # subclasses set this to True if they can use the copy buffer
Exporters = []
@classmethod
def register(cls):
"""
Used to register Exporter classes to appear in the export dialog.
"""
Exporter.Exporters.append(cls)
def __init__(self, item):
"""
......@@ -20,9 +28,6 @@ class Exporter(object):
object.__init__(self)
self.item = item
#def item(self):
#return self.item
def parameters(self):
"""Return the parameters used to configure this exporter."""
raise Exception("Abstract method must be overridden in subclass.")
......@@ -131,45 +136,4 @@ class Exporter(object):
return preItems + rootItem + postItems
def render(self, painter, targetRect, sourceRect, item=None):
#if item is None:
#item = self.item
#preItems = []
#postItems = []
#if isinstance(item, QtGui.QGraphicsScene):
#childs = [i for i in item.items() if i.parentItem() is None]
#rootItem = []
#else:
#childs = item.childItems()
#rootItem = [item]
#childs.sort(lambda a,b: cmp(a.zValue(), b.zValue()))
#while len(childs) > 0:
#ch = childs.pop(0)
#if int(ch.flags() & ch.ItemStacksBehindParent) > 0 or (ch.zValue() < 0 and int(ch.flags() & ch.ItemNegativeZStacksBehindParent) > 0):
#preItems.extend(tree)
#else:
#postItems.extend(tree)
#for ch in preItems:
#self.render(painter, sourceRect, targetRect, item=ch)
### paint root here
#for ch in postItems:
#self.render(painter, sourceRect, targetRect, item=ch)
self.getScene().render(painter, QtCore.QRectF(targetRect), QtCore.QRectF(sourceRect))
#def writePs(self, fileName=None, item=None):
#if fileName is None:
#self.fileSaveDialog(self.writeSvg, filter="PostScript (*.ps)")
#return
#if item is None:
#item = self
#printer = QtGui.QPrinter(QtGui.QPrinter.HighResolution)
#printer.setOutputFileName(fileName)
#painter = QtGui.QPainter(printer)
#self.render(painter)
#painter.end()
#def writeToPrinter(self):
#pass
......@@ -98,4 +98,5 @@ class ImageExporter(Exporter):
else:
self.png.save(fileName)
ImageExporter.register()
\ No newline at end of file
......@@ -57,6 +57,7 @@ class MatplotlibExporter(Exporter):
else:
raise Exception("Matplotlib export currently only works with plot items")
MatplotlibExporter.register()
class MatplotlibWindow(QtGui.QMainWindow):
......@@ -72,3 +73,5 @@ class MatplotlibWindow(QtGui.QMainWindow):
def closeEvent(self, ev):
MatplotlibExporter.windows.remove(self)
......@@ -63,3 +63,6 @@ class PrintExporter(Exporter):
finally:
self.setExportMode(False)
painter.end()
#PrintExporter.register()
......@@ -404,6 +404,10 @@ def correctCoordinates(node, item):
if removeTransform:
grp.removeAttribute('transform')
SVGExporter.register()
def itemTransform(item, root):
## Return the transformation mapping item to root
## (actually to parent coordinate system of root)
......
Exporters = []
from pyqtgraph import importModules
#from .. import frozenSupport
import os
d = os.path.split(__file__)[0]
#files = []
#for f in frozenSupport.listdir(d):
#if frozenSupport.isdir(os.path.join(d, f)) and f != '__pycache__':
#files.append(f)
#elif f[-3:] == '.py' and f not in ['__init__.py', 'Exporter.py']:
#files.append(f[:-3])
#for modName in files:
#mod = __import__(modName, globals(), locals(), fromlist=['*'])
for mod in importModules('', globals(), locals(), excludes=['Exporter']).values():
if hasattr(mod, '__all__'):
names = mod.__all__
else:
names = [n for n in dir(mod) if n[0] != '_']
for k in names:
if hasattr(mod, k):
Exporters.append(getattr(mod, k))
#Exporters = []
#from pyqtgraph import importModules
#import os
#d = os.path.split(__file__)[0]
#for mod in importModules('', globals(), locals(), excludes=['Exporter']).values():
#if hasattr(mod, '__all__'):
#names = mod.__all__
#else:
#names = [n for n in dir(mod) if n[0] != '_']
#for k in names:
#if hasattr(mod, k):
#Exporters.append(getattr(mod, k))
import Exporter
from .ImageExporter import *
from .SVGExporter import *
from .Matplotlib import *
from .CSVExporter import *
from .PrintExporter import *
def listExporters():
return Exporters[:]
return Exporter.Exporter.Exporters[:]
from .GLViewWidget import GLViewWidget
from pyqtgraph import importAll
#import os
#def importAll(path):
#d = os.path.join(os.path.split(__file__)[0], path)
#files = []
#for f in os.listdir(d):
#if os.path.isdir(os.path.join(d, f)) and f != '__pycache__':
#files.append(f)
#elif f[-3:] == '.py' and f != '__init__.py':
#files.append(f[:-3])
#for modName in files:
#mod = __import__(path+"."+modName, globals(), locals(), fromlist=['*'])
#if hasattr(mod, '__all__'):
#names = mod.__all__
#else:
#names = [n for n in dir(mod) if n[0] != '_']
#for k in names:
#if hasattr(mod, k):
#globals()[k] = getattr(mod, k)
## dynamic imports cause too many problems.
#from pyqtgraph import importAll
#importAll('items', globals(), locals())
from .items.GLGridItem import *
from .items.GLBarGraphItem import *
from .items.GLScatterPlotItem import *
from .items.GLMeshItem import *
from .items.GLLinePlotItem import *
from .items.GLAxisItem import *
from .items.GLImageItem import *
from .items.GLSurfacePlotItem import *
from .items.GLBoxItem import *
from .items.GLVolumeItem import *
importAll('items', globals(), locals())
\
from .MeshData import MeshData
## for backward compatibility:
#MeshData.MeshData = MeshData ## breaks autodoc.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment