Skip to content

Url

Qt Base Class: QUrl

Signature: QUrl(self) -> None QUrl(self, copy: Union[PySide6.QtCore.QUrl, str]) -> None QUrl(self, url: str, mode: PySide6.QtCore.QUrl.ParsingMode = Instance(QUrl.ParsingMode.TolerantMode)) -> None

Base classes

Name Children Inherits
SerializeMixin
prettyqt.utils.serializemixin
QUrl
PySide6.QtCore
QUrl(self) -> None

⋔ Inheritance diagram

graph TD
  1473299829664["core.Url"]
  1473299806240["utils.SerializeMixin"]
  140713234304496["builtins.object"]
  1473289014016["QtCore.QUrl"]
  1473291690208["Shiboken.Object"]
  1473299806240 --> 1473299829664
  140713234304496 --> 1473299806240
  1473289014016 --> 1473299829664
  1473291690208 --> 1473289014016
  140713234304496 --> 1473291690208

🛈 DocStrings

Bases: SerializeMixin, QUrl

Convenient interface for working with URLs.

Source code in prettyqt\core\url.py
class Url(serializemixin.SerializeMixin, QtCore.QUrl):
    """Convenient interface for working with URLs."""

    def __init__(self, *args, **kwargs):
        match args:
            case (os.PathLike(), *rest):
                path = os.fspath(args[0])
                if pathlib.Path(path).exists():
                    path = self.fromLocalFile(path)
                super().__init__(path, *rest, **kwargs)
            case _:
                super().__init__(*args, **kwargs)

    @property
    def _toString(self) -> str:
        return self.toString()

    __match_args__ = ("_toString",)

    # def __str__(self):
    #     return self.absolutePath()

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

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

    def serialize_fields(self):
        return dict(path=self.toString())

    def serialize(self) -> dict[str, Any]:
        return self.serialize_fields()

    def to_string(self) -> str:
        return self.toString()

    def to_path(self) -> pathlib.Path:
        """Get pathlib object from the URL.

        Returns:
            Path
        """
        return pathlib.Path(str(self))

    def is_local_file(self) -> bool:
        return self.isLocalFile()

    @classmethod
    def from_user_input(cls, url: str, working_dir: str | None = None) -> Self:
        if working_dir is None:
            working_dir = ""
        return cls(cls.fromUserInput(url, working_dir))

    @classmethod
    def from_local_file(cls, path: datatypes.PathType) -> Self:
        url = cls.fromLocalFile(os.fspath(path))
        return cls(url)

    def _has_explicit_scheme(self) -> bool:
        """Check if a url has an explicit scheme given."""
        return bool(
            self.isValid()
            and self.scheme()
            and (self.host() or self.path())
            and not self.path().startswith(":")
        )

    def is_special_url(self) -> bool:
        """Return True if url is an about:... or other special URL."""
        return self.scheme() in ("about", "file") if self.isValid() else False

is_special_url() -> bool

Return True if url is an about:... or other special URL.

Source code in prettyqt\core\url.py
def is_special_url(self) -> bool:
    """Return True if url is an about:... or other special URL."""
    return self.scheme() in ("about", "file") if self.isValid() else False

to_path() -> pathlib.Path

Get pathlib object from the URL.

Source code in prettyqt\core\url.py
def to_path(self) -> pathlib.Path:
    """Get pathlib object from the URL.

    Returns:
        Path
    """
    return pathlib.Path(str(self))