def start(self): self.cycleTimer.stop() path = self.config.get("db", "path", fallback=None) if not path: return paths = [os.path.join(path, entry) for entry in os.listdir(path)] paths = [path for path in paths if \ (path.endswith('.dme') or \ path.endswith('.xml') or \ path.endswith('.json')) and \ os.path.isfile(path)] paths = sorted(paths, reverse=True) self.alarms = [] index = 0 while index < self.historySize and len(paths) > 0: path = paths[0] paths = paths[1:] alarm = Alarm(self.config) try: alarm.load(path) except Exception as e: self.logger.error('History failed to load %s: %s', path, e) continue if alarm.fallbackStr: # ignore incomplete or invalid alarms in history continue if len(self.alarms) and self.alarms[-1].matches(alarm): self.alarms[-1].merge(alarm) else: self.alarms.append(alarm) index += 1 local_tz = get_localzone() now = local_tz.localize(datetime.datetime.now()) index = 0 for alarm in self.alarms: dateStr = alarm.datetime.strftime('%A, %d. %B, %H:%M') delta = alarm.datetime - now dateStr += ' (' + babel.dates.format_timedelta( delta, add_direction=True) + ')' image = alarm.imageBase() if image: image += '.svg' pixmap = pixmapFromSvg(os.path.join(self.imageDir, image), 40) else: pixmap = QPixmap() self.symbolLabels[index].setPixmap(pixmap) title = alarm.title() if not title: title = alarm.fallbackStr self.titleLabels[index].setText(title) desc = dateStr loc = alarm.location() if loc: desc += '\n' + loc self.descLabels[index].setText(desc) index += 1 self.index = 0 if len(self.alarms): alarm = self.alarms[self.index] self.targetMap.setTarget(alarm.lat, alarm.lon, ([], )) self.cycleTimer.start() self.updateStyles() else: self.finished.emit()