changeset 33:e0dc3d213c9a

Client: vastly improve stock widget allocation algorithm
author Lewin Bormann <lbo@spheniscida.de>
date Sun, 10 Mar 2019 14:50:45 +0100
parents d7ab662b4d8a
children 6696a7342e35
files client/client.py
diffstat 1 files changed, 11 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/client/client.py	Sun Mar 10 14:43:23 2019 +0100
+++ b/client/client.py	Sun Mar 10 14:50:45 2019 +0100
@@ -553,14 +553,17 @@
     group_table = None
 
     def add_stock_widget(self, sw):
-        if len(self.stockrows) == 0 or self.stockrows[-1].count() >= self.widgets_per_hbox:
-            hbox = wid.QHBoxLayout()
-            hbox.addWidget(sw)
-            self.stockrows.append(hbox)
-            self.stocksvbox.addLayout(hbox)
+        dst_hbox = None
+        if len(self.stockrows) == 0 or not any([r.count() < self.widgets_per_hbox for r in self.stockrows]):
+            dst_hbox = wid.QHBoxLayout()
+            self.stockrows.append(dst_hbox)
+            self.stocksvbox.addLayout(dst_hbox)
         else:
-            self.stockrows[-1].addWidget(sw)
-        return
+            for hb in self.stockrows:
+                if hb.count() < self.widgets_per_hbox:
+                    dst_hbox = hb
+        assert dst_hbox is not None
+        dst_hbox.addWidget(sw)
 
     def start_wait_window(self):
         self.mainhbox = wid.QHBoxLayout(self)
@@ -592,6 +595,7 @@
         """React to new stock data from the server."""
         self.waiting.hide()
         self.depot.update(stockdata)
+
         for sym, upd in sorted(stockdata.items()):
             if sym != '_stockdata' and sym not in self.stock_widgets:
                 depotstock = DepotStock(sym)