53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
## Interface with only a path widget (combo of QLineEdit and QPushButton to explore the file system)
|
|
## and a button : verify (call a temp verify function)
|
|
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton, QLineEdit, QFileDialog
|
|
import sys
|
|
import os
|
|
import tempfile
|
|
|
|
def verify_path(path):
|
|
# Temporary verification function
|
|
if os.path.exists(path):
|
|
print(f"Path '{path}' exists.")
|
|
else:
|
|
print(f"Path '{path}' does not exist.")
|
|
|
|
class PathWidget(QWidget):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.init_ui()
|
|
|
|
def init_ui(self):
|
|
self.layout = QVBoxLayout()
|
|
|
|
# Create a QLineEdit for the path input
|
|
self.path_input = QLineEdit(self)
|
|
self.path_input.setPlaceholderText("Enter or select a path")
|
|
self.layout.addWidget(self.path_input)
|
|
|
|
# Create a QPushButton to open the file dialog
|
|
self.browse_button = QPushButton("Browse", self)
|
|
self.browse_button.clicked.connect(self.open_file_dialog)
|
|
self.layout.addWidget(self.browse_button)
|
|
|
|
# Create a QPushButton to verify the path
|
|
self.verify_button = QPushButton("Verify", self)
|
|
self.verify_button.clicked.connect(self.verify_path)
|
|
self.layout.addWidget(self.verify_button)
|
|
|
|
self.setLayout(self.layout)
|
|
self.setWindowTitle("Path Widget Example")
|
|
|
|
def open_file_dialog(self):
|
|
path, _ = QFileDialog.getExistingDirectory(self, "Select Directory")
|
|
if path:
|
|
self.path_input.setText(path)
|
|
|
|
def verify_path(self):
|
|
verify_path(self.path_input.text())
|
|
|
|
if __name__ == "__main__":
|
|
app = QApplication(sys.argv)
|
|
widget = PathWidget()
|
|
widget.show()
|
|
sys.exit(app.exec_()) |