2011-02-08 00:40:38 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
### import all the goodies and add some helper functions for easy CLI use
|
|
|
|
|
2012-03-02 02:55:32 +00:00
|
|
|
## 'Qt' is a local module; it is intended mainly to cover up the differences
|
|
|
|
## between PyQt4 and PySide.
|
|
|
|
from Qt import QtGui
|
|
|
|
|
|
|
|
## not really safe.
|
|
|
|
#if QtGui.QApplication.instance() is None:
|
|
|
|
#app = QtGui.QApplication([])
|
|
|
|
|
2012-03-27 16:30:51 +00:00
|
|
|
## in general openGL is poorly supported in Qt.
|
|
|
|
## we only enable it where the performance benefit is critical.
|
|
|
|
## Note this only applies to 2D graphics; 3D graphics always use OpenGL.
|
|
|
|
import sys
|
|
|
|
if 'linux' in sys.platform: ## linux has numerous bugs in opengl implementation
|
|
|
|
useOpenGL = False
|
|
|
|
elif 'darwin' in sys.platform: ## openGL greatly speeds up display on mac
|
|
|
|
useOpenGL = True
|
|
|
|
else:
|
|
|
|
useOpenGL = True ## on windows there's a more even performance / bugginess tradeoff.
|
|
|
|
|
2012-03-02 02:55:32 +00:00
|
|
|
CONFIG_OPTIONS = {
|
2012-03-27 16:30:51 +00:00
|
|
|
'useOpenGL': None, ## by default, this is platform-dependent (see widgets/GraphicsView). Set to True or False to explicitly enable/disable opengl.
|
2012-03-02 02:55:32 +00:00
|
|
|
'leftButtonPan': True ## if false, left button drags a rubber band for zooming in viewbox
|
|
|
|
}
|
|
|
|
|
|
|
|
def setConfigOption(opt, value):
|
|
|
|
CONFIG_OPTIONS[opt] = value
|
|
|
|
|
|
|
|
def getConfigOption(opt):
|
|
|
|
return CONFIG_OPTIONS[opt]
|
|
|
|
|
2012-03-11 15:59:45 +00:00
|
|
|
|
|
|
|
## Rename orphaned .pyc files. This is *probably* safe :)
|
|
|
|
|
|
|
|
def renamePyc(startDir):
|
|
|
|
### Used to rename orphaned .pyc files
|
|
|
|
### When a python file changes its location in the repository, usually the .pyc file
|
|
|
|
### is left behind, possibly causing mysterious and difficult to track bugs.
|
|
|
|
|
|
|
|
printed = False
|
|
|
|
startDir = os.path.abspath(startDir)
|
|
|
|
for path, dirs, files in os.walk(startDir):
|
|
|
|
for f in files:
|
|
|
|
fileName = os.path.join(path, f)
|
|
|
|
base, ext = os.path.splitext(fileName)
|
|
|
|
py = base + ".py"
|
|
|
|
if ext == '.pyc' and not os.path.isfile(py):
|
|
|
|
if not printed:
|
|
|
|
print "NOTE: Renaming orphaned .pyc files:"
|
|
|
|
printed = True
|
|
|
|
n = 1
|
|
|
|
while True:
|
|
|
|
name2 = fileName + ".renamed%d" % n
|
|
|
|
if not os.path.exists(name2):
|
|
|
|
break
|
|
|
|
n += 1
|
|
|
|
print " " + fileName + " ==>"
|
|
|
|
print " " + name2
|
|
|
|
os.rename(fileName, name2)
|
|
|
|
|
|
|
|
import os
|
|
|
|
path = os.path.split(__file__)[0]
|
|
|
|
renamePyc(path)
|
|
|
|
|
|
|
|
|
2012-03-02 02:55:32 +00:00
|
|
|
## 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.
|
|
|
|
|
2012-03-24 02:13:41 +00:00
|
|
|
def importAll(path, excludes=()):
|
2012-03-02 02:55:32 +00:00
|
|
|
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)):
|
|
|
|
files.append(f)
|
|
|
|
elif f[-3:] == '.py' and f != '__init__.py':
|
|
|
|
files.append(f[:-3])
|
|
|
|
|
|
|
|
for modName in files:
|
2012-03-24 02:13:41 +00:00
|
|
|
if modName in excludes:
|
|
|
|
continue
|
2012-03-02 02:55:32 +00:00
|
|
|
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)
|
|
|
|
|
|
|
|
importAll('graphicsItems')
|
2012-03-24 02:13:41 +00:00
|
|
|
importAll('widgets', excludes=['MatplotlibWidget'])
|
2012-03-02 02:55:32 +00:00
|
|
|
|
|
|
|
from imageview import *
|
|
|
|
from WidgetGroup import *
|
2011-04-25 12:51:18 +00:00
|
|
|
from Point import Point
|
|
|
|
from Transform import Transform
|
2012-03-02 02:55:32 +00:00
|
|
|
from functions import *
|
|
|
|
from graphicsWindows import *
|
|
|
|
from SignalProxy import *
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Convenience functions for command-line use
|
|
|
|
|
|
|
|
|
2011-02-08 00:40:38 +00:00
|
|
|
|
|
|
|
plots = []
|
|
|
|
images = []
|
|
|
|
QAPP = None
|
|
|
|
|
|
|
|
def plot(*args, **kargs):
|
2012-03-02 02:55:32 +00:00
|
|
|
"""
|
|
|
|
| Create and return a PlotWindow (this is just a window with PlotWidget inside), plot data in it.
|
|
|
|
| Accepts a *title* argument to set the title of the window.
|
|
|
|
| All other arguments are used to plot data. (see :func:`PlotItem.plot() <pyqtgraph.PlotItem.plot>`)
|
|
|
|
"""
|
2011-02-08 00:40:38 +00:00
|
|
|
mkQApp()
|
2012-03-23 06:45:11 +00:00
|
|
|
#if 'title' in kargs:
|
|
|
|
#w = PlotWindow(title=kargs['title'])
|
|
|
|
#del kargs['title']
|
|
|
|
#else:
|
|
|
|
#w = PlotWindow()
|
|
|
|
#if len(args)+len(kargs) > 0:
|
|
|
|
#w.plot(*args, **kargs)
|
2012-03-23 07:21:04 +00:00
|
|
|
|
|
|
|
pwArgList = ['title', 'label', 'name', 'left', 'right', 'top', 'bottom']
|
|
|
|
pwArgs = {}
|
|
|
|
dataArgs = {}
|
|
|
|
for k in kargs:
|
|
|
|
if k in pwArgList:
|
|
|
|
pwArgs[k] = kargs[k]
|
|
|
|
else:
|
|
|
|
dataArgs[k] = kargs[k]
|
|
|
|
|
|
|
|
w = PlotWindow(**pwArgs)
|
|
|
|
w.plot(*args, **dataArgs)
|
2011-02-08 00:40:38 +00:00
|
|
|
plots.append(w)
|
|
|
|
w.show()
|
|
|
|
return w
|
|
|
|
|
2012-03-02 02:55:32 +00:00
|
|
|
def image(*args, **kargs):
|
|
|
|
"""
|
|
|
|
| Create and return an ImageWindow (this is just a window with ImageView widget inside), show image data inside.
|
|
|
|
| Will show 2D or 3D image data.
|
|
|
|
| Accepts a *title* argument to set the title of the window.
|
|
|
|
| All other arguments are used to show data. (see :func:`ImageView.setImage() <pyqtgraph.ImageView.setImage>`)
|
|
|
|
"""
|
2011-02-08 00:40:38 +00:00
|
|
|
mkQApp()
|
|
|
|
w = ImageWindow(*args, **kargs)
|
|
|
|
images.append(w)
|
|
|
|
w.show()
|
|
|
|
return w
|
2012-03-02 02:55:32 +00:00
|
|
|
show = image ## for backward compatibility
|
|
|
|
|
2011-02-08 00:40:38 +00:00
|
|
|
|
|
|
|
def mkQApp():
|
|
|
|
if QtGui.QApplication.instance() is None:
|
|
|
|
global QAPP
|
2012-03-11 15:59:45 +00:00
|
|
|
QAPP = QtGui.QApplication([])
|
|
|
|
|
|
|
|
|