2010-03-22 05:48:52 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
graphicsWindows.py - Convenience classes which create a new window with PlotWidget or ImageView.
|
|
|
|
Copyright 2010 Luke Campagnola
|
|
|
|
Distributed under MIT/X11 license. See license.txt for more infomation.
|
|
|
|
"""
|
|
|
|
|
2012-03-02 02:55:32 +00:00
|
|
|
from Qt import QtCore, QtGui
|
|
|
|
from widgets.PlotWidget import *
|
|
|
|
from imageview import *
|
|
|
|
from widgets.GraphicsLayoutWidget import GraphicsLayoutWidget
|
|
|
|
from widgets.GraphicsView import GraphicsView
|
2010-07-24 18:29:09 +00:00
|
|
|
QAPP = None
|
2011-02-08 00:40:38 +00:00
|
|
|
|
|
|
|
def mkQApp():
|
|
|
|
if QtGui.QApplication.instance() is None:
|
|
|
|
global QAPP
|
|
|
|
QAPP = QtGui.QApplication([])
|
|
|
|
|
|
|
|
|
|
|
|
class GraphicsWindow(GraphicsLayoutWidget):
|
2012-03-02 02:55:32 +00:00
|
|
|
def __init__(self, title=None, size=(800,600), **kargs):
|
2011-02-08 00:40:38 +00:00
|
|
|
mkQApp()
|
|
|
|
self.win = QtGui.QMainWindow()
|
2012-03-02 02:55:32 +00:00
|
|
|
GraphicsLayoutWidget.__init__(self, **kargs)
|
2011-02-08 00:40:38 +00:00
|
|
|
self.win.setCentralWidget(self)
|
|
|
|
self.win.resize(*size)
|
2010-03-22 05:48:52 +00:00
|
|
|
if title is not None:
|
2011-02-08 00:40:38 +00:00
|
|
|
self.win.setWindowTitle(title)
|
|
|
|
self.win.show()
|
|
|
|
|
2010-03-22 05:48:52 +00:00
|
|
|
|
2011-02-08 00:40:38 +00:00
|
|
|
class TabWindow(QtGui.QMainWindow):
|
|
|
|
def __init__(self, title=None, size=(800,600)):
|
|
|
|
mkQApp()
|
2010-03-22 05:48:52 +00:00
|
|
|
QtGui.QMainWindow.__init__(self)
|
2011-02-08 00:40:38 +00:00
|
|
|
self.resize(*size)
|
|
|
|
self.cw = QtGui.QTabWidget()
|
2010-03-22 05:48:52 +00:00
|
|
|
self.setCentralWidget(self.cw)
|
|
|
|
if title is not None:
|
|
|
|
self.setWindowTitle(title)
|
|
|
|
self.show()
|
2011-02-08 00:40:38 +00:00
|
|
|
|
|
|
|
def __getattr__(self, attr):
|
|
|
|
if hasattr(self.cw, attr):
|
|
|
|
return getattr(self.cw, attr)
|
|
|
|
else:
|
|
|
|
raise NameError(attr)
|
|
|
|
|
|
|
|
|
|
|
|
class PlotWindow(PlotWidget):
|
|
|
|
def __init__(self, title=None, **kargs):
|
|
|
|
mkQApp()
|
|
|
|
self.win = QtGui.QMainWindow()
|
|
|
|
PlotWidget.__init__(self, **kargs)
|
|
|
|
self.win.setCentralWidget(self)
|
|
|
|
for m in ['resize']:
|
|
|
|
setattr(self, m, getattr(self.win, m))
|
|
|
|
if title is not None:
|
|
|
|
self.win.setWindowTitle(title)
|
|
|
|
self.win.show()
|
|
|
|
|
|
|
|
|
|
|
|
class ImageWindow(ImageView):
|
|
|
|
def __init__(self, *args, **kargs):
|
|
|
|
mkQApp()
|
|
|
|
self.win = QtGui.QMainWindow()
|
2011-06-14 23:47:52 +00:00
|
|
|
self.win.resize(800,600)
|
2011-02-08 00:40:38 +00:00
|
|
|
if 'title' in kargs:
|
|
|
|
self.win.setWindowTitle(kargs['title'])
|
|
|
|
del kargs['title']
|
|
|
|
ImageView.__init__(self, self.win)
|
|
|
|
if len(args) > 0 or len(kargs) > 0:
|
|
|
|
self.setImage(*args, **kargs)
|
|
|
|
self.win.setCentralWidget(self)
|
|
|
|
for m in ['resize']:
|
|
|
|
setattr(self, m, getattr(self.win, m))
|
|
|
|
#for m in ['setImage', 'autoRange', 'addItem', 'removeItem', 'blackLevel', 'whiteLevel', 'imageItem']:
|
|
|
|
#setattr(self, m, getattr(self.cw, m))
|
|
|
|
self.win.show()
|