-
Notifications
You must be signed in to change notification settings - Fork 2
/
windows_integration.py
74 lines (63 loc) · 2.36 KB
/
windows_integration.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
#!/usr/bin/env python3
"""
Windows integration module for Miller Columns File Manager application.
This module contains functions for platform-specific functionalities on Windows,
including displaying context menus and retrieving file properties.
"""
import os
from PyQt6.QtWidgets import QMessageBox
from PyQt6.QtCore import QModelIndex
import windows_map_drives
def show_context_menu(window, pos, column_view):
"""
Display a context menu at the given position for the specified column view.
"""
indexes = column_view.selectedIndexes()
if not indexes:
parent_index = column_view.rootIndex()
if parent_index.isValid():
file_paths = [window.file_model.filePath(parent_index)]
else:
return
else:
file_paths = [window.file_model.filePath(index) for index in indexes]
if os.name == 'nt':
try:
import windows_context_menu
windows_context_menu.show_context_menu(file_paths)
except Exception as e:
QMessageBox.critical(window, "Error", f"{e}")
return
else:
QMessageBox.critical(window, "Error", "Context menu not supported on this platform.")
def show_properties(window, index: QModelIndex):
"""
Show properties for the file or directory specified by the QModelIndex.
"""
if index.isValid():
file_path = window.file_model.filePath(index)
if os.name == 'nt':
import windows_properties
windows_properties.get_file_properties(file_path)
else:
print("show_properties not implemented for this platform")
def map_network_drive(window):
"""
Map a network drive.
"""
if os.name == 'nt':
network_drive_manager = windows_map_drives.NetworkDriveManager()
map_dialog = windows_map_drives.MapDriveDialog(network_drive_manager)
map_dialog.exec()
else:
QMessageBox.critical(window, "Error", "Network drive mapping not supported on this platform.")
def unmap_network_drive(window):
"""
Unmap a network drive.
"""
if os.name == 'nt':
network_drive_manager = windows_map_drives.NetworkDriveManager()
unmap_dialog = windows_map_drives.UnmapDriveDialog(network_drive_manager)
unmap_dialog.exec()
else:
QMessageBox.critical(window, "Error", "Network drive unmapping not supported on this platform.")