Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoranishmangal2002 <anishmangal2002@gmail.com>2011-01-21 20:03:45 (GMT)
committer Sascha Silbe <sascha-pgp@silbe.org>2011-02-05 15:25:17 (GMT)
commitecae03a35a505c4212271e415e618a1c5d271b3e (patch)
tree7608814c644c82d5958b18003b8475550eaea5ce
parenteb51cca5e84818a98c3ca258918824530c194791 (diff)
Dynamically set number of control panel columns (SL#2280)
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@gmail.com> [style fixup; added comments] Signed-off-by: Sascha Silbe <silbe@activitycentral.com> Reviewed-by: Sascha Silbe <silbe@activitycentral.com> Reviewed-by: Aleksey Lim <alsroot@member.fsf.org>
-rw-r--r--src/jarabe/controlpanel/gui.py20
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