def handle_eta(self, data): """Handles the "eta" signal.""" state, eta = data if state in (SIM_STATES['pending'], SIM_STATES['running']): self.cur_eta = '<calculation in progress>' elif state == SIM_STATES['failed']: self.cur_eta = '<calculation failed>' elif state == SIM_STATES['success'] and eta > currenttime(): self.cur_eta = formatEndtime(eta - currenttime())
def on_client_eta(self, data): if not self.showETA or self._status not in self.SHOW_ETA_STATES: return state, eta = data if state == SIM_STATES['pending']: self.etaWidget.hide() elif state == SIM_STATES['running']: self.etaLabel.setText('Calculating...') self.etaWidget.show() elif state == SIM_STATES['success'] and eta > time(): self.etaLabel.setText(formatEndtime(eta - time())) self.etaWidget.show() elif state == SIM_STATES['failed']: self.etaLabel.setText('Could not calculate ETA') self.etaWidget.show()
def on_client_simresult(self, data): timing, devinfo, uuid = data if uuid != self.simuuid: return self.simuuid = None # show timing if timing < 0: self.simTotalTime.setText('Error occurred') self.simFinished.setText('See messages') else: self.simTotalTime.setText(formatDuration(timing, precise=False)) self.simFinished.setText(formatEndtime(timing)) # device ranges for devname, (_dval, dmin, dmax, aliases) in devinfo.items(): if dmin is not None: aliascol = 'aliases: ' + ', '.join(aliases) if aliases else '' item = QTreeWidgetItem([devname, dmin, '-', dmax, '', aliascol]) self.simRanges.addTopLevelItem(item) self.simRanges.sortByColumn(0, Qt.AscendingOrder)
def signal(self, name, data=None, exc=None): """Handles any kind of signal/event sent by the daemon.""" try: # try to order the elifs by frequency if name == 'message': if self.in_editing: self.message_queue.append(data) else: self.put_message(data) elif name == 'status': status, line = data if status == STATUS_IDLE or status == STATUS_IDLEEXC: new_status = 'idle' self.stop_pending = False elif status != STATUS_INBREAK: new_status = 'running' else: new_status = 'paused' if status != self.status: self.set_status(new_status) if line != self.current_line: self.current_line = line elif name == 'cache': if data[1].endswith('/scriptpath'): self.scriptpath = self.eval( 'session.experiment.scriptpath', '.') elif name == 'processing': script = data.get('script') if script is None: return self.current_filename = data.get('name') or '' script = script.splitlines() or [''] if script != self.current_script: self.current_script = script self.pending_requests.pop(data['reqid'], None) self.set_status(self.status) elif name == 'request': if 'script' in data: self.pending_requests[data['reqid']] = data self.set_status(self.status) elif name == 'blocked': removed = [ _f for _f in (self.pending_requests.pop(reqid, None) for reqid in data) if _f ] if removed: self.put_client('%d script(s) or command(s) removed from ' 'queue.' % len(removed)) self.show_pending() self.set_status(self.status) elif name == 'updated': if 'script' in data: self.pending_requests[data['reqid']] = data elif name == 'rearranged': old_reqs = self.pending_requests.copy() self.pending_requests.clear() for reqid in data: self.pending_requests[reqid] = old_reqs[reqid] elif name == 'connected': self.reconnect_count = 0 self.initial_update() elif name == 'disconnected': self.put_client('Disconnected from server, use /reconnect to ' 'try reconnecting.') self.current_mode = MASTER self.debug_mode = False self.pending_requests.clear() self.set_status('disconnected') elif name == 'showhelp': self.showhelp(data[1]) elif name == 'simmessage': if data[5] in [self.simuuid, '0']: if not self.in_editing: self.put_message(data, sim=True) elif name == 'simresult': if data and data[2] in [self.simuuid, '0']: timing, devinfo, _ = data if timing < 0: self.put_client('Dry run resulted in an error.') return self.put_client( 'Simulated minimum runtime: %s ' '(finishes approximately %s). Device ranges:' % (formatDuration(timing, precise=False), formatEndtime(timing))) if devinfo: dnwidth = max(map(len, devinfo)) sorteditems = sorted(devinfo.items(), key=lambda x: x[0].lower()) for devname, (_, dmin, dmax, aliases) in sorteditems: aliascol = 'aliases: ' + ', '.join( aliases) if aliases else '' self.put('# %-*s: %10s <-> %-10s %s' % (dnwidth, devname, dmin, dmax, aliascol)) elif name == 'mode': self.current_mode = data self.set_status(self.status) elif name == 'setup': self.scriptpath = self.eval('session.experiment.scriptpath', '.') self.instrument = self.eval('session.instrument.instrument', self.instrument) elif name == 'debugging': self.debug_mode = data readline_finish_callback(False) elif name == 'plugplay': if data[0] == 'added': self.put_client('new sample environment detected: load ' 'setup %r to activate' % data[1]) elif data[0] == 'removed': self.put_client('sample environment removed: unload ' 'setup %r to clear devices' % data[1]) elif name == 'eta': self.handle_eta(data) elif name == 'broken': self.put_error(data) self.reconnect_count = self.RECONNECT_TRIES self.reconnect_time = self.RECONNECT_INTERVAL_SHORT self.schedule_reconnect() elif name == 'failed': if self.reconnect_count: self.schedule_reconnect() else: self.put_error(data) elif name == 'error': self.put_error(data) # and we ignore all other signals except Exception as e: self.put_error('In %s event handler: %s.' % (name, e))