Added interactive diff gui
[ugit.git] / py / qtutils.py
blobf1fdd496098d382f72cc6cf16236f618783461fb
1 from PyQt4 import QtGui
2 from PyQt4.QtGui import QClipboard
3 from PyQt4.QtGui import QIcon
4 from PyQt4.QtGui import QListWidgetItem
5 from PyQt4.QtGui import QMessageBox
6 from PyQt4.QtGui import QPixmap
7 from views import GitCommandDialog
9 def create_listwidget_item (text, filename):
10 icon = QIcon (QPixmap (filename))
11 item = QListWidgetItem()
12 item.setIcon (icon)
13 item.setText (text)
14 return item
16 def information (parent, title, message):
17 '''Launches a QMessageBox information with the
18 provided title and message.'''
19 QMessageBox.information(parent, title, message)
21 def get_selected_row (list_widget):
22 '''Returns a (row_number, is_selected) tuple for a QListWidget.'''
23 row = list_widget.currentRow()
24 item = list_widget.item (row)
25 selected = item is not None and item.isSelected()
26 return (row, selected)
28 def get_selection_from_list (list_widget, items):
29 '''Returns an array of model items that correspond to
30 the selected QListWidget indices.'''
31 selected = []
32 for idx in range (list_widget.count()):
33 item = list_widget.item (idx)
34 if item.isSelected():
35 selected.append (items[idx])
36 return selected
38 def qapp (): return QtGui.qApp
40 def question (parent, title, message, default=True):
41 '''Launches a QMessageBox question with the provided title and message.
42 Passing "default=False" will make "No" the default choice.'''
43 yes = QMessageBox.Yes
44 no = QMessageBox.No
45 buttons = yes | no
47 if default:
48 default = yes
49 else:
50 default = no
52 result = QMessageBox.question (parent,
53 title, message, buttons, default)
54 return result == QMessageBox.Yes
56 def set_clipboard (text):
57 qapp().clipboard().setText (text, QClipboard.Clipboard)
58 qapp().clipboard().setText (text, QClipboard.Selection)
60 def show_command (parent, output):
61 if not output: return
62 dialog = GitCommandDialog (parent, output=output)
63 dialog.show()
64 dialog.exec_()