From 9d8196e93a85a2f6fc9c28e86f69cebb02aa6b9c Mon Sep 17 00:00:00 2001
From: Srikanth Ravipati <rsri131@gmail.com>
Date: Tue, 16 Mar 2021 16:47:12 +0000
Subject: [PATCH] Made use of height-fractions for the widgets in a column

and a few other changes
---
 .../workbench/workbench/app/mainwindow.py     | 29 +++++++++++++++----
 .../workbench/workbench/plugins/memoryinfo.py |  9 +++---
 .../workbench/plugins/test/test_memoryinfo.py |  2 +-
 3 files changed, 29 insertions(+), 11 deletions(-)

diff --git a/qt/applications/workbench/workbench/app/mainwindow.py b/qt/applications/workbench/workbench/app/mainwindow.py
index 29faf569841..1a8e7016e82 100644
--- a/qt/applications/workbench/workbench/app/mainwindow.py
+++ b/qt/applications/workbench/workbench/app/mainwindow.py
@@ -476,6 +476,13 @@ class MainWindow(QMainWindow):
         editor = self.editor
         algorithm_selector = self.algorithm_selector
         plot_selector = self.plot_selector
+
+        # If more than two rows are needed in a column,
+        # arrange_layout function needs to be revisited for
+        # the hegiht_fractions to be applied correctly.
+        # In the first column, there are three widgets in two rows
+        # as the algorithm_selector and plot_selector are tabified.
+        # Currently, the arrange_layout function does not use width-fraction.
         default_layout = {
             'widgets': [
                 # column 0
@@ -485,11 +492,11 @@ class MainWindow(QMainWindow):
                 # column 2
                 [[memorywidget], [logmessages]]
             ],
-            'width-fraction': [
-                0.25,  # column 0 width
-                0.50,  # column 1 width
-                0.25
-            ],  # column 2 width
+            # 'width-fraction': [
+            #     0.25,  # column 0 width
+            #     0.50,  # column 1 width
+            #     0.25
+            # ],  # column 2 width
             'height-fraction': [
                 [0.5, 0.5],  # column 0 row heights
                 [1.0],  # column 1 row heights
@@ -505,6 +512,7 @@ class MainWindow(QMainWindow):
         """Arrange the layout of the child widgets according to the supplied layout"""
         self.prep_window_for_reset()
         widgets_layout = layout['widgets']
+        widgets_height_fractions = layout['height-fraction']
         with widget_updates_disabled(self):
             # flatten list
             widgets = [item for column in widgets_layout for row in column for item in row]
@@ -516,11 +524,22 @@ class MainWindow(QMainWindow):
                 first, second = widgets[i], widgets[i + 1]
                 self.splitDockWidget(first.dockwidget, second.dockwidget, Qt.Horizontal)
             # now arrange the rows
+
+            idx_column = -1
             for column in widgets_layout:
+                idx_column += 1
+                height_fractions = widgets_height_fractions[idx_column]
                 for i in range(len(column) - 1):
                     first_row, second_row = column[i], column[i + 1]
+                    height_fraction_first_row, height_fraction_second_row = height_fractions[i], \
+                        height_fractions[i+1]
                     self.splitDockWidget(first_row[0].dockwidget, second_row[0].dockwidget,
                                          Qt.Vertical)
+                    height = first_row[0].dockwidget.rect().height()
+                    self.resizeDocks((first_row[0].dockwidget, second_row[0].dockwidget), \
+                        (height_fraction_first_row*height, height_fraction_second_row*height), \
+                        Qt.Vertical)
+
             # and finally tabify those in the same position
             for column in widgets_layout:
                 for row in column:
diff --git a/qt/applications/workbench/workbench/plugins/memoryinfo.py b/qt/applications/workbench/workbench/plugins/memoryinfo.py
index 719c0d635f4..e1a331547b3 100644
--- a/qt/applications/workbench/workbench/plugins/memoryinfo.py
+++ b/qt/applications/workbench/workbench/plugins/memoryinfo.py
@@ -11,10 +11,9 @@ from psutil import virtual_memory
 
 def getMemoryUsed():
     mem_used  = virtual_memory().used
-    mem_avail = virtual_memory().available
-    mem_used_percent = min(int(round(mem_used * 100 / mem_avail)),100)
+    mem_total = virtual_memory().total
+    mem_used_percent = min(int(round(mem_used * 100 / mem_total)),100)
     conversion_factor_to_GB = 1.0 / 1024 / 1024 / 1024
     mem_used_GB = mem_used * conversion_factor_to_GB
-    mem_avail_GB = mem_avail * conversion_factor_to_GB
-    return mem_used_percent, mem_used_GB, mem_avail_GB
-
+    mem_total_GB = mem_total * conversion_factor_to_GB
+    return mem_used_percent, mem_used_GB, mem_total_GB
diff --git a/qt/applications/workbench/workbench/plugins/test/test_memoryinfo.py b/qt/applications/workbench/workbench/plugins/test/test_memoryinfo.py
index 8ad2446e5b1..2a2abfab949 100644
--- a/qt/applications/workbench/workbench/plugins/test/test_memoryinfo.py
+++ b/qt/applications/workbench/workbench/plugins/test/test_memoryinfo.py
@@ -13,7 +13,7 @@ from workbench.plugins.memoryinfo import getMemoryUsed
 class MemoryInfoTest(unittest.TestCase):
 
     def test_MemoryInfo(self):
-        mem_used_percent, mem_used, mem_avail = getMemoryUsed()
+        mem_used_percent, mem_used, mem_total = getMemoryUsed()
         self.assertTrue(isinstance(mem_used_percent, int))
         self.assertTrue(0 <= mem_used_percent <= 100)
 
-- 
GitLab