Merge lp:~nataliabidart/ubuntuone-control-panel/open-in-a-tab into lp:ubuntuone-control-panel

Proposed by Natalia Bidart
Status: Merged
Approved by: Natalia Bidart
Approved revision: 50
Merged at revision: 50
Proposed branch: lp:~nataliabidart/ubuntuone-control-panel/open-in-a-tab
Merge into: lp:ubuntuone-control-panel
Diff against target: 121 lines (+67/-4)
3 files modified
bin/ubuntuone-control-panel-gtk (+21/-2)
ubuntuone/controlpanel/gtk/gui.py (+11/-2)
ubuntuone/controlpanel/gtk/tests/test_gui.py (+35/-0)
To merge this branch: bzr merge lp:~nataliabidart/ubuntuone-control-panel/open-in-a-tab
Reviewer Review Type Date Requested Status
Alejandro J. Cura (community) Approve
Eric Casteleijn (community) Approve
Review via email: mp+46978@code.launchpad.net

Commit message

- Added a command line option to start the UI on a given panel (LP: #702968).

Description of the change

If you run the UI, you can check that
DEBUG=True PYTHONPATH=. ./bin/ubuntuone-control-panel-gtk --help

Returns:

Usage: ubuntuone-control-panel-gtk [option]

Options:
  -h, --help show this help message and exit
  --switch-to=PANEL_NAME
                        Start the Ubuntu One Control Panel (GTK) in the
                        PANEL_NAME tab. Possible values are: dashboard,
                        folders, devices, applications

Also, you can play passing different values to switch_to to check it works.

To post a comment you must log in.
50. By Natalia Bidart

Added a missing space.

Revision history for this message
Eric Casteleijn (thisfred) wrote :

Looks great, works as advertised. I wonder if falling back to the default option when an unrecognized option is passed in to --switch-to is the right thing, rather than refuse to switch at all.

Revision history for this message
Eric Casteleijn (thisfred) :
review: Approve
Revision history for this message
Alejandro J. Cura (alecu) :
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-gtk'
2--- bin/ubuntuone-control-panel-gtk 2010-12-16 21:09:46 +0000
3+++ bin/ubuntuone-control-panel-gtk 2011-01-20 21:29:26 +0000
4@@ -20,13 +20,32 @@
5
6 # Invalid name "ubuntuone-control-panel-gtk", pylint: disable=C0103
7
8+import sys
9+
10 import dbus.mainloop.glib
11
12-import ubuntuone.controlpanel.gtk.gui
13+from optparse import OptionParser
14+
15+from ubuntuone.controlpanel.gtk.gui import ControlPanelWindow
16
17 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
18
19
20+def parser_options():
21+ """Parse command line parameters."""
22+ usage = "Usage: %prog [option]"
23+ parser = OptionParser(usage=usage)
24+ parser.add_option("", "--switch-to", dest="switch_to", type="string",
25+ metavar="PANEL_NAME",
26+ help="Start the Ubuntu One Control Panel (GTK) in the "
27+ "PANEL_NAME tab. Possible values are: "
28+ "dashboard, folders, devices, applications")
29+ return parser
30+
31+
32 if __name__ == "__main__":
33- gui = ubuntuone.controlpanel.gtk.gui.ControlPanelWindow()
34+ parser = parser_options()
35+ (options, args) = parser.parse_args(sys.argv)
36+
37+ gui = ControlPanelWindow(switch_to=options.switch_to)
38 gui.main()
39
40=== modified file 'ubuntuone/controlpanel/gtk/gui.py'
41--- ubuntuone/controlpanel/gtk/gui.py 2011-01-19 16:16:38 +0000
42+++ ubuntuone/controlpanel/gtk/gui.py 2011-01-20 21:29:26 +0000
43@@ -169,7 +169,7 @@
44
45 TITLE = _('My %(app_name)s Dashboard')
46
47- def __init__(self):
48+ def __init__(self, switch_to=None):
49 super(ControlPanelWindow, self).__init__()
50
51 self.set_title(self.TITLE % {'app_name': U1_APP_NAME})
52@@ -183,6 +183,16 @@
53 self.control_panel = ControlPanel(window_id=self.window.xid)
54 self.add(self.control_panel)
55
56+ logger.info('Starting %s pointing at panel: %r.',
57+ self.__class__.__name__, switch_to)
58+ if switch_to is not None:
59+ button = getattr(self.control_panel.management,
60+ '%s_button' % switch_to, None)
61+ if button is not None:
62+ button.clicked()
63+ else:
64+ logger.warning('Could not start at panel: %r.', switch_to)
65+
66 logger.debug('%s: started (window size %r).',
67 self.__class__.__name__, self.get_size_request())
68
69@@ -1280,7 +1290,6 @@
70 """Load the account info and file sync status list."""
71 self.backend.account_info(reply_handler=NO_OP,
72 error_handler=error_handler)
73- self.dashboard_button.clicked()
74
75 @log_call(logger.debug)
76 def on_account_info_ready(self, info):
77
78=== modified file 'ubuntuone/controlpanel/gtk/tests/test_gui.py'
79--- ubuntuone/controlpanel/gtk/tests/test_gui.py 2011-01-19 12:19:28 +0000
80+++ ubuntuone/controlpanel/gtk/tests/test_gui.py 2011-01-20 21:29:26 +0000
81@@ -184,6 +184,41 @@
82 self.assertTrue(self.ui.get_size_request() <= (736, 525))
83
84
85+class ControlPanelWindowParamsTestCase(ControlPanelWindowTestCase):
86+ """The test suite for the control panel window when passing params."""
87+
88+ kwargs = {'switch_to': 'devices'}
89+
90+ def test_switch_to(self):
91+ """Can pass a 'switch_to' parameter to start on a particular tab."""
92+ actual = self.ui.control_panel.management.notebook.get_current_page()
93+ self.assertEqual(actual, self.ui.control_panel.management.DEVICES_PAGE)
94+
95+
96+class ControlPanelWindowParamsNoneTestCase(ControlPanelWindowTestCase):
97+ """The suite for the control panel window when passing None params."""
98+
99+ kwargs = {'switch_to': None}
100+
101+ def test_switch_to(self):
102+ """Can pass a 'switch_to' being None. Should default to dashboard."""
103+ actual = self.ui.control_panel.management.notebook.get_current_page()
104+ expected = self.ui.control_panel.management.DASHBOARD_PAGE
105+ self.assertEqual(actual, expected)
106+
107+
108+class ControlPanelWindowInvalidParamsTestCase(ControlPanelWindowTestCase):
109+ """The suite for the control panel window when passing invalid params."""
110+
111+ kwargs = {'switch_to': 'yadda-yadda'}
112+
113+ def test_switch_to(self):
114+ """Can pass an invalid 'switch_to'. Should default to dashboard."""
115+ actual = self.ui.control_panel.management.notebook.get_current_page()
116+ expected = self.ui.control_panel.management.DASHBOARD_PAGE
117+ self.assertEqual(actual, expected)
118+
119+
120 class ControlPanelTestCase(BaseTestCase):
121 """The test suite for the control panel itself."""
122

Subscribers

People subscribed via source and target branches