Tree rerendering cleanup

Fixes #76
This commit is contained in:
mailchuck 2016-01-24 18:21:15 +01:00 committed by Peter Surda
parent 1cc4fac7f4
commit 2dc230db90

View File

@ -24,7 +24,7 @@ class AccountMixin (object):
return QtGui.QApplication.palette().text().color() return QtGui.QApplication.palette().text().color()
def folderColor (self): def folderColor (self):
if not self.parent.isEnabled: if not self.parent().isEnabled:
return QtGui.QColor(128, 128, 128) return QtGui.QColor(128, 128, 128)
else: else:
return QtGui.QApplication.palette().text().color() return QtGui.QApplication.palette().text().color()
@ -44,11 +44,9 @@ class AccountMixin (object):
self.address = None self.address = None
else: else:
self.address = str(address) self.address = str(address)
self.updateText()
def setUnreadCount(self, cnt): def setUnreadCount(self, cnt):
self.unreadCount = int(cnt) self.unreadCount = int(cnt)
self.updateText()
def setEnabled(self, enabled): def setEnabled(self, enabled):
self.isEnabled = enabled self.isEnabled = enabled
@ -58,7 +56,8 @@ class AccountMixin (object):
for i in range(self.childCount()): for i in range(self.childCount()):
if isinstance(self.child(i), Ui_FolderWidget): if isinstance(self.child(i), Ui_FolderWidget):
self.child(i).setEnabled(enabled) self.child(i).setEnabled(enabled)
self.updateText() if isinstance(self, QtGui.QTreeWidgetItem)
self.emitDataChanged()
def setType(self): def setType(self):
self.setFlags(self.flags() | QtCore.Qt.ItemIsEditable) self.setFlags(self.flags() | QtCore.Qt.ItemIsEditable)
@ -99,43 +98,36 @@ class AccountMixin (object):
else: else:
return retval return retval
def updateText(self):
pass
class Ui_FolderWidget(QtGui.QTreeWidgetItem, AccountMixin): class Ui_FolderWidget(QtGui.QTreeWidgetItem, AccountMixin):
folderWeight = {"inbox": 1, "new": 2, "sent": 3, "trash": 4} folderWeight = {"inbox": 1, "new": 2, "sent": 3, "trash": 4}
def __init__(self, parent, pos = 0, address = "", folderName = "", unreadCount = 0): def __init__(self, parent, pos = 0, address = "", folderName = "", unreadCount = 0):
super(QtGui.QTreeWidgetItem, self).__init__() super(QtGui.QTreeWidgetItem, self).__init__()
self.initialised = False
self.setAddress(address) self.setAddress(address)
self.setFolderName(folderName) self.setFolderName(folderName)
self.setUnreadCount(unreadCount) self.setUnreadCount(unreadCount)
self.parent = parent
self.initialised = True
self.updateText()
parent.insertChild(pos, self) parent.insertChild(pos, self)
def setFolderName(self, fname): def setFolderName(self, fname):
self.folderName = str(fname) self.folderName = str(fname)
self.setData(0, QtCore.Qt.UserRole, self.folderName)
self.updateText()
def updateText(self): def data(self, column, role):
if not self.initialised: if column == 0:
return if role == QtCore.Qt.DisplayRole:
text = QtGui.QApplication.translate("MainWindow", self.folderName) return QtGui.QApplication.translate("MainWindow", self.folderName) + (" (" + str(self.unreadCount) + ")" if self.unreadCount > 0 else "")
font = QtGui.QFont() elif role == QtCore.Qt.EditRole:
if self.unreadCount > 0: return QtGui.QApplication.translate("MainWindow", self.folderName)
text += " (" + str(self.unreadCount) + ")" elif role == QtCore.Qt.ToolTipRole:
font.setBold(True) return QtGui.QApplication.translate("MainWindow", self.folderName)
else: elif role == QtCore.Qt.DecorationRole:
font.setBold(False) pass
self.setFont(0, font) elif role == QtCore.Qt.FontRole:
self.setForeground(0, self.folderBrush()) font = QtGui.QFont()
self.setText(0, text) font.setBold(self.unreadCount > 0)
self.setToolTip(0, text) return font
# self.setData(0, QtCore.Qt.UserRole, [self.address, self.folderName]) elif role == QtCore.Qt.ForegroundRole:
return self.folderBrush()
return super(Ui_FolderWidget, self).data(column, role)
# inbox, sent, thrash first, rest alphabetically # inbox, sent, thrash first, rest alphabetically
def __lt__(self, other): def __lt__(self, other):
@ -165,12 +157,10 @@ class Ui_AddressWidget(QtGui.QTreeWidgetItem, AccountMixin, SettingsMixin):
parent.insertTopLevelItem(pos, self) parent.insertTopLevelItem(pos, self)
# only set default when creating # only set default when creating
#super(QtGui.QTreeWidgetItem, self).setExpanded(shared.config.getboolean(self.address, 'enabled')) #super(QtGui.QTreeWidgetItem, self).setExpanded(shared.config.getboolean(self.address, 'enabled'))
self.initialised = False
self.setAddress(address) self.setAddress(address)
self.setEnabled(enabled) self.setEnabled(enabled)
self.setUnreadCount(unreadCount) self.setUnreadCount(unreadCount)
self.initialised = True self.setType()
self.setType() # does updateText
def _getLabel(self): def _getLabel(self):
if self.address is None: if self.address is None:
@ -226,13 +216,8 @@ class Ui_AddressWidget(QtGui.QTreeWidgetItem, AccountMixin, SettingsMixin):
super(Ui_AddressWidget, self).setAddress(address) super(Ui_AddressWidget, self).setAddress(address)
self.setData(0, QtCore.Qt.UserRole, self.address) self.setData(0, QtCore.Qt.UserRole, self.address)
def updateText(self):
if not self.initialised:
return
def setExpanded(self, expand): def setExpanded(self, expand):
super(Ui_AddressWidget, self).setExpanded(expand) super(Ui_AddressWidget, self).setExpanded(expand)
self.updateText()
def _getSortRank(self): def _getSortRank(self):
ret = self.type ret = self.type
@ -261,12 +246,10 @@ class Ui_SubscriptionWidget(Ui_AddressWidget, AccountMixin):
parent.insertTopLevelItem(pos, self) parent.insertTopLevelItem(pos, self)
# only set default when creating # only set default when creating
#super(QtGui.QTreeWidgetItem, self).setExpanded(shared.config.getboolean(self.address, 'enabled')) #super(QtGui.QTreeWidgetItem, self).setExpanded(shared.config.getboolean(self.address, 'enabled'))
self.initialised = False
self.setAddress(address) self.setAddress(address)
self.setEnabled(enabled) self.setEnabled(enabled)
self.setType() self.setType()
self.initialised = True self.setUnreadCount(unreadCount)
self.setUnreadCount (unreadCount) # does updateText
def _getLabel(self): def _getLabel(self):
queryreturn = sqlQuery( queryreturn = sqlQuery(
@ -292,10 +275,6 @@ class Ui_SubscriptionWidget(Ui_AddressWidget, AccountMixin):
label, self.address) label, self.address)
return super(Ui_SubscriptionWidget, self).setData(column, role, value) return super(Ui_SubscriptionWidget, self).setData(column, role, value)
def updateText(self):
if not self.initialised:
return
class MessageList_AddressWidget(QtGui.QTableWidgetItem, AccountMixin, SettingsMixin): class MessageList_AddressWidget(QtGui.QTableWidgetItem, AccountMixin, SettingsMixin):
def __init__(self, parent, address = None, label = None, unread = False): def __init__(self, parent, address = None, label = None, unread = False):
@ -303,14 +282,12 @@ class MessageList_AddressWidget(QtGui.QTableWidgetItem, AccountMixin, SettingsMi
#parent.insertTopLevelItem(pos, self) #parent.insertTopLevelItem(pos, self)
# only set default when creating # only set default when creating
#super(QtGui.QTreeWidgetItem, self).setExpanded(shared.config.getboolean(self.address, 'enabled')) #super(QtGui.QTreeWidgetItem, self).setExpanded(shared.config.getboolean(self.address, 'enabled'))
self.initialised = False
self.isEnabled = True self.isEnabled = True
self.setAddress(address) self.setAddress(address)
self.setLabel(label) self.setLabel(label)
self.setUnread(unread) self.setUnread(unread)
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
self.initialised = True self.setType()
self.setType() # does updateText
parent.append(self) parent.append(self)
def setLabel(self, label = None): def setLabel(self, label = None):