[Sugar-devel] [PATCH sugar] Dynamically set number of control panel columns (SL#2280)

Sascha Silbe sascha-pgp at silbe.org
Fri Jan 21 10:03:45 EST 2011


From: anishmangal2002 <anishmangal2002 at gmail.com>

This patch sets the number of icon-columns in the control
panel based on the screen resolution. This patch also sets
the table row spacing to GRID_CELL_SIZE.

How the number of columns are calculated:
Let 'W' be the screen width, 's' be the GRID_CELL_SIZE and
'n' be the number of icon columns that can be comfortably
accomodated. Further, lets assume that the width an icon
and its text-label occupies a horizontal space equivalent to
(2.5 * s). We may represent 'W', 'n' and 's' by the following
expression:

     W - (2 * s) =  (n * s + s) + (2.5 * n * s)

where 'W - (2 * s)' is the width of the control panel menu,
'(n * s + s)' is the cumulative column spacing of 'n' icons,
and '(2.5 * n * s)' is the width occupied by 'n' icons and
their text-labels. From the above, 'n' may be computed as

     n = (1/3.5) * ( W/s - 3 )

Signed-off-by: anishmangal2002 <anishmangal2002 at gmail.com>
[style fixup; added comments]
Signed-off-by: Sascha Silbe <sascha-pgp at silbe.org>
Reviewed-by: Sascha Silbe <sascha-pgp at silbe.org>
---

I couldn't quite reproduce Michaels results. At scaling 72 (default on
most systems) there are four rows at 1024x768. At 100 (default on most
XO builds), the cut-over point between two and three rows is at
1014/1015x768. While it looks odd to have so much space at 1014x768,
you can see at 1015x768 that it fits exactly - so if we wanted to use
more columns below 1015x768, we'd have to reduce the spacing. That is
out of scope for this patch, however.

The fix for wrapping the labels is needed both with and without this
patch; it only changes the text length that triggers the bug.

 src/jarabe/controlpanel/gui.py |   20 ++++++++++++++++----
 1 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/jarabe/controlpanel/gui.py b/src/jarabe/controlpanel/gui.py
index 9ce8cfd..91792c9 100644
--- a/src/jarabe/controlpanel/gui.py
+++ b/src/jarabe/controlpanel/gui.py
@@ -32,7 +32,6 @@ from jarabe import config
 
 
 _logger = logging.getLogger('ControlPanel')
-_MAX_COLUMNS = 5
 
 
 class ControlPanel(gtk.Window):
@@ -41,6 +40,9 @@ class ControlPanel(gtk.Window):
     def __init__(self):
         gtk.Window.__init__(self)
 
+        self._max_columns = int(0.285 * (float(gtk.gdk.screen_width()) /
+            style.GRID_CELL_SIZE - 3))
+
         self.set_border_width(style.LINE_WIDTH)
         offset = style.GRID_CELL_SIZE
         width = gtk.gdk.screen_width() - offset * 2
@@ -110,6 +112,7 @@ class ControlPanel(gtk.Window):
 
         self._table = gtk.Table()
         self._table.set_col_spacings(style.GRID_CELL_SIZE)
+        self._table.set_row_spacings(style.GRID_CELL_SIZE)
         self._table.set_border_width(style.GRID_CELL_SIZE)
 
         self._scrolledwindow = gtk.ScrolledWindow()
@@ -134,8 +137,17 @@ class ControlPanel(gtk.Window):
         except ImportError:
             del self._options['keyboard']
 
-        row = 0
-        column = 2
+        # If the screen width only supports two columns, start
+        # placing from the second row.
+        if self._max_columns == 2:
+            row = 1
+            column = 0
+        else:
+            # About Me and About my computer are hardcoded below to use the
+            # first two slots so we need to leave them free.
+            row = 0
+            column = 2
+
         options = self._options.keys()
         options.sort()
 
@@ -157,7 +169,7 @@ class ControlPanel(gtk.Window):
                                    column, column + 1,
                                    row, row + 1)
                 column += 1
-                if column == _MAX_COLUMNS:
+                if column == self._max_columns:
                     column = 0
                     row += 1
 
-- 
1.7.2.3



More information about the Sugar-devel mailing list