1 from PyQt4
import QtCore
2 from PyQt4
import QtGui
3 from PyQt4
.QtCore
import SIGNAL
5 from cola
.views
import standard
8 class ComboView(standard
.StandardDialog
):
9 """A dialog for choosing branches."""
11 def __init__(self
, parent
=None, title
='', items
=None):
12 standard
.StandardDialog
.__init
__(self
, parent
=parent
)
14 self
.setWindowTitle(title
)
16 self
._main
_layt
= QtGui
.QVBoxLayout(self
)
19 self
.items_widget
= QtGui
.QComboBox(self
)
20 self
.items_widget
.setEditable(True)
22 self
._main
_layt
.addWidget(self
.items_widget
)
24 self
.button_box
= QtGui
.QDialogButtonBox(self
)
25 self
.button_box
.setOrientation(QtCore
.Qt
.Horizontal
)
26 self
.button_box
.setStandardButtons(QtGui
.QDialogButtonBox
.Ok |
27 QtGui
.QDialogButtonBox
.Cancel
)
29 self
._main
_layt
.addWidget(self
.button_box
)
30 self
.setTabOrder(self
.items_widget
, self
.button_box
)
33 self
.items_widget
.addItems(items
)
35 self
.connect(self
.button_box
, SIGNAL('accepted()'), self
.accept
)
36 self
.connect(self
.button_box
, SIGNAL('rejected()'), self
.reject
)
39 return self
.items_widget
.currentIndex()
42 return str(self
.items_widget
.currentText())
45 """Present the dialog and return the chosen item."""
46 geom
= QtGui
.QApplication
.instance().desktop().screenGeometry()
48 height
= geom
.height()
50 x
= self
.parent().x() + self
.parent().width()/2 - self
.width()/2
51 y
= self
.parent().y() + self
.parent().height()/3 - self
.height()/2
54 if self
.exec_() == QtGui
.QDialog
.Accepted
:
60 if __name__
== "__main__":
62 app
= QtGui
.QApplication(sys
.argv
)