From f80228681aea75738ab5e149fec187ba8fcb2588 Mon Sep 17 00:00:00 2001 From: Pavel 'LEdoian' Turinsky Date: Fri, 20 Aug 2021 04:26:26 +0200 Subject: [PATCH] Make UI responsive :-) --- ddresc_visu/draw.py | 64 ++++++++++++++++++++++++++++++++------------- ddwatch.sh | 5 +++- test.py | 2 +- 3 files changed, 51 insertions(+), 20 deletions(-) diff --git a/ddresc_visu/draw.py b/ddresc_visu/draw.py index d2d33b2..09618fa 100644 --- a/ddresc_visu/draw.py +++ b/ddresc_visu/draw.py @@ -7,7 +7,7 @@ colors = { '*' : (0 , 0 , 255), # Non-trimmed '/' : (255, 255, 0) , # Non-scraped '-' : (255, 0 , 0) , # Bad - '+' : (0 , 128, 0) , # Recovered + '+' : (0 , 0 , 0) , # Recovered '@' : (0 , 255, 255), # Own position None: (0 , 0 , 0) , # Not on disk } @@ -26,17 +26,6 @@ COLUMNS = W // CELLOFFSET ROWS = H // CELLOFFSET CELLS = COLUMNS * ROWS -def get_symb(hist): - ## Majority: - #symb, _count = max(hist.items(), key=lambda x: x[1]) - #return symb - - # The worst: - order = ['@', '-', '/', '*', '?', '+'] - for ch in order: - if ch in hist: - return ch - class Visualisation: def __init__(self, fn, **kwargs): pygame.init() @@ -46,17 +35,28 @@ class Visualisation: self.mapfile = MapFile(fn, **kwargs) self.mapfile.load() + self.histograms = None self.squares = None - - def gen_squares(self): - self.squares = [] + + # Order of colors to show... + self.order = ['@', '-', '/', '*', '?', '+'] + + def gen_histograms(self): + self.histograms = [] sz = self.mapfile.size sqsz = max(sz / CELLS, 4096) for cid in range(CELLS): start = cid * sqsz end = (cid + 1) * sqsz hist = self.mapfile.get_hist(start, end) - symb = get_symb(hist) + self.histograms.append(hist) + + + def gen_squares(self): + if self.histograms is None: self.gen_histograms() + self.squares = [] + for hist in self.histograms: + symb = self.get_symb(hist) color = colors[symb] self.squares.append(color) @@ -67,6 +67,8 @@ class Visualisation: line = cell // COLUMNS col = cell % COLUMNS pos = (line, col) +# DARKEN = 0.7 +# if line % 2 == 0: color = (color[0] * DARKEN, color[1] * DARKEN, color[2] * DARKEN) rect = pygame.Rect(col * CELLOFFSET + CELLBORDER, line * CELLOFFSET + CELLBORDER, CELLSIZE+2*CELLBORDER, CELLSIZE+2*CELLBORDER) pygame.draw.rect(self.disp, color, rect) @@ -78,9 +80,19 @@ class Visualisation: self.mapfile.load() self.squares = None self.draw() + + def get_symb(self, hist): + ## Majority: + #symb, _count = max(hist.items(), key=lambda x: x[1]) + #return symb + + for ch in self.order: + if ch in hist: + return ch + - def run(self, *, refresh=2): -# pygame.time.set_timer(pygame.USEREVENT, refresh * 1000) + def run(self, *, refresh=1800): + pygame.time.set_timer(pygame.USEREVENT, refresh * 1000) pygame.event.set_blocked(None) # pygame.event.set_allowed([pygame.USEREVENT, pygame.VIDEORESIZE, pygame.VIDEOEXPOSE, pygame.QUIT, pygame.KEYDOWN]) pygame.event.set_allowed([pygame.VIDEORESIZE, pygame.VIDEOEXPOSE, pygame.QUIT, pygame.KEYDOWN]) @@ -93,5 +105,21 @@ class Visualisation: self.draw() if ev.type == pygame.KEYDOWN and ev.key == pygame.K_r: self.reload() + if ev.type == pygame.KEYDOWN and ev.key == pygame.K_a: + self.order = ['@', '-', '/', '*', '?', '+'] + self.squares = None + self.draw() + if ev.type == pygame.KEYDOWN and ev.key == pygame.K_m: + self.order = ['@', '?', '-', '/', '*', '+'] + self.squares = None + self.draw() + if ev.type == pygame.KEYDOWN and ev.key == pygame.K_g: + colors['+'] = (0, 128, 0) + self.squares = None + self.draw() + if ev.type == pygame.KEYDOWN and ev.key == pygame.K_b: + colors['+'] = (0, 0, 0) + self.squares = None + self.draw() diff --git a/ddwatch.sh b/ddwatch.sh index 9e438e6..0edd0c3 100755 --- a/ddwatch.sh +++ b/ddwatch.sh @@ -10,6 +10,9 @@ last="$(grep "$str" "$file")" while sleep $interval do cur="$(grep "$str" "$file")" - test "$cur" != "$last" && mpv "$ding" + test "$cur" != "$last" && { + mpv "$ding" + date + } last="$cur" done diff --git a/test.py b/test.py index 3b99369..c45a964 100755 --- a/test.py +++ b/test.py @@ -30,4 +30,4 @@ args = ap.parse_args() visu = v.Visualisation(args.file, start=args.start, end=args.end) -visu.run(refresh=35) +visu.run(refresh=1800)