mirror of
https://github.com/arsenetar/dupeguru.git
synced 2025-05-07 09:19:50 +00:00
Add type hinting to desktop.py
This commit is contained in:
parent
f587c7b5d8
commit
f7ed1c801c
@ -134,7 +134,7 @@ class DupeGuru(Broadcaster):
|
|||||||
logging.debug("Debug mode enabled")
|
logging.debug("Debug mode enabled")
|
||||||
Broadcaster.__init__(self)
|
Broadcaster.__init__(self)
|
||||||
self.view = view
|
self.view = view
|
||||||
self.appdata = desktop.special_folder_path(desktop.SpecialFolder.APPDATA, appname=self.NAME, portable=portable)
|
self.appdata = desktop.special_folder_path(desktop.SpecialFolder.APPDATA, portable=portable)
|
||||||
if not op.exists(self.appdata):
|
if not op.exists(self.appdata):
|
||||||
os.makedirs(self.appdata)
|
os.makedirs(self.appdata)
|
||||||
self.app_mode = AppMode.STANDARD
|
self.app_mode = AppMode.STANDARD
|
||||||
|
@ -6,31 +6,33 @@
|
|||||||
# which should be included with this package. The terms are also available at
|
# which should be included with this package. The terms are also available at
|
||||||
# http://www.gnu.org/licenses/gpl-3.0.html
|
# http://www.gnu.org/licenses/gpl-3.0.html
|
||||||
|
|
||||||
|
from enum import Enum
|
||||||
|
from os import PathLike
|
||||||
import os.path as op
|
import os.path as op
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
|
||||||
class SpecialFolder:
|
class SpecialFolder(Enum):
|
||||||
APPDATA = 1
|
APPDATA = 1
|
||||||
CACHE = 2
|
CACHE = 2
|
||||||
|
|
||||||
|
|
||||||
def open_url(url):
|
def open_url(url: str) -> None:
|
||||||
"""Open ``url`` with the default browser."""
|
"""Open ``url`` with the default browser."""
|
||||||
_open_url(url)
|
_open_url(url)
|
||||||
|
|
||||||
|
|
||||||
def open_path(path):
|
def open_path(path: PathLike) -> None:
|
||||||
"""Open ``path`` with its associated application."""
|
"""Open ``path`` with its associated application."""
|
||||||
_open_path(str(path))
|
_open_path(str(path))
|
||||||
|
|
||||||
|
|
||||||
def reveal_path(path):
|
def reveal_path(path: PathLike) -> None:
|
||||||
"""Open the folder containing ``path`` with the default file browser."""
|
"""Open the folder containing ``path`` with the default file browser."""
|
||||||
_reveal_path(str(path))
|
_reveal_path(str(path))
|
||||||
|
|
||||||
|
|
||||||
def special_folder_path(special_folder, appname=None, portable=False):
|
def special_folder_path(special_folder: SpecialFolder, portable: bool = False) -> str:
|
||||||
"""Returns the path of ``special_folder``.
|
"""Returns the path of ``special_folder``.
|
||||||
|
|
||||||
``special_folder`` is a SpecialFolder.* const. The result is the special folder for the current
|
``special_folder`` is a SpecialFolder.* const. The result is the special folder for the current
|
||||||
@ -38,7 +40,7 @@ def special_folder_path(special_folder, appname=None, portable=False):
|
|||||||
|
|
||||||
You can override the application name with ``appname``. This argument is ingored under Qt.
|
You can override the application name with ``appname``. This argument is ingored under Qt.
|
||||||
"""
|
"""
|
||||||
return _special_folder_path(special_folder, appname, portable=portable)
|
return _special_folder_path(special_folder, portable=portable)
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -49,14 +51,14 @@ try:
|
|||||||
from hscommon.plat import ISWINDOWS, ISOSX
|
from hscommon.plat import ISWINDOWS, ISOSX
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
def _open_url(url):
|
def _open_url(url: str) -> None:
|
||||||
QDesktopServices.openUrl(QUrl(url))
|
QDesktopServices.openUrl(QUrl(url))
|
||||||
|
|
||||||
def _open_path(path):
|
def _open_path(path: str) -> None:
|
||||||
url = QUrl.fromLocalFile(str(path))
|
url = QUrl.fromLocalFile(str(path))
|
||||||
QDesktopServices.openUrl(url)
|
QDesktopServices.openUrl(url)
|
||||||
|
|
||||||
def _reveal_path(path):
|
def _reveal_path(path: str) -> None:
|
||||||
if ISWINDOWS:
|
if ISWINDOWS:
|
||||||
subprocess.run(["explorer", "/select,", op.abspath(path)])
|
subprocess.run(["explorer", "/select,", op.abspath(path)])
|
||||||
elif ISOSX:
|
elif ISOSX:
|
||||||
@ -64,7 +66,7 @@ try:
|
|||||||
else:
|
else:
|
||||||
_open_path(op.dirname(str(path)))
|
_open_path(op.dirname(str(path)))
|
||||||
|
|
||||||
def _special_folder_path(special_folder, appname=None, portable=False):
|
def _special_folder_path(special_folder: SpecialFolder, portable: bool = False) -> str:
|
||||||
if special_folder == SpecialFolder.CACHE:
|
if special_folder == SpecialFolder.CACHE:
|
||||||
if ISWINDOWS and portable:
|
if ISWINDOWS and portable:
|
||||||
folder = op.join(executable_folder(), "cache")
|
folder = op.join(executable_folder(), "cache")
|
||||||
@ -79,13 +81,17 @@ except ImportError:
|
|||||||
# weird situation. Let's just have dummy fallbacks.
|
# weird situation. Let's just have dummy fallbacks.
|
||||||
logging.warning("Can't setup desktop functions!")
|
logging.warning("Can't setup desktop functions!")
|
||||||
|
|
||||||
def _open_path(path):
|
def _open_url(url: str) -> None:
|
||||||
# Dummy for tests
|
# Dummy for tests
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _reveal_path(path):
|
def _open_path(path: str) -> None:
|
||||||
# Dummy for tests
|
# Dummy for tests
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def _special_folder_path(special_folder, appname=None, portable=False):
|
def _reveal_path(path: str) -> None:
|
||||||
|
# Dummy for tests
|
||||||
|
pass
|
||||||
|
|
||||||
|
def _special_folder_path(special_folder: SpecialFolder, portable: bool = False) -> str:
|
||||||
return "/tmp"
|
return "/tmp"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user