Ejemplo n.º 1
0
 def on_client_connected(self):
     # retrieve datasets and put them into the scans window
     pd = QProgressDialog(labelText='Transferring datasets, please wait...')
     pd.setRange(0, 1)
     pd.setCancelButton(None)
     pd.show()
     QApplication.processEvents()
     datasets = self.client.ask('getdataset', '*', default=[])
     self.bulk_adding = True
     for dataset in (datasets or []):
         try:
             self.on_client_dataset(dataset)
         except Exception:
             from nicos.clients.gui.main import log
             log.error('Error adding dataset', exc=1)
     self.bulk_adding = False
     pd.setValue(1)
     pd.close()
Ejemplo n.º 2
0
 def on_client_dataset(self, dataset):
     self.sets.append(dataset)
     self.uid2set[dataset.uid] = dataset
     self.currentset = dataset
     self.dependent = []
     # add some custom attributes of the dataset
     dataset.invisible = False
     dataset.name = str(dataset.counter)
     dataset.default_xname = name_unit(dataset.xnames[dataset.xindex],
                                       dataset.xunits[dataset.xindex])
     dataset.curves = self._init_curves(dataset)
     for xvalues, yvalues in zip(dataset.xresults, dataset.yresults):
         try:
             self._update_curves(dataset, xvalues, yvalues)
         except Exception:
             from nicos.clients.gui.main import log
             log.error('Error adding datapoint', exc=1)
     self.datasetAdded.emit(dataset)
Ejemplo n.º 3
0
    def __init__(self, widget, name, keys_indices, interval, fromtime, totime,
                 yfrom, yto, window, meta, dlginfo, query_func):
        QObject.__init__(self)
        self.name = name
        self.dlginfo = dlginfo

        self.fromtime = fromtime
        self.totime = totime
        self.yfrom = yfrom
        self.yto = yto
        self.window = window

        self._key_indices = {}
        self.uniq_keys = set()
        self.series = OrderedDict()
        self.timer = None

        # + 60 seconds: get all values, also those added while querying
        hist_totime = self.totime or currenttime() + 60
        hist_cache = {}

        iterator = enumerate(keys_indices)
        if fromtime is not None:
            iterator = enumerateWithProgress(keys_indices,
                                             'Querying history...',
                                             force_display=True)

        for _, (key, index, scale, offset) in iterator:
            real_indices = [index]
            history = None
            self.uniq_keys.add(key)

            if fromtime is not None:
                if key not in hist_cache:
                    history = query_func(key, self.fromtime, hist_totime)
                    if not history:
                        from nicos.clients.gui.main import log
                        if log is None:
                            from __main__ import log  # pylint: disable=no-name-in-module
                        log.error('Error getting history for %s.', key)
                        QMessageBox.warning(
                            widget, 'Error', 'Could not get history for %s, '
                            'there are no values to show.\n'
                            'Is it spelled correctly?' % key)
                        history = []
                    hist_cache[key] = history
                else:
                    history = hist_cache[key]
                # if the value is a list/tuple and we don't have an index
                # specified, add a plot for each item
                if history:
                    first_value = history[0][1]
                    if not index and isinstance(first_value, (list, tuple)):
                        real_indices = tuple(
                            (i, ) for i in range(len(first_value)))
            for index in real_indices:
                name = '%s[%s]' % (key,
                                   ','.join(map(str, index))) if index else key
                series = TimeSeries(name, interval, scale, offset, window,
                                    self, meta[0].get(key), meta[1].get(key))
                self.series[key, index] = series
                if history:
                    series.init_from_history(history, fromtime, totime
                                             or currenttime(), index)
                else:
                    series.init_empty()
            self._key_indices.setdefault(key, []).extend(real_indices)

        self.listitem = None
        self.plot = None
        if self.totime is None:
            # add another point with the same value every interval time (but
            # not more often than 11 seconds)
            self.timer = QTimer(self, interval=max(interval, 11) * 1000)
            self.timer.timeout.connect(self.on_timer_timeout)
            self.timer.start()

        self.timeSeriesUpdate.connect(self.on_timeSeriesUpdate)