Enable adding transactions from file through Drag and Drop
This commit is contained in:
@@ -635,6 +635,40 @@ class ColorScheme:
|
||||
if ColorScheme.has_dark_background(widget):
|
||||
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__":
|
||||
app = QApplication([])
|
||||
t = WaitingDialog(None, 'testing ...', lambda: [time.sleep(1)], lambda x: QMessageBox.information(None, 'done', "done"))
|
||||
|
||||
Reference in New Issue
Block a user