- use data instead of the text from the parallel combobox (i considered this safer)
This commit is contained in:
parent
6b6f3a67c8
commit
90017df53d
|
@ -386,9 +386,19 @@ class MyForm(QtGui.QMainWindow):
|
||||||
newItem.setFlags(
|
newItem.setFlags(
|
||||||
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
||||||
self.ui.tableWidgetAddressBook.setItem(0, 1, newItem)
|
self.ui.tableWidgetAddressBook.setItem(0, 1, newItem)
|
||||||
# tableWidgetRecipients ###
|
# tableWidgetRecipients ###
|
||||||
self.ui.comboboxFindLabel.addItem(label)
|
sorted_by_label = sorted(queryreturn, key=lambda label: label[0])
|
||||||
self.ui.comboboxFindAddress.addItem(address)
|
sorted_by_address = sorted(queryreturn, key=lambda address: address[1])
|
||||||
|
for element in sorted_by_label:
|
||||||
|
label, address = element
|
||||||
|
self.ui.comboboxFindLabel.addItem(label, address)
|
||||||
|
for element in sorted_by_address:
|
||||||
|
label, address = element
|
||||||
|
self.ui.comboboxFindAddress.addItem(address, label)
|
||||||
|
|
||||||
|
|
||||||
|
# self.ui.comboboxFindLabel.insertSeparator(0)
|
||||||
|
# self.ui.comboboxFindAddress.insertSeparator(0)
|
||||||
|
|
||||||
# key binding for the "new recipient" comboboxes ###
|
# key binding for the "new recipient" comboboxes ###
|
||||||
self.ui.comboboxFindLabel.keyPressEvent = self.on_comboboxFindLabel_enter
|
self.ui.comboboxFindLabel.keyPressEvent = self.on_comboboxFindLabel_enter
|
||||||
|
@ -2573,94 +2583,93 @@ class MyForm(QtGui.QMainWindow):
|
||||||
clipboard = QtGui.QApplication.clipboard()
|
clipboard = QtGui.QApplication.clipboard()
|
||||||
clipboard.setText(str(addressAtCurrentRow))
|
clipboard.setText(str(addressAtCurrentRow))
|
||||||
|
|
||||||
# "new recipient" combobox change ###
|
# synchronize the "new recipient" comboboxes on change
|
||||||
|
|
||||||
def on_comboboxFindLabel_change(self, int):
|
def on_comboboxFindLabel_change(self, int):
|
||||||
self.ui.comboboxFindAddress.setCurrentIndex(int)
|
print 'on_comboboxFindLabel_change', int
|
||||||
|
# use the current text
|
||||||
|
label = self.ui.comboboxFindLabel.currentText()
|
||||||
|
# find a matching address
|
||||||
|
found = self.ui.comboboxFindAddress.findData(label)
|
||||||
|
# synchronize the other combobox
|
||||||
|
self.ui.comboboxFindAddress.setCurrentIndex(found if found > 0 else 0)
|
||||||
|
|
||||||
def on_comboboxFindAddress_change(self, int):
|
def on_comboboxFindAddress_change(self, int):
|
||||||
self.ui.comboboxFindLabel.setCurrentIndex(int)
|
print 'on_comboboxFindAddress_change', int
|
||||||
|
# use the current text
|
||||||
|
address = self.ui.comboboxFindAddress.currentText()
|
||||||
|
# find a matching address
|
||||||
|
found = self.ui.comboboxFindLabel.findData(address)
|
||||||
|
# synchronize the other combobox
|
||||||
|
self.ui.comboboxFindLabel.setCurrentIndex(found if found > 0 else 0)
|
||||||
|
|
||||||
|
# handle input on enter
|
||||||
|
|
||||||
def on_comboboxFindLabel_enter(self, event):
|
def on_comboboxFindLabel_enter(self, event):
|
||||||
|
print 'on_comboboxFindLabel_enter'
|
||||||
if (event.key() == QtCore.Qt.Key_Enter) | (event.key() == QtCore.Qt.Key_Return):
|
if (event.key() == QtCore.Qt.Key_Enter) | (event.key() == QtCore.Qt.Key_Return):
|
||||||
index = self.ui.comboboxFindLabel.currentIndex()
|
index = self.ui.comboboxFindLabel.currentIndex()
|
||||||
text = self.ui.comboboxFindLabel.currentText()
|
label = self.ui.comboboxFindLabel.currentText()
|
||||||
found = self.ui.comboboxFindLabel.findText(text)
|
found = self.ui.comboboxFindLabel.findText(label)
|
||||||
if found > 0:
|
if (found > 0) & (index == found):
|
||||||
# adjust both comboboxes on first "enter"
|
address = self.ui.comboboxFindLabel.itemData(found).toString()
|
||||||
self.ui.comboboxFindAddress.setCurrentIndex(found)
|
self.on_addRecipient_submit(label, address)
|
||||||
self.ui.comboboxFindLabel.setCurrentIndex(found)
|
|
||||||
# so we have chosen a proper address
|
|
||||||
if index == found:
|
|
||||||
# add the address to the list on second "enter"
|
|
||||||
self.on_addRecipient_submit()
|
|
||||||
else:
|
|
||||||
# no matching contact
|
|
||||||
self.ui.comboboxFindAddress.setCurrentIndex(0) # set the Address to "BM-2D"
|
|
||||||
self.ui.comboboxFindLabel.setEditText(text) # otherwise you will lose the text on enter
|
|
||||||
return QtGui.QComboBox.keyPressEvent(self.ui.comboboxFindLabel, event)
|
return QtGui.QComboBox.keyPressEvent(self.ui.comboboxFindLabel, event)
|
||||||
|
|
||||||
def on_comboboxFindAddress_enter(self, event):
|
def on_comboboxFindAddress_enter(self, event):
|
||||||
if (event.key() == QtCore.Qt.Key_Enter) | (event.key() == QtCore.Qt.Key_Return):
|
if (event.key() == QtCore.Qt.Key_Enter) | (event.key() == QtCore.Qt.Key_Return):
|
||||||
index = self.ui.comboboxFindAddress.currentIndex()
|
index = self.ui.comboboxFindAddress.currentIndex()
|
||||||
text = self.ui.comboboxFindAddress.currentText()
|
address = self.ui.comboboxFindAddress.currentText()
|
||||||
found = self.ui.comboboxFindAddress.findText(text)
|
found = self.ui.comboboxFindAddress.findText(address)
|
||||||
if found > 0:
|
if (found > 0) & (index == found):
|
||||||
# adjust both comboboxes on first "enter"
|
label = self.ui.comboboxFindAddress.itemData(found).toString()
|
||||||
self.ui.comboboxFindLabel.setCurrentIndex(found)
|
self.on_addRecipient_submit(label, address)
|
||||||
self.ui.comboboxFindAddress.setCurrentIndex(found)
|
|
||||||
# so we have chosen a proper address
|
|
||||||
if index == found:
|
|
||||||
# add the address to the list on second "enter"
|
|
||||||
self.on_addRecipient_submit()
|
|
||||||
else:
|
else:
|
||||||
# no matching contact
|
# no matching contact
|
||||||
self.ui.comboboxFindLabel.setCurrentIndex(0) # set the label to ""
|
self.ui.comboboxFindLabel.setCurrentIndex(0)
|
||||||
self.ui.comboboxFindAddress.setEditText(text) # otherwise you will lose the text on enter
|
label = False
|
||||||
|
self.ui.comboboxFindAddress.setEditText(address) # otherwise you will lose the text on enter
|
||||||
# but maybe the address is valid?
|
# but maybe the address is valid?
|
||||||
# random address for testing: BM-2DAArASbJckBdn3HvTt7kHAbPA5tGxc2R1
|
# random address for testing: BM-2DAArASbJckBdn3HvTt7kHAbPA5tGxc2R1
|
||||||
status, a, b, c = decodeAddress(str(text))
|
status, a, b, c = decodeAddress(str(address))
|
||||||
if status == 'success':
|
if status == 'success':
|
||||||
# valid address
|
# valid address
|
||||||
print _translate("MainWindow", "Address is valid.")
|
print _translate("MainWindow", "Address is valid.")
|
||||||
self.on_addRecipient_submit()
|
self.on_addRecipient_submit(label, address)
|
||||||
else:
|
else:
|
||||||
# not valid
|
# not valid
|
||||||
print 'sorry, invalid address'
|
print 'sorry, invalid address'
|
||||||
return QtGui.QComboBox.keyPressEvent(self.ui.comboboxFindAddress, event)
|
return QtGui.QComboBox.keyPressEvent(self.ui.comboboxFindAddress, event)
|
||||||
|
|
||||||
|
def on_addRecipient_submit(self, label, address):
|
||||||
|
remove_label = True
|
||||||
|
status, a, b, c = decodeAddress(str(address))
|
||||||
|
if status == 'success':
|
||||||
|
# remove them so we won't add them again
|
||||||
|
if label:
|
||||||
|
found = self.ui.comboboxFindLabel.findText(label)
|
||||||
|
self.ui.comboboxFindLabel.removeItem(found)
|
||||||
|
found = self.ui.comboboxFindAddress.findText(address)
|
||||||
|
self.ui.comboboxFindAddress.removeItem(found)
|
||||||
|
# jump to the first item
|
||||||
|
self.ui.comboboxFindAddress.setCurrentIndex(0)
|
||||||
|
self.ui.comboboxFindLabel.setCurrentIndex(0)
|
||||||
|
# find a label name
|
||||||
|
if label == False:
|
||||||
|
label = _translate("MainWindow", "--unknown Address--")
|
||||||
|
# add the label and address as a row
|
||||||
|
addToBottom = False
|
||||||
|
rowIndex = self.ui.tableWidgetRecipients.rowCount()-1 if addToBottom else 1
|
||||||
|
self.ui.tableWidgetRecipients.insertRow(rowIndex)
|
||||||
|
newItem = QtGui.QTableWidgetItem(unicode(label, 'utf-8'))
|
||||||
|
newItem.setFlags(
|
||||||
|
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
||||||
|
self.ui.tableWidgetRecipients.setItem(rowIndex, 0, newItem)
|
||||||
|
newItem = QtGui.QTableWidgetItem(unicode(address, 'utf-8'))
|
||||||
|
newItem.setFlags(
|
||||||
|
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
||||||
|
self.ui.tableWidgetRecipients.setItem(rowIndex, 1, newItem)
|
||||||
|
|
||||||
def on_addRecipient_submit(self):
|
|
||||||
# sanity check frist
|
|
||||||
index = labelIndex = self.ui.comboboxFindLabel.currentIndex()
|
|
||||||
labelText = self.ui.comboboxFindLabel.currentText()
|
|
||||||
addressIndex = self.ui.comboboxFindAddress.currentIndex()
|
|
||||||
addressText = self.ui.comboboxFindAddress.currentText()
|
|
||||||
status, a, b, c = decodeAddress(str(addressText))
|
|
||||||
if ((labelIndex == addressIndex) & (self.ui.comboboxFindLabel.itemText(index) == labelText) & (self.ui.comboboxFindAddress.itemText(index) == addressText)):
|
|
||||||
pass
|
|
||||||
elif ((labelIndex <= 0) & (status == 'success')):
|
|
||||||
labelText = _translate("MainWindow", "--unknown Address--")
|
|
||||||
index = -1
|
|
||||||
else:
|
|
||||||
print 'how did you get here?!'
|
|
||||||
return
|
|
||||||
addToBottom = False
|
|
||||||
rowIndex = self.ui.tableWidgetRecipients.rowCount()-1 if addToBottom else 1
|
|
||||||
self.ui.tableWidgetRecipients.insertRow(rowIndex)
|
|
||||||
newItem = QtGui.QTableWidgetItem(unicode(labelText, 'utf-8'))
|
|
||||||
newItem.setFlags(
|
|
||||||
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
|
||||||
self.ui.tableWidgetRecipients.setItem(rowIndex, 0, newItem)
|
|
||||||
newItem = QtGui.QTableWidgetItem(unicode(addressText, 'utf-8'))
|
|
||||||
newItem.setFlags(
|
|
||||||
QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
|
||||||
self.ui.tableWidgetRecipients.setItem(rowIndex, 1, newItem)
|
|
||||||
# clean up so we won't add it again
|
|
||||||
self.ui.comboboxFindAddress.removeItem(index)
|
|
||||||
self.ui.comboboxFindLabel.removeItem(index)
|
|
||||||
# jump to the first item
|
|
||||||
self.ui.comboboxFindAddress.setCurrentIndex(0)
|
|
||||||
self.ui.comboboxFindLabel.setCurrentIndex(0)
|
|
||||||
|
|
||||||
# Group of functions for the Address Book dialog box
|
# Group of functions for the Address Book dialog box
|
||||||
def on_action_AddressBookNew(self):
|
def on_action_AddressBookNew(self):
|
||||||
|
|
Reference in New Issue
Block a user