PageRenderTime 40ms CodeModel.GetById 19ms app.highlight 16ms RepoModel.GetById 1ms app.codeStats 0ms

/tortoisehg/hgqt/logcolumns.py

https://bitbucket.org/tortoisehg/hgtk/
Python | 89 lines | 67 code | 13 blank | 9 comment | 19 complexity | 8726b5890fdd6925a82443df655e0017 MD5 | raw file
 1# logcolumns.py - select and reorder columns in log model
 2#
 3# Copyright 2010 Steve Borho <steve@borho.org>
 4#
 5# This software may be used and distributed according to the terms of the
 6# GNU General Public License version 2, incorporated herein by reference.
 7
 8import os
 9
10from tortoisehg.hgqt import qtlib
11from tortoisehg.util import hglib
12from tortoisehg.hgqt.i18n import _
13from tortoisehg.hgqt import repomodel
14
15from PyQt4.QtCore import *
16from PyQt4.QtGui import *
17
18class ColumnSelectDialog(QDialog):
19    def __init__(self, all, curcolumns=None, parent=None):
20        QDialog.__init__(self, parent)
21
22        self.setWindowTitle(_('Workbench Log Columns'))
23        self.setWindowFlags(self.windowFlags() & \
24                            ~Qt.WindowContextHelpButtonHint)
25        self.setMinimumSize(250, 265)
26
27        self.curcolumns = curcolumns
28        if not self.curcolumns:
29            s = QSettings()
30            cols = s.value('workbench/columns').toStringList()
31            if cols:
32                self.curcolumns = [c for c in cols if c in all]
33            else:
34                self.curcolumns = all
35        self.disabled = [c for c in all if c not in self.curcolumns]
36
37        layout = QVBoxLayout()
38        layout.setMargin(0)
39        self.setLayout(layout)
40
41        list = QListWidget()
42        # enabled cols are listed in sorted order
43        for c in self.curcolumns:
44            item = QListWidgetItem(c)
45            item.setFlags(Qt.ItemIsSelectable |
46                          Qt.ItemIsEnabled |
47                          Qt.ItemIsDragEnabled |
48                          Qt.ItemIsUserCheckable)
49            item.setCheckState(Qt.Checked)
50            list.addItem(item)
51        # disabled cols are listed last
52        for c in self.disabled:
53            item = QListWidgetItem(c)
54            item.setFlags(Qt.ItemIsSelectable |
55                          Qt.ItemIsEnabled |
56                          Qt.ItemIsDragEnabled |
57                          Qt.ItemIsUserCheckable)
58            item.setCheckState(Qt.Unchecked)
59            list.addItem(item)
60        list.setDragDropMode(QListView.InternalMove)
61        layout.addWidget(list)
62        self.list = list
63
64        layout.addWidget(QLabel(_('Drag to change order')))
65
66        # dialog buttons
67        BB = QDialogButtonBox
68        bb = QDialogButtonBox(BB.Ok|BB.Cancel)
69        self.apply_button = bb.button(BB.Apply)
70        bb.accepted.connect(self.accept)
71        bb.rejected.connect(self.reject)
72        bb.button(BB.Ok).setDefault(True)
73        layout.addWidget(bb)
74
75    def accept(self):
76        s = QSettings()
77        cols = []
78        for i in xrange(self.list.count()):
79            item = self.list.item(i)
80            if item.checkState() == Qt.Checked:
81                cols.append(str(item.text()))
82        s.setValue('workbench/columns', cols)
83        QDialog.accept(self)
84
85    def reject(self):
86        QDialog.reject(self)
87
88def run(ui, *pats, **opts):
89    return ColumnSelectDialog(repomodel.ALLCOLUMNS)