~ubuntu-branches/ubuntu/vivid/git-cola/vivid-proposed

« back to all changes in this revision

Viewing changes to cola/qtutils.py

  • Committer: Package Import Robot
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2014-09-06 09:21:48 UTC
  • mfrom: (1.3.25)
  • Revision ID: package-import@ubuntu.com-20140906092148-flthdpxj2ytedr6d
Tags: 2.0.6-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
 
63
63
class TreeWidgetItem(QtGui.QTreeWidgetItem):
64
64
 
65
 
    def __init__(self, text, filename, exists):
 
65
    TYPE = QtGui.QStandardItem.UserType + 101
 
66
 
 
67
    def __init__(self, path, icon, exists):
66
68
        QtGui.QTreeWidgetItem.__init__(self)
 
69
        self.path = path
67
70
        self.exists = exists
68
 
        self.setIcon(0, cached_icon_from_path(filename))
69
 
        self.setText(0, text)
 
71
        self.setIcon(0, cached_icon_from_path(icon))
 
72
        self.setText(0, path)
 
73
 
 
74
    def type(self):
 
75
        return self.TYPE
70
76
 
71
77
 
72
78
def create_treewidget_item(text, filename, exists=True):
74
80
    return TreeWidgetItem(text, filename, exists)
75
81
 
76
82
 
 
83
def paths_from_indexes(model, indexes,
 
84
                       item_type=TreeWidgetItem.TYPE,
 
85
                       item_filter=None):
 
86
    """Return paths from a list of QStandardItemModel indexes"""
 
87
    items = [model.itemFromIndex(i) for i in indexes]
 
88
    return paths_from_items(items, item_type=item_type, item_filter=item_filter)
 
89
 
 
90
 
 
91
def paths_from_items(items,
 
92
                     item_type=TreeWidgetItem.TYPE,
 
93
                     item_filter=None):
 
94
    """Return a list of paths from a list of items"""
 
95
    if item_filter is None:
 
96
        item_filter = lambda x: True
 
97
    return [i.path for i in items
 
98
            if i.type() == item_type and item_filter(i)]
 
99
 
 
100
 
77
101
@memoize
78
102
def cached_icon_from_path(filename):
79
103
    return QtGui.QIcon(filename)
279
303
    flags = (QtGui.QFileDialog.ShowDirsOnly |
280
304
             QtGui.QFileDialog.DontResolveSymlinks)
281
305
    return ustr(QtGui.QFileDialog
282
 
                        .getExistingDirectory(active_window(),
283
 
                                              title, path, flags))
 
306
                     .getExistingDirectory(active_window(),
 
307
                                           title, path, flags))
284
308
 
285
309
 
286
310
def save_as(filename, title='Save As...'):
457
481
    return icon('options.svg')
458
482
 
459
483
 
 
484
def filter_icon():
 
485
    """Return a filter icon"""
 
486
    return icon('view-filter.png')
 
487
 
 
488
 
460
489
def dir_close_icon():
461
490
    """Return a standard closed directory icon"""
462
491
    return cached_icon(QtGui.QStyle.SP_DirClosedIcon)
554
583
    button.setCursor(Qt.PointingHandCursor)
555
584
    if text:
556
585
        button.setText(text)
557
 
    if icon:
 
586
    if icon is not None:
558
587
        button.setIcon(icon)
559
588
    if tooltip is not None:
560
589
        button.setToolTip(tooltip)
689
718
    return button
690
719
 
691
720
 
 
721
def mimedata_from_paths(paths):
 
722
    """Return mimedata with a list of absolute path URLs"""
 
723
    urls = [QtCore.QUrl(core.abspath(path)) for path in paths]
 
724
    mimedata = QtCore.QMimeData()
 
725
    mimedata.setUrls(urls)
 
726
    return mimedata
 
727
 
692
728
# Syntax highlighting
693
729
 
694
730
def TERMINAL(pattern):