Commit f81e9406 authored by Luke Campagnola's avatar Luke Campagnola
Browse files

added dockarea example

parent 43849449
...@@ -2,6 +2,7 @@ ...@@ -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
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()
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)
print("===build complete====")
for d in [d1, d2, d3, d4, d5]:
w = QtGui.QWidget()
l = QtGui.QVBoxLayout()
btns = []
for i in range(4):
btns.append(QtGui.QPushButton("%s Button %d"%(, i)))
d.w = (w, l, btns)
import pyqtgraph as pg
p = pg.PlotWidget()
print("===widgets added===")
#s = area.saveState()
#print "\n\n-------restore----------\n\n"
s = None
def save():
global s
s = area.saveState()
def load():
global s
#win2 = QtGui.QMainWindow()
#area2 = DockArea()
...@@ -17,6 +17,7 @@ examples = OrderedDict([ ...@@ -17,6 +17,7 @@ examples = OrderedDict([
('Plot speed test', ''), ('Plot speed test', ''),
('Data Slicing', ''), ('Data Slicing', ''),
('Plot Customization', ''), ('Plot Customization', ''),
('Dock widgets', ''),
('GraphicsItems', OrderedDict([ ('GraphicsItems', OrderedDict([
('Scatter Plot', ''), ('Scatter Plot', ''),
#('PlotItem', ''), #('PlotItem', ''),
...@@ -67,9 +68,9 @@ class ExampleLoader(QtGui.QMainWindow): ...@@ -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.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)
# -*- 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()
## 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')
w1.addWidget(label, row=0, col=0)
w1.addWidget(saveBtn, row=1, col=0)
w1.addWidget(restoreBtn, row=2, col=0)
state = None
def save():
global state
state = area.saveState()
def load():
global state
w2 = pg.console.ConsoleWidget()
## Hide title bar on dock 3
w3 = pg.PlotWidget(title="Plot inside dock with no title bar")
w4 = pg.PlotWidget(title="Dock 4 plot")
w5 = pg.ImageView()
w6 = pg.PlotWidget(title="Dock 6 plot")
## 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'):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment