def __init__(self, max_n, parent=None, **kwargs): super(BMDemo, self).__init__(parent=parent) self.setWindowTitle('Curve benchmark') tabs = QTabWidget() self.setCentralWidget(tabs) contents = BMText() tabs.addTab(contents, 'Contents') self.resize(1000, 600) # Force window to show up and refresh (for test purpose only) self.show() QApplication.processEvents() t0g = time.time() for idx in range(4, -1, -1): points = max_n/10**idx t0 = time.time() widget = BMWidget(points) title = '%d points' % points tabs.addTab(widget, title) tabs.setCurrentWidget(widget) # Force widget to refresh (for test purpose only) QApplication.processEvents() time_str = "Elapsed time: %d ms" % ((time.time()-t0)*1000) widget.text.setText(time_str) contents.append("<br><i>%s:</i><br>%s" % (title, time_str)) dt = time.time()-t0g contents.append("<br><br><u>Total elapsed time</u>: %d ms" % (dt*1000)) tabs.setCurrentIndex(0)
def __init__(self, max_n, parent=None, **kwargs): super(BMDemo, self).__init__(parent=parent) self.setWindowTitle('Curve styles') tabs = QTabWidget() self.resize(1000, 800) # Force window to show up and refresh (for test purpose only) self.show() QApplication.processEvents() self.setCentralWidget(tabs) pts = 1000 for points, symbols in zip((pts/10, pts/10, pts, pts), (True, False)*2): t0 = time.time() widget = CSWidget(points, symbols) symtext = "with%s symbols" % ("" if symbols else "out") title = '%d points, %s' % (points, symtext) tabs.addTab(widget, title) tabs.setCurrentWidget(widget) # Force widget to refresh (for test purpose only) QApplication.processEvents() time_str = "Elapsed time: %d ms" % ((time.time()-t0)*1000) widget.text.setText(time_str) tabs.setCurrentIndex(0)
def __init__(self, max_n, parent=None, **kwargs): super(BMDemo, self).__init__(parent=parent) self.setWindowTitle('Curve styles') tabs = QTabWidget() self.resize(1000, 800) # Force window to show up and refresh (for test purpose only) self.show() QApplication.processEvents() self.setCentralWidget(tabs) pts = 1000 for points, symbols in zip((pts / 10, pts / 10, pts, pts), (True, False) * 2): t0 = time.time() widget = CSWidget(points, symbols) symtext = "with%s symbols" % ("" if symbols else "out") title = '%d points, %s' % (points, symtext) tabs.addTab(widget, title) tabs.setCurrentWidget(widget) # Force widget to refresh (for test purpose only) QApplication.processEvents() time_str = "Elapsed time: %d ms" % ((time.time() - t0) * 1000) widget.text.setText(time_str) tabs.setCurrentIndex(0)
def main(args): app = QApplication(args) x_values = numpy.array([1.0, 2.0, 3.0, 4.0]) y_values = numpy.array([15.0, 25.0, 35.0, 45.0]) flags = numpy.array([0.0, 0.0, 0.0, 0.0]) demo = ZoomPopup(1, x_values, y_values, flags, Qt.yellow, None, None) demo.show() app.exec_()
def process_iteration(self, title, description, widget, t0): self.tabs.addTab(widget, title) self.tabs.setCurrentWidget(widget) # Force widget to refresh (for test purpose only) QApplication.processEvents() time_str = "Elapsed time: %d ms" % ((time.time() - t0) * 1000) widget.text.setText(time_str) self.text.append("<br><i>%s:</i><br>%s" % (description, time_str))
def process_iteration(self, title, description, widget, t0): self.tabs.addTab(widget, title) self.tabs.setCurrentWidget(widget) # Force widget to refresh (for test purpose only) QApplication.processEvents() time_str = "Elapsed time: %d ms" % ((time.time()-t0)*1000) widget.text.setText(time_str) self.text.append("<br><i>%s:</i><br>%s" % (description, time_str))
def eventFilter(self, object_, event): if object_ is self.__data.view.contentsWidget: if event.type() == QEvent.ChildRemoved: ce = event #TODO: cast to QChildEvent if ce.child().isWidgetType(): w = ce.child() #TODO: cast to QWidget self.__data.itemMap.removeWidget(w) elif event.type() == QEvent.LayoutRequest: self.__data.view.layoutContents() if self.parentWidget() and self.parentWidget().layout() is None: QApplication.postEvent(self.parentWidget(), QEvent(QEvent.LayoutRequest)) return QwtAbstractLegend.eventFilter(self, object_, event)
def eventFilter(self, object, event): if event.type() == QEvent.FocusIn: self.__showCursor(True) if event.type() == QEvent.FocusOut: self.__showCursor(False) if event.type() == QEvent.Paint: QApplication.postEvent(self, QEvent(QEvent.User)) elif event.type() == QEvent.MouseButtonPress: self.__select(event.pos()) return True elif event.type() == QEvent.MouseMove: self.__move(event.pos()) return True if event.type() == QEvent.KeyPress: delta = 5 key = event.key() if key == Qt.Key_Up: self.__shiftCurveCursor(True) return True elif key == Qt.Key_Down: self.__shiftCurveCursor(False) return True elif key == Qt.Key_Right or key == Qt.Key_Plus: if self.__selectedCurve: self.__shiftPointCursor(True) else: self.__shiftCurveCursor(True) return True elif key == Qt.Key_Left or key == Qt.Key_Minus: if self.__selectedCurve: self.__shiftPointCursor(False) else: self.__shiftCurveCursor(True) return True if key == Qt.Key_1: self.__moveBy(-delta, delta) elif key == Qt.Key_2: self.__moveBy(0, delta) elif key == Qt.Key_3: self.__moveBy(delta, delta) elif key == Qt.Key_4: self.__moveBy(-delta, 0) elif key == Qt.Key_6: self.__moveBy(delta, 0) elif key == Qt.Key_7: self.__moveBy(-delta, -delta) elif key == Qt.Key_8: self.__moveBy(0, -delta) elif key == Qt.Key_9: self.__moveBy(delta, -delta) return QwtPlot.eventFilter(self.__plot, object, event)
def replot(self): doAutoReplot = self.autoReplot() self.setAutoReplot(False) self.updateAxes() QApplication.sendPostedEvents(self, QEvent.LayoutRequest) if self.__data.canvas: try: self.__data.canvas.replot() except (AttributeError, TypeError): self.__data.canvas.update(self.__data.canvas.contentsRect()) self.setAutoReplot(doAutoReplot)
def eventFilter(self, object_, event): if object_ is self.__data.view.contentsWidget: if event.type() == QEvent.ChildRemoved: ce = event #TODO: cast to QChildEvent if ce.child().isWidgetType(): w = ce.child() #TODO: cast to QWidget self.__data.itemMap.removeWidget(w) elif event.type() == QEvent.LayoutRequest: self.__data.view.layoutContents() if self.parentWidget( ) and self.parentWidget().layout() is None: QApplication.postEvent(self.parentWidget(), QEvent(QEvent.LayoutRequest)) return QwtAbstractLegend.eventFilter(self, object_, event)
def sizeHint(self): sz = QwtTextLabel.sizeHint(self) sz.setHeight(max([sz.height(), self.__data.icon.height()+4])) if self.__data.itemMode != QwtLegendData.ReadOnly: sz += buttonShift(self) sz = sz.expandedTo(QApplication.globalStrut()) return sz
def sizeHint(self): sz = QwtTextLabel.sizeHint(self) sz.setHeight(max([sz.height(), self.__data.icon.height() + 4])) if self.__data.itemMode != QwtLegendData.ReadOnly: sz += buttonShift(self) sz = sz.expandedTo(QApplication.globalStrut()) return sz
def qwtScreenResolution(): screenResolution = QSize() if not screenResolution.isValid(): desktop = QApplication.desktop() if desktop is not None: screenResolution.setWidth(desktop.logicalDpiX()) screenResolution.setHeight(desktop.logicalDpiY()) return screenResolution
def _desktopwidget(self): """ Property used to store the Application Desktop Widget to avoid calling the `QApplication.desktop()" function more than necessary as its calling time is not negligible. """ if self.__desktopwidget is None: self.__desktopwidget = QApplication.desktop() return self.__desktopwidget
def qwtUnscaleFont(painter): if painter.font().pixelSize() >= 0: return screenResolution = qwtScreenResolution() pd = painter.device() if pd.logicalDpiX() != screenResolution.width() or\ pd.logicalDpiY() != screenResolution.height(): pixelFont = QFont(painter.font(), QApplication.desktop()) pixelFont.setPixelSize(QFontInfo(pixelFont).pixelSize()) painter.setFont(pixelFont)
def __init__(self, max_n, parent=None, **kwargs): super(BMDemo, self).__init__(parent=parent) title = self.TITLE if kwargs.get('only_lines', False): title = '%s (%s)' % (title, 'only lines') self.setWindowTitle(title) self.tabs = QTabWidget() self.setCentralWidget(self.tabs) self.text = BMText(self) self.tabs.addTab(self.text, 'Contents') self.resize(*self.SIZE) # Force window to show up and refresh (for test purpose only) self.show() QApplication.processEvents() t0g = time.time() self.run_benchmark(max_n, **kwargs) dt = time.time()-t0g self.text.append("<br><br><u>Total elapsed time</u>: %d ms" % (dt*1e3)) self.tabs.setCurrentIndex(0)
def eventFilter(self, object_, event): """ Handle QEvent.ChildRemoved andQEvent.LayoutRequest events for the contentsWidget(). :param QObject object: Object to be filtered :param QEvent event: Event :return: Forwarded to QwtAbstractLegend.eventFilter() """ if object_ is self.__data.view.contentsWidget: if event.type() == QEvent.ChildRemoved: ce = event #TODO: cast to QChildEvent if ce.child().isWidgetType(): w = ce.child() #TODO: cast to QWidget self.__data.itemMap.removeWidget(w) elif event.type() == QEvent.LayoutRequest: self.__data.view.layoutContents() if self.parentWidget() and self.parentWidget().layout() is None: QApplication.postEvent(self.parentWidget(), QEvent(QEvent.LayoutRequest)) return QwtAbstractLegend.eventFilter(self, object_, event)
def __init__(self, max_n, parent=None, **kwargs): super(BMDemo, self).__init__(parent=parent) title = self.TITLE if kwargs.get('only_lines', False): title = '%s (%s)' % (title, 'only lines') self.setWindowTitle(title) self.tabs = QTabWidget() self.setCentralWidget(self.tabs) self.text = BMText(self) self.tabs.addTab(self.text, 'Contents') self.resize(*self.SIZE) # Force window to show up and refresh (for test purpose only) self.show() QApplication.processEvents() t0g = time.time() self.run_benchmark(max_n, **kwargs) dt = time.time() - t0g self.text.append("<br><br><u>Total elapsed time</u>: %d ms" % (dt * 1e3)) self.tabs.setCurrentIndex(0)
def main(args): app = QApplication(args) demo = QwtPlot() grid = QwtPlotGrid() grid.attach(demo) grid.setPen(QPen(Qt.black, 0, Qt.DotLine)) grid.enableX(True) grid.enableY(True) complex_divider = 50.0 myXScale = ComplexScaleDraw(start_value=0.0, end_value=complex_divider) #print('myXScale', myXScale) demo.setAxisScaleDraw(QwtPlot.xBottom, myXScale) m = QwtPlotMarker() m.attach(demo) m.setValue(complex_divider, 0.0) m.setLineStyle(QwtPlotMarker.VLine) m.setLabelAlignment(Qt.AlignRight | Qt.AlignBottom) m.setLinePen(QPen(Qt.black, 2, Qt.SolidLine)) vector_array = numpy.zeros((100, ), numpy.float32) for i in range(100): vector_array[i] = i curve = QwtPlotCurve('example data') curve.attach(demo) x_array = numpy.zeros(100, numpy.float32) y_array = numpy.zeros(100, numpy.float32) for i in range(100): x_array[i] = 1.0 * i y_array[i] = 2.0 * i curve.setSamples(x_array, y_array) demo.resize(600, 400) demo.replot() demo.show() # app.setMainWidget(demo) app.exec_()
def desktopwidget(self): if self._desktopwidget is None: self._desktopwidget = QApplication.desktop() return self._desktopwidget
self.show() QApplication.processEvents() self.setCentralWidget(tabs) pts = 1000 for points, symbols in zip((pts / 10, pts / 10, pts, pts), (True, False) * 2): t0 = time.time() widget = CSWidget(points, symbols) symtext = "with%s symbols" % ("" if symbols else "out") title = '%d points, %s' % (points, symtext) tabs.addTab(widget, title) tabs.setCurrentWidget(widget) # Force widget to refresh (for test purpose only) QApplication.processEvents() time_str = "Elapsed time: %d ms" % ((time.time() - t0) * 1000) widget.text.setText(time_str) tabs.setCurrentIndex(0) if __name__ == '__main__': app = QApplication([]) for name in ('Calibri', 'Verdana', 'Arial'): if name in QFontDatabase().families(): app.setFont(QFont(name)) break demo = BMDemo(100000) app.exec_()
self.phase = 0.0 # y moves from left to right: # shift y array right and assign new value y[0] self.y = np.concatenate((self.y[:1], self.y[:-1]), 1) self.y[0] = np.sin(self.phase) * (-1.0 + 2.0*random.random()) # z moves from right to left: # Shift z array left and assign new value to z[n-1]. self.z = np.concatenate((self.z[1:], self.z[:1]), 1) self.z[-1] = 0.8 - (2.0 * self.phase/np.pi) + 0.4*random.random() self.curveR.setData(self.x, self.y) self.curveL.setData(self.x, self.z) self.replot() self.phase += np.pi*0.02 def make(): demo = DataPlot() demo.resize(500, 300) demo.show() return demo if __name__ == '__main__': app = QApplication(sys.argv) demo = make() sys.exit(app.exec_())
def main(args): app = QApplication(args) demo = BufferSizeDialog(10) demo.show() app.exec_()
QApplication.processEvents() t0g = time.time() for idx in range(4, -1, -1): points = max_n/10**idx t0 = time.time() widget = BMWidget(points) title = '%d points' % points tabs.addTab(widget, title) tabs.setCurrentWidget(widget) # Force widget to refresh (for test purpose only) QApplication.processEvents() time_str = "Elapsed time: %d ms" % ((time.time()-t0)*1000) widget.text.setText(time_str) contents.append("<br><i>%s:</i><br>%s" % (title, time_str)) dt = time.time()-t0g contents.append("<br><br><u>Total elapsed time</u>: %d ms" % (dt*1000)) tabs.setCurrentIndex(0) if __name__ == '__main__': app = QApplication([]) for name in ('Calibri', 'Verdana', 'Arial'): if name in QFontDatabase().families(): app.setFont(QFont(name)) break demo = BMDemo(1000000) app.exec_()
def main(args): app = QApplication(args) demo = make() # app.setMainWidget(demo) app.exec_()
# -*- coding: utf-8 -*- __author__ = 'Valeriy' from qwt.qt.QtGui import QApplication from qwt import QwtPlot, QwtPlotCurve import numpy as np app = QApplication([]) # x = [1,2,3,4,5,6,7,8,9] # y1 = [3.2, 5.1 ,7.0, 4.24, 4.41, 8.34, 2.21, 5.657, 6.1] x = [] y1 = [] my_plot = QwtPlot("Two curves") curve1 = QwtPlotCurve("Curve 1") my_plot.resize(600, 300) curve1.setData(x, y1) curve1.attach(my_plot) # my_plot.replot() my_plot.show() app.exec_() # SELECT PrepData FROM= Pdata WHERE ((PNameId=2) AND (SNameId = 14) AND (YearId=2012))
"plotLayout().scaleRect(QwtPlot.yLeft):\n%r\n\n" "axisWidget(QwtPlot.yLeft).geometry():\n%r\n\n" "plotLayout().scaleRect(QwtPlot.yRight):\n%r\n\n" "axisWidget(QwtPlot.yRight).geometry():\n%r\n\n" "plotLayout().scaleRect(QwtPlot.xBottom):\n%r\n\n" "axisWidget(QwtPlot.xBottom).geometry():\n%r\n\n" "plotLayout().scaleRect(QwtPlot.xTop):\n%r\n\n" "axisWidget(QwtPlot.xTop).geometry():\n%r\n\n" % ( self.plotLayout().canvasRect().getCoords(), self.canvas().geometry().getCoords(), self.plotLayout().scaleRect(QwtPlot.yLeft).getCoords(), self.axisWidget(QwtPlot.yLeft).geometry().getCoords(), self.plotLayout().scaleRect(QwtPlot.yRight).getCoords(), self.axisWidget(QwtPlot.yRight).geometry().getCoords(), self.plotLayout().scaleRect(QwtPlot.xBottom).getCoords(), self.axisWidget(QwtPlot.xBottom).geometry().getCoords(), self.plotLayout().scaleRect(QwtPlot.xTop).getCoords(), self.axisWidget(QwtPlot.xTop).geometry().getCoords(), )) text.setFont(QFont('Courier New')) text.setColor(Qt.blue) self.marker.setLabel(text) if __name__ == '__main__': app = QApplication([]) plot = TestPlot() plot.resize(300, 1000) plot.show() app.exec_()
def main(args): app = QApplication(args) demo = make() app.exec_()
def showInfo(self, text=""): self.statusBar().showMessage(text) def moved(self, point): info = "Freq=%g, Ampl=%g, Phase=%g" % ( self.plot.invTransform(QwtPlot.xBottom, point.x()), self.plot.invTransform(QwtPlot.yLeft, point.y()), self.plot.invTransform(QwtPlot.yRight, point.y())) self.showInfo(info) def selected(self, _): self.showInfo() def make(): demo = BodeDemo() demo.resize(540, 400) demo.show() return demo if __name__ == '__main__': app = QApplication(sys.argv) fonts = QFontDatabase() for name in ('Verdana', 'STIXGeneral'): if name in fonts.families(): app.setFont(QFont(name)) break demo = make() sys.exit(app.exec_())
# calculate data and errors for a curve with error bars x = np.arange(0, 10.1, 0.5, np.float) y = np.sin(x) dy = 0.2 * abs(y) # dy = (0.15 * abs(y), 0.25 * abs(y)) # uncomment for asymmetric error bars dx = 0.2 # all error bars the same size errorOnTop = False # uncomment to draw the curve on top of the error bars # errorOnTop = True # uncomment to draw the error bars on top of the curve curve = ErrorBarPlotCurve( x=x, y=y, dx=dx, dy=dy, curvePen=QPen(Qt.black, 2), curveSymbol=QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.red), QPen(Qt.black, 2), QSize(9, 9)), errorPen=QPen(Qt.blue, 2), errorCap=10, errorOnTop=errorOnTop, ) curve.attach(demo) demo.resize(640, 480) demo.show() return demo if __name__ == '__main__': app = QApplication(sys.argv) demo = make() sys.exit(app.exec_())