-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathstate.py
More file actions
70 lines (56 loc) · 2.18 KB
/
state.py
File metadata and controls
70 lines (56 loc) · 2.18 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from typing import Optional
from PySide6.QtCore import QObject, Signal
from PySide6.QtGui import QColor
from utils import config
class AppState(QObject):
dirty_changed = Signal(bool)
file_path_changed = Signal(str)
primary_color_changed = Signal(QColor)
secondary_color_changed = Signal(QColor)
tool_changed = Signal(str)
image_changed = Signal()
def __init__(self):
super().__init__()
self._is_dirty: bool = False
self._current_file_path: Optional[str] = None
self._primary_color: QColor = config.DEFAULT_PRIMARY_COLOR
self._secondary_color: QColor = config.DEFAULT_SECONDARY_COLOR
self._current_tool: str = config.ToolType.PENCIL
@property
def is_dirty(self) -> bool:
return self._is_dirty
def set_dirty(self, dirty: bool):
if self._is_dirty != dirty:
self._is_dirty = dirty
self.dirty_changed.emit(dirty)
@property
def current_file_path(self) -> Optional[str]:
return self._current_file_path
def set_file_path(self, path: Optional[str], mark_dirty: bool = False):
self._current_file_path = path
self.set_dirty(mark_dirty)
self.file_path_changed.emit(path or "Untitled")
@property
def primary_color(self) -> QColor:
return self._primary_color
def set_primary_color(self, color: QColor):
if color.isValid() and self._primary_color != color:
self._primary_color = color
self.primary_color_changed.emit(color)
@property
def secondary_color(self) -> QColor:
return self._secondary_color
def set_secondary_color(self, color: QColor):
if color.isValid() and self._secondary_color != color:
self._secondary_color = color
self.secondary_color_changed.emit(color)
@property
def current_tool(self) -> str:
return self._current_tool
def set_tool(self, tool_name: str):
if self._current_tool != tool_name and tool_name in config.TOOLS:
self._current_tool = tool_name
self.tool_changed.emit(tool_name)
def notify_image_changed(self):
self.set_dirty(True)
self.image_changed.emit()