Merge lp:~sinzui/bzr-gtk/gpush into lp:bzr-gtk

Proposed by Curtis Hovey
Status: Merged
Merged at revision: 782
Proposed branch: lp:~sinzui/bzr-gtk/gpush
Merge into: lp:bzr-gtk
Diff against target: 378 lines (+202/-47)
3 files modified
push.py (+59/-44)
tests/__init__.py (+8/-3)
tests/test_push.py (+135/-0)
To merge this branch: bzr merge lp:~sinzui/bzr-gtk/gpush
Reviewer Review Type Date Requested Status
Jelmer Vernooij (community) Approve
Review via email: mp+95769@code.launchpad.net

Description of the change

Integrate the pogress bar and message into the push dialog.

    Launchpad bug: https://bugs.launchpad.net/bugs/113660
    Pre-implementation: jelmer

This branch replaces the progress dialog with a progress panel and
the info dialog with a message label. When the user choosed to push,
the progress panel is shown, and the message is shown when completed.

--------------------------------------------------------------------

RULES

    * Add a progress panel and a label to the push dialog that are not
      visible until the push starts.
    * Update HBox to Box.
    * Remove the unused attrs and variables from the code.
      * I decided not to remove two unused attributes because it breaks
        anything that calls PushDialog. Do we want to change the API?
    * Fix the spacing and padding to conform to the GNOME Human
      Interface guidelines.
    * ADDENDUM: I made a minor change to do_push to return the message
      instead of the count. PushResult.__int__ is deprecated. I decided
      I want to fix do_push() in my next branch without changing
      _on_push_clicked().

QA

    http://people.canonical.com/~curtis/push-progress.png
    http://people.canonical.com/~curtis/push-complete.png

    Run this command from a branch with theses changes.
    BZR_PLUGINS_AT=gtk@./ bzr gpush

To post a comment you must log in.
lp:~sinzui/bzr-gtk/gpush updated
793. By Curtis Hovey

Merged trunk.

794. By Curtis Hovey

Fixed spelling.

Revision history for this message
Jelmer Vernooij (jelmer) wrote :

Thanks, very nice.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'push.py'
2--- push.py 2012-02-27 18:47:21 +0000
3+++ push.py 2012-03-04 02:24:17 +0000
4@@ -1,4 +1,5 @@
5-# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
6+# Copyright (C) 2006 by Szilveszter Farkas (Phanatic)
7+# <szilveszter.farkas@gmail.com>
8 # Copyright (C) 2007 by Jelmer Vernooij <jelmer@samba.org>
9 #
10 # This program is free software; you can redistribute it and/or modify
11@@ -15,20 +16,23 @@
12 # along with this program; if not, write to the Free Software
13 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14
15-from gi.repository import GObject
16 from gi.repository import Gtk
17
18 from errors import show_bzr_error
19
20-import bzrlib.errors as errors
21+from bzrlib import (
22+ errors,
23+ ui,
24+ )
25+from bzrlib.bzrdir import BzrDir
26+from bzrlib.transport import get_transport
27
28 from bzrlib.plugins.gtk.dialog import (
29- info_dialog,
30 question_dialog,
31 )
32-
33 from bzrlib.plugins.gtk.history import UrlHistory
34 from bzrlib.plugins.gtk.i18n import _i18n
35+from bzrlib.plugins.gtk.ui import ProgressPanel
36
37
38 class PushDialog(Gtk.Dialog):
39@@ -37,39 +41,43 @@
40 def __init__(self, repository, revid, branch=None, parent=None):
41 """Initialize the Push dialog. """
42 super(PushDialog, self).__init__(
43- title="Push", parent=parent, flags=0,
44- buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL))
45-
46-
47- # Get arguments
48+ title="Push", parent=parent, flags=0, border_width=6,
49+ buttons=(Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE))
50+ self.branch = branch
51+
52+ # Unused arguments
53 self.repository = repository
54 self.revid = revid
55- self.branch = branch
56
57 # Create the widgets
58 self._label_location = Gtk.Label(label=_i18n("Location:"))
59 self._combo = Gtk.ComboBox.new_with_entry()
60 self._button_push = Gtk.Button(_i18n("_Push"), use_underline=True)
61- self._hbox_location = Gtk.HBox()
62+ self._hbox_location = Gtk.Box(Gtk.Orientation.HORIZONTAL, 6)
63+ self._push_message = Gtk.Label(xalign=0)
64+ self._progress_widget = ProgressPanel()
65
66 # Set callbacks
67+ ui.ui_factory.set_progress_bar_widget(self._progress_widget)
68+ self.connect('close', self._on_close_clicked)
69 self._button_push.connect('clicked', self._on_push_clicked)
70
71 # Set properties
72- self._label_location.set_alignment(0, 0.5)
73- self._hbox_location.set_spacing(3)
74- self.get_content_area().set_spacing(3)
75+ content_area = self.get_content_area()
76+ content_area.set_spacing(6)
77
78 # Pack widgets
79- self._hbox_location.pack_start(
80- self._label_location, False, False, 0)
81- self._hbox_location.pack_start(self._combo, True, True, 0)
82- self.get_content_area().pack_start(self._hbox_location, True, True, 0)
83- # XXX sinzui 2011-08-12: maybe False, False, 0
84+ self._hbox_location.pack_start(self._label_location, False, False, 0)
85+ self._hbox_location.pack_start(self._combo, False, False, 0)
86+ content_area.pack_start(self._hbox_location, True, True, 0)
87+ content_area.pack_start(self._progress_widget, True, True, 0)
88+ content_area.pack_start(self._push_message, True, True, 0)
89 self.get_action_area().pack_end(self._button_push, True, True, 0)
90
91 # Show the dialog
92- self.get_content_area().show_all()
93+ content_area.show_all()
94+ self._progress_widget.hide()
95+ self._push_message.hide()
96
97 # Build location history
98 self._history = UrlHistory(self.branch.get_config(), 'push_history')
99@@ -79,7 +87,7 @@
100 """Build up the location history. """
101 self._combo_model = Gtk.ListStore(str)
102 for item in self._history.get_entries():
103- self._combo_model.append([ item ])
104+ self._combo_model.append([item])
105 self._combo.set_model(self._combo_model)
106 self._combo.set_entry_text_column(0)
107
108@@ -88,28 +96,36 @@
109 if location is not None:
110 self._combo.get_child().set_text(location)
111
112+ def _on_close_clicked(self, widget):
113+ """Close dialog handler."""
114+ ui.ui_factory.set_progress_bar_widget(None)
115+
116 @show_bzr_error
117 def _on_push_clicked(self, widget):
118 """Push button clicked handler. """
119+ self._push_message.hide()
120+ self._progress_widget.tick()
121 location = self._combo.get_child().get_text()
122- revs = 0
123
124 try:
125- revs = do_push(self.branch, location=location, overwrite=False)
126+ message = do_push(self.branch, location, overwrite=False)
127 except errors.DivergedBranches:
128- response = question_dialog(_i18n('Branches have been diverged'),
129- _i18n('You cannot push if branches have diverged.\nOverwrite?'))
130+ response = question_dialog(
131+ _i18n('Branches have been diverged'),
132+ _i18n('You cannot push if branches have diverged.\n'
133+ 'Overwrite?'))
134 if response == Gtk.ResponseType.YES:
135- revs = do_push(self.branch, location=location, overwrite=True)
136-
137- if self.branch is not None and self.branch.get_push_location() is None:
138+ message = do_push(self.branch, location, overwrite=True)
139+ else:
140+ return
141+ self._history.add_entry(location)
142+ if (self.branch is not None
143+ and self.branch.get_push_location() is None):
144 self.branch.set_push_location(location)
145-
146- self._history.add_entry(location)
147- info_dialog(_i18n('Push successful'),
148- _i18n("%d revision(s) pushed.") % revs)
149-
150- self.response(Gtk.ResponseType.OK)
151+ if message:
152+ self._progress_widget.finished()
153+ self._push_message.props.label = message
154+ self._push_message.show()
155
156
157 def do_push(br_from, location, overwrite):
158@@ -120,14 +136,9 @@
159 :param overwrite: overwrite target location if it diverged
160 :return: number of revisions pushed
161 """
162- from bzrlib.bzrdir import BzrDir
163- from bzrlib.transport import get_transport
164-
165 transport = get_transport(location)
166 location_url = transport.base
167
168- old_rh = []
169-
170 try:
171 dir_to = BzrDir.open(location_url)
172 br_to = dir_to.open_branch()
173@@ -138,8 +149,10 @@
174 relurl = transport.relpath(location_url)
175 transport.mkdir(relurl)
176 except errors.NoSuchFile:
177- response = question_dialog(_i18n('Non existing parent directory'),
178- _i18n("The parent directory (%s)\ndoesn't exist. Create?") % location)
179+ response = question_dialog(
180+ _i18n('Non existing parent directory'),
181+ _i18n("The parent directory (%s)\ndoesn't exist. Create?") %
182+ location)
183 if response == Gtk.ResponseType.OK:
184 transport.create_prefix()
185 else:
186@@ -149,7 +162,7 @@
187 br_to = dir_to.open_branch()
188 count = len(br_to.revision_history())
189 else:
190- old_rh = br_to.revision_history()
191+ br_to.revision_history()
192 try:
193 tree_to = dir_to.open_workingtree()
194 except errors.NotLocalUrl:
195@@ -160,4 +173,6 @@
196 else:
197 count = tree_to.pull(br_from, overwrite)
198
199- return count
200+ # The count var is either an int or a PushResult. PushResult is being
201+ # coerced into an int, but the method is deprecated.
202+ return _i18n("%d revision(s) pushed.") % int(count)
203
204=== modified file 'tests/__init__.py'
205--- tests/__init__.py 2012-02-28 17:52:54 +0000
206+++ tests/__init__.py 2012-03-04 02:24:17 +0000
207@@ -46,23 +46,28 @@
208 class MockMethod(object):
209
210 @classmethod
211- def bind(klass, test_instance, obj, method_name, return_value=None):
212+ def bind(klass, test_instance, obj, method_name,
213+ return_value=None, raise_error=None, raise_on=1):
214 original_method = getattr(obj, method_name)
215 test_instance.addCleanup(setattr, obj, method_name, original_method)
216- setattr(obj, method_name, klass(return_value))
217+ setattr(obj, method_name, klass(return_value, raise_error, raise_on))
218
219- def __init__(self, return_value=None):
220+ def __init__(self, return_value=None, raise_error=None, raise_on=1):
221 self.called = False
222 self.call_count = 0
223 self.args = None
224 self.kwargs = None
225 self.return_value = return_value
226+ self.raise_error = raise_error
227+ self.raise_on = raise_on
228
229 def __call__(self, *args, **kwargs):
230 self.called = True
231 self.call_count += 1
232 self.args = args
233 self.kwargs = kwargs
234+ if self.raise_error is not None and self.call_count == self.raise_on:
235+ raise self.raise_error
236 return self.return_value
237
238
239
240=== added file 'tests/test_push.py'
241--- tests/test_push.py 1970-01-01 00:00:00 +0000
242+++ tests/test_push.py 2012-03-04 02:24:17 +0000
243@@ -0,0 +1,135 @@
244+# Copyright (C) 2012 Curtis Hovey <sinzui.is@verizon.net>
245+#
246+# This program is free software; you can redistribute it and/or modify
247+# it under the terms of the GNU General Public License as published by
248+# the Free Software Foundation; either version 2 of the License, or
249+# (at your option) any later version.
250+#
251+# This program is distributed in the hope that it will be useful,
252+# but WITHOUT ANY WARRANTY; without even the implied warranty of
253+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
254+# GNU General Public License for more details.
255+#
256+# You should have received a copy of the GNU General Public License
257+# along with this program; if not, write to the Free Software
258+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
259+
260+"""Test the ui functionality."""
261+
262+from gi.repository import Gtk
263+
264+from bzrlib import (
265+ errors,
266+ tests,
267+ ui,
268+ )
269+
270+from bzrlib.plugins.gtk import (
271+ push,
272+ set_ui_factory,
273+ )
274+from bzrlib.plugins.gtk.tests import MockMethod
275+from bzrlib.plugins.gtk.history import UrlHistory
276+from bzrlib.plugins.gtk.ui import ProgressPanel
277+
278+
279+class PushTestCase(tests.TestCaseWithMemoryTransport):
280+
281+ def make_push_branch(self):
282+ tree = self.make_branch_and_memory_tree('test')
283+ return tree.branch
284+
285+ def test_init(self):
286+ set_ui_factory()
287+ branch = self.make_push_branch()
288+ dialog = push.PushDialog(
289+ repository=None, revid=None, branch=branch, parent=None)
290+ self.assertIs(None, dialog.props.parent)
291+ self.assertIs(None, dialog.repository)
292+ self.assertIs(None, dialog.revid)
293+ self.assertIs(branch, dialog.branch)
294+ # Layout rules to match HIG.
295+ self.assertIsInstance(dialog._label_location, Gtk.Label)
296+ self.assertIsInstance(dialog._combo, Gtk.ComboBox)
297+ self.assertIsInstance(dialog._button_push, Gtk.Button)
298+ self.assertIsInstance(dialog._hbox_location, Gtk.Box)
299+ self.assertIsInstance(dialog._progress_widget, ProgressPanel)
300+ self.assertIsInstance(dialog._push_message, Gtk.Label)
301+ self.assertIsInstance(dialog._history, UrlHistory)
302+ self.assertIs(
303+ ui.ui_factory._progress_bar_widget, dialog._progress_widget)
304+ self.assertEqual(
305+ Gtk.Orientation.HORIZONTAL,
306+ dialog._hbox_location.props.orientation)
307+ self.assertEqual(0.0, dialog._push_message.props.xalign)
308+ self.assertEqual(6, dialog.props.border_width)
309+ self.assertEqual(6, dialog._hbox_location.props.spacing)
310+ self.assertEqual(6, dialog.get_content_area().props.spacing)
311+ # Show rules.
312+ self.assertIs(True, dialog._combo.props.visible)
313+ self.assertIs(False, dialog._progress_widget.props.visible)
314+ self.assertIs(False, dialog._push_message.props.visible)
315+
316+ def test_build_history(self):
317+ set_ui_factory()
318+ branch = self.make_push_branch()
319+ branch.set_push_location('lp:~user/fnord/trunk')
320+ dialog = push.PushDialog(None, None, branch)
321+ dialog._history.add_entry('lp:~user/fnord/test1')
322+ dialog._history.add_entry('lp:~user/fnord/test2')
323+ dialog._build_history()
324+ self.assertEqual(
325+ 'lp:~user/fnord/trunk', dialog._combo.get_child().props.text)
326+ self.assertIsInstance(dialog._combo_model, Gtk.ListStore)
327+ self.assertIs(dialog._combo.get_model(), dialog._combo_model)
328+ locations = [row[0] for row in dialog._combo_model]
329+ self.assertEqual(
330+ ['lp:~user/fnord/test1', 'lp:~user/fnord/test2'], locations)
331+
332+ def test_on_close_clicked(self):
333+ # The ui_factory's progress bar widget is set to None.
334+ set_ui_factory()
335+ branch = self.make_push_branch()
336+ dialog = push.PushDialog(None, None, branch)
337+ dialog._on_close_clicked(None)
338+ self.assertIs(None, ui.ui_factory._progress_bar_widget)
339+
340+ def test_on_push_clicked_without_errors(self):
341+ # Verify the dialog's and branch's final states after a push.
342+ MockMethod.bind(self, push, 'do_push', "test success")
343+ set_ui_factory()
344+ branch = self.make_push_branch()
345+ dialog = push.PushDialog(None, None, branch)
346+ MockMethod.bind(self, dialog._progress_widget, 'tick')
347+ dialog._combo.get_child().props.text = 'lp:~user/fnord/test'
348+ dialog._on_push_clicked(None)
349+ self.assertIs(True, dialog._progress_widget.tick.called)
350+ self.assertIs(False, dialog._progress_widget.props.visible)
351+ self.assertIs(True, push.do_push.called)
352+ self.assertEqual(
353+ (branch, 'lp:~user/fnord/test'), push.do_push.args)
354+ self.assertEqual(
355+ {'overwrite': False}, push.do_push.kwargs)
356+ self.assertIs(True, dialog._push_message.props.visible)
357+ self.assertEqual('test success', dialog._push_message.props.label)
358+ self.assertEqual(
359+ 'lp:~user/fnord/test', dialog._history.get_entries()[-1])
360+ self.assertEqual('lp:~user/fnord/test', branch.get_push_location())
361+
362+ def test_on_push_clicked_with_divered_branches(self):
363+ # Verify that when DivergedBranches is raise, the user can choose
364+ # to overwrite the branch.
365+ error = errors.DivergedBranches(None, None)
366+ MockMethod.bind(self, push, 'do_push', raise_error=error)
367+ MockMethod.bind(self, push, 'question_dialog', Gtk.ResponseType.YES)
368+ set_ui_factory()
369+ branch = self.make_push_branch()
370+ dialog = push.PushDialog(None, None, branch)
371+ dialog._combo.get_child().props.text = 'lp:~user/fnord/test'
372+ dialog._on_push_clicked(None)
373+ self.assertIs(True, push.do_push.called)
374+ self.assertEqual(2, push.do_push.call_count)
375+ self.assertEqual(
376+ (branch, 'lp:~user/fnord/test'), push.do_push.args)
377+ self.assertEqual(
378+ {'overwrite': True}, push.do_push.kwargs)

Subscribers

People subscribed via source and target branches

to all changes: