models.gitrepo: Use a custom event type for GitRepoInfoEvents
[git-cola.git] / cola / views / remote.py
blob8431a218c1672ce001f13e91fca55bad07daaedb
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
13 """
14 standard.StandardDialog.__init__(self, parent=parent)
16 self.resize(550, 512)
17 self._main_vbox_layt = QtGui.QVBoxLayout(self)
19 # Local branch section
20 self._local_branch_hbox_layt = QtGui.QHBoxLayout()
21 # Exposed
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)
25 # Exposed
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)
29 # Exposed
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)
38 # Exposed
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)
42 # Exposed
43 self.remotes = QtGui.QListWidget(self)
44 self._main_vbox_layt.addWidget(self.remotes)
46 self._remote_branches_hbox_layt = QtGui.QHBoxLayout()
47 # Exposed
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)
51 # Exposed
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()
60 # Exposed
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)
66 # Exposed
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)
78 # Exposed
79 self.action_button = QtGui.QPushButton(self)
80 self.action_button.setText(self.tr('Push'))
81 self._options_hbox_layt.addWidget(self.action_button)
82 # Exposed
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)
87 if action:
88 self.action_button.setText(action.title())
89 self.setWindowTitle(action.title())
90 if action == 'pull':
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()
96 if action != 'pull':
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)
108 if item:
109 self.remotes.setItemSelected(item, True)
110 self.remotes.setCurrentItem(item)
111 self.remotename.setText(item.text())
112 return True
113 else:
114 return False
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)
119 if not item:
120 return False
121 self.local_branches.setItemSelected(item, True)
122 self.local_branches.setCurrentItem(item)
123 self.local_branch.setText(item.text())
124 return True
127 if __name__ == "__main__":
128 import sys
129 app = QtGui.QApplication(sys.argv)
130 remote = RemoteView()
131 remote.show()
132 sys.exit(app.exec_())