-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrop_area.py
More file actions
68 lines (51 loc) · 1.97 KB
/
Copy pathdrop_area.py
File metadata and controls
68 lines (51 loc) · 1.97 KB
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
from PySide6.QtCore import Qt, Signal
from PySide6.QtWidgets import QFrame, QFileDialog
import zipfile
import json
class DropArea(QFrame):
fileDropped = Signal(str, str, str, str)
def __init__(self, parent=None):
super().__init__(parent)
self.setAcceptDrops(True)
self.file_path = None
# drop
def dragEnterEvent(self, event):
if event.mimeData().hasUrls():
file = event.mimeData().urls()[0].toLocalFile()
if file.lower().endswith(".mrpack"):
event.acceptProposedAction()
self.setProperty("dragging", True)
self.style().unpolish(self)
self.style().polish(self)
return
event.ignore()
def dragLeaveEvent(self, event):
self.setProperty("dragging", False)
self.style().unpolish(self)
self.style().polish(self)
def dropEvent(self, event):
self.setProperty("dragging", False)
self.style().unpolish(self)
self.style().polish(self)
file = event.mimeData().urls()[0].toLocalFile()
self.file_path = file
self.fileDropped.emit(file)
event.acceptProposedAction()
# click
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
file, _ = QFileDialog.getOpenFileName(
self,
"Choose Modrinth modpack",
"",
"Modrinth Pack (*.mrpack)"
)
if file:
with zipfile.ZipFile(file, "r") as archive:
with archive.open("modrinth.index.json") as json_file:
manifest = json.load(json_file)
name = manifest.get("name")
modpack_version = manifest.get("versionId")
minecraft_version = manifest.get("dependencies")["minecraft"]
self.fileDropped.emit(file, name, modpack_version, minecraft_version)
super().mousePressEvent(event)