From 9abc937cb3ad97bbe1ecfcac1998108a8c7441e1 Mon Sep 17 00:00:00 2001 From: mailchuck Date: Sat, 31 Oct 2015 10:12:12 +0100 Subject: [PATCH] More unified colors in foldertree and messagelists Some parts still not colored in a unified way. Fixes #84 --- src/bitmessageqt/__init__.py | 10 ++++------ src/bitmessageqt/account.py | 19 +++++++++++++++++++ src/bitmessageqt/foldertree.py | 17 ++++++++++------- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 824c8cf8..bfb71f14 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -921,6 +921,7 @@ class MyForm(QtGui.QMainWindow): toAddressItem.setToolTip(unicode(acct.toLabel, 'utf-8')) toAddressItem.setIcon(avatarize(toAddress)) toAddressItem.setData(Qt.UserRole, str(toAddress)) + toAddressItem.setTextColor(AccountColor(toAddress).accountColor()) toAddressItem.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) tableWidget.setItem(0, 0, toAddressItem) @@ -929,6 +930,7 @@ class MyForm(QtGui.QMainWindow): fromAddressItem.setToolTip(unicode(acct.fromLabel, 'utf-8')) fromAddressItem.setIcon(avatarize(fromAddress)) fromAddressItem.setData(Qt.UserRole, str(fromAddress)) + fromAddressItem.setTextColor(AccountColor(fromAddress).accountColor()) fromAddressItem.setFlags( QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) tableWidget.setItem(0, 1, fromAddressItem) @@ -1058,10 +1060,7 @@ class MyForm(QtGui.QMainWindow): if not read: to_item.setFont(font) to_item.setData(Qt.UserRole, str(toAddress)) - if shared.safeConfigGetBoolean(toAddress, 'mailinglist'): - to_item.setTextColor(QtGui.QColor(137, 04, 177)) # magenta - if shared.safeConfigGetBoolean(str(toAddress), 'chan'): - to_item.setTextColor(QtGui.QColor(216, 119, 0)) # orange + to_item.setTextColor(AccountColor(toAddress).accountColor()) to_item.setIcon(avatarize(toAddress)) tableWidget.setItem(0, 0, to_item) # from @@ -1072,8 +1071,7 @@ class MyForm(QtGui.QMainWindow): if not read: from_item.setFont(font) from_item.setData(Qt.UserRole, str(fromAddress)) - if shared.safeConfigGetBoolean(str(fromAddress), 'chan'): - from_item.setTextColor(QtGui.QColor(216, 119, 0)) # orange + from_item.setTextColor(AccountColor(fromAddress).accountColor()) from_item.setIcon(avatarize(fromAddress)) tableWidget.setItem(0, 1, from_item) # subject diff --git a/src/bitmessageqt/account.py b/src/bitmessageqt/account.py index 2342bcc5..6e1083f6 100644 --- a/src/bitmessageqt/account.py +++ b/src/bitmessageqt/account.py @@ -6,6 +6,7 @@ import sys import inspect from helper_sql import * from addresses import decodeAddress +from foldertree import AccountMixin from pyelliptic.openssl import OpenSSL from utils import str_broadcast_subscribers import time @@ -41,6 +42,24 @@ def accountClass(address): # no gateway return BMAccount(address) +class AccountColor(AccountMixin): + def __init__(self, address, type = None): + self.isEnabled = True + self.address = address + if type is None: + if shared.safeConfigGetBoolean(self.address, 'mailinglist'): + self.type = "mailinglist" + elif shared.safeConfigGetBoolean(self.address, 'chan'): + self.type = "chan" + elif sqlQuery( + '''select label from subscriptions where address=?''', self.address): + self.type = 'subscription' + else: + self.type = "normal" + else: + self.type = type + + class BMAccount(object): def __init__(self, address = None): self.address = address diff --git a/src/bitmessageqt/foldertree.py b/src/bitmessageqt/foldertree.py index f49b1d6d..e0ce72b8 100644 --- a/src/bitmessageqt/foldertree.py +++ b/src/bitmessageqt/foldertree.py @@ -6,13 +6,16 @@ import shared class AccountMixin (object): def accountColor (self): if not self.isEnabled: - return QtGui.QBrush(QtGui.QColor(128, 128, 128)) + return QtGui.QColor(128, 128, 128) elif self.type == "chan": - return QtGui.QBrush(QtGui.QColor(216, 119, 0)) + return QtGui.QColor(216, 119, 0) elif self.type == "mailinglist" or self.type == "subscription": - return QtGui.QBrush(QtGui.QColor(137, 04, 177)) + return QtGui.QColor(137, 04, 177) else: - return QtGui.QBrush(QtGui.QApplication.palette().text().color()) + return QtGui.QApplication.palette().text().color() + + def accountBrush(self): + return QtGui.QBrush(self.accountColor()) def setAddress(self, address): self.address = str(address) @@ -121,7 +124,7 @@ class Ui_AddressWidget(QtGui.QTreeWidgetItem, AccountMixin): self.setFont(0, font) #set text color - brush = self.accountColor() + brush = self.accountBrush() brush.setStyle(QtCore.Qt.NoBrush) self.setForeground(0, brush) @@ -204,7 +207,7 @@ class Ui_SubscriptionWidget(Ui_AddressWidget, AccountMixin): self.setFont(0, font) #set text color - brush = self.accountColor() + brush = self.accountBrush() brush.setStyle(QtCore.Qt.NoBrush) self.setForeground(0, brush) @@ -246,7 +249,7 @@ class Ui_AddressBookWidgetItem(QtGui.QTableWidgetItem, AccountMixin): except: self.type = 0 self.setEnabled(True) - brush = self.accountColor() + brush = self.accountBrush() brush.setStyle(QtCore.Qt.NoBrush) self.setForeground(brush)