Skip to content

FileDeviceMixin

Base classes

Name Children Inherits
IODeviceMixin
prettyqt.core.iodevice

Subclasses

Class Module Description
FileDevice prettyqt.core.filedevice
FileMixin prettyqt.core.file
SaveFile prettyqt.core.savefile

⋔ Inheritance diagram

graph TD
  1473299857968["core.FileDeviceMixin"]
  1473299871632["core.IODeviceMixin"]
  1473299815024["core.ObjectMixin"]
  140713234304496["builtins.object"]
  1473299871632 --> 1473299857968
  1473299815024 --> 1473299871632
  140713234304496 --> 1473299815024

🛈 DocStrings

Bases: IODeviceMixin

Interface for reading from and writing to open files.

Source code in prettyqt\core\filedevice.py
class FileDeviceMixin(core.IODeviceMixin):
    """Interface for reading from and writing to open files."""

    def __repr__(self):
        return get_repr(self, self.fileName())

    def __str__(self):
        return self.fileName()

    # def __fspath__(self) -> str:
    #     return self.fileName()

    def get_permissions(self) -> list[PermissionStr]:
        return PERMISSIONS.get_list(self.permissions())

    def set_file_time(
        self,
        file_time: datatypes.DateTimeType,
        typ: FileTimeStr | core.QFileDevice.FileTime,
    ) -> bool:
        """Set file time.

        Args:
            file_time: file time to set
            typ: file time type
        """
        file_time = datatypes.to_datetime(file_time)
        return self.setFileTime(file_time, FILE_TIME.get_enum_value(typ))  # type: ignore

    def get_file_time(
        self, typ: FileTimeStr | core.QFileDevice.FileTime
    ) -> datetime.datetime | None:
        """Return current file time.

        Returns:
            file time
        """
        if date := self.fileTime(FILE_TIME.get_enum_value(typ)):
            return date.toPython()  # type: ignore
        return None

    def get_error(self) -> FileErrorStr:
        """Return file error status.

        Returns:
            file error status
        """
        return FILE_ERROR.inverse[self.error()]

    def is_readable(self) -> bool:
        """Returns whether file has ReadUser permission flag."""
        return self.permissions() & core.QFileDevice.Permission.ReadUser

    def is_writable(self) -> bool:
        """Returns whether file has WriteUser permission flag."""
        return self.permissions() & core.QFileDevice.Permission.WriteUser

    def is_executable(self) -> bool:
        """Returns whether file has ExeUser permission flag."""
        return self.permissions() & core.QFileDevice.Permission.ExeUser

get_error() -> FileErrorStr

Return file error status.

Source code in prettyqt\core\filedevice.py
def get_error(self) -> FileErrorStr:
    """Return file error status.

    Returns:
        file error status
    """
    return FILE_ERROR.inverse[self.error()]

get_file_time(typ: FileTimeStr | core.QFileDevice.FileTime) -> datetime.datetime | None

Return current file time.

Source code in prettyqt\core\filedevice.py
def get_file_time(
    self, typ: FileTimeStr | core.QFileDevice.FileTime
) -> datetime.datetime | None:
    """Return current file time.

    Returns:
        file time
    """
    if date := self.fileTime(FILE_TIME.get_enum_value(typ)):
        return date.toPython()  # type: ignore
    return None

is_executable() -> bool

Returns whether file has ExeUser permission flag.

Source code in prettyqt\core\filedevice.py
def is_executable(self) -> bool:
    """Returns whether file has ExeUser permission flag."""
    return self.permissions() & core.QFileDevice.Permission.ExeUser

is_readable() -> bool

Returns whether file has ReadUser permission flag.

Source code in prettyqt\core\filedevice.py
def is_readable(self) -> bool:
    """Returns whether file has ReadUser permission flag."""
    return self.permissions() & core.QFileDevice.Permission.ReadUser

is_writable() -> bool

Returns whether file has WriteUser permission flag.

Source code in prettyqt\core\filedevice.py
def is_writable(self) -> bool:
    """Returns whether file has WriteUser permission flag."""
    return self.permissions() & core.QFileDevice.Permission.WriteUser

set_file_time(file_time: datatypes.DateTimeType, typ: FileTimeStr | core.QFileDevice.FileTime) -> bool

Set file time.

Parameters:

Name Type Description Default
file_time DateTimeType

file time to set

required
typ FileTimeStr | FileTime

file time type

required
Source code in prettyqt\core\filedevice.py
def set_file_time(
    self,
    file_time: datatypes.DateTimeType,
    typ: FileTimeStr | core.QFileDevice.FileTime,
) -> bool:
    """Set file time.

    Args:
        file_time: file time to set
        typ: file time type
    """
    file_time = datatypes.to_datetime(file_time)
    return self.setFileTime(file_time, FILE_TIME.get_enum_value(typ))  # type: ignore