forked from b-init/ImagePaste
-
Notifications
You must be signed in to change notification settings - Fork 0
/
image.py
43 lines (34 loc) · 1.23 KB
/
image.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class Image:
"""A class to represent an image file."""
pasted_images = {}
def __init__(self, filepath: str, pasted: bool = False) -> None:
"""Constructor for the Image class.
Args:
filepath (str): The path to the image file.
filename (str, optional): The name of the image file.
pasted (bool, optional): Whether the image is pasted.
"""
self.filepath = filepath
if pasted:
Image.pasted_images[self.filepath] = self
@property
def filepath(self) -> str:
"""Get the path to the image file."""
return self._filepath
@filepath.setter
def filepath(self, filepath: str) -> None:
"""Set the path to the image file.
Args:
filepath (str): The path to the image file.
"""
from os.path import basename
from os.path import dirname
self._filepath = filepath
self.filename = basename(filepath)
self.filebase = dirname(filepath)
def __repr__(self) -> str:
"""Return a string representation of the Image class.
Returns:
str: A string representation of the Image class.
"""
return f"{self.filename}<{self.filepath}>"