Make UI responsive :-)

master
LEdoian 3 years ago
parent 2a1fbf0bdc
commit f80228681a

@ -7,7 +7,7 @@ colors = {
'*' : (0 , 0 , 255), # Non-trimmed '*' : (0 , 0 , 255), # Non-trimmed
'/' : (255, 255, 0) , # Non-scraped '/' : (255, 255, 0) , # Non-scraped
'-' : (255, 0 , 0) , # Bad '-' : (255, 0 , 0) , # Bad
'+' : (0 , 128, 0) , # Recovered '+' : (0 , 0 , 0) , # Recovered
'@' : (0 , 255, 255), # Own position '@' : (0 , 255, 255), # Own position
None: (0 , 0 , 0) , # Not on disk None: (0 , 0 , 0) , # Not on disk
} }
@ -26,17 +26,6 @@ COLUMNS = W // CELLOFFSET
ROWS = H // CELLOFFSET ROWS = H // CELLOFFSET
CELLS = COLUMNS * ROWS 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: class Visualisation:
def __init__(self, fn, **kwargs): def __init__(self, fn, **kwargs):
pygame.init() pygame.init()
@ -46,17 +35,28 @@ class Visualisation:
self.mapfile = MapFile(fn, **kwargs) self.mapfile = MapFile(fn, **kwargs)
self.mapfile.load() self.mapfile.load()
self.histograms = None
self.squares = None self.squares = None
def gen_squares(self): # Order of colors to show...
self.squares = [] self.order = ['@', '-', '/', '*', '?', '+']
def gen_histograms(self):
self.histograms = []
sz = self.mapfile.size sz = self.mapfile.size
sqsz = max(sz / CELLS, 4096) sqsz = max(sz / CELLS, 4096)
for cid in range(CELLS): for cid in range(CELLS):
start = cid * sqsz start = cid * sqsz
end = (cid + 1) * sqsz end = (cid + 1) * sqsz
hist = self.mapfile.get_hist(start, end) 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] color = colors[symb]
self.squares.append(color) self.squares.append(color)
@ -67,6 +67,8 @@ class Visualisation:
line = cell // COLUMNS line = cell // COLUMNS
col = cell % COLUMNS col = cell % COLUMNS
pos = (line, col) 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) rect = pygame.Rect(col * CELLOFFSET + CELLBORDER, line * CELLOFFSET + CELLBORDER, CELLSIZE+2*CELLBORDER, CELLSIZE+2*CELLBORDER)
pygame.draw.rect(self.disp, color, rect) pygame.draw.rect(self.disp, color, rect)
@ -78,9 +80,19 @@ class Visualisation:
self.mapfile.load() self.mapfile.load()
self.squares = None self.squares = None
self.draw() 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): def run(self, *, refresh=1800):
# pygame.time.set_timer(pygame.USEREVENT, refresh * 1000) pygame.time.set_timer(pygame.USEREVENT, refresh * 1000)
pygame.event.set_blocked(None) pygame.event.set_blocked(None)
# pygame.event.set_allowed([pygame.USEREVENT, pygame.VIDEORESIZE, pygame.VIDEOEXPOSE, pygame.QUIT, pygame.KEYDOWN]) # 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]) pygame.event.set_allowed([pygame.VIDEORESIZE, pygame.VIDEOEXPOSE, pygame.QUIT, pygame.KEYDOWN])
@ -93,5 +105,21 @@ class Visualisation:
self.draw() self.draw()
if ev.type == pygame.KEYDOWN and ev.key == pygame.K_r: if ev.type == pygame.KEYDOWN and ev.key == pygame.K_r:
self.reload() 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()

@ -10,6 +10,9 @@ last="$(grep "$str" "$file")"
while sleep $interval while sleep $interval
do do
cur="$(grep "$str" "$file")" cur="$(grep "$str" "$file")"
test "$cur" != "$last" && mpv "$ding" test "$cur" != "$last" && {
mpv "$ding"
date
}
last="$cur" last="$cur"
done done

@ -30,4 +30,4 @@ args = ap.parse_args()
visu = v.Visualisation(args.file, start=args.start, end=args.end) visu = v.Visualisation(args.file, start=args.start, end=args.end)
visu.run(refresh=35) visu.run(refresh=1800)

Loading…
Cancel
Save