Merge lp:~nataliabidart/ubuntuone-control-panel/center-me into lp:ubuntuone-control-panel

Proposed by Natalia Bidart
Status: Merged
Approved by: Natalia Bidart
Approved revision: 262
Merged at revision: 261
Proposed branch: lp:~nataliabidart/ubuntuone-control-panel/center-me
Merge into: lp:ubuntuone-control-panel
Diff against target: 80 lines (+27/-6)
2 files modified
ubuntuone/controlpanel/gui/qt/gui.py (+7/-5)
ubuntuone/controlpanel/gui/qt/tests/test_start.py (+20/-1)
To merge this branch: bzr merge lp:~nataliabidart/ubuntuone-control-panel/center-me
Reviewer Review Type Date Requested Status
Diego Sarmentero (community) Approve
Roberto Alsina (community) Approve
Review via email: mp+93582@code.launchpad.net

Commit message

- Center the main window when openning it (LP: #934173).

To post a comment you must log in.
Revision history for this message
Roberto Alsina (ralsina) wrote :

+1 code review + IRL test

review: Approve
Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ubuntuone/controlpanel/gui/qt/gui.py'
2--- ubuntuone/controlpanel/gui/qt/gui.py 2012-02-07 13:54:46 +0000
3+++ ubuntuone/controlpanel/gui/qt/gui.py 2012-02-17 14:47:20 +0000
4@@ -1,8 +1,6 @@
5 # -*- coding: utf-8 -*-
6-
7-# Authors: Alejandro J. Cura <alecu@canonical.com>
8 #
9-# Copyright 2011 Canonical Ltd.
10+# Copyright 2011-2012 Canonical Ltd.
11 #
12 # This program is free software: you can redistribute it and/or modify it
13 # under the terms of the GNU General Public License version 3, as published
14@@ -18,8 +16,7 @@
15
16 """The user interface for the control panel for Ubuntu One."""
17
18-
19-from PyQt4 import QtGui
20+from PyQt4 import QtGui, QtCore
21
22 from ubuntuone.controlpanel.gui.qt.systray import TrayIcon
23 from ubuntuone.controlpanel.gui.qt.ui import mainwindow_ui
24@@ -60,6 +57,11 @@
25 window = MainWindow()
26 else:
27 window = MainWindow(close_callback=close_callback)
28+ app = QtGui.QApplication.instance()
29+ style = QtGui.QStyle.alignedRect(
30+ QtCore.Qt.LeftToRight, QtCore.Qt.AlignCenter,
31+ window.size(), app.desktop().availableGeometry())
32+ window.setGeometry(style)
33 window.show()
34 else:
35 window = None
36
37=== modified file 'ubuntuone/controlpanel/gui/qt/tests/test_start.py'
38--- ubuntuone/controlpanel/gui/qt/tests/test_start.py 2012-02-07 13:54:46 +0000
39+++ ubuntuone/controlpanel/gui/qt/tests/test_start.py 2012-02-17 14:47:20 +0000
40@@ -28,9 +28,12 @@
41
42 """A fake thing."""
43
44+ shown = False
45+ size = lambda *a: gui.QtCore.QSize(123456, 654321)
46+ style = None
47+
48 def __init__(self):
49 self.args = []
50- self.shown = False
51
52 def __call__(self, *args, **kwargs):
53 self.args.append((args, kwargs))
54@@ -40,6 +43,13 @@
55 """Show."""
56 self.shown = True
57
58+ # Invalid name "setGeometry"
59+ # pylint: disable=C0103
60+
61+ def setGeometry(self, style):
62+ """Save the new geometry."""
63+ self.style = style
64+
65
66 class StartTestCase(TestCase):
67 """Test the qt control panel."""
68@@ -87,3 +97,12 @@
69 kwargs = {'close_callback': self.close_cb, 'window': None}
70 self.assertEqual(self.tray_icon.args, [((), kwargs)])
71 self.assertEqual(self.main_window.args, [])
72+
73+ def test_center_window(self):
74+ """The main window should be centered."""
75+ gui.start(close_callback=self.close_cb)
76+ app = gui.QtGui.QApplication.instance()
77+ expected = gui.QtGui.QStyle.alignedRect(gui.QtCore.Qt.LeftToRight,
78+ gui.QtCore.Qt.AlignCenter, self.main_window.size(),
79+ app.desktop().availableGeometry())
80+ self.assertEqual(self.main_window.style, expected)

Subscribers

People subscribed via source and target branches