def _do_update(self): if self.sender().text() == 'Abort': self._update_task.terminate() now = Time.now().strftime('%Y/%m/%d-%H:%M:%S') item = QListWidgetItem(now + ' Aborted.') self._progress_list.addItem(item) self._progress_list.scrollToBottom() self._setup_search_button() else: if self.dt_start.dateTime() >= self.dt_stop.dateTime() or \ self.dt_start.dateTime() > Time.now() or \ self.dt_stop.dateTime() > Time.now(): QMessageBox.warning(self, 'Ops...', 'Insert a valid time interval.') return self._macreport.timestamp_start = \ self.dt_start.dateTime().toSecsSinceEpoch() self._macreport.timestamp_stop = \ self.dt_stop.dateTime().toSecsSinceEpoch() self._progress_list.clear() self._pb_showraw.setEnabled(False) self._pb_showpvsd.setEnabled(False) self._setup_search_button() self._update_task = UpdateTask(self._macreport) self._update_task.updated.connect(self._update_progress) self._update_task.start()
def _setupTimePeriodSelWidget(self): tnow = Time.now() ld_tstart = QLabel('Time start: ') self.dt_start = QDateTimeEdit(tnow - 10 * 60, self) self.dt_start.setCalendarPopup(True) self.dt_start.setMinimumDate(Time(2020, 1, 1)) self.dt_start.setDisplayFormat('dd/MM/yyyy hh:mm') ld_tstop = QLabel('Time stop: ') self.dt_stop = QDateTimeEdit(tnow, self) self.dt_stop.setCalendarPopup(True) self.dt_stop.setMinimumDate(Time(2020, 1, 1)) self.dt_stop.setDisplayFormat('dd/MM/yyyy hh:mm') self.pb_search = QPushButton(qta.icon('fa5s.search'), 'Search', self) self.pb_search.clicked.connect(self._do_update) self.pb_search.setObjectName('pb_search') self.pb_search.setStyleSheet(""" #pb_search{ min-width:100px; max-width:100px; min-height:25px; max-height:25px; icon-size:20px;} """) wid = QGroupBox('Select interval: ', self) lay = QGridLayout(wid) lay.addWidget(ld_tstart, 0, 0) lay.addWidget(self.dt_start, 0, 1) lay.addWidget(ld_tstop, 1, 0) lay.addWidget(self.dt_stop, 1, 1) lay.addWidget(self.pb_search, 2, 1, alignment=Qt.AlignRight) return wid
def updateXAxis(self, update_immediately=False): """Reimplement to show only existing range.""" if len(self._curves) == 0: return if self._plot_by_timestamps: if self._update_mode == PyDMTimePlot.SynchronousMode: maxrange = max([curve.max_x() for curve in self._curves]) else: maxrange = time.time() mini = Time.now().timestamp() for curve in self._curves: firstvalid = (curve.data_buffer[0] != 0).argmax() if curve.data_buffer[0, firstvalid] == 0: continue mini = min(mini, curve.data_buffer[0, firstvalid]) minrange = max(maxrange - self._time_span, mini) self.plotItem.setXRange(minrange, maxrange, padding=0.0, update=update_immediately) else: diff_time = self.starting_epoch_time - \ max([curve.max_x() for curve in self._curves]) if diff_time > DEFAULT_X_MIN: diff_time = DEFAULT_X_MIN self.getViewBox().setLimits(minXRange=diff_time)
def _handle_mouse_moved(self, pos): """Show tooltip at mouse move.""" if not self._show_tooltip: return # create label tooltip, if needed if not hasattr(self, 'label_tooltip'): self.label_tooltip = QLabel(self, Qt.ToolTip) self.timer_tooltip = QTimer(self) self.timer_tooltip.timeout.connect(self.label_tooltip.hide) self.timer_tooltip.setInterval(1000) # find nearest curve point nearest = (self._curves[0], _np.inf, None, None) for idx, curve in enumerate(self._curves): if not curve.isVisible(): continue mappos = curve.mapFromScene(pos) posx, posy = mappos.x(), mappos.y() xData, yData = curve.curve.xData, curve.curve.yData if not xData.size: continue diffx = xData - posx idx = _np.argmin(_np.abs(diffx)) if diffx[idx] < 0.5: valx, valy = xData[idx], yData[idx] diffy = abs(valy - posy) if diffy < nearest[1]: nearest = (curve, diffy, valx, valy) # show tooltip curve, diffy, valx, valy = nearest ylimts = self.getViewBox().state['viewRange'][1] ydelta = ylimts[1] - ylimts[0] if diffy < 1e-2 * ydelta: txt = Time(timestamp=valx).get_iso8601() + '\n' txt += f'{curve.name()}: {valy:.3f}' font = QApplication.instance().font() font.setPointSize(font.pointSize() - 10) palette = QPalette() palette.setColor(QPalette.WindowText, curve.color) self.label_tooltip.setText(txt) self.label_tooltip.setFont(font) self.label_tooltip.setPalette(palette) self.label_tooltip.move(self.mapToGlobal(pos.toPoint())) self.label_tooltip.show() self.timer_tooltip.start() curve.scatter.setData(pos=[ (valx, valy), ], symbol='o', size=15, brush=mkBrush(curve.color)) curve.scatter.show()
def redrawCurve(self): """ Rederive redrawCurve to use data only refered to timespan. """ try: now = Time.now().timestamp() xmin = now - self.parent.timeSpan idcs = _np.where(self.data_buffer[0] >= xmin)[0] x = self.data_buffer[0, idcs].astype(_np.float) y = self.data_buffer[1, idcs].astype(_np.float) if not self._plot_by_timestamps: x -= now self.setData(y=y, x=x) except (ZeroDivisionError, OverflowError): # Solve an issue with pyqtgraph and initial downsampling pass
def _changeTimeSpan(self): new_time_span, ok = QInputDialog.getInt( self, 'Input', 'Set new time span value [s]: ') if not ok: return if new_time_span > self.timeSpan: t_end = Time.now() t_init = t_end - new_time_span for pvname, info in self._filled_with_arch_data.items(): self.fill_curve_with_archdata(info['curve'], pvname, t_init.get_iso8601(), t_end.get_iso8601(), info['factor'], info['process_type'], info['process_bin_intvl']) self.timeSpan = new_time_span self.timeSpanChanged.emit()
def _update(self): text = _Time.strftime(_Time.now(), '%H:%M:%S') self.setText(text)
def update(self, message): """Send log.""" now = Time.now().strftime('%Y/%m/%d-%H:%M:%S') self.updated.emit(now + ' ' + message)