Debian Codegraph @

lib/bind.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 #
3 # QBrz - Qt frontend to Breezy commands
4 #
5 # Contributors:
6 # Javier Der Derian <[email protected]>
7 #
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License
10 # as published by the Free Software Foundation; either version 2
11 # of the License, or (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
22
23 from PyQt5 import QtCore, QtGui, QtWidgets
24
25 from breezy import errors, osutils
26
27 from breezy.plugins.qbrz.lib.i18n import gettext
28 from breezy.plugins.qbrz.lib.subprocess import SubProcessDialog
29 from breezy.plugins.qbrz.lib.util import (
30 url_for_display,
31 )
32 from breezy.plugins.qbrz.lib.uifactory import ui_current_widget
33 from breezy.plugins.qbrz.lib.trace import (
34 reports_exception,
35 SUB_LOAD_METHOD,
36 )
37
38
39 class QBzrBindDialog(SubProcessDialog):
40
41 def __init__(self, branch, location=None, ui_mode = None):
42 self.branch = branch
43 super(QBzrBindDialog, self).__init__(
44 gettext("Bind branch"),
45 name = "bind",
46 default_size = (400, 400),
47 ui_mode = ui_mode,
48 dialog = True,
49 parent = None,
50 hide_progress=False,
51 )
52
53 # Display information fields
54 gbBind = QtWidgets.QGroupBox(gettext("Bind"), self)
55 bind_box = QtWidgets.QFormLayout(gbBind)
56 bind_box.addRow(gettext("Branch location:"),
57 QtWidgets.QLabel(url_for_display(branch.base)))
58 self.currbound = branch.get_bound_location()
59 if self.currbound != None:
60 bind_box.addRow(gettext("Currently bound to:"),
61 QtWidgets.QLabel(url_for_display(self.currbound)))
62
63 # Build the "Bind to" widgets
64 branch_label = QtWidgets.QLabel(gettext("Bind to:"))
65 branch_combo = QtWidgets.QComboBox()
66 branch_combo.setEditable(True)
67 self.branch_combo = branch_combo
68 browse_button = QtWidgets.QPushButton(gettext("Browse"))
69 browse_button.clicked[bool].connect(self.browse_clicked)
70
71 # Add some useful values into the combo box. If a location was given,
72 # default to it. If an old bound location exists, suggest it.
73 # Otherwise suggest the parent branch, if any.
74 suggestions = []
75 if location:
76 suggestions.append(osutils.abspath(location))
77 self._maybe_add_suggestion(suggestions, branch.get_old_bound_location())
78 self._maybe_add_suggestion(suggestions, branch.get_parent())
79 self._maybe_add_suggestion(suggestions, branch.get_push_location())
80 if suggestions:
81 branch_combo.addItems(suggestions)
82
83 # Build the "Bind to" row/panel
84 bind_hbox = QtWidgets.QHBoxLayout()
85 bind_hbox.addWidget(branch_label)
86 bind_hbox.addWidget(branch_combo)
87 bind_hbox.addWidget(browse_button)
88 bind_hbox.setStretchFactor(branch_label,0)
89 bind_hbox.setStretchFactor(branch_combo,1)
90 bind_hbox.setStretchFactor(browse_button,0)
91 bind_box.addRow(bind_hbox)
92
93 # Put the form together
94 layout = QtWidgets.QVBoxLayout(self)
95 layout.addWidget(gbBind)
96 layout.addWidget(self.make_default_status_box())
97 layout.addWidget(self.buttonbox)
98
99 branch_combo.setFocus()
100
101 def _maybe_add_suggestion(self, suggestions, location):
102 if location:
103 url = url_for_display(location)
104 if url not in suggestions:
105 suggestions.append(url)
106
107 def browse_clicked(self):
108 fileName = QtWidgets.QFileDialog.getExistingDirectory(self,
109 gettext("Select branch location"));
110 if fileName != '':
111 self.branch_combo.insertItem(0,fileName)
112 self.branch_combo.setCurrentIndex(0)
113
114 def _get_location(self):
115 return str(self.branch_combo.currentText())
116
117 def validate(self):
118 if not self._get_location():
119 self.operation_blocked(gettext("Master branch location not specified."))
120 return False
121 return True
122
123 def do_start(self):
124 self.process_widget.do_start(None, 'bind', self._get_location())