From 692c95f3fc673e039e56ab1f4ae538964031db89 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Mon, 25 Feb 2013 13:08:35 +0000 Subject: Control Panel: handle switching between landscape and portrait mode, SL #4444 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 removes the section icons and sets it up again to recompute the number of columns and to resize the window and it's containing table. Signed-off-by: Walter Bender Signed-off-by: Manuel QuiƱones Acked-by: Simon Schampijer --- diff --git a/src/jarabe/controlpanel/gui.py b/src/jarabe/controlpanel/gui.py index f28b248..c61fb4e 100644 --- a/src/jarabe/controlpanel/gui.py +++ b/src/jarabe/controlpanel/gui.py @@ -42,14 +42,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) @@ -88,15 +82,31 @@ 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'): + for child in self._table.get_children(): + child.destroy() + self._setup_options() + def _set_canvas(self, canvas): if self._canvas: self._main_view.remove(self._canvas) -- cgit v0.9.1