diff --git a/ddresc_visu/draw.py b/ddresc_visu/draw.py index f29914d..e664dea 100644 --- a/ddresc_visu/draw.py +++ b/ddresc_visu/draw.py @@ -68,3 +68,15 @@ class Visualisation: def reload(self): self.mapfile.load() self.draw() + + def run(self, *, refresh=2): + pygame.time.set_timer(pygame.USEREVENT, refresh * 1000) + self.draw() + while True: + ev = pygame.event.wait() + if ev.type == pygame.QUIT or ev.type == pygame.KEYDOWN and ev.key == pygame.K_q: + return + if ev.type in [pygame.VIDEOEXPOSE, pygame.VIDEORESIZE, pygame.USEREVENT]: + self.draw() + + diff --git a/ddresc_visu/mapfile.py b/ddresc_visu/mapfile.py index e940384..e82efa5 100644 --- a/ddresc_visu/mapfile.py +++ b/ddresc_visu/mapfile.py @@ -31,17 +31,16 @@ def read_mapfile(fn): class MapFile: def __init__(self, filename, start=None, end=None): self.mapfilename = filename - self.start = start + self.start = start if start is not None else 0 self.end = end def load(self): self.status, self.blocks, self.comments = read_mapfile(self.mapfilename) - if self.start is not None or self.end is not None: + if self.end is not None: # FIXME: what about only start being set? self.filter_data() self.size = max(map(lambda blk: blk[0]+blk[1], self.blocks)) def filter_data(self): - assert self.start is not None and self.end is not None self.blocks = self.filter_blocks(self.blocks, self.start, self.end) self.blocks = self.trim_blocks(self.blocks, self.start, self.end)