Esempio n. 1
0
 def test_on_close_clicked(self):
     # The ui_factory's progress bar widget is set to None.
     set_ui_factory()
     branch = self.make_push_branch()
     dialog = push.PushDialog(None, None, branch)
     dialog._on_close_clicked(None)
     self.assertIs(None, ui.ui_factory._progress_bar_widget)
Esempio n. 2
0
 def test_init(self):
     set_ui_factory()
     branch = self.make_push_branch()
     dialog = push.PushDialog(
         repository=None, revid=None, branch=branch, parent=None)
     self.assertIs(None, dialog.props.parent)
     self.assertIs(branch.repository, dialog.repository)
     self.assertIs(branch.last_revision(), dialog.revid)
     self.assertIs(branch, dialog.branch)
     # Layout rules to match HIG.
     self.assertIsInstance(dialog._label_location, Gtk.Label)
     self.assertIsInstance(dialog._combo, Gtk.ComboBox)
     self.assertIsInstance(dialog._button_push, Gtk.Button)
     self.assertIsInstance(dialog._hbox_location, Gtk.Box)
     self.assertIsInstance(dialog._progress_widget, ProgressPanel)
     self.assertIsInstance(dialog._push_message, Gtk.Label)
     self.assertIsInstance(dialog._history, UrlHistory)
     self.assertIs(
         ui.ui_factory._progress_bar_widget, dialog._progress_widget)
     self.assertEqual(
         Gtk.Orientation.HORIZONTAL,
         dialog._hbox_location.props.orientation)
     self.assertEqual(0.0, dialog._push_message.props.xalign)
     self.assertEqual(6, dialog.props.border_width)
     self.assertEqual(6, dialog._hbox_location.props.spacing)
     self.assertEqual(6, dialog.get_content_area().props.spacing)
     # Show rules.
     self.assertIs(True, dialog._combo.props.visible)
     self.assertIs(False, dialog._progress_widget.props.visible)
     self.assertIs(False, dialog._push_message.props.visible)
Esempio n. 3
0
 def setup_ui(self):
     set_ui_factory()
     progress_panel = ProgressPanel()
     ui.ui_factory.set_progress_bar_widget(progress_panel)
     MockMethod.bind(self, progress_panel.pb, 'tick')
     MockMethod.bind(self, progress_panel.pb, 'update')
     MockMethod.bind(self, progress_panel.pb, 'finished')
     return progress_panel
Esempio n. 4
0
 def test_build_history(self):
     set_ui_factory()
     branch = self.make_push_branch()
     branch.set_push_location('lp:~user/fnord/trunk')
     dialog = push.PushDialog(None, None, branch)
     dialog._history.add_entry('lp:~user/fnord/test1')
     dialog._history.add_entry('lp:~user/fnord/test2')
     dialog._build_history()
     self.assertEqual(
         'lp:~user/fnord/trunk', dialog._combo.get_child().props.text)
     self.assertIsInstance(dialog._combo_model, Gtk.ListStore)
     self.assertIs(dialog._combo.get_model(), dialog._combo_model)
     locations = [row[0] for row in dialog._combo_model]
     self.assertEqual(
         ['lp:~user/fnord/test1', 'lp:~user/fnord/test2'], locations)
Esempio n. 5
0
 def run(self, locations_list, revision=None, limit=None):
     set_ui_factory()
     if locations_list is None:
         locations_list = ["."]
     revids = []
     for location in locations_list:
         (br, path) = branch.Branch.open_containing(location)
         if revision is None:
             revids.append(br.last_revision())
         else:
             revids.append(revision[0].as_revision_id(br))
     from gi.repository import Gtk
     pp = start_viz_window(br, revids, limit)
     pp.connect("destroy", lambda w: Gtk.main_quit())
     pp.show()
     Gtk.main()
Esempio n. 6
0
 def test_on_push_clicked_with_divered_branches(self):
     # Verify that when DivergedBranches is raise, the user can choose
     # to overwrite the branch.
     error = errors.DivergedBranches(None, None)
     MockMethod.bind(self, push, 'do_push', raise_error=error)
     MockMethod.bind(self, push, 'question_dialog', Gtk.ResponseType.YES)
     set_ui_factory()
     branch = self.make_push_branch()
     dialog = push.PushDialog(None, None, branch)
     dialog._combo.get_child().props.text = 'lp:~user/fnord/test'
     dialog._on_push_clicked(None)
     self.assertIs(True, push.do_push.called)
     self.assertEqual(2, push.do_push.call_count)
     self.assertEqual(
         (branch, 'lp:~user/fnord/test'), push.do_push.args)
     self.assertEqual(
         {'overwrite': True}, push.do_push.kwargs)
Esempio n. 7
0
 def test_on_push_clicked_without_errors(self):
     # Verify the dialog's and branch's final states after a push.
     MockMethod.bind(self, push, 'do_push', "test success")
     set_ui_factory()
     branch = self.make_push_branch()
     dialog = push.PushDialog(None, None, branch)
     MockMethod.bind(self, dialog._progress_widget, 'tick')
     dialog._combo.get_child().props.text = 'lp:~user/fnord/test'
     dialog._on_push_clicked(None)
     self.assertIs(True, dialog._progress_widget.tick.called)
     self.assertIs(False, dialog._progress_widget.props.visible)
     self.assertIs(True, push.do_push.called)
     self.assertEqual(
         (branch, 'lp:~user/fnord/test'), push.do_push.args)
     self.assertEqual(
         {'overwrite': False}, push.do_push.kwargs)
     self.assertIs(True, dialog._push_message.props.visible)
     self.assertEqual('test success', dialog._push_message.props.label)
     self.assertEqual(
         'lp:~user/fnord/test', dialog._history.get_entries()[-1])
     self.assertEqual('lp:~user/fnord/test', branch.get_push_location())
Esempio n. 8
0
    def run(self, revision=None, filename=None):
        set_ui_factory()
        wt = workingtree.WorkingTree.open_containing(".")[0]
        wt.lock_read()
        try:
            branch = wt.branch
            if revision is not None:
                if len(revision) == 1:
                    tree1 = wt
                    revision_id = revision[0].as_revision_id(tree1.branch)
                    tree2 = branch.repository.revision_tree(revision_id)
                elif len(revision) == 2:
                    revision_id_0 = revision[0].as_revision_id(branch)
                    tree2 = branch.repository.revision_tree(revision_id_0)
                    revision_id_1 = revision[1].as_revision_id(branch)
                    tree1 = branch.repository.revision_tree(revision_id_1)
            else:
                tree1 = wt
                tree2 = tree1.basis_tree()

            from diff import DiffWindow
            from gi.repository import Gtk
            window = DiffWindow()
            window.connect("destroy", Gtk.main_quit)
            window.set_diff("Working Tree", tree1, tree2)
            if filename is not None:
                tree_filename = wt.relpath(filename)
                try:
                    window.set_file(tree_filename)
                except NoSuchFile:
                    if (tree1.path2id(tree_filename) is None and 
                        tree2.path2id(tree_filename) is None):
                        raise NotVersionedError(filename)
                    raise BzrCommandError('No changes found for file "%s"' % 
                                          filename)
            window.show()

            Gtk.main()
        finally:
            wt.unlock()
Esempio n. 9
0

class NoDisplayError(errors.BzrCommandError):
    """gtk could not find a proper display"""

    def __str__(self):
        return "No DISPLAY. Unable to run GTK+ application."


def open_display():
    try:
        from gi.repository import Gtk
    except RuntimeError, e:
        if str(e) == "could not open display":
            raise NoDisplayError
    set_ui_factory()
    return Gtk



class GTKCommand(Command):
    """Abstract class providing GTK specific run commands."""

    def run(self):
        open_display()
        dialog = self.get_gtk_dialog(os.path.abspath('.'))
        dialog.run()


class cmd_gbranch(GTKCommand):
    """GTK+ branching.