-
Notifications
You must be signed in to change notification settings - Fork 0
/
dnd.py
102 lines (85 loc) · 2.51 KB
/
dnd.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# use os
import os
import sys
from PyQt5.QtWidgets import (
QApplication, QListWidget, QWidget, QVBoxLayout
)
from PyQt5.QtGui import QFont
from collections import deque
class Main(QWidget):
def __init__(self):
super(Main, self).__init__()
self.setAcceptDrops(True)
self.__FileList = QListWidget()
self.__initUI()
def __initUI(self):
layout = QVBoxLayout()
layout.addWidget(self.__FileList)
self.setLayout(layout)
self.setGeometry(1000, 500, 800, 500)
def dragEnterEvent(self, event):
if event.mimeData().hasUrls():
event.accept()
else:
event.ignore()
def dropEvent(self, event):
urls = event.mimeData().urls()
for url in urls:
path = url.toLocalFile()
tmp = path.split('.')
if len(tmp) != 1:
self.__FileList.addItem(basename(path))
else:
self.__addDir(tmp[0])
def __addDir(self, item):
for roots, dirs, files in os.walk(item):
for f in files:
self.__FileList.addItem(basename(f))
if len(dirs) != 0:
for d in dirs:
self.__que.append(d)
return self.__addDir(self.__que.popleft())
try:
if len(self.__que) != 0:
return self.__addDir(self.__que.popleft())
except:
return
def main():
app = QApplication(sys.argv)
font = QFont("Meiryo")
app.setFont(font)
w = Main()
w.setWindowTitle("title")
w.show()
w.raise_()
app.exec_()
if __name__ == '__main__':
main()
# use pathlib
"""
def dragEnterEvent(self, event) -> None:
if event.mimeData().hasUrls():
event.accept()
else:
event.ignore()
def dropEvent(self, event) -> None:
urls = event.mimeData().urls()
for url in urls:
path = url.toLocalFile()
x = Path(path)
tmp = path.split('.')
if x in self.__xmlPathList:
QMessageBox.information(self, 'Warning', 'This file already in.', QMessageBox.Ok)
continue
if len(tmp) != 1:
if inExtension(x, "db"):
self.xmlList.addItem(x.name)
self.__xmlPathList.append(x)
else:
print(tmp[0])
self.__addDir(Path(tmp[0]))
def __addDir(self, item: str) -> None:
for f in list(item.glob("**/*.db")):
self.xmlList.addItem(f.name)
self.__xmlPathList.append(f)
"""