checkpoint
This commit is contained in:
@@ -2,6 +2,8 @@ from PyQt5 import QtCore, QtGui, QtWidgets
|
||||
import psutil
|
||||
import os
|
||||
import pathlib
|
||||
import platform
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class Location_Validator(QtGui.QValidator):
|
||||
@@ -25,16 +27,17 @@ class Location_Validator(QtGui.QValidator):
|
||||
location {str} -- A string representing a folder path
|
||||
"""
|
||||
parent_dirs = [str(parent_dir) for parent_dir in pathlib.Path(location).parents]
|
||||
match = [drive for drive in psutil.disk_partitions() if (drive.mountpoint in parent_dirs and drive.fstype == "NTFS")]
|
||||
match = [drive for drive in psutil.disk_partitions() if (drive.mountpoint in parent_dirs and drive.fstype.lower() == "ntfs")]
|
||||
if match:
|
||||
self._ntfs_location_selected = True
|
||||
return True
|
||||
#elif platform.system() == "Linux":
|
||||
# pass
|
||||
else:
|
||||
self._ntfs_location_selected = False
|
||||
if QtWidgets.QMessageBox.question(self.parent(), "", f"{pathlib.Path(location)} is not an NTFS-formatted volume. Tools which require a NTFS filesystem to function will not be available. Continue anyway?") in (QtWidgets.QMessageBox.No, 0):
|
||||
self._ntfs_location_selected = False
|
||||
return False
|
||||
else:
|
||||
self._ntfs_location_selected = False
|
||||
return True
|
||||
|
||||
def validate(self, input_, pos):
|
||||
@@ -45,14 +48,14 @@ class Location_Validator(QtGui.QValidator):
|
||||
pos {int} -- The current location of the cursor in the QLineEdit widget
|
||||
"""
|
||||
if not input_.strip():
|
||||
self._previous["location"] = input_
|
||||
self._previous["location"] = Path(input_.strip())
|
||||
self._previous["disposition"] = (QtGui.QValidator.Intermediate, input_, pos,)
|
||||
return (QtGui.QValidator.Intermediate, input_, pos,)
|
||||
elif input_.strip() == self._previous["location"]:
|
||||
elif Path(input_.strip()) == self._previous["location"]:
|
||||
#I really hate that I have to do this
|
||||
return self._previous["disposition"]
|
||||
elif input_.strip().endswith(r":"):
|
||||
self._previous["location"] = input_
|
||||
self._previous["location"] = Path(input_.strip())
|
||||
self._previous["disposition"] = (QtGui.QValidator.Intermediate, input_, pos,)
|
||||
# bugfix. _onNTFSDrive triggers when typing the : in a drive name e.g. C:\
|
||||
return (QtGui.QValidator.Intermediate, input_, pos,)
|
||||
@@ -65,28 +68,27 @@ class Location_Validator(QtGui.QValidator):
|
||||
input_ = os.path.expandvars(input_.strip()) # expand any environment variables in input
|
||||
location = QtCore.QFileInfo(input_)
|
||||
if location.exists() and location.isDir():
|
||||
|
||||
if input_ and not self._onNTFSDrive(input_):
|
||||
self._previous["location"] = input_
|
||||
self._previous["location"] = Path(input_)
|
||||
self._previous["disposition"] = (QtGui.QValidator.Intermediate, "", 0)
|
||||
# clear the location, reset cursor, but allow continued edits
|
||||
return (QtGui.QValidator.Intermediate, "", 0)
|
||||
|
||||
test_file = QtCore.QTemporaryFile(input_ + r"\testXXXXXX.tmp")
|
||||
test_file = QtCore.QTemporaryFile(f"{Path(input_)/'testXXXXXX.tmp'}")
|
||||
|
||||
if test_file.open(QtCore.QIODevice.ReadWrite):
|
||||
test_file.close()
|
||||
test_file.remove()
|
||||
self._previous["location"] = input_
|
||||
self._previous["location"] = Path(input_)
|
||||
self._previous["disposition"] = (QtGui.QValidator.Acceptable, input_, pos,)
|
||||
return (QtGui.QValidator.Acceptable, input_, pos,)
|
||||
else:
|
||||
self._previous["location"] = input_
|
||||
self._previous["location"] = Path(input_)
|
||||
self._previous["disposition"] = (QtGui.QValidator.Intermediate, input_, pos,)
|
||||
return (QtGui.QValidator.Intermediate, input_, pos,)
|
||||
|
||||
else:
|
||||
self._previous["location"] = input_
|
||||
self._previous["location"] = Path(input_)
|
||||
self._previous["disposition"] = (QtGui.QValidator.Intermediate, input_, pos,)
|
||||
# I wanted to return invalid, but that would prevent input of anything not instantly acceptable
|
||||
# or editing something acceptable to something else acceptable, passing through an invalid on the way
|
||||
|
||||
Reference in New Issue
Block a user