Ticket #4444: 0001-account-for-size-change-when-rotating-between-landsc.patch

File 0001-account-for-size-change-when-rotating-between-landsc.patch, 3.0 KB (added by manuq, 10 years ago)

Patch based on Walter one, fixes the columns number after screen rotate

  • src/jarabe/controlpanel/gui.py

    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  
    1515# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    1616
    1717import os
     18from math import ceil
    1819import logging
    1920from gettext import gettext as _
    2021
    class ControlPanel(Gtk.Window): 
    4243    def __init__(self):
    4344        Gtk.Window.__init__(self)
    4445
    45         self._max_columns = int(0.285 * (float(Gdk.Screen.width()) /
    46             style.GRID_CELL_SIZE - 3))
    47 
     46        self._calculate_max_columns()
    4847        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)
    5348        self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
    5449        self.set_decorated(False)
    5550        self.set_resizable(False)
    class ControlPanel(Gtk.Window): 
    8883        self._setup_main()
    8984        self._setup_section()
    9085        self._show_main_view()
     86        Gdk.Screen.get_default().connect('size-changed', self.__size_changed_cb)
    9187
    9288    def __realize_cb(self, widget):
    9389        self.set_type_hint(Gdk.WindowTypeHint.DIALOG)
    9490        self.get_window().set_accept_focus(True)
    9591
     92    def __size_changed_cb(self, event):
     93        self._calculate_max_columns()
     94
    9695    def grab_focus(self):
    9796        # overwrite grab focus in order to grab focus on the view
    9897        self._main_view.get_child().grab_focus()
    9998
     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
    100111    def _set_canvas(self, canvas):
    101112        if self._canvas:
    102113            self._main_view.remove(self._canvas)