def plot_main( models=(), config_file=None, x_axis_mode="n", demo=False, window_name="TaurusPlot (pg)", ): """Launch a TaurusPlot""" import sys from taurus.qt.qtgui.application import TaurusApplication app = TaurusApplication(cmd_line_parser=None, app_name="taurusplot(pg)") w = TaurusPlot() # w.loadConfigFile('tmp/TaurusPlot.pck') w.setWindowTitle(window_name) if demo: models = list(models) models.extend(["eval:rand(100)", "eval:0.5*sqrt(arange(100))"]) if x_axis_mode.lower() == "t": from taurus.qt.qtgui.tpg import DateAxisItem axis = DateAxisItem(orientation="bottom") axis.attachToPlotItem(w.getPlotItem()) if config_file is not None: w.loadConfigFile(config_file) if models: w.setModel(models) w.show() ret = app.exec_() # import pprint # pprint.pprint(w.createConfig()) sys.exit(ret)
def __init__(self, parent=None): TaurusPlot.__init__(self) plot = self #plot.setBackgroundBrush(Qt.QColor('white')) self.time_selector = None axis = self.axis = DateAxisItem(orientation='bottom') plot_items = self.plot_items = plot.getPlotItem() axis.attachToPlotItem(plot_items) # TODO (cleanup menu actions) if plot_items.legend is not None: plot_items.legend.hide() vb = plot.getPlotItem().getViewBox() vb.sigXRangeChanged.connect(self.onUpdateXViewRange)
TaurusTrendSet, DateAxisItem, XAutoPanTool, ForcedReadTool, ) import pyqtgraph as pg from taurus.core.taurusmanager import TaurusManager taurusM = TaurusManager() taurusM.changeDefaultPollingPeriod(1000) # ms app = TaurusApplication() # Add a date-time X axis axis = DateAxisItem(orientation="bottom") w = pg.PlotWidget() axis.attachToPlotItem(w.getPlotItem()) # Add the auto-pan ("oscilloscope mode") tool autopan = XAutoPanTool() autopan.attachToPlotItem(w.getPlotItem()) # Add Forced-read tool fr = ForcedReadTool(w, period=1000) fr.attachToPlotItem(w.getPlotItem()) # add legend the legend tool w.addLegend() # adding a taurus data item...
def TaurusPlotMain(): import sys import taurus.qt.qtgui.application import taurus.core.util.argparse parser = taurus.core.util.argparse.get_taurus_parser() parser.set_usage("%prog [options] [<model1> [<model2>] ...]") parser.set_description("a taurus application for plotting 1D data sets") parser.add_option("--config", "--config-file", dest="config_file", default=None, help="use the given config file for initialization") parser.add_option("-x", "--x-axis-mode", dest="x_axis_mode", default='n', metavar="t|n", help=('X axis mode. "t" implies using a Date axis' + '"n" uses the regular axis')) parser.add_option("--demo", action="store_true", dest="demo", default=False, help="show a demo of the widget") parser.add_option("--window-name", dest="window_name", default="TaurusPlot (pg)", help="Name of the window") app = taurus.qt.qtgui.application.TaurusApplication( cmd_line_parser=parser, app_name="taurusplot(pg)", app_version=taurus.Release.version) args = app.get_command_line_args() options = app.get_command_line_options() models = args w = TaurusPlot() # w.loadConfigFile('tmp/TaurusPlot.pck') w.setWindowTitle(options.window_name) if options.demo: args.extend(['eval:rand(100)', 'eval:0.5*sqrt(arange(100))']) if options.x_axis_mode.lower() == 't': from taurus.qt.qtgui.tpg import DateAxisItem axis = DateAxisItem(orientation='bottom') axis.attachToPlotItem(w.getPlotItem()) if options.config_file is not None: w.loadConfigFile(options.config_file) if models: w.setModel(models) w.show() ret = app.exec_() # import pprint # pprint.pprint(w.createConfig()) sys.exit(ret)
def run(): # Simplify TaurusGui TaurusGui.TAURUS_MENU_ENABLED = False TaurusGui.TOOLS_MENU_ENABLED = False TaurusGui.HELP_MENU_ENABLED = False TaurusGui.FULLSCREEN_TOOLBAR_ENABLED = False TaurusGui.PANELS_MENU_ENABLED = False TaurusGui.APPLETS_TOOLBAR_ENABLED = False TaurusGui.QUICK_ACCESS_TOOLBAR_ENABLED = False app = TaurusApplication(app_name='tpgArchiving') gui = TaurusGui() gui.setWindowTitle('Taurus Archiving Plot') plot = TaurusPlot() #class MyPlot(TaurusPlot): #pass ##def dropEvent(self, event): ##print('In dropEvent(%s)' % str(dir(event))) ##def dragMoveEvent(self,event): ##print('Dragging ...') ##event.acceptProposedAction() ##def dragEnterEvent(self,event): ##print('Entering ...') ##event.acceptProposedAction() #plot = MyPlot() #plot.setAcceptDrops(True) #plot = fandango.qt.Dropable(TaurusPlot)() #plot.setDropLogger(fandango.printf) #plot.setSupportedMimeTypes(fandango.qt.MIMETYPES) plot.setBackgroundBrush(Qt.QColor('white')) axis = DateAxisItem(orientation='bottom') plot_items = plot.getPlotItem() axis.attachToPlotItem(plot_items) # TODO (cleanup menu actions) if plot_items.legend is not None: plot_items.legend.hide() msi = TangoArchivingModelSelectorItem() # hide time stamp selector msi.ui.ts_checkBox.setVisible(False) # hide add single Y model msi._addSelectedAction.setVisible(False) msi.setModel(msi.default_model) # progress bar pb = Qt.QProgressBar() pb.setGeometry(0, 0, 300, 25) def updateProgressBar(stop=True): if stop is True: final = 1 else: final = 0 pb.setRange(0, final) updateProgressBar() ########################################################################### # Update t0 and t1 based on sigXRangeChanged ########################################################################### def onUpdateXViewRange(): x, _ = plot.viewRange() t0, t1 = x t0s = str2localtime(t0) t1s = str2localtime(t1) msi.time_selector.ui.comboBox_begin.setItemText(5, t0s) msi.time_selector.ui.comboBox_end.setItemText(7, t1s) msi.time_selector.ui.comboBox_begin.setItemText(5, t0s) msi.time_selector.ui.comboBox_end.setItemText(7, t1s) msi.time_selector.ui.comboBox_begin.setCurrentIndex(5) msi.time_selector.ui.comboBox_end.setCurrentIndex(7) vb = plot.getPlotItem().getViewBox() vb.sigXRangeChanged.connect(onUpdateXViewRange) ########################################################################### # Legend ########################################################################### gv = Qt.QGraphicsView(Qt.QGraphicsScene()) gv.setBackgroundBrush(Qt.QBrush(Qt.QColor('white'))) l = pg.LegendItem(None, offset=(0, 0)) gv.scene().addItem(l) def updateExternalLegend(): for dataitem in plot_items.listDataItems(): l.removeItem(dataitem.name()) for dataitem in plot_items.listDataItems(): if dataitem.name(): l.addItem(dataitem, dataitem.name()) ########################################################################### # Connect CurvesAppearanceChooser to external legend ########################################################################### from taurus_pyqtgraph.curveproperties import (CurvesAppearanceChooser, CurveAppearanceProperties) def onApply(self): names = self.getSelectedCurveNames() prop = self.getShownProperties() # Update self.curvePropDict for selected properties for n in names: self.curvePropDict[n] = CurveAppearanceProperties.merge( [self.curvePropDict[n], prop], conflict=CurveAppearanceProperties.inConflict_update_a) # emit a (PyQt) signal telling what properties (first argument) need to # be applied to which curves (second argument) # self.curveAppearanceChanged.emit(prop, names) # return both values self.curvePropAdapter.setCurveProperties(self.curvePropDict, names) # Update legend updateExternalLegend() return prop, names # Override CurvesAppearanceChooser.onApply CurvesAppearanceChooser.onApply = onApply ########################################################################### # Helper ########################################################################### def updateAll(legend=True): # Update legend if legend is True: updateExternalLegend() # run plot auto range time.sleep(0.2) # Wait till models are loading plot_items.getViewBox().menu.autoRange() # Stop progress bar updateProgressBar() ########################################################################### # onAddXYModel ########################################################################### def onAddXYModel(models=None): # Update progress bar # updateProgressBar(False) print('onAddXYModel(%s)' % models) if not isSequenceType(models): print('Overriding models ...') models = msi.getSelectedModels() c = msi.cursor() msi.setCursor(Qt.Qt.WaitCursor) current = plot._model_chooser_tool.getModelNames() print('current: %s' % str(current)) models = [m for m in models if m not in current] print('new models: %s' % str(models)) plot.addModels(models) updateAll() msi.setCursor(c) # Connect button msi.modelsAdded.connect(onAddXYModel) #plot.setDropEventCallback(onAddXYModel) ########################################################################### # Override TaurusGui close event ########################################################################### def closeEvent(self, event): try: self.__macroBroker.removeTemporaryPanels() except: pass TaurusMainWindow.closeEvent(self, event) for n, panel in self._TaurusGui__panels.items(): panel.closeEvent(event) panel.widget().closeEvent(event) if not event.isAccepted(): result = Qt.QMessageBox.question( self, 'Closing error', "Panel '%s' cannot be closed. Proceed closing?" % n, Qt.QMessageBox.Yes | Qt.QMessageBox.No) if result == Qt.QMessageBox.Yes: event.accept() else: break for curve in plot_items.listDataItems(): plot.removeItem(curve) l.removeItem(curve.name()) gui.saveSettings() # Override TaurusGui close event TaurusGui.closeEvent = closeEvent ########################################################################### # Create tgarch tool bar ########################################################################### def _onRefresh(): t0, t1 = msi.time_selector.getTimes() # Validate models v = TangoArchivingAttributeNameValidator() query = "{0};t0={1};t1={2}" for curve in plot.getPlotItem().listDataItems(): if isinstance(curve, TaurusPlotDataItem): ymodel = curve.getModel() # tgarch attr if v.getUriGroups(ymodel).get('scheme') != 'tgarch': continue fullname, _, _ = v.getNames(ymodel) bmodel, current_query = fullname.split('?') db = current_query.split(';')[0] q = query.format(db, t0, t1) model = "{0}?{1}".format(bmodel, q) xmodel = "{};ts".format(model) curve.setModel(None) curve.setXModel(None) curve.setModel(model) curve.setXModel(xmodel) updateAll(legend=False) def onRefresh(): # Update progress bar updateProgressBar(False) t1 = threading.Thread(target=_onRefresh) t1.start() tgarchToolBar = gui.addToolBar("TgArch") tgarchToolBar.addAction(Qt.QIcon.fromTheme("view-refresh"), "refresh tgarch curves", onRefresh) ########################################################################### # Create panels ########################################################################### gui.createPanel(plot, 'Plot') gui.createPanel(msi, 'Chooser') gui.createPanel(pb, 'Progress bar') gui.createPanel(gv, 'Legend') # Load configuration gui.loadSettings() gui.show() app.exec_()