pyqtgraph/examples/designerExample.py

43 lines
1.2 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
"""
Simple example of loading UI template created with Qt Designer.
This example uses uic.loadUiType to parse and load the ui at runtime. It is also
possible to pre-compile the .ui file using pyuic (see VideoSpeedTest and
ScatterPlotSpeedTest examples; these .ui files have been compiled with the
tools/rebuildUi.py script).
"""
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 numpy as np
import os
pg.mkQApp()
## Define main window class from template
path = os.path.dirname(os.path.abspath(__file__))
uiFile = os.path.join(path, 'designerExample.ui')
WindowTemplate, TemplateBaseClass = pg.Qt.loadUiType(uiFile)
class MainWindow(TemplateBaseClass):
def __init__(self):
TemplateBaseClass.__init__(self)
self.setWindowTitle('pyqtgraph example: Qt Designer')
# Create the main window
self.ui = WindowTemplate()
self.ui.setupUi(self)
self.ui.plotBtn.clicked.connect(self.plot)
self.show()
def plot(self):
self.ui.plot.plot(np.random.normal(size=100), clear=True)
win = MainWindow()
if __name__ == '__main__':
pg.mkQApp().exec_()