1 from PyQt4
import QtCore
2 from PyQt4
import QtGui
3 from PyQt4
.QtGui
import QClipboard
4 from PyQt4
.QtGui
import QFileDialog
5 from PyQt4
.QtGui
import QIcon
6 from PyQt4
.QtGui
import QListWidgetItem
7 from PyQt4
.QtGui
import QMessageBox
8 from PyQt4
.QtGui
import QPixmap
11 def create_listwidget_item(text
, filename
):
12 icon
= QIcon(QPixmap(filename
))
13 item
= QListWidgetItem()
18 def information(parent
, title
, message
):
19 '''Launches a QMessageBox information with the
20 provided title and message.'''
21 QMessageBox
.information(parent
, title
, message
)
23 def get_selected_row(list_widget
):
24 '''Returns a(row_number, is_selected) tuple for a QListWidget.'''
25 row
= list_widget
.currentRow()
26 item
= list_widget
.item(row
)
27 selected
= item
is not None and item
.isSelected()
30 def get_selection_list(list_widget
, items
):
31 '''Returns an array of model items that correspond to
32 the selected QListWidget indices.'''
34 for idx
in range(list_widget
.count()):
35 item
= list_widget
.item(idx
)
37 selected
.append(items
[idx
])
40 def get_selected_item(list_widget
, items
):
41 selected
= get_selection_list(list_widget
, items
)
42 if not selected
: return None
45 def open_dialog(parent
, title
, filename
=None):
46 qstr
= QFileDialog
.getOpenFileName(
47 parent
, title
, filename
)
50 def save_dialog(parent
, title
, filename
=None):
51 qstr
= QFileDialog
.getSaveFileName(
52 parent
, title
, filename
)
55 def dir_dialog(parent
, title
, directory
):
56 directory
= QFileDialog
.getExistingDirectory(
57 parent
, title
, directory
)
58 return unicode(directory
)
60 def question(parent
, title
, message
, default
=True):
61 '''Launches a QMessageBox question with the provided title and message.
62 Passing "default=False" will make "No" the default choice.'''
72 result
= QMessageBox
.question(parent
,
73 title
, message
, buttons
, default
)
74 return result
== QMessageBox
.Yes
76 def set_clipboard(text
):
77 QtGui
.qApp
.clipboard().setText(text
, QClipboard
.Clipboard
)
78 QtGui
.qApp
.clipboard().setText(text
, QClipboard
.Selection
)
80 def set_items(widget
, items
):
82 for item
in items
: widget
.addItem(item
)
84 def show_command(parent
, output
):
86 dialog
= views
.GitCommandDialog(parent
, output
=output
)
91 trtext
= unicode(QtGui
.qApp
.tr(txt
))
92 if trtext
.endswith('@@verb'):
93 trtext
= trtext
.replace('@@verb','')
94 if trtext
.endswith('@@noun'):
95 trtext
= trtext
.replace('@@noun','')