mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-01 17:55:20 +00:00
Enable adding transactions from file through Drag and Drop
This commit is contained in:
parent
fbcee9a6f6
commit
95da5a8bed
2 changed files with 45 additions and 1 deletions
|
@ -47,11 +47,12 @@ TX_ICONS = [
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class HistoryList(MyTreeWidget):
|
class HistoryList(MyTreeWidget, AcceptFileDragDrop):
|
||||||
filter_columns = [2, 3, 4] # Date, Description, Amount
|
filter_columns = [2, 3, 4] # Date, Description, Amount
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
MyTreeWidget.__init__(self, parent, self.create_menu, [], 3)
|
MyTreeWidget.__init__(self, parent, self.create_menu, [], 3)
|
||||||
|
AcceptFileDragDrop.__init__(self, ".txn")
|
||||||
self.refresh_headers()
|
self.refresh_headers()
|
||||||
self.setColumnHidden(1, True)
|
self.setColumnHidden(1, True)
|
||||||
|
|
||||||
|
@ -205,3 +206,12 @@ class HistoryList(MyTreeWidget):
|
||||||
if item.data(0, Qt.UserRole) in to_delete:
|
if item.data(0, Qt.UserRole) in to_delete:
|
||||||
root.removeChild(item)
|
root.removeChild(item)
|
||||||
_offset += 1
|
_offset += 1
|
||||||
|
|
||||||
|
def onFileAdded(self, fn):
|
||||||
|
with open(fn) as f:
|
||||||
|
tx = self.parent.tx_from_text(f.read())
|
||||||
|
self.wallet.add_transaction(tx.txid(), tx)
|
||||||
|
self.wallet.save_transactions()
|
||||||
|
self.on_update()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -635,6 +635,40 @@ class ColorScheme:
|
||||||
if ColorScheme.has_dark_background(widget):
|
if ColorScheme.has_dark_background(widget):
|
||||||
ColorScheme.dark_scheme = True
|
ColorScheme.dark_scheme = True
|
||||||
|
|
||||||
|
|
||||||
|
class AcceptFileDragDrop:
|
||||||
|
def __init__(self, file_type=""):
|
||||||
|
assert isinstance(self, QWidget)
|
||||||
|
self.setAcceptDrops(True)
|
||||||
|
self.file_type = file_type
|
||||||
|
|
||||||
|
def validateEvent(self, event):
|
||||||
|
if not event.mimeData().hasUrls():
|
||||||
|
event.ignore()
|
||||||
|
return False
|
||||||
|
for url in event.mimeData().urls():
|
||||||
|
if not url.toLocalFile().endswith(self.file_type):
|
||||||
|
event.ignore()
|
||||||
|
return False
|
||||||
|
event.accept()
|
||||||
|
return True
|
||||||
|
|
||||||
|
def dragEnterEvent(self, event):
|
||||||
|
self.validateEvent(event)
|
||||||
|
|
||||||
|
def dragMoveEvent(self, event):
|
||||||
|
if self.validateEvent(event):
|
||||||
|
event.setDropAction(Qt.CopyAction)
|
||||||
|
|
||||||
|
def dropEvent(self, event):
|
||||||
|
if self.validateEvent(event):
|
||||||
|
for url in event.mimeData().urls():
|
||||||
|
self.onFileAdded(url.toLocalFile())
|
||||||
|
|
||||||
|
def onFileAdded(self, fn):
|
||||||
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app = QApplication([])
|
app = QApplication([])
|
||||||
t = WaitingDialog(None, 'testing ...', lambda: [time.sleep(1)], lambda x: QMessageBox.information(None, 'done', "done"))
|
t = WaitingDialog(None, 'testing ...', lambda: [time.sleep(1)], lambda x: QMessageBox.information(None, 'done', "done"))
|
||||||
|
|
Loading…
Add table
Reference in a new issue