1 from PyQt4
import QtCore
2 from PyQt4
import QtGui
3 from PyQt4
.QtCore
import SIGNAL
5 from cola
.views
import standard
8 class RemoteView(standard
.StandardDialog
):
9 """A dialog for choosing branches."""
11 def __init__(self
, parent
, action
):
12 """Customizes the dialog based on the remote action
14 standard
.StandardDialog
.__init
__(self
, parent
=parent
)
17 self
._main
_vbox
_layt
= QtGui
.QVBoxLayout(self
)
19 # Local branch section
20 self
._local
_branch
_hbox
_layt
= QtGui
.QHBoxLayout()
22 self
.local_label
= QtGui
.QLabel(self
)
23 self
.local_label
.setText(self
.tr('Local Branches'))
25 self
.local_branch
= QtGui
.QLineEdit(self
)
27 self
.local_branches
= QtGui
.QListWidget(self
)
29 # Remote branch section
30 self
._remote
_branch
_hbox
_layt
= QtGui
.QHBoxLayout()
31 self
._remote
_label
= QtGui
.QLabel(self
)
32 self
._remote
_label
.setText(self
.tr('Remote'))
34 self
.remotename
= QtGui
.QLineEdit(self
)
36 self
.remotes
= QtGui
.QListWidget(self
)
38 self
._remote
_branches
_hbox
_layt
= QtGui
.QHBoxLayout()
40 self
.remote_label
= QtGui
.QLabel(self
)
41 self
.remote_label
.setText(self
.tr('Remote Branch'))
43 self
.remote_branch
= QtGui
.QLineEdit(self
)
44 self
.remote_branches
= QtGui
.QListWidget(self
)
46 self
._options
_hbox
_layt
= QtGui
.QHBoxLayout()
48 self
.ffwd_only_checkbox
= QtGui
.QCheckBox(self
)
49 self
.ffwd_only_checkbox
.setText(self
.tr('Fast Forward Only'))
50 self
.ffwd_only_checkbox
.setChecked(True)
51 self
.ffwd_only_checkbox
.setObjectName("ffwd_only_checkbox")
54 self
.tags_checkbox
= QtGui
.QCheckBox(self
)
55 self
.tags_checkbox
.setText(self
.tr('Include tags'))
57 self
.rebase_checkbox
= QtGui
.QCheckBox(self
)
58 self
.rebase_checkbox
.setText(self
.tr('Rebase'))
60 self
._options
_spacer
= QtGui
.QSpacerItem(1, 1,
61 QtGui
.QSizePolicy
.Expanding
,
62 QtGui
.QSizePolicy
.Minimum
)
63 self
._options
_hbox
_layt
.addItem(self
._options
_spacer
)
65 self
.action_button
= QtGui
.QPushButton(self
)
66 self
.action_button
.setText(self
.tr('Push'))
68 self
.cancel_button
= QtGui
.QPushButton(self
)
69 self
.cancel_button
.setText(self
.tr('Cancel'))
72 self
.connect(self
.cancel_button
, SIGNAL('released()'), self
.reject
)
75 self
.action_button
.setText(action
.title())
76 self
.setWindowTitle(action
.title())
79 self
.tags_checkbox
.hide()
80 self
.ffwd_only_checkbox
.hide()
81 self
.local_label
.hide()
82 self
.local_branch
.hide()
83 self
.local_branches
.hide()
84 self
.remote_branch
.setFocus(True)
86 self
.rebase_checkbox
.hide()
88 # Action-dependent focus
90 self
.remotename
.setFocus(True)
93 self
.local_branch
.setFocus(True)
97 self
.layout_remote_branches()
98 self
.layout_local_branches()
99 elif action
== 'pull':
100 self
.layout_remote_branches()
101 self
.layout_remotes()
102 self
.layout_local_branches()
104 self
.layout_local_branches()
105 self
.layout_remotes()
106 self
.layout_remote_branches()
108 self
.layout_options()
110 def layout_options(self
):
111 self
._options
_hbox
_layt
.addWidget(self
.ffwd_only_checkbox
)
112 self
._options
_hbox
_layt
.addWidget(self
.tags_checkbox
)
113 self
._options
_hbox
_layt
.addWidget(self
.rebase_checkbox
)
114 self
._options
_hbox
_layt
.addWidget(self
.action_button
)
115 self
._options
_hbox
_layt
.addWidget(self
.cancel_button
)
116 self
._main
_vbox
_layt
.addLayout(self
._options
_hbox
_layt
)
118 def layout_local_branches(self
):
119 self
._local
_branch
_hbox
_layt
.addWidget(self
.local_label
)
120 self
._local
_branch
_hbox
_layt
.addWidget(self
.local_branch
)
121 self
._main
_vbox
_layt
.addLayout(self
._local
_branch
_hbox
_layt
)
122 self
._main
_vbox
_layt
.addWidget(self
.local_branches
)
124 def layout_remotes(self
):
125 self
._remote
_branch
_hbox
_layt
.addWidget(self
._remote
_label
)
126 self
._remote
_branch
_hbox
_layt
.addWidget(self
.remotename
)
127 self
._main
_vbox
_layt
.addLayout(self
._remote
_branch
_hbox
_layt
)
128 self
._main
_vbox
_layt
.addWidget(self
.remotes
)
130 def layout_remote_branches(self
):
131 self
._remote
_branches
_hbox
_layt
.addWidget(self
.remote_label
)
132 self
._remote
_branches
_hbox
_layt
.addWidget(self
.remote_branch
)
133 self
._main
_vbox
_layt
.addLayout(self
._remote
_branches
_hbox
_layt
)
134 self
._main
_vbox
_layt
.addWidget(self
.remote_branches
)
136 def select_first_remote(self
):
137 """Selects the first remote in the list view"""
138 return self
.select_remote(0)
140 def select_remote(self
, idx
):
141 """Selects a remote by index"""
142 item
= self
.remotes
.item(idx
)
144 self
.remotes
.setItemSelected(item
, True)
145 self
.remotes
.setCurrentItem(item
)
146 self
.remotename
.setText(item
.text())
151 def select_local_branch(self
, idx
):
152 """Selects a local branch by index in the list view"""
153 item
= self
.local_branches
.item(idx
)
156 self
.local_branches
.setItemSelected(item
, True)
157 self
.local_branches
.setCurrentItem(item
)
158 self
.local_branch
.setText(item
.text())
162 if __name__
== "__main__":
164 app
= QtGui
.QApplication(sys
.argv
)
165 remote
= RemoteView()
167 sys
.exit(app
.exec_())