Skip to content

Commit b78285e

Browse files
authored
Create main.py
1 parent 683a240 commit b78285e

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

src/main.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import sys
2+
import os
3+
from PyQt5.QtCore import Qt
4+
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QLabel, QPushButton, QFileDialog
5+
6+
class DragDropWindow(QWidget):
7+
def __init__(self):
8+
super().__init__()
9+
self.setWindowTitle('AdminFreeExec')
10+
self.setGeometry(100, 100, 500, 250)
11+
12+
self.label = QLabel('Arrastra un archivo aquí', self)
13+
self.label.setAlignment(Qt.AlignCenter)
14+
self.label.setStyleSheet('font-size: 20px;')
15+
16+
self.button = QPushButton('Abrir archivo', self)
17+
self.button.clicked.connect(self.open_file)
18+
19+
layout = QVBoxLayout()
20+
layout.addWidget(self.label)
21+
layout.addWidget(self.button)
22+
23+
self.setLayout(layout)
24+
25+
def open_file(self):
26+
file_path, _ = QFileDialog.getOpenFileName(self, 'Seleccionar un archivo')
27+
if file_path:
28+
self.label.setText(f"Archivo seleccionado: {file_path}")
29+
self.run_as_invoker(file_path)
30+
31+
def run_as_invoker(self, exe_path):
32+
exe_path = f'"{exe_path}"'
33+
os.system(f'cmd /min /C "set __COMPAT_LAYER=RUNASINVOKER && start "" {exe_path}"')
34+
35+
def dragEnterEvent(self, event):
36+
if event.mimeData().hasUrls():
37+
event.accept()
38+
else:
39+
event.ignore()
40+
41+
def dropEvent(self, event):
42+
file_path = event.mimeData().urls()[0].toLocalFile()
43+
self.label.setText(f"Archivo arrastrado: {file_path}")
44+
self.run_as_invoker(file_path)
45+
46+
47+
if __name__ == '__main__':
48+
app = QApplication(sys.argv)
49+
window = DragDropWindow()
50+
window.setAcceptDrops(True)
51+
window.show()
52+
sys.exit(app.exec_())

0 commit comments

Comments
 (0)