CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
dockarea.py111 linesDownload Raw Back to examples
1"""2This example demonstrates the use of pyqtgraph's dock widget system.3 4The dockarea system allows the design of user interfaces which can be rearranged by5the user at runtime. Docks can be moved, resized, stacked, and torn out of the main6window. This is similar in principle to the docking system built into Qt, but 7offers a more deterministic dock placement API (in Qt it is very difficult to 8programatically generate complex dock arrangements). Additionally, Qt's docks are 9designed to be used as small panels around the outer edge of a window. Pyqtgraph's 10docks were created with the notion that the entire window (or any portion of it) 11would consist of dockable components.12"""13 14import numpy as np15 16import pyqtgraph as pg17from pyqtgraph.console import ConsoleWidget18from pyqtgraph.dockarea.Dock import Dock19from pyqtgraph.dockarea.DockArea import DockArea20from pyqtgraph.Qt import QtWidgets21 22app = pg.mkQApp("DockArea Example")23win = QtWidgets.QMainWindow()24area = DockArea()25win.setCentralWidget(area)26win.resize(1000,500)27win.setWindowTitle('pyqtgraph example: dockarea')28 29## Create docks, place them into the window one at a time.30## Note that size arguments are only a suggestion; docks will still have to31## fill the entire dock area and obey the limits of their internal widgets.32d1 = Dock("Dock1", size=(1, 1))     ## give this dock the minimum possible size33d2 = Dock("Dock2 - Console", size=(500,300), closable=True)34d3 = Dock("Dock3", size=(500,400))35d4 = Dock("Dock4 (tabbed) - Plot", size=(500,200))36d5 = Dock("Dock5 - Image", size=(500,200))37d6 = Dock("Dock6 (tabbed) - Plot", size=(500,200))38area.addDock(d1, 'left')      ## place d1 at left edge of dock area (it will fill the whole space since there are no other docks yet)39area.addDock(d2, 'right')     ## place d2 at right edge of dock area40area.addDock(d3, 'bottom', d1)## place d3 at bottom edge of d141area.addDock(d4, 'right')     ## place d4 at right edge of dock area42area.addDock(d5, 'left', d1)  ## place d5 at left edge of d143area.addDock(d6, 'top', d4)   ## place d6 at top edge of d444 45## Test ability to move docks programatically after they have been placed46area.moveDock(d4, 'top', d2)     ## move d4 to top edge of d247area.moveDock(d6, 'above', d4)   ## move d6 to stack on top of d448area.moveDock(d5, 'top', d2)     ## move d5 to top edge of d249 50 51## Add widgets into each dock52 53## first dock gets save/restore buttons54w1 = pg.LayoutWidget()55label = QtWidgets.QLabel(""" -- DockArea Example -- 56This window has 6 Dock widgets in it. Each dock can be dragged57by its title bar to occupy a different space within the window 58but note that one dock has its title bar hidden). Additionally,59the borders between docks may be dragged to resize. Docks that are dragged on top60of one another are stacked in a tabbed layout. Double-click a dock title61bar to place it in its own window.62""")63saveBtn = QtWidgets.QPushButton('Save dock state')64restoreBtn = QtWidgets.QPushButton('Restore dock state')65restoreBtn.setEnabled(False)66w1.addWidget(label, row=0, col=0)67w1.addWidget(saveBtn, row=1, col=0)68w1.addWidget(restoreBtn, row=2, col=0)69d1.addWidget(w1)70state = None71def save():72    global state73    state = area.saveState()74    restoreBtn.setEnabled(True)75def load():76    global state77    area.restoreState(state)78saveBtn.clicked.connect(save)79restoreBtn.clicked.connect(load)80 81 82w2 = ConsoleWidget()83d2.addWidget(w2)84 85## Hide title bar on dock 386d3.hideTitleBar()87w3 = pg.PlotWidget(title="Plot inside dock with no title bar")88w3.plot(np.random.normal(size=100))89d3.addWidget(w3)90 91w4 = pg.PlotWidget(title="Dock 4 plot")92w4.plot(np.random.normal(size=100))93d4.addWidget(w4)94 95w5 = pg.ImageView()96w5.setImage(np.random.normal(size=(100,100)))97d5.addWidget(w5)98 99w6 = pg.PlotWidget(title="Dock 6 plot")100w6.plot(np.random.normal(size=100))101d6.addWidget(w6)102 103 104 105win.show()106 107 108 109if __name__ == '__main__':110    pg.exec()111 
Aluode/PerceptionLabPortable · CoolFace