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'))
24 self
._local
_branch
_hbox
_layt
.addWidget(self
.local_label
)
26 self
.local_branch
= QtGui
.QLineEdit(self
)
27 self
._local
_branch
_hbox
_layt
.addWidget(self
.local_branch
)
28 self
._main
_vbox
_layt
.addLayout(self
._local
_branch
_hbox
_layt
)
30 self
.local_branches
= QtGui
.QListWidget(self
)
31 self
._main
_vbox
_layt
.addWidget(self
.local_branches
)
33 # Remote branch section
34 self
._remote
_branch
_hbox
_layt
= QtGui
.QHBoxLayout()
35 self
._remote
_label
= QtGui
.QLabel(self
)
36 self
._remote
_label
.setText(self
.tr('Remote'))
37 self
._remote
_branch
_hbox
_layt
.addWidget(self
._remote
_label
)
39 self
.remotename
= QtGui
.QLineEdit(self
)
40 self
._remote
_branch
_hbox
_layt
.addWidget(self
.remotename
)
41 self
._main
_vbox
_layt
.addLayout(self
._remote
_branch
_hbox
_layt
)
43 self
.remotes
= QtGui
.QListWidget(self
)
44 self
._main
_vbox
_layt
.addWidget(self
.remotes
)
46 self
._remote
_branches
_hbox
_layt
= QtGui
.QHBoxLayout()
48 self
.remote_label
= QtGui
.QLabel(self
)
49 self
.remote_label
.setText(self
.tr('Remote Branch'))
50 self
._remote
_branches
_hbox
_layt
.addWidget(self
.remote_label
)
52 self
.remote_branch
= QtGui
.QLineEdit(self
)
53 self
._remote
_branches
_hbox
_layt
.addWidget(self
.remote_branch
)
54 self
._main
_vbox
_layt
.addLayout(self
._remote
_branches
_hbox
_layt
)
56 self
.remote_branches
= QtGui
.QListWidget(self
)
57 self
._main
_vbox
_layt
.addWidget(self
.remote_branches
)
59 self
._options
_hbox
_layt
= QtGui
.QHBoxLayout()
61 self
.ffwd_only_checkbox
= QtGui
.QCheckBox(self
)
62 self
.ffwd_only_checkbox
.setText(self
.tr('Fast Forward Only'))
63 self
.ffwd_only_checkbox
.setChecked(True)
64 self
.ffwd_only_checkbox
.setObjectName("ffwd_only_checkbox")
65 self
._options
_hbox
_layt
.addWidget(self
.ffwd_only_checkbox
)
67 self
.tags_checkbox
= QtGui
.QCheckBox(self
)
68 self
.tags_checkbox
.setText(self
.tr('Include tags'))
69 self
._options
_hbox
_layt
.addWidget(self
.tags_checkbox
)
70 self
.rebase_checkbox
= QtGui
.QCheckBox(self
)
71 self
.rebase_checkbox
.setText(self
.tr('Rebase'))
72 self
._options
_hbox
_layt
.addWidget(self
.rebase_checkbox
)
74 self
._options
_spacer
= QtGui
.QSpacerItem(1, 1,
75 QtGui
.QSizePolicy
.Expanding
,
76 QtGui
.QSizePolicy
.Minimum
)
77 self
._options
_hbox
_layt
.addItem(self
._options
_spacer
)
79 self
.action_button
= QtGui
.QPushButton(self
)
80 self
.action_button
.setText(self
.tr('Push'))
81 self
._options
_hbox
_layt
.addWidget(self
.action_button
)
83 self
.cancel_button
= QtGui
.QPushButton(self
)
84 self
.cancel_button
.setText(self
.tr('Cancel'))
85 self
._options
_hbox
_layt
.addWidget(self
.cancel_button
)
86 self
._main
_vbox
_layt
.addLayout(self
._options
_hbox
_layt
)
88 self
.action_button
.setText(action
.title())
89 self
.setWindowTitle(action
.title())
91 self
.tags_checkbox
.hide()
92 self
.ffwd_only_checkbox
.hide()
93 self
.local_label
.hide()
94 self
.local_branch
.hide()
95 self
.local_branches
.hide()
97 self
.rebase_checkbox
.hide()
99 self
.connect(self
.cancel_button
, SIGNAL('released()'), self
.reject
)
101 def select_first_remote(self
):
102 """Selects the first remote in the list view"""
103 return self
.select_remote(0)
105 def select_remote(self
, idx
):
106 """Selects a remote by index"""
107 item
= self
.remotes
.item(idx
)
109 self
.remotes
.setItemSelected(item
, True)
110 self
.remotes
.setCurrentItem(item
)
111 self
.remotename
.setText(item
.text())
116 def select_local_branch(self
, idx
):
117 """Selects a local branch by index in the list view"""
118 item
= self
.local_branches
.item(idx
)
121 self
.local_branches
.setItemSelected(item
, True)
122 self
.local_branches
.setCurrentItem(item
)
123 self
.local_branch
.setText(item
.text())
127 if __name__
== "__main__":
129 app
= QtGui
.QApplication(sys
.argv
)
130 remote
= RemoteView()
132 sys
.exit(app
.exec_())