-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbdlWidgets.py
80 lines (62 loc) · 2.52 KB
/
bdlWidgets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Collection of Qt widgets subclassed for use in BDL.
from PyQt5.QtWidgets import QListWidget, QComboBox, QLineEdit
# Hacky solution to allow custom widgets to interface with bdl.py
bdlInstance = None
def setBDLInstance(newBDLInstance):
global bdlInstance
bdlInstance = newBDLInstance
class bdlListWidget(QListWidget):
'''
Custom QListWidget class that allows external file drag-and-drop.
Actual event functions were taken from this github example,
since figuring this out normally was essentially impossible:
https://gist.github.com/peace098beat/db8ef7161508e6500ebe
Used for the iwad and pwad lists.
'''
def __init__(self, parent):
super().__init__(parent)
self.setAcceptDrops(True)
def dragEnterEvent(self, event):
if event.mimeData().hasUrls():
event.accept()
else:
event.ignore()
super().dragEnterEvent(event) # run QListWidget's built-in behavior
def dropEvent(self, event):
files = [url.toLocalFile() for url in event.mimeData().urls()]
bdlInstance.addFile(self, files, dragAndDropped=True)
super().dropEvent(event) # run QListWidget's built-in behavior
class bdlComboBox(QComboBox):
'''
Custom QComboBox (dropdown) class that allows external
file drag-and-drop. Used for the source port dropdown.
'''
def __init__(self, parent):
super().__init__(parent)
self.setAcceptDrops(True)
def dragEnterEvent(self, event):
if event.mimeData().hasUrls():
event.accept()
else:
event.ignore()
def dropEvent(self, event):
files = [url.toLocalFile() for url in event.mimeData().urls()]
bdlInstance.addFile(self, files, dragAndDropped=True)
class bdlDemoLineEdit(QLineEdit):
'''
Custom QLineEdit class that allows external file drag-and-drop.
This version is explicitly designed to allow Doom demo (.lmp) files
only. Used for the "Play Demo" line edit under the settings tab.
'''
def __init__(self, parent):
super().__init__(parent)
self.setAcceptDrops(True)
def dragEnterEvent(self, event):
if event.mimeData().hasUrls():
path = event.mimeData().urls()[0].toLocalFile() # only accept demo files (.lmp)
if path.endswith('.lmp'): event.accept()
else: event.ignore()
else:
event.ignore()
def dropEvent(self, event):
bdlInstance.addFile(self, files=event.mimeData().urls()[0].toLocalFile(), dragAndDropped=True)