Allow file drops
This commit is contained in:
@@ -24,6 +24,7 @@ class VlcSyncApp(QMainWindow):
|
|||||||
|
|
||||||
self.setMinimumSize(900, 600)
|
self.setMinimumSize(900, 600)
|
||||||
self.resize(1100, 700)
|
self.resize(1100, 700)
|
||||||
|
self.setAcceptDrops(True)
|
||||||
|
|
||||||
# Main stacked widget to switch between Lobby and Room
|
# Main stacked widget to switch between Lobby and Room
|
||||||
self.stacked_widget = QStackedWidget()
|
self.stacked_widget = QStackedWidget()
|
||||||
@@ -362,19 +363,38 @@ class VlcSyncApp(QMainWindow):
|
|||||||
def on_volume_changed(self, value):
|
def on_volume_changed(self, value):
|
||||||
self.vlc_player.set_volume(value)
|
self.vlc_player.set_volume(value)
|
||||||
|
|
||||||
|
def _set_local_file(self, file_path: str):
|
||||||
|
self.local_file_path = file_path
|
||||||
|
self.local_file_name = os.path.basename(file_path)
|
||||||
|
self.local_file_size = os.path.getsize(file_path)
|
||||||
|
|
||||||
|
size_mb = self.local_file_size / (1024 * 1024)
|
||||||
|
self.create_file_info.setText(f"{self.local_file_name}\n{size_mb:.1f} MB")
|
||||||
|
self.create_file_info.show()
|
||||||
|
self.check_inputs()
|
||||||
|
|
||||||
def select_file(self):
|
def select_file(self):
|
||||||
file_path, _ = QFileDialog.getOpenFileName(
|
file_path, _ = QFileDialog.getOpenFileName(
|
||||||
self, "Select Video File", "", "Video Files (*.mp4 *.mkv *.avi *.mov *.webm);;All Files (*)"
|
self, "Select Video File", "", "Video Files (*.mp4 *.mkv *.avi *.mov *.webm);;All Files (*)"
|
||||||
)
|
)
|
||||||
if file_path:
|
if file_path:
|
||||||
self.local_file_path = file_path
|
self._set_local_file(file_path)
|
||||||
self.local_file_name = os.path.basename(file_path)
|
|
||||||
self.local_file_size = os.path.getsize(file_path)
|
|
||||||
|
|
||||||
size_mb = self.local_file_size / (1024 * 1024)
|
def dragEnterEvent(self, event):
|
||||||
self.create_file_info.setText(f"{self.local_file_name}\n{size_mb:.1f} MB")
|
if event.mimeData().hasUrls():
|
||||||
self.create_file_info.show()
|
event.accept()
|
||||||
self.check_inputs()
|
else:
|
||||||
|
event.ignore()
|
||||||
|
|
||||||
|
def dropEvent(self, event):
|
||||||
|
if self.stacked_widget.currentIndex() == 0:
|
||||||
|
for url in event.mimeData().urls():
|
||||||
|
file_path = url.toLocalFile()
|
||||||
|
if os.path.isfile(file_path):
|
||||||
|
ext = os.path.splitext(file_path)[1].lower()
|
||||||
|
if ext in ['.mp4', '.mkv', '.avi', '.mov', '.webm']:
|
||||||
|
self._set_local_file(file_path)
|
||||||
|
break
|
||||||
|
|
||||||
def copy_room_code(self):
|
def copy_room_code(self):
|
||||||
if self.room_code:
|
if self.room_code:
|
||||||
|
|||||||
Reference in New Issue
Block a user