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()
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.'''
32 for idx
in range (list_widget
.count()):
33 item
= list_widget
.item (idx
)
35 selected
.append (items
[idx
])
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.'''
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
):
62 dialog
= GitCommandDialog (parent
, output
=output
)