Skip to content

Commit

Permalink
feat: add locking and extended layout handling to handle view size ch…
Browse files Browse the repository at this point in the history
…anges

- works only mildly better but ... oh, well
  • Loading branch information
atennert committed Nov 15, 2020
1 parent a8eb591 commit 6b3caa5
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/lcarsde-status-bar.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env python3
from threading import Thread
from threading import Thread, Lock
from time import sleep
import importlib
import numpy as np
from lcarsde import internal_widgets as iw
import xml.etree.ElementTree as ET
import os.path
import sys

import gi
gi.require_version("Gtk", "3.0")
Expand Down Expand Up @@ -172,6 +173,7 @@ def __init__(self):
self.stop_threads = False
self.update_thread = Thread(target=self.update_widgets, args=(lambda: self.stop_threads, self))
self.update_thread.daemon = True
self.lock = Lock()

self.connect("size-allocate", self.on_size_allocate)
self.connect("realize", self.on_create)
Expand Down Expand Up @@ -211,8 +213,9 @@ def on_size_allocate(self, window, event):
"""
new_width = self.get_allocation().width
if new_width != self.width:
self.width = new_width
self.update_layout()
with self.lock:
self.width = new_width
self.update_layout()

def import_widgets(self):
"""
Expand Down Expand Up @@ -247,6 +250,15 @@ def update_layout(self):
"""
horizontal_cells, left_over_pixels = self.get_cells_and_overflow()
self.cleanup_grid()
self.remove(self.grid)
self.set_size_request(self.width, self.height)

self.grid = Gtk.Grid()
self.grid.set_column_spacing(GAP_SIZE)
self.grid.set_row_spacing(GAP_SIZE)
self.grid.get_style_context().add_provider(self.css_provider, Gtk.STYLE_PROVIDER_PRIORITY_USER)
self.add(self.grid)

self.fill_status_bar(horizontal_cells, left_over_pixels)

def get_cells_and_overflow(self):
Expand Down Expand Up @@ -280,7 +292,10 @@ def fill_status_bar(self, horizontal_cells, left_over_pixels):

self.fill_empty_space(widget_map, left_over_pixels)

self.grid.queue_draw()
self.grid.show_all()
self.queue_draw()
self.show_all()

def fill_configured_widgets(self, horizontal_cells):
"""
Expand Down Expand Up @@ -373,8 +388,12 @@ def update_widgets(stop, self):
Trigger a widget update (called in daemon thread).
"""
while True:
for widget in self.widget_dict:
GLib.idle_add(widget.update)
try:
with self.lock:
for widget in self.widget_dict:
GLib.idle_add(widget.update)
except Exception:
print(sys.exc_info()[0])

if stop():
break
Expand Down

0 comments on commit 6b3caa5

Please sign in to comment.