(code cleanup)

This commit is contained in:
sendiulo 2013-09-07 11:48:43 +02:00
parent ddb6e3bf05
commit b9906e316f

View File

@ -2407,18 +2407,18 @@ class MyForm(QtGui.QMainWindow):
self.quit() self.quit()
def on_action_InboxMessageForceHtml(self): def on_action_InboxMessageForceHtml(self):
here = self.ui.tableWidgetInbox thisTableWidget = self.ui.tableWidgetInbox
there = self.ui.textEditInboxMessage thisTextEdit = self.ui.textEditInboxMessage
self.on_action_MessageForceHtml(here, there) self.on_action_MessageForceHtml(thisTableWidget, thisTextEdit)
def on_action_SentMessageForceHtml(self): def on_action_SentMessageForceHtml(self):
here = self.ui.tableWidgetSent thisTableWidget = self.ui.tableWidgetSent
there = self.ui.textEditSentMessage thisTextEdit = self.ui.textEditSentMessage
self.on_action_MessageForceHtml(here, there) self.on_action_MessageForceHtml(thisTableWidget, thisTextEdit)
def on_action_MessageForceHtml(self, here, there): def on_action_MessageForceHtml(self, thisTableWidget, thisTextEdit):
currentInboxRow = here.currentRow() currentInboxRow = thisTableWidget.currentRow()
lines = here.item( lines = thisTableWidget.item(
currentInboxRow, 2).data(Qt.UserRole).toPyObject().split('\n') currentInboxRow, 2).data(Qt.UserRole).toPyObject().split('\n')
for i in xrange(len(lines)): for i in xrange(len(lines)):
if lines[i].contains('Message ostensibly from '): if lines[i].contains('Message ostensibly from '):
@ -2430,72 +2430,72 @@ class MyForm(QtGui.QMainWindow):
for i in xrange(len(lines)): for i in xrange(len(lines)):
content += lines[i] content += lines[i]
content = content.replace('\n\n', '<br><br>') content = content.replace('\n\n', '<br><br>')
there.setHtml(QtCore.QString(content)) thisTextEdit.setHtml(QtCore.QString(content))
def on_action_InboxMarkUnread(self): def on_action_InboxMarkUnread(self):
here = self.ui.tableWidgetInbox thisTableWidget = self.ui.tableWidgetInbox
read = False read = False
self.on_action_InboxMarkReadUnread(here, read) self.on_action_InboxMarkReadUnread(thisTableWidget, read)
def on_action_InboxMarkRead(self): def on_action_InboxMarkRead(self):
here = self.ui.tableWidgetInbox thisTableWidget = self.ui.tableWidgetInbox
read = True read = True
self.on_action_InboxMarkReadUnread(here, read) self.on_action_InboxMarkReadUnread(thisTableWidget, read)
def on_action_InboxMarkReadUnread(self, here, read): def on_action_InboxMarkReadUnread(self, thisTableWidget, read):
here = self.ui.tableWidgetInbox thisTableWidget = self.ui.tableWidgetInbox
font = QFont() font = QFont()
font.setBold(read==False) font.setBold(read==False)
for row in here.selectedIndexes(): for row in thisTableWidget.selectedIndexes():
currentRow = row.row() currentRow = row.row()
inventoryHashToMarkUnread = str(here.item( inventoryHashToMarkUnread = str(thisTableWidget.item(
currentRow, 3).data(Qt.UserRole).toPyObject()) currentRow, 3).data(Qt.UserRole).toPyObject())
t = (inventoryHashToMarkUnread,) t = (inventoryHashToMarkUnread,)
shared.sqlLock.acquire() shared.sqlLock.acquire()
shared.sqlSubmitQueue.put( shared.sqlSubmitQueue.put(
'''UPDATE inbox SET read='''+ str(int(read)) +''' WHERE msgid=?''') '''UPDATE inbox SET read='''+ str(int(read)) +''' WthisTableWidget msgid=?''')
shared.sqlSubmitQueue.put(t) shared.sqlSubmitQueue.put(t)
shared.sqlReturnQueue.get() shared.sqlReturnQueue.get()
shared.sqlLock.release() shared.sqlLock.release()
here.item(currentRow, 0).setFont(font) thisTableWidget.item(currentRow, 0).setFont(font)
here.item(currentRow, 1).setFont(font) thisTableWidget.item(currentRow, 1).setFont(font)
here.item(currentRow, 2).setFont(font) thisTableWidget.item(currentRow, 2).setFont(font)
here.item(currentRow, 3).setFont(font) thisTableWidget.item(currentRow, 3).setFont(font)
shared.sqlLock.acquire() shared.sqlLock.acquire()
shared.sqlSubmitQueue.put('commit') shared.sqlSubmitQueue.put('commit')
shared.sqlLock.release() shared.sqlLock.release()
# here.selectRow(currentRow + 1) # thisTableWidget.selectRow(currentRow + 1)
# This doesn't de-select the last message if you try to mark it unread, but that doesn't interfere. Might not be necessary. # This doesn't de-select the last message if you try to mark it unread, but that doesn't interfere. Might not be necessary.
# We could also select upwards, but then our problem would be with the topmost message. # We could also select upwards, but then our problem would be with the topmost message.
# here.clearSelection() manages to mark the message as read again. # thisTableWidget.clearSelection() manages to mark the message as read again.
def on_action_InboxReply(self): def on_action_InboxReply(self):
here = self.ui.tableWidgetInbox thisTableWidget = self.ui.tableWidgetInbox
newFromAddressColumn = 0 newFromAddressColumn = 0
newToAddressColumn = 1 newToAddressColumn = 1
self.on_action_ReplyGeneric(here, newFromAddressColumn, newToAddressColumn) self.on_action_ReplyGeneric(thisTableWidget, newFromAddressColumn, newToAddressColumn)
def on_action_InboxReplyChan(self): def on_action_InboxReplyChan(self):
here = self.ui.tableWidgetInbox thisTableWidget = self.ui.tableWidgetInbox
newFromAddressColumn = 0 newFromAddressColumn = 0
newToAddressColumn = 0 newToAddressColumn = 0
self.on_action_ReplyGeneric(here, newFromAddressColumn, newToAddressColumn) self.on_action_ReplyGeneric(thisTableWidget, newFromAddressColumn, newToAddressColumn)
def on_action_SentSendAnother(self): def on_action_SentSendAnother(self):
here = self.ui.tableWidgetSent thisTableWidget = self.ui.tableWidgetSent
newFromAddressColumn = 1 newFromAddressColumn = 1
newToAddressColumn = 0 newToAddressColumn = 0
self.on_action_ReplyGeneric(here, newFromAddressColumn, newToAddressColumn) self.on_action_ReplyGeneric(thisTableWidget, newFromAddressColumn, newToAddressColumn)
def on_action_ReplyGeneric(self, here, newFromAddressColumn, newToAddressColumn): def on_action_ReplyGeneric(self, thisTableWidget, newFromAddressColumn, newToAddressColumn):
currentRow = here.currentRow() currentRow = thisTableWidget.currentRow()
newFromAddress = str(here.item( newFromAddress = str(thisTableWidget.item(
currentRow, newFromAddressColumn).data(Qt.UserRole).toPyObject()) currentRow, newFromAddressColumn).data(Qt.UserRole).toPyObject())
newToAddress = str(here.item( newToAddress = str(thisTableWidget.item(
currentRow, newToAddressColumn).data(Qt.UserRole).toPyObject()) currentRow, newToAddressColumn).data(Qt.UserRole).toPyObject())
newContent = ('\n\n------------------------------------------------------\n' + here.item( newContent = ('\n\n------------------------------------------------------\n' + thisTableWidget.item(
currentRow, 2).data(Qt.UserRole).toPyObject()) currentRow, 2).data(Qt.UserRole).toPyObject())
newSubject = here.item(currentRow, 2).text() newSubject = thisTableWidget.item(currentRow, 2).text()
if not newSubject[0:3] in ['Re:', 'RE:']: if not newSubject[0:3] in ['Re:', 'RE:']:
newSubject = 'Re: ' + newSubject newSubject = 'Re: ' + newSubject
self.on_action_NewDraft(newFromAddress, [newToAddress], newSubject, newContent) self.on_action_NewDraft(newFromAddress, [newToAddress], newSubject, newContent)
@ -2526,7 +2526,7 @@ class MyForm(QtGui.QMainWindow):
# only ask if message body would be overwritten # only ask if message body would be overwritten
current_text = str( current_text = str(
self.ui.textEditMessage.document().toPlainText().toUtf8()) self.ui.textEditMessage.document().toPlainText().toUtf8())
if len(current_text) > 0: if (len(current_text) > 0) & (newContent != current_text):
# switch to Send Tab to see the message # switch to Send Tab to see the message
# so you can check if you want to overwrite # so you can check if you want to overwrite
current_index = self.ui.tabWidget.currentIndex() current_index = self.ui.tabWidget.currentIndex()
@ -2541,7 +2541,7 @@ class MyForm(QtGui.QMainWindow):
return return
# check from address # check from address
if newFromAddress==False: if newFromAddress==False:
# keep the current from address # keep the current FROM address
pass pass
elif newFromAddress == self.str_broadcast_subscribers: elif newFromAddress == self.str_broadcast_subscribers:
self.set_comboBoxSendFrom_to_address(False) self.set_comboBoxSendFrom_to_address(False)
@ -2837,52 +2837,52 @@ class MyForm(QtGui.QMainWindow):
# Send to Address context menu items # Send to Address context menu items
def on_action_InboxSendtoRecipient(self): def on_action_InboxSendtoRecipient(self):
here = self.ui.tableWidgetInbox thisTableWidget = self.ui.tableWidgetInbox
address_column = 0 address_column = 0
useData = True useData = True
self.on_action_SendToAddress(here,address_column,useData) self.on_action_SendToAddress(thisTableWidget,address_column,useData)
def on_action_InboxSendtoSender(self): def on_action_InboxSendtoSender(self):
here = self.ui.tableWidgetInbox thisTableWidget = self.ui.tableWidgetInbox
address_column = 1 address_column = 1
useData = True useData = True
self.on_action_SendToAddress(here,address_column,useData) self.on_action_SendToAddress(thisTableWidget,address_column,useData)
def on_action_SentSendtoRecipient(self): def on_action_SentSendtoRecipient(self):
here = self.ui.tableWidgetSent thisTableWidget = self.ui.tableWidgetSent
address_column = 0 address_column = 0
useData = True useData = True
self.on_action_SendToAddress(here,address_column,useData) self.on_action_SendToAddress(thisTableWidget,address_column,useData)
def on_action_SentSendtoSender(self): def on_action_SentSendtoSender(self):
here = self.ui.tableWidgetSent thisTableWidget = self.ui.tableWidgetSent
address_column = 1 address_column = 1
useData = True useData = True
self.on_action_SendToAddress(here,address_column,useData) self.on_action_SendToAddress(thisTableWidget,address_column,useData)
def on_action_YourIdentitiesSendToChan(self): def on_action_YourIdentitiesSendToChan(self):
here = self.ui.tableWidgetYourIdentities thisTableWidget = self.ui.tableWidgetYourIdentities
address_column = 1 address_column = 1
useData = False useData = False
self.on_action_SendToAddress(here,address_column,useData) self.on_action_SendToAddress(thisTableWidget,address_column,useData)
def on_action_SubscriptionsSend(self): def on_action_SubscriptionsSend(self):
here = self.ui.tableWidgetSubscriptions thisTableWidget = self.ui.tableWidgetSubscriptions
address_column = 1 address_column = 1
useData = False useData = False
self.on_action_SendToAddress(here,address_column,useData) self.on_action_SendToAddress(thisTableWidget,address_column,useData)
def on_action_AddressBookSend(self): def on_action_AddressBookSend(self):
here = self.ui.tableWidgetAddressBook thisTableWidget = self.ui.tableWidgetAddressBook
address_column = 1 address_column = 1
useData = False useData = False
self.on_action_SendToAddress(here,address_column,useData) self.on_action_SendToAddress(thisTableWidget,address_column,useData)
def on_action_BlacklistSend(self): def on_action_BlacklistSend(self):
here = self.ui.tableWidgetBlacklist thisTableWidget = self.ui.tableWidgetBlacklist
address_column = 1 address_column = 1
useData = False useData = False
self.on_action_SendToAddress(here,address_column,useData) self.on_action_SendToAddress(thisTableWidget,address_column,useData)
def filter_own_addresses(self, addressList): def filter_own_addresses(self, addressList):
outputList = [] outputList = []
@ -2900,18 +2900,18 @@ class MyForm(QtGui.QMainWindow):
outputList += [address] outputList += [address]
return outputList return outputList
def on_action_SendToAddress(self, here, address_column, use_data): def on_action_SendToAddress(self, thisTableWidget, address_column, use_data):
listOfSelectedRows = {} listOfSelectedRows = {}
for i in range(len(here.selectedIndexes())): for i in range(len(thisTableWidget.selectedIndexes())):
listOfSelectedRows[ listOfSelectedRows[
here.selectedIndexes()[i].row()] = 0 thisTableWidget.selectedIndexes()[i].row()] = 0
addressList = [] addressList = []
for currentRow in listOfSelectedRows: for currentRow in listOfSelectedRows:
if use_data: if use_data:
addressAtCurrentRow = here.item(currentRow, address_column addressAtCurrentRow = thisTableWidget.item(currentRow, address_column
).data(Qt.UserRole).toPyObject() ).data(Qt.UserRole).toPyObject()
else: else:
addressAtCurrentRow = here.item( addressAtCurrentRow = thisTableWidget.item(
currentRow, address_column).text() currentRow, address_column).text()
addressList += [str(addressAtCurrentRow)] addressList += [str(addressAtCurrentRow)]
not_own = self.filter_own_addresses(addressList) not_own = self.filter_own_addresses(addressList)
@ -2941,10 +2941,10 @@ class MyForm(QtGui.QMainWindow):
self.ui.tabWidget.setCurrentIndex(1) self.ui.tabWidget.setCurrentIndex(1)
def on_action_YourIdentitiesSendFromAddress(self): def on_action_YourIdentitiesSendFromAddress(self):
here = self.ui.tableWidgetYourIdentities thisTableWidget = self.ui.tableWidgetYourIdentities
newFromAddressColumn = 1 newFromAddressColumn = 1
currentRow = here.currentRow() currentRow = thisTableWidget.currentRow()
newFromAddress = str(here.item( newFromAddress = str(thisTableWidget.item(
currentRow, newFromAddressColumn).text()) currentRow, newFromAddressColumn).text())
self.on_action_NewDraft(newFromAddress, [False], False, False) self.on_action_NewDraft(newFromAddress, [False], False, False)