checkpoint
This commit is contained in:
@@ -2,6 +2,8 @@ from PyQt5 import QtCore, QtGui, QtWidgets
|
|||||||
import psutil
|
import psutil
|
||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
|
import platform
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
class Location_Validator(QtGui.QValidator):
|
class Location_Validator(QtGui.QValidator):
|
||||||
@@ -25,16 +27,17 @@ class Location_Validator(QtGui.QValidator):
|
|||||||
location {str} -- A string representing a folder path
|
location {str} -- A string representing a folder path
|
||||||
"""
|
"""
|
||||||
parent_dirs = [str(parent_dir) for parent_dir in pathlib.Path(location).parents]
|
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:
|
if match:
|
||||||
self._ntfs_location_selected = True
|
self._ntfs_location_selected = True
|
||||||
return True
|
return True
|
||||||
|
#elif platform.system() == "Linux":
|
||||||
|
# pass
|
||||||
else:
|
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):
|
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
|
return False
|
||||||
else:
|
else:
|
||||||
self._ntfs_location_selected = False
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def validate(self, input_, pos):
|
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
|
pos {int} -- The current location of the cursor in the QLineEdit widget
|
||||||
"""
|
"""
|
||||||
if not input_.strip():
|
if not input_.strip():
|
||||||
self._previous["location"] = input_
|
self._previous["location"] = Path(input_.strip())
|
||||||
self._previous["disposition"] = (QtGui.QValidator.Intermediate, input_, pos,)
|
self._previous["disposition"] = (QtGui.QValidator.Intermediate, input_, pos,)
|
||||||
return (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
|
#I really hate that I have to do this
|
||||||
return self._previous["disposition"]
|
return self._previous["disposition"]
|
||||||
elif input_.strip().endswith(r":"):
|
elif input_.strip().endswith(r":"):
|
||||||
self._previous["location"] = input_
|
self._previous["location"] = Path(input_.strip())
|
||||||
self._previous["disposition"] = (QtGui.QValidator.Intermediate, input_, pos,)
|
self._previous["disposition"] = (QtGui.QValidator.Intermediate, input_, pos,)
|
||||||
# bugfix. _onNTFSDrive triggers when typing the : in a drive name e.g. C:\
|
# bugfix. _onNTFSDrive triggers when typing the : in a drive name e.g. C:\
|
||||||
return (QtGui.QValidator.Intermediate, input_, pos,)
|
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
|
input_ = os.path.expandvars(input_.strip()) # expand any environment variables in input
|
||||||
location = QtCore.QFileInfo(input_)
|
location = QtCore.QFileInfo(input_)
|
||||||
if location.exists() and location.isDir():
|
if location.exists() and location.isDir():
|
||||||
|
|
||||||
if input_ and not self._onNTFSDrive(input_):
|
if input_ and not self._onNTFSDrive(input_):
|
||||||
self._previous["location"] = input_
|
self._previous["location"] = Path(input_)
|
||||||
self._previous["disposition"] = (QtGui.QValidator.Intermediate, "", 0)
|
self._previous["disposition"] = (QtGui.QValidator.Intermediate, "", 0)
|
||||||
# clear the location, reset cursor, but allow continued edits
|
# clear the location, reset cursor, but allow continued edits
|
||||||
return (QtGui.QValidator.Intermediate, "", 0)
|
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):
|
if test_file.open(QtCore.QIODevice.ReadWrite):
|
||||||
test_file.close()
|
test_file.close()
|
||||||
test_file.remove()
|
test_file.remove()
|
||||||
self._previous["location"] = input_
|
self._previous["location"] = Path(input_)
|
||||||
self._previous["disposition"] = (QtGui.QValidator.Acceptable, input_, pos,)
|
self._previous["disposition"] = (QtGui.QValidator.Acceptable, input_, pos,)
|
||||||
return (QtGui.QValidator.Acceptable, input_, pos,)
|
return (QtGui.QValidator.Acceptable, input_, pos,)
|
||||||
else:
|
else:
|
||||||
self._previous["location"] = input_
|
self._previous["location"] = Path(input_)
|
||||||
self._previous["disposition"] = (QtGui.QValidator.Intermediate, input_, pos,)
|
self._previous["disposition"] = (QtGui.QValidator.Intermediate, input_, pos,)
|
||||||
return (QtGui.QValidator.Intermediate, input_, pos,)
|
return (QtGui.QValidator.Intermediate, input_, pos,)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self._previous["location"] = input_
|
self._previous["location"] = Path(input_)
|
||||||
self._previous["disposition"] = (QtGui.QValidator.Intermediate, input_, pos,)
|
self._previous["disposition"] = (QtGui.QValidator.Intermediate, input_, pos,)
|
||||||
# I wanted to return invalid, but that would prevent input of anything not instantly acceptable
|
# 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
|
# or editing something acceptable to something else acceptable, passing through an invalid on the way
|
||||||
|
|||||||
Reference in New Issue
Block a user