From c7eeeaa2d89079e158fbe273fa4baac87c5a6b8a Mon Sep 17 00:00:00 2001
From: Walter Bender <walter.bender@gmail.com>
Date: Mon, 25 Feb 2013 08:08:35 -0500
Subject: [PATCH 1/1] account for size-change when rotating between landscape
and portrait modes - 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 setups it again to recompute the number of columns and to resize the table and its containing window.
---
src/jarabe/controlpanel/gui.py | 25 ++++++++++++++++++-------
1 file changed, 18 insertions(+), 7 deletions(-)
diff --git a/src/jarabe/controlpanel/gui.py b/src/jarabe/controlpanel/gui.py
index f28b248..be75e54 100644
a
|
b
|
|
15 | 15 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
16 | 16 | |
17 | 17 | import os |
| 18 | from math import ceil |
18 | 19 | import logging |
19 | 20 | from gettext import gettext as _ |
20 | 21 | |
… |
… |
class ControlPanel(Gtk.Window): |
42 | 43 | def __init__(self): |
43 | 44 | Gtk.Window.__init__(self) |
44 | 45 | |
45 | | self._max_columns = int(0.285 * (float(Gdk.Screen.width()) / |
46 | | style.GRID_CELL_SIZE - 3)) |
47 | | |
| 46 | self._calculate_max_columns() |
48 | 47 | self.set_border_width(style.LINE_WIDTH) |
49 | | offset = style.GRID_CELL_SIZE |
50 | | width = Gdk.Screen.width() - offset * 2 |
51 | | height = Gdk.Screen.height() - offset * 2 |
52 | | self.set_size_request(width, height) |
53 | 48 | self.set_position(Gtk.WindowPosition.CENTER_ALWAYS) |
54 | 49 | self.set_decorated(False) |
55 | 50 | self.set_resizable(False) |
… |
… |
class ControlPanel(Gtk.Window): |
88 | 83 | self._setup_main() |
89 | 84 | self._setup_section() |
90 | 85 | self._show_main_view() |
| 86 | Gdk.Screen.get_default().connect('size-changed', self.__size_changed_cb) |
91 | 87 | |
92 | 88 | def __realize_cb(self, widget): |
93 | 89 | self.set_type_hint(Gdk.WindowTypeHint.DIALOG) |
94 | 90 | self.get_window().set_accept_focus(True) |
95 | 91 | |
| 92 | def __size_changed_cb(self, event): |
| 93 | self._calculate_max_columns() |
| 94 | |
96 | 95 | def grab_focus(self): |
97 | 96 | # overwrite grab focus in order to grab focus on the view |
98 | 97 | self._main_view.get_child().grab_focus() |
99 | 98 | |
| 99 | def _calculate_max_columns(self): |
| 100 | self._max_columns = int(0.285 * (float(Gdk.Screen.width()) / |
| 101 | style.GRID_CELL_SIZE - 3)) |
| 102 | offset = style.GRID_CELL_SIZE |
| 103 | width = Gdk.Screen.width() - offset * 2 |
| 104 | height = Gdk.Screen.height() - offset * 2 |
| 105 | self.set_size_request(width, height) |
| 106 | if hasattr(self, '_table'): |
| 107 | for child in self._table.get_children(): |
| 108 | child.destroy() |
| 109 | self._setup_options() |
| 110 | |
100 | 111 | def _set_canvas(self, canvas): |
101 | 112 | if self._canvas: |
102 | 113 | self._main_view.remove(self._canvas) |