[Sugar-devel] [PATCH] Dynamically set number of control panel columns

anishmangal2002 at gmail.com anishmangal2002 at gmail.com
Sun Jun 20 13:27:46 EDT 2010


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>
---
 src/jarabe/controlpanel/gui.py |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/jarabe/controlpanel/gui.py b/src/jarabe/controlpanel/gui.py
index 51d9820..4a54310 100644
--- a/src/jarabe/controlpanel/gui.py
+++ b/src/jarabe/controlpanel/gui.py
@@ -33,7 +33,6 @@ from jarabe.controlpanel.toolbar import SectionToolbar
 from jarabe import config
 
 _logger = logging.getLogger('ControlPanel')
-_MAX_COLUMNS = 5
 
 class ControlPanel(gtk.Window):
     __gtype_name__ = 'SugarControlPanel'
@@ -41,6 +40,9 @@ class ControlPanel(gtk.Window):
     def __init__(self):
         gtk.Window.__init__(self)
 
+        self._MAX_COLUMNS = int( 0.285 * ( ( gtk.gdk.screen_width() /
+            style.GRID_CELL_SIZE ) - 3.0 ) )
+
         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,15 @@ 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:
+            row = 0
+            column = 2
+
         options = self._options.keys()
         options.sort()
 
@@ -157,7 +167,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.0.1



More information about the Sugar-devel mailing list