Merge lp:~ralsina/ubuntuone-control-panel/you-have-two-options into lp:ubuntuone-control-panel

Proposed by Roberto Alsina
Status: Merged
Approved by: Natalia Bidart
Approved revision: 237
Merged at revision: 227
Proposed branch: lp:~ralsina/ubuntuone-control-panel/you-have-two-options
Merge into: lp:ubuntuone-control-panel
Diff against target: 263 lines (+134/-37)
6 files modified
bin/ubuntuone-control-panel-qt (+8/-3)
ubuntuone/controlpanel/gui/qt/gui.py (+20/-4)
ubuntuone/controlpanel/gui/qt/main/linux.py (+6/-13)
ubuntuone/controlpanel/gui/qt/main/windows.py (+7/-15)
ubuntuone/controlpanel/gui/qt/systray.py (+2/-2)
ubuntuone/controlpanel/gui/qt/tests/test_start.py (+91/-0)
To merge this branch: bzr merge lp:~ralsina/ubuntuone-control-panel/you-have-two-options
Reviewer Review Type Date Requested Status
Natalia Bidart (community) Approve
Diego Sarmentero (community) Approve
Review via email: mp+75371@code.launchpad.net

Commit message

Adds a --with-icon option to control panel.

Description of the change

Adds a --with-icon option to control panel.

To test IRL:

* Run bin/ubuntuone-control-panel-qt --with-icon [you should get a icon and a u1cp window]
* Run bin/ubuntuone-control-panel-qt --minimized [you should get a icon and no u1cp window]
* Run bin/ubuntuone-control-panel-qt [you should get a u1cp window and no icon]

If you want to:

* Run bin/ubuntuone-control-panel-qt --minimized --with-icon [you should get a icon and no u1cp window]

To post a comment you must log in.
Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

Tests missing!

review: Needs Fixing
229. By Roberto Alsina

Made it testable, added tests

230. By Roberto Alsina

oops

231. By Roberto Alsina

added missing docstring

232. By Roberto Alsina

docstring fixes

233. By Roberto Alsina

unused import

Revision history for this message
Roberto Alsina (ralsina) wrote :

> Tests missing!

Tests added!

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

+1

review: Approve
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

* Like we talked in IRC, the start() method should be moved to ubuntuone/controlpanel/gui/qt/gui.py, this way we avoid having to "hide" the MainWindow import.

* Also, this set of imports:

+from ubuntuone.controlpanel.tests import TestCase
+from ubuntuone.controlpanel.gui.qt.tests import NO_OP
+import ubuntuone.controlpanel.gui.qt as qt
+from ubuntuone.controlpanel.gui.qt import gui

should be alphabetically sorted and properly grouped in blocks.

* Always yield on super() calls to setUp/tearDown.

Looks good!

review: Needs Fixing
234. By Roberto Alsina

fixes

235. By Roberto Alsina

fixes suggested by nessita

236. By Roberto Alsina

fixes

Revision history for this message
Natalia Bidart (nataliabidart) wrote :

I'm getting:

ubuntuone/controlpanel/gui/qt/main/linux.py:
    30: [E0611] No name 'start' in module 'ubuntuone.controlpanel.gui.qt'
    53: [W0621, main] Redefining name 'start' from outer scope (line 30)
    30: [W0611] Unused import start

review: Needs Fixing
237. By Roberto Alsina

fixed linux main

Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Looks great! works as expected.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/ubuntuone-control-panel-qt'
2--- bin/ubuntuone-control-panel-qt 2011-09-01 19:15:39 +0000
3+++ bin/ubuntuone-control-panel-qt 2011-09-15 17:13:52 +0000
4@@ -47,12 +47,17 @@
5 "alerting the user to its presence.")
6 result.add_option("--minimized", dest="minimized", action="store_true",
7 default=False, help="Start Ubuntu One "
8- "in the notification area.")
9+ "only in the notification area, with no visible window. "
10+ "Implies --with-icon")
11+ result.add_option("--with-icon", dest="with_icon", action="store_true",
12+ default=False, help="Start Ubuntu One "
13+ "with an icon in the notification area.")
14 return result
15
16
17 if __name__ == "__main__":
18 parser = parser_options()
19 (options, args) = parser.parse_args(sys.argv)
20- main.main(switch_to=options.switch_to,
21- alert=options.alert, minimized=options.minimized)
22+ main.main(switch_to=options.switch_to,
23+ alert=options.alert, minimized=options.minimized,
24+ with_icon=options.with_icon)
25
26=== modified file 'ubuntuone/controlpanel/gui/qt/gui.py'
27--- ubuntuone/controlpanel/gui/qt/gui.py 2011-09-02 17:59:39 +0000
28+++ ubuntuone/controlpanel/gui/qt/gui.py 2011-09-15 17:13:52 +0000
29@@ -21,13 +21,10 @@
30
31 from PyQt4 import QtGui
32
33-from ubuntuone.controlpanel.logger import setup_logging
34+from ubuntuone.controlpanel.gui.qt.systray import TrayIcon
35 from ubuntuone.controlpanel.gui.qt.ui import mainwindow_ui
36
37
38-logger = setup_logging('qt.gui')
39-
40-
41 class MainWindow(QtGui.QMainWindow):
42 """The Main Window of the Control Panel."""
43
44@@ -53,3 +50,22 @@
45 event.accept()
46
47 # pylint: enable=C0103
48+
49+
50+def start(stop, minimized=False, with_icon=False):
51+ """Show the UI elements."""
52+ # pylint: disable=W0404, F0401
53+ if not minimized:
54+ if with_icon or minimized:
55+ window = MainWindow()
56+ else:
57+ window = MainWindow(close_callback=stop)
58+ window.show()
59+ else:
60+ window = None
61+ if with_icon or minimized:
62+ QtGui.QApplication.instance().setQuitOnLastWindowClosed(False)
63+ icon = TrayIcon(window=window)
64+ else:
65+ icon = None
66+ return icon, window
67
68=== modified file 'ubuntuone/controlpanel/gui/qt/main/linux.py'
69--- ubuntuone/controlpanel/gui/qt/main/linux.py 2011-09-01 19:31:36 +0000
70+++ ubuntuone/controlpanel/gui/qt/main/linux.py 2011-09-15 17:13:52 +0000
71@@ -27,10 +27,9 @@
72 # pylint: disable=W0611
73 from ubuntuone.controlpanel.gui.qt.ui import images_rc
74 # pylint: enable=W0611
75-from ubuntuone.controlpanel.gui.qt.systray import TrayIcon
76-
77-
78-def main(switch_to='', alert=False, minimized=False):
79+
80+
81+def main(switch_to='', alert=False, minimized=False, with_icon=False):
82 """Start the Qt reactor and open the main window."""
83
84 # The DBus main loop MUST be initialized before importing the reactor
85@@ -50,15 +49,9 @@
86 from qtreactor import qt4reactor
87 qt4reactor.install()
88 from twisted.internet import reactor
89-
90- # pylint believes that reactor has no run nor stop methods. Silence it.
91- if minimized:
92- app.setQuitOnLastWindowClosed(False)
93- icon = TrayIcon()
94- else:
95- from ubuntuone.controlpanel.gui.qt.gui import MainWindow
96- window = MainWindow(close_callback=reactor.stop)
97- window.show()
98+ from ubuntuone.controlpanel.gui.qt.gui import start
99
100 # pylint: disable=E1101
101+ icon, window = start(reactor.stop,
102+ minimized=minimized, with_icon=with_icon)
103 reactor.run()
104
105=== modified file 'ubuntuone/controlpanel/gui/qt/main/windows.py'
106--- ubuntuone/controlpanel/gui/qt/main/windows.py 2011-09-08 13:11:33 +0000
107+++ ubuntuone/controlpanel/gui/qt/main/windows.py 2011-09-15 17:13:52 +0000
108@@ -25,10 +25,9 @@
109 # pylint: disable=W0611
110 from ubuntuone.controlpanel.gui.qt.ui import images_rc
111 # pylint: enable=W0611
112-from ubuntuone.controlpanel.gui.qt.systray import TrayIcon
113-
114-
115-def main(switch_to='', alert=False, minimized=False):
116+
117+
118+def main(switch_to='', alert=False, minimized=False, with_icon=False):
119 """Start the Qt reactor and open the main window."""
120
121 # The following cannot be imported outside this function
122@@ -36,6 +35,8 @@
123 # pylint: disable=F0401, W0404
124 import qtreactor.qt4reactor
125 qtreactor.qt4reactor.install()
126+ from twisted.internet import reactor
127+ from ubuntuone.controlpanel.gui.qt.gui import start
128
129 # The main loop MUST be initialized before importing the reactor
130 # pylint: disable=W0612
131@@ -49,16 +50,7 @@
132 stylesheet = QtCore.QLatin1String(qss_file.readAll())
133 app.setStyleSheet(stylesheet)
134
135- # pylint: disable=W0404, F0401
136- from twisted.internet import reactor
137-
138- if minimized:
139- app.setQuitOnLastWindowClosed(False)
140- icon = TrayIcon()
141- else:
142- from ubuntuone.controlpanel.gui.qt.gui import MainWindow
143- window = MainWindow(close_callback=reactor.stop)
144- window.show()
145-
146+ icon, window = start(reactor.stop,
147+ minimized=minimized, with_icon=with_icon)
148 # pylint: disable=E1101
149 reactor.run()
150
151=== modified file 'ubuntuone/controlpanel/gui/qt/systray.py'
152--- ubuntuone/controlpanel/gui/qt/systray.py 2011-09-07 13:55:49 +0000
153+++ ubuntuone/controlpanel/gui/qt/systray.py 2011-09-15 17:13:52 +0000
154@@ -24,11 +24,11 @@
155
156 """System notification icon."""
157
158- def __init__(self):
159+ def __init__(self, window=None):
160 super(TrayIcon, self).__init__(None)
161 self.setIcon(QtGui.QIcon(":/u1icon.png"))
162 self.setVisible(True)
163- self.window = None
164+ self.window = window
165 self.activated.connect(self.on_activated)
166 self.context_menu = QtGui.QMenu()
167 self.restore = QtGui.QAction("Restore", self,
168
169=== added file 'ubuntuone/controlpanel/gui/qt/tests/test_start.py'
170--- ubuntuone/controlpanel/gui/qt/tests/test_start.py 1970-01-01 00:00:00 +0000
171+++ ubuntuone/controlpanel/gui/qt/tests/test_start.py 2011-09-15 17:13:52 +0000
172@@ -0,0 +1,91 @@
173+# -*- coding: utf-8 -*-
174+
175+# Author: Roberto Alsina <roberto.alsina@canonical.com>
176+#
177+# Copyright 2011 Canonical Ltd.
178+#
179+# This program is free software: you can redistribute it and/or modify it
180+# under the terms of the GNU General Public License version 3, as published
181+# by the Free Software Foundation.
182+#
183+# This program is distributed in the hope that it will be useful, but
184+# WITHOUT ANY WARRANTY; without even the implied warranties of
185+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
186+# PURPOSE. See the GNU General Public License for more details.
187+#
188+# You should have received a copy of the GNU General Public License along
189+# with this program. If not, see <http://www.gnu.org/licenses/>.
190+
191+"""Tests for the start function."""
192+
193+from twisted.internet import defer
194+
195+from ubuntuone.controlpanel.gui.qt import gui
196+from ubuntuone.controlpanel.gui.qt.tests import NO_OP
197+from ubuntuone.controlpanel.tests import TestCase
198+
199+
200+class FakeThing(object):
201+
202+ """A fake thing."""
203+
204+ def __init__(self):
205+ self.args = []
206+ self.shown = False
207+
208+ def __call__(self, *args, **kwargs):
209+ self.args.append((args, kwargs))
210+ return self
211+
212+ def show(self):
213+ """Show."""
214+ self.shown = True
215+
216+
217+class FakeReactor(object):
218+ """A fake reactor."""
219+
220+ def run(self):
221+ """Start."""
222+
223+ def stop(self):
224+ """Stop."""
225+
226+
227+class StartTestCase(TestCase):
228+ """Test the qt control panel."""
229+
230+ @defer.inlineCallbacks
231+ def setUp(self):
232+ yield super(StartTestCase, self).setUp()
233+ self.main_window = FakeThing()
234+ self.tray_icon = FakeThing()
235+ self.patch(gui, "MainWindow", self.main_window)
236+ self.patch(gui, "TrayIcon", self.tray_icon)
237+
238+ def test_minimized(self):
239+ """Test behaviour with minimized=True."""
240+ gui.start(NO_OP, minimized=True, with_icon=True)
241+ self.assertEqual(self.tray_icon.args, [((), {'window': None})])
242+ self.assertEqual(self.main_window.args, [])
243+
244+ def test_with_icon(self):
245+ """Test behaviour with with_icon=True."""
246+ gui.start(NO_OP, with_icon=True, minimized=False)
247+ self.assertEqual(self.main_window.args, [((), {})])
248+ self.assertEqual(self.tray_icon.args, [((),
249+ {'window': self.main_window})])
250+
251+ def test_both_false(self):
252+ """Test behaviour when with_icon and minimized are False."""
253+ gui.start(NO_OP, with_icon=False, minimized=False)
254+ # Should be called
255+ self.assertNotEqual(self.main_window.args, [])
256+ # Should not be called
257+ self.assertEqual(self.tray_icon.args, [])
258+
259+ def test_both_true(self):
260+ """Test behaviour when with_icon and minimized are True."""
261+ gui.start(NO_OP, with_icon=True, minimized=True)
262+ self.assertEqual(self.tray_icon.args, [((), {'window': None})])
263+ self.assertEqual(self.main_window.args, [])

Subscribers

People subscribed via source and target branches