added dockarea example
This commit is contained in:
parent
4384944952
commit
f81e94061f
@ -2,6 +2,7 @@
|
|||||||
from pyqtgraph.Qt import QtCore, QtGui
|
from pyqtgraph.Qt import QtCore, QtGui
|
||||||
from .Container import *
|
from .Container import *
|
||||||
from .DockDrop import *
|
from .DockDrop import *
|
||||||
|
from .Dock import Dock
|
||||||
import pyqtgraph.debug as debug
|
import pyqtgraph.debug as debug
|
||||||
import weakref
|
import weakref
|
||||||
|
|
||||||
|
@ -1,83 +0,0 @@
|
|||||||
import sys
|
|
||||||
|
|
||||||
## Make sure pyqtgraph is importable
|
|
||||||
p = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
p = os.path.join(p, '..', '..')
|
|
||||||
sys.path.insert(0, p)
|
|
||||||
|
|
||||||
from pyqtgraph.Qt import QtCore, QtGui
|
|
||||||
|
|
||||||
from .DockArea import *
|
|
||||||
from .Dock import *
|
|
||||||
|
|
||||||
app = QtGui.QApplication([])
|
|
||||||
win = QtGui.QMainWindow()
|
|
||||||
area = DockArea()
|
|
||||||
win.setCentralWidget(area)
|
|
||||||
win.resize(800,800)
|
|
||||||
from .Dock import Dock
|
|
||||||
d1 = Dock("Dock1", size=(200,200))
|
|
||||||
d2 = Dock("Dock2", size=(100,100))
|
|
||||||
d3 = Dock("Dock3", size=(1,1))
|
|
||||||
d4 = Dock("Dock4", size=(50,50))
|
|
||||||
d5 = Dock("Dock5", size=(100,100))
|
|
||||||
d6 = Dock("Dock6", size=(300,300))
|
|
||||||
area.addDock(d1, 'left')
|
|
||||||
area.addDock(d2, 'right')
|
|
||||||
area.addDock(d3, 'bottom')
|
|
||||||
area.addDock(d4, 'right')
|
|
||||||
area.addDock(d5, 'left', d1)
|
|
||||||
area.addDock(d6, 'top', d4)
|
|
||||||
|
|
||||||
area.moveDock(d6, 'above', d4)
|
|
||||||
d3.hideTitleBar()
|
|
||||||
|
|
||||||
print("===build complete====")
|
|
||||||
|
|
||||||
for d in [d1, d2, d3, d4, d5]:
|
|
||||||
w = QtGui.QWidget()
|
|
||||||
l = QtGui.QVBoxLayout()
|
|
||||||
w.setLayout(l)
|
|
||||||
btns = []
|
|
||||||
for i in range(4):
|
|
||||||
btns.append(QtGui.QPushButton("%s Button %d"%(d.name(), i)))
|
|
||||||
l.addWidget(btns[-1])
|
|
||||||
d.w = (w, l, btns)
|
|
||||||
d.addWidget(w)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import pyqtgraph as pg
|
|
||||||
p = pg.PlotWidget()
|
|
||||||
d6.addWidget(p)
|
|
||||||
|
|
||||||
print("===widgets added===")
|
|
||||||
|
|
||||||
|
|
||||||
#s = area.saveState()
|
|
||||||
|
|
||||||
|
|
||||||
#print "\n\n-------restore----------\n\n"
|
|
||||||
#area.restoreState(s)
|
|
||||||
s = None
|
|
||||||
def save():
|
|
||||||
global s
|
|
||||||
s = area.saveState()
|
|
||||||
|
|
||||||
def load():
|
|
||||||
global s
|
|
||||||
area.restoreState(s)
|
|
||||||
|
|
||||||
|
|
||||||
#d6.container().setCurrentIndex(0)
|
|
||||||
#d2.label.setTabPos(40)
|
|
||||||
|
|
||||||
#win2 = QtGui.QMainWindow()
|
|
||||||
#area2 = DockArea()
|
|
||||||
#win2.setCentralWidget(area2)
|
|
||||||
#win2.resize(800,800)
|
|
||||||
|
|
||||||
|
|
||||||
win.show()
|
|
||||||
#win2.show()
|
|
||||||
|
|
@ -17,6 +17,7 @@ examples = OrderedDict([
|
|||||||
('Plot speed test', 'PlotSpeedTest.py'),
|
('Plot speed test', 'PlotSpeedTest.py'),
|
||||||
('Data Slicing', 'DataSlicing.py'),
|
('Data Slicing', 'DataSlicing.py'),
|
||||||
('Plot Customization', 'customPlot.py'),
|
('Plot Customization', 'customPlot.py'),
|
||||||
|
('Dock widgets', 'dockarea.py'),
|
||||||
('GraphicsItems', OrderedDict([
|
('GraphicsItems', OrderedDict([
|
||||||
('Scatter Plot', 'ScatterPlot.py'),
|
('Scatter Plot', 'ScatterPlot.py'),
|
||||||
#('PlotItem', 'PlotItem.py'),
|
#('PlotItem', 'PlotItem.py'),
|
||||||
@ -67,9 +68,9 @@ class ExampleLoader(QtGui.QMainWindow):
|
|||||||
self.populateTree(self.ui.exampleTree.invisibleRootItem(), examples)
|
self.populateTree(self.ui.exampleTree.invisibleRootItem(), examples)
|
||||||
self.ui.exampleTree.expandAll()
|
self.ui.exampleTree.expandAll()
|
||||||
|
|
||||||
self.resize(900,500)
|
self.resize(1000,500)
|
||||||
self.show()
|
self.show()
|
||||||
self.ui.splitter.setSizes([150,750])
|
self.ui.splitter.setSizes([250,750])
|
||||||
self.ui.loadBtn.clicked.connect(self.loadFile)
|
self.ui.loadBtn.clicked.connect(self.loadFile)
|
||||||
self.ui.exampleTree.currentItemChanged.connect(self.showFile)
|
self.ui.exampleTree.currentItemChanged.connect(self.showFile)
|
||||||
self.ui.exampleTree.itemDoubleClicked.connect(self.loadFile)
|
self.ui.exampleTree.itemDoubleClicked.connect(self.loadFile)
|
||||||
|
116
examples/dockarea.py
Normal file
116
examples/dockarea.py
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
This example demonstrates the use of pyqtgraph's dock widget system.
|
||||||
|
|
||||||
|
The dockarea system allows the design of user interfaces which can be rearranged by
|
||||||
|
the user at runtime. Docks can be moved, resized, stacked, and torn out of the main
|
||||||
|
window. This is similar in principle to the docking system built into Qt, but
|
||||||
|
offers a more deterministic dock placement API (in Qt it is very difficult to
|
||||||
|
programatically generate complex dock arrangements). Additionally, Qt's docks are
|
||||||
|
designed to be used as small panels around the outer edge of a window. Pyqtgraph's
|
||||||
|
docks were created with the notion that the entire window (or any portion of it)
|
||||||
|
would consist of dockable components.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import initExample ## Add path to library (just for examples; you do not need this)
|
||||||
|
|
||||||
|
import pyqtgraph as pg
|
||||||
|
from pyqtgraph.Qt import QtCore, QtGui
|
||||||
|
import pyqtgraph.console
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
from pyqtgraph.dockarea import *
|
||||||
|
|
||||||
|
app = QtGui.QApplication([])
|
||||||
|
win = QtGui.QMainWindow()
|
||||||
|
area = DockArea()
|
||||||
|
win.setCentralWidget(area)
|
||||||
|
win.resize(1000,500)
|
||||||
|
|
||||||
|
## Create docks, place them into the window one at a time.
|
||||||
|
## Note that size arguments are only a suggestion; docks will still have to
|
||||||
|
## fill the entire dock area and obey the limits of their internal widgets.
|
||||||
|
d1 = Dock("Dock1", size=(1, 1)) ## give this dock the minimum possible size
|
||||||
|
d2 = Dock("Dock2 - Console", size=(500,300))
|
||||||
|
d3 = Dock("Dock3", size=(500,400))
|
||||||
|
d4 = Dock("Dock4 (tabbed) - Plot", size=(500,200))
|
||||||
|
d5 = Dock("Dock5 - Image", size=(500,200))
|
||||||
|
d6 = Dock("Dock6 (tabbed) - Plot", size=(500,200))
|
||||||
|
area.addDock(d1, 'left') ## place d1 at left edge of dock area (it will fill the whole space since there are no other docks yet)
|
||||||
|
area.addDock(d2, 'right') ## place d2 at right edge of dock area
|
||||||
|
area.addDock(d3, 'bottom', d1)## place d3 at bottom edge of d1
|
||||||
|
area.addDock(d4, 'right') ## place d4 at right edge of dock area
|
||||||
|
area.addDock(d5, 'left', d1) ## place d5 at left edge of d1
|
||||||
|
area.addDock(d6, 'top', d4) ## place d5 at top edge of d4
|
||||||
|
|
||||||
|
## Test ability to move docks programatically after they have been placed
|
||||||
|
area.moveDock(d4, 'top', d2) ## move d4 to top edge of d2
|
||||||
|
area.moveDock(d6, 'above', d4) ## move d6 to stack on top of d4
|
||||||
|
area.moveDock(d5, 'top', d2) ## move d5 to top edge of d2
|
||||||
|
|
||||||
|
|
||||||
|
## Add widgets into each dock
|
||||||
|
|
||||||
|
## first dock gets save/restore buttons
|
||||||
|
w1 = pg.LayoutWidget()
|
||||||
|
label = QtGui.QLabel(""" -- DockArea Example --
|
||||||
|
This window has 6 Dock widgets in it. Each dock can be dragged
|
||||||
|
by its title bar to occupy a different space within the window
|
||||||
|
but note that one dock has its title bar hidden). Additionally,
|
||||||
|
the borders between docks may be dragged to resize. Docks that are dragged on top
|
||||||
|
of one another are stacked in a tabbed layout. Double-click a dock title
|
||||||
|
bar to place it in its own window.
|
||||||
|
""")
|
||||||
|
saveBtn = QtGui.QPushButton('Save dock state')
|
||||||
|
restoreBtn = QtGui.QPushButton('Restore dock state')
|
||||||
|
restoreBtn.setEnabled(False)
|
||||||
|
w1.addWidget(label, row=0, col=0)
|
||||||
|
w1.addWidget(saveBtn, row=1, col=0)
|
||||||
|
w1.addWidget(restoreBtn, row=2, col=0)
|
||||||
|
d1.addWidget(w1)
|
||||||
|
state = None
|
||||||
|
def save():
|
||||||
|
global state
|
||||||
|
state = area.saveState()
|
||||||
|
restoreBtn.setEnabled(True)
|
||||||
|
def load():
|
||||||
|
global state
|
||||||
|
area.restoreState(state)
|
||||||
|
saveBtn.clicked.connect(save)
|
||||||
|
restoreBtn.clicked.connect(load)
|
||||||
|
|
||||||
|
|
||||||
|
w2 = pg.console.ConsoleWidget()
|
||||||
|
d2.addWidget(w2)
|
||||||
|
|
||||||
|
## Hide title bar on dock 3
|
||||||
|
d3.hideTitleBar()
|
||||||
|
w3 = pg.PlotWidget(title="Plot inside dock with no title bar")
|
||||||
|
w3.plot(np.random.normal(size=100))
|
||||||
|
d3.addWidget(w3)
|
||||||
|
|
||||||
|
w4 = pg.PlotWidget(title="Dock 4 plot")
|
||||||
|
w4.plot(np.random.normal(size=100))
|
||||||
|
d4.addWidget(w4)
|
||||||
|
|
||||||
|
w5 = pg.ImageView()
|
||||||
|
w5.setImage(np.random.normal(size=(100,100)))
|
||||||
|
d5.addWidget(w5)
|
||||||
|
|
||||||
|
w6 = pg.PlotWidget(title="Dock 6 plot")
|
||||||
|
w6.plot(np.random.normal(size=100))
|
||||||
|
d6.addWidget(w6)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
win.show()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## Start Qt event loop unless running in interactive mode or using pyside.
|
||||||
|
import sys
|
||||||
|
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
|
||||||
|
QtGui.QApplication.instance().exec_()
|
Loading…
Reference in New Issue
Block a user