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
=== modified file 'push.py'
--- push.py 2012-02-27 18:47:21 +0000
+++ push.py 2012-03-04 02:24:17 +0000
@@ -1,4 +1,5 @@
1# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>1# Copyright (C) 2006 by Szilveszter Farkas (Phanatic)
2# <szilveszter.farkas@gmail.com>
2# Copyright (C) 2007 by Jelmer Vernooij <jelmer@samba.org>3# Copyright (C) 2007 by Jelmer Vernooij <jelmer@samba.org>
3#4#
4# This program is free software; you can redistribute it and/or modify5# This program is free software; you can redistribute it and/or modify
@@ -15,20 +16,23 @@
15# along with this program; if not, write to the Free Software16# along with this program; if not, write to the Free Software
16# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA17# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1718
18from gi.repository import GObject
19from gi.repository import Gtk19from gi.repository import Gtk
2020
21from errors import show_bzr_error21from errors import show_bzr_error
2222
23import bzrlib.errors as errors23from bzrlib import (
24 errors,
25 ui,
26 )
27from bzrlib.bzrdir import BzrDir
28from bzrlib.transport import get_transport
2429
25from bzrlib.plugins.gtk.dialog import (30from bzrlib.plugins.gtk.dialog import (
26 info_dialog,
27 question_dialog,31 question_dialog,
28 )32 )
29
30from bzrlib.plugins.gtk.history import UrlHistory33from bzrlib.plugins.gtk.history import UrlHistory
31from bzrlib.plugins.gtk.i18n import _i18n34from bzrlib.plugins.gtk.i18n import _i18n
35from bzrlib.plugins.gtk.ui import ProgressPanel
3236
3337
34class PushDialog(Gtk.Dialog):38class PushDialog(Gtk.Dialog):
@@ -37,39 +41,43 @@
37 def __init__(self, repository, revid, branch=None, parent=None):41 def __init__(self, repository, revid, branch=None, parent=None):
38 """Initialize the Push dialog. """42 """Initialize the Push dialog. """
39 super(PushDialog, self).__init__(43 super(PushDialog, self).__init__(
40 title="Push", parent=parent, flags=0,44 title="Push", parent=parent, flags=0, border_width=6,
41 buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL))45 buttons=(Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE))
4246 self.branch = branch
4347
44 # Get arguments48 # Unused arguments
45 self.repository = repository49 self.repository = repository
46 self.revid = revid50 self.revid = revid
47 self.branch = branch
4851
49 # Create the widgets52 # Create the widgets
50 self._label_location = Gtk.Label(label=_i18n("Location:"))53 self._label_location = Gtk.Label(label=_i18n("Location:"))
51 self._combo = Gtk.ComboBox.new_with_entry()54 self._combo = Gtk.ComboBox.new_with_entry()
52 self._button_push = Gtk.Button(_i18n("_Push"), use_underline=True)55 self._button_push = Gtk.Button(_i18n("_Push"), use_underline=True)
53 self._hbox_location = Gtk.HBox()56 self._hbox_location = Gtk.Box(Gtk.Orientation.HORIZONTAL, 6)
57 self._push_message = Gtk.Label(xalign=0)
58 self._progress_widget = ProgressPanel()
5459
55 # Set callbacks60 # Set callbacks
61 ui.ui_factory.set_progress_bar_widget(self._progress_widget)
62 self.connect('close', self._on_close_clicked)
56 self._button_push.connect('clicked', self._on_push_clicked)63 self._button_push.connect('clicked', self._on_push_clicked)
5764
58 # Set properties65 # Set properties
59 self._label_location.set_alignment(0, 0.5)66 content_area = self.get_content_area()
60 self._hbox_location.set_spacing(3)67 content_area.set_spacing(6)
61 self.get_content_area().set_spacing(3)
6268
63 # Pack widgets69 # Pack widgets
64 self._hbox_location.pack_start(70 self._hbox_location.pack_start(self._label_location, False, False, 0)
65 self._label_location, False, False, 0)71 self._hbox_location.pack_start(self._combo, False, False, 0)
66 self._hbox_location.pack_start(self._combo, True, True, 0)72 content_area.pack_start(self._hbox_location, True, True, 0)
67 self.get_content_area().pack_start(self._hbox_location, True, True, 0)73 content_area.pack_start(self._progress_widget, True, True, 0)
68 # XXX sinzui 2011-08-12: maybe False, False, 074 content_area.pack_start(self._push_message, True, True, 0)
69 self.get_action_area().pack_end(self._button_push, True, True, 0)75 self.get_action_area().pack_end(self._button_push, True, True, 0)
7076
71 # Show the dialog77 # Show the dialog
72 self.get_content_area().show_all()78 content_area.show_all()
79 self._progress_widget.hide()
80 self._push_message.hide()
7381
74 # Build location history82 # Build location history
75 self._history = UrlHistory(self.branch.get_config(), 'push_history')83 self._history = UrlHistory(self.branch.get_config(), 'push_history')
@@ -79,7 +87,7 @@
79 """Build up the location history. """87 """Build up the location history. """
80 self._combo_model = Gtk.ListStore(str)88 self._combo_model = Gtk.ListStore(str)
81 for item in self._history.get_entries():89 for item in self._history.get_entries():
82 self._combo_model.append([ item ])90 self._combo_model.append([item])
83 self._combo.set_model(self._combo_model)91 self._combo.set_model(self._combo_model)
84 self._combo.set_entry_text_column(0)92 self._combo.set_entry_text_column(0)
8593
@@ -88,28 +96,36 @@
88 if location is not None:96 if location is not None:
89 self._combo.get_child().set_text(location)97 self._combo.get_child().set_text(location)
9098
99 def _on_close_clicked(self, widget):
100 """Close dialog handler."""
101 ui.ui_factory.set_progress_bar_widget(None)
102
91 @show_bzr_error103 @show_bzr_error
92 def _on_push_clicked(self, widget):104 def _on_push_clicked(self, widget):
93 """Push button clicked handler. """105 """Push button clicked handler. """
106 self._push_message.hide()
107 self._progress_widget.tick()
94 location = self._combo.get_child().get_text()108 location = self._combo.get_child().get_text()
95 revs = 0
96109
97 try:110 try:
98 revs = do_push(self.branch, location=location, overwrite=False)111 message = do_push(self.branch, location, overwrite=False)
99 except errors.DivergedBranches:112 except errors.DivergedBranches:
100 response = question_dialog(_i18n('Branches have been diverged'),113 response = question_dialog(
101 _i18n('You cannot push if branches have diverged.\nOverwrite?'))114 _i18n('Branches have been diverged'),
115 _i18n('You cannot push if branches have diverged.\n'
116 'Overwrite?'))
102 if response == Gtk.ResponseType.YES:117 if response == Gtk.ResponseType.YES:
103 revs = do_push(self.branch, location=location, overwrite=True)118 message = do_push(self.branch, location, overwrite=True)
104119 else:
105 if self.branch is not None and self.branch.get_push_location() is None:120 return
121 self._history.add_entry(location)
122 if (self.branch is not None
123 and self.branch.get_push_location() is None):
106 self.branch.set_push_location(location)124 self.branch.set_push_location(location)
107125 if message:
108 self._history.add_entry(location)126 self._progress_widget.finished()
109 info_dialog(_i18n('Push successful'),127 self._push_message.props.label = message
110 _i18n("%d revision(s) pushed.") % revs)128 self._push_message.show()
111
112 self.response(Gtk.ResponseType.OK)
113129
114130
115def do_push(br_from, location, overwrite):131def do_push(br_from, location, overwrite):
@@ -120,14 +136,9 @@
120 :param overwrite: overwrite target location if it diverged136 :param overwrite: overwrite target location if it diverged
121 :return: number of revisions pushed137 :return: number of revisions pushed
122 """138 """
123 from bzrlib.bzrdir import BzrDir
124 from bzrlib.transport import get_transport
125
126 transport = get_transport(location)139 transport = get_transport(location)
127 location_url = transport.base140 location_url = transport.base
128141
129 old_rh = []
130
131 try:142 try:
132 dir_to = BzrDir.open(location_url)143 dir_to = BzrDir.open(location_url)
133 br_to = dir_to.open_branch()144 br_to = dir_to.open_branch()
@@ -138,8 +149,10 @@
138 relurl = transport.relpath(location_url)149 relurl = transport.relpath(location_url)
139 transport.mkdir(relurl)150 transport.mkdir(relurl)
140 except errors.NoSuchFile:151 except errors.NoSuchFile:
141 response = question_dialog(_i18n('Non existing parent directory'),152 response = question_dialog(
142 _i18n("The parent directory (%s)\ndoesn't exist. Create?") % location)153 _i18n('Non existing parent directory'),
154 _i18n("The parent directory (%s)\ndoesn't exist. Create?") %
155 location)
143 if response == Gtk.ResponseType.OK:156 if response == Gtk.ResponseType.OK:
144 transport.create_prefix()157 transport.create_prefix()
145 else:158 else:
@@ -149,7 +162,7 @@
149 br_to = dir_to.open_branch()162 br_to = dir_to.open_branch()
150 count = len(br_to.revision_history())163 count = len(br_to.revision_history())
151 else:164 else:
152 old_rh = br_to.revision_history()165 br_to.revision_history()
153 try:166 try:
154 tree_to = dir_to.open_workingtree()167 tree_to = dir_to.open_workingtree()
155 except errors.NotLocalUrl:168 except errors.NotLocalUrl:
@@ -160,4 +173,6 @@
160 else:173 else:
161 count = tree_to.pull(br_from, overwrite)174 count = tree_to.pull(br_from, overwrite)
162175
163 return count176 # The count var is either an int or a PushResult. PushResult is being
177 # coerced into an int, but the method is deprecated.
178 return _i18n("%d revision(s) pushed.") % int(count)
164179
=== modified file 'tests/__init__.py'
--- tests/__init__.py 2012-02-28 17:52:54 +0000
+++ tests/__init__.py 2012-03-04 02:24:17 +0000
@@ -46,23 +46,28 @@
46class MockMethod(object):46class MockMethod(object):
4747
48 @classmethod48 @classmethod
49 def bind(klass, test_instance, obj, method_name, return_value=None):49 def bind(klass, test_instance, obj, method_name,
50 return_value=None, raise_error=None, raise_on=1):
50 original_method = getattr(obj, method_name)51 original_method = getattr(obj, method_name)
51 test_instance.addCleanup(setattr, obj, method_name, original_method)52 test_instance.addCleanup(setattr, obj, method_name, original_method)
52 setattr(obj, method_name, klass(return_value))53 setattr(obj, method_name, klass(return_value, raise_error, raise_on))
5354
54 def __init__(self, return_value=None):55 def __init__(self, return_value=None, raise_error=None, raise_on=1):
55 self.called = False56 self.called = False
56 self.call_count = 057 self.call_count = 0
57 self.args = None58 self.args = None
58 self.kwargs = None59 self.kwargs = None
59 self.return_value = return_value60 self.return_value = return_value
61 self.raise_error = raise_error
62 self.raise_on = raise_on
6063
61 def __call__(self, *args, **kwargs):64 def __call__(self, *args, **kwargs):
62 self.called = True65 self.called = True
63 self.call_count += 166 self.call_count += 1
64 self.args = args67 self.args = args
65 self.kwargs = kwargs68 self.kwargs = kwargs
69 if self.raise_error is not None and self.call_count == self.raise_on:
70 raise self.raise_error
66 return self.return_value71 return self.return_value
6772
6873
6974
=== added file 'tests/test_push.py'
--- tests/test_push.py 1970-01-01 00:00:00 +0000
+++ tests/test_push.py 2012-03-04 02:24:17 +0000
@@ -0,0 +1,135 @@
1# Copyright (C) 2012 Curtis Hovey <sinzui.is@verizon.net>
2#
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 2 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program; if not, write to the Free Software
15# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
17"""Test the ui functionality."""
18
19from gi.repository import Gtk
20
21from bzrlib import (
22 errors,
23 tests,
24 ui,
25 )
26
27from bzrlib.plugins.gtk import (
28 push,
29 set_ui_factory,
30 )
31from bzrlib.plugins.gtk.tests import MockMethod
32from bzrlib.plugins.gtk.history import UrlHistory
33from bzrlib.plugins.gtk.ui import ProgressPanel
34
35
36class PushTestCase(tests.TestCaseWithMemoryTransport):
37
38 def make_push_branch(self):
39 tree = self.make_branch_and_memory_tree('test')
40 return tree.branch
41
42 def test_init(self):
43 set_ui_factory()
44 branch = self.make_push_branch()
45 dialog = push.PushDialog(
46 repository=None, revid=None, branch=branch, parent=None)
47 self.assertIs(None, dialog.props.parent)
48 self.assertIs(None, dialog.repository)
49 self.assertIs(None, dialog.revid)
50 self.assertIs(branch, dialog.branch)
51 # Layout rules to match HIG.
52 self.assertIsInstance(dialog._label_location, Gtk.Label)
53 self.assertIsInstance(dialog._combo, Gtk.ComboBox)
54 self.assertIsInstance(dialog._button_push, Gtk.Button)
55 self.assertIsInstance(dialog._hbox_location, Gtk.Box)
56 self.assertIsInstance(dialog._progress_widget, ProgressPanel)
57 self.assertIsInstance(dialog._push_message, Gtk.Label)
58 self.assertIsInstance(dialog._history, UrlHistory)
59 self.assertIs(
60 ui.ui_factory._progress_bar_widget, dialog._progress_widget)
61 self.assertEqual(
62 Gtk.Orientation.HORIZONTAL,
63 dialog._hbox_location.props.orientation)
64 self.assertEqual(0.0, dialog._push_message.props.xalign)
65 self.assertEqual(6, dialog.props.border_width)
66 self.assertEqual(6, dialog._hbox_location.props.spacing)
67 self.assertEqual(6, dialog.get_content_area().props.spacing)
68 # Show rules.
69 self.assertIs(True, dialog._combo.props.visible)
70 self.assertIs(False, dialog._progress_widget.props.visible)
71 self.assertIs(False, dialog._push_message.props.visible)
72
73 def test_build_history(self):
74 set_ui_factory()
75 branch = self.make_push_branch()
76 branch.set_push_location('lp:~user/fnord/trunk')
77 dialog = push.PushDialog(None, None, branch)
78 dialog._history.add_entry('lp:~user/fnord/test1')
79 dialog._history.add_entry('lp:~user/fnord/test2')
80 dialog._build_history()
81 self.assertEqual(
82 'lp:~user/fnord/trunk', dialog._combo.get_child().props.text)
83 self.assertIsInstance(dialog._combo_model, Gtk.ListStore)
84 self.assertIs(dialog._combo.get_model(), dialog._combo_model)
85 locations = [row[0] for row in dialog._combo_model]
86 self.assertEqual(
87 ['lp:~user/fnord/test1', 'lp:~user/fnord/test2'], locations)
88
89 def test_on_close_clicked(self):
90 # The ui_factory's progress bar widget is set to None.
91 set_ui_factory()
92 branch = self.make_push_branch()
93 dialog = push.PushDialog(None, None, branch)
94 dialog._on_close_clicked(None)
95 self.assertIs(None, ui.ui_factory._progress_bar_widget)
96
97 def test_on_push_clicked_without_errors(self):
98 # Verify the dialog's and branch's final states after a push.
99 MockMethod.bind(self, push, 'do_push', "test success")
100 set_ui_factory()
101 branch = self.make_push_branch()
102 dialog = push.PushDialog(None, None, branch)
103 MockMethod.bind(self, dialog._progress_widget, 'tick')
104 dialog._combo.get_child().props.text = 'lp:~user/fnord/test'
105 dialog._on_push_clicked(None)
106 self.assertIs(True, dialog._progress_widget.tick.called)
107 self.assertIs(False, dialog._progress_widget.props.visible)
108 self.assertIs(True, push.do_push.called)
109 self.assertEqual(
110 (branch, 'lp:~user/fnord/test'), push.do_push.args)
111 self.assertEqual(
112 {'overwrite': False}, push.do_push.kwargs)
113 self.assertIs(True, dialog._push_message.props.visible)
114 self.assertEqual('test success', dialog._push_message.props.label)
115 self.assertEqual(
116 'lp:~user/fnord/test', dialog._history.get_entries()[-1])
117 self.assertEqual('lp:~user/fnord/test', branch.get_push_location())
118
119 def test_on_push_clicked_with_divered_branches(self):
120 # Verify that when DivergedBranches is raise, the user can choose
121 # to overwrite the branch.
122 error = errors.DivergedBranches(None, None)
123 MockMethod.bind(self, push, 'do_push', raise_error=error)
124 MockMethod.bind(self, push, 'question_dialog', Gtk.ResponseType.YES)
125 set_ui_factory()
126 branch = self.make_push_branch()
127 dialog = push.PushDialog(None, None, branch)
128 dialog._combo.get_child().props.text = 'lp:~user/fnord/test'
129 dialog._on_push_clicked(None)
130 self.assertIs(True, push.do_push.called)
131 self.assertEqual(2, push.do_push.call_count)
132 self.assertEqual(
133 (branch, 'lp:~user/fnord/test'), push.do_push.args)
134 self.assertEqual(
135 {'overwrite': True}, push.do_push.kwargs)

Subscribers

People subscribed via source and target branches

to all changes: