From af580ced171c3b8badf178091286fdf22bbd549a Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Mon, 25 Feb 2013 13:08:35 +0000 Subject: 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. --- 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) -- cgit v0.9.1