Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWalter Bender <walter.bender@gmail.com>2013-02-25 13:08:35 (GMT)
committer Ajay Garg <ajay@activitycentral.com>2013-02-26 05:25:56 (GMT)
commitaf580ced171c3b8badf178091286fdf22bbd549a (patch)
tree284330042595dd3522ccde99ea332d7935a11ebf
parentb9e587bdd527557de1ed724eb7d54e17f2c44ac3 (diff)
account for size-change when rotating between landscape and portrait modes
When the control panel is opened for the first time, a table is generated with a number of columns based on screen width. If the screen is subsequently rotated, the column number is no longer correct. In addition, the scrolled window holding the table needs to be resized so that it fits on the screen. This patch adds a size-changed callback that recomputes the number of columns and resizes the table and its containing window.
-rw-r--r--src/jarabe/controlpanel/gui.py24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/jarabe/controlpanel/gui.py b/src/jarabe/controlpanel/gui.py
index 6b0f240..0a53a60 100644
--- a/src/jarabe/controlpanel/gui.py
+++ b/src/jarabe/controlpanel/gui.py
@@ -16,6 +16,7 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import os
+from math import ceil
import logging
from gettext import gettext as _
@@ -43,14 +44,8 @@ class ControlPanel(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self)
- self._max_columns = int(0.285 * (float(Gdk.Screen.width()) /
- style.GRID_CELL_SIZE - 3))
-
+ self._calculate_max_columns()
self.set_border_width(style.LINE_WIDTH)
- offset = style.GRID_CELL_SIZE
- width = Gdk.Screen.width() - offset * 2
- height = Gdk.Screen.height() - offset * 2
- self.set_size_request(width, height)
self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
self.set_decorated(False)
self.set_resizable(False)
@@ -89,15 +84,30 @@ class ControlPanel(Gtk.Window):
self._setup_main()
self._setup_section()
self._show_main_view()
+ Gdk.Screen.get_default().connect('size-changed', self.__size_changed_cb)
def __realize_cb(self, widget):
self.set_type_hint(Gdk.WindowTypeHint.DIALOG)
self.get_window().set_accept_focus(True)
+ def __size_changed_cb(self, event):
+ self._calculate_max_columns()
+
def grab_focus(self):
# overwrite grab focus in order to grab focus on the view
self._main_view.get_child().grab_focus()
+ def _calculate_max_columns(self):
+ self._max_columns = int(0.285 * (float(Gdk.Screen.width()) /
+ style.GRID_CELL_SIZE - 3))
+ offset = style.GRID_CELL_SIZE
+ width = Gdk.Screen.width() - offset * 2
+ height = Gdk.Screen.height() - offset * 2
+ self.set_size_request(width, height)
+ if hasattr(self, '_table'):
+ rows = int(ceil(len(self._options.keys()) / self._max_columns))
+ self._table.resize(rows, self._max_columns)
+
def _set_canvas(self, canvas):
if self._canvas:
self._main_view.remove(self._canvas)