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
13 def create_listwidget_item(text
, filename
):
14 icon
= QIcon(QPixmap(filename
))
15 item
= QListWidgetItem()
20 def information(parent
, title
, message
):
21 '''Launches a QMessageBox information with the
22 provided title and message.'''
23 QMessageBox
.information(parent
, title
, message
)
25 def get_selected_row(list_widget
):
26 '''Returns a(row_number, is_selected) tuple for a QListWidget.'''
27 row
= list_widget
.currentRow()
28 item
= list_widget
.item(row
)
29 selected
= item
is not None and item
.isSelected()
32 def get_selection_list(list_widget
, items
):
33 '''Returns an array of model items that correspond to
34 the selected QListWidget indices.'''
36 for idx
in range(list_widget
.count()):
37 item
= list_widget
.item(idx
)
39 selected
.append(items
[idx
])
42 def get_selected_item(list_widget
, items
):
43 selected
= get_selection_list(list_widget
, items
)
44 if not selected
: return None
47 def open_dialog(parent
, title
, filename
=None):
48 qstr
= QFileDialog
.getOpenFileName(
49 parent
, parent
.tr(title
), filename
)
52 def save_dialog(parent
, title
, filename
=None):
53 qstr
= QFileDialog
.getSaveFileName(
54 parent
, parent
.tr(title
), filename
)
57 def dir_dialog(parent
, title
, directory
):
58 directory
= QFileDialog
.getExistingDirectory(
59 parent
, title
, directory
)
60 return unicode(directory
)
62 def question(parent
, title
, message
, default
=True):
63 '''Launches a QMessageBox question with the provided title and message.
64 Passing "default=False" will make "No" the default choice.'''
74 result
= QMessageBox
.question(parent
,
75 title
, message
, buttons
, default
)
76 return result
== QMessageBox
.Yes
78 def set_clipboard(text
):
79 QtGui
.qApp
.clipboard().setText(text
, QClipboard
.Clipboard
)
80 QtGui
.qApp
.clipboard().setText(text
, QClipboard
.Selection
)
82 def add_items(widget
, items
):
83 for item
in items
: widget
.addItem(item
)
85 def set_items(widget
, items
):
87 add_items(widget
, items
)
89 def show_command(parent
, output
):
91 dialog
= views
.CommandDialog(parent
, output
=output
)
96 trtext
= unicode(QtGui
.qApp
.tr(txt
))
97 if trtext
.endswith('@@verb'):
98 trtext
= trtext
.replace('@@verb','')
99 if trtext
.endswith('@@noun'):
100 trtext
= trtext
.replace('@@noun','')
103 def create_item(filename
, staged
, untracked
=False):
104 '''Given a filename, return a QListWidgetItem suitable
105 for adding to a QListWidget. "staged" controls whether
106 to use icons for the staged or unstaged list widget.'''
108 icon_file
= utils
.get_staged_icon(filename
)
110 icon_file
= utils
.get_untracked_icon()
112 icon_file
= utils
.get_icon(filename
)
114 return create_listwidget_item(filename
, icon_file
)