Created
October 25, 2013 15:28
-
-
Save darkopetrovic/7156541 to your computer and use it in GitHub Desktop.
Very simple Qwt dockable widget with PyQt.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from guidata.qt.QtGui import QWidget, QMainWindow, QVBoxLayout, qApp | |
from guidata.qtwidgets import DockableWidget | |
from guidata.qt.QtCore import Qt, QThread | |
from guiqwt.plot import CurveWidget, CurvePlot | |
from guiqwt.builder import make | |
from guiqwt.config import _ | |
APP_NAME = _("Very simple Qwt dockable widget with PyQt") | |
class DockablePlotWidget( DockableWidget ): | |
LOCATION = Qt.RightDockWidgetArea | |
def __init__(self, parent, plotwidgetclass, toolbar = None): | |
super(DockablePlotWidget, self).__init__(parent) | |
self.toolbar = toolbar | |
layout = QVBoxLayout() | |
self.plotwidget = plotwidgetclass() | |
layout.addWidget(self.plotwidget) | |
self.setLayout(layout) | |
def get_plot(self): | |
return self.plotwidget.plot | |
class MainWindow(QMainWindow): | |
def __init__(self): | |
QMainWindow.__init__(self) | |
# Allow dockable widgets to be side by side | |
self.setDockOptions(QMainWindow.AnimatedDocks | QMainWindow.AllowNestedDocks) | |
self.curvewidget = DockablePlotWidget(self, CurveWidget) | |
self.curvewidget2 = DockablePlotWidget(self, CurveWidget) | |
self.curveplot = self.curvewidget.get_plot() | |
#x, y = self.sampleData() | |
#self.valueCurve= make.curve(x,y,'b-') | |
#self.curveplot.add_item(self.valueCurve) | |
# Add the DockWidget to the main window | |
self.curve_dock = self.add_dockwidget( self.curvewidget, _("Curve plotting panel") ) | |
self.curve_dock2 = self.add_dockwidget( self.curvewidget2, _("Curve plotting panel2") ) | |
self.show() | |
# After this call the widget will be visually in front of any | |
# overlapping sibling widgets. | |
self.curve_dock.raise_() | |
#------GUI refresh/setup | |
def add_dockwidget(self, child, title): | |
"""Add QDockWidget and toggleViewAction""" | |
dockwidget, location = child.create_dockwidget(title) | |
self.addDockWidget(location, dockwidget) | |
return dockwidget | |
def run(): | |
from guidata import qapplication | |
app = qapplication() | |
window = MainWindow() | |
window.show() | |
app.exec_() | |
if __name__ == "__main__": | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment