#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This is only needed for Python v2 but is harmless for Python v3.
import sip
sip.setapi('QVariant', 2)
from PyQt4 import QtCore, QtGui
import codebase
SUBJECT, SENDER, DATE, KAIJIANGLI = range(4)
# Work around the fact that QSortFilterProxyModel always filters datetime
# values in QtCore.Qt.ISODate formeat, but the tree views display using
# QtCore.Qt.DefaultLocaleShortDate format.
class SortFilterProxyModel(QtGui.QSortFilterProxyModel):
def filterAcceptsRow(self, sourceRow, sourceParent):
# Do we filter for the date column?
if self.filterKeyColumn() == DATE:
# Fetch datetime value.
index = self.sourceModel().index(sourceRow, DATE, sourceParent)
data = self.sourceModel().data(index)
# Return, if regExp match in displayed format.
return (self.filterRegExp().indexIn(data.toString(QtCore.Qt.DefaultLocaleShortDate)) >= 0)
# Not our business.
return super(SortFilterProxyModel, self).filterAcceptsRow(sourceRow, sourceParent)
class Window(QtGui.QWidget):
def __init__(self):
super(Window, self).__init__()