Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clear canvas on file new #452

Merged
merged 1 commit into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/airunner/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class SignalCode(Enum):
CANVAS_RESIZE_SIGNAL = "canvas_resize_signal"
CANVAS_UPDATE_CURSOR = "canvas_update_cursor"
CANVAS_ZOOM_LEVEL_CHANGED = "zoom_level_changed"
CANVAS_CLEAR = "clear_canvas"

CLEAR_MEMORY_SIGNAL = "clear_memory_signal"
CONTROLNET_IMAGE_GENERATED_SIGNAL = "controlnet_image_generated_signal"
Expand Down
12 changes: 12 additions & 0 deletions src/airunner/widgets/canvas_plus/canvas_plus_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def __init__(self, *args, **kwargs):
self.register(SignalCode.CANVAS_UPDATE_SIGNAL, self.on_update_canvas_signal)
self.register(SignalCode.LAYER_SET_CURRENT_SIGNAL, self.on_set_current_layer_signal)
self.register(SignalCode.APPLICATION_SETTINGS_CHANGED_SIGNAL, self.on_application_settings_changed_signal)
self.register(SignalCode.CANVAS_CLEAR, self.on_canvas_clear_signal)

self.register_service("canvas_drag_pos", self.canvas_drag_pos)
self.register_service("canvas_current_active_image", self.canvas_current_active_image)
Expand Down Expand Up @@ -537,6 +538,17 @@ def draw_layers(self):
self.scene.addItem(self.pixmaps[index])
continue

def on_canvas_clear_signal(self):
print("on canvas clear signal")
self.scene.clear()
self.line_group = QGraphicsItemGroup()
self.pixmaps = {}
settings = self.settings
settings["layers"] = []
self.settings = settings
self.add_layer()
self.do_draw()

def set_scene_rect(self):
self.scene.setSceneRect(0, 0, self.view_size.width(), self.view_size.height())

Expand Down
8 changes: 4 additions & 4 deletions src/airunner/windows/main/layer_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ def delete_layer(self, index, layer):
def on_clear_layers_signal(self, _ignore):
# delete all widgets from self.container.layout()
layers = self.settings["layers"]
for index, layer in enumerate(layers):
if not layer.layer_widget:
continue
layer.layer_widget.deleteLater()
# for index, layer in enumerate(layers):
# if not layer["layer_widget"]:
# continue
# layer["layer_widget"].deleteLater()
self.add_layer()
settings = self.settings
settings["layers"] = layers
Expand Down
2 changes: 1 addition & 1 deletion src/airunner/windows/main/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ def quick_export(self):
"""
def action_new_document_triggered(self):
self.new_document()
self.emit(SignalCode.CANVAS_CLEAR)

def action_quick_export_image_triggered(self):
self.quick_export()
Expand Down Expand Up @@ -963,7 +964,6 @@ def set_window_title(self):

def new_document(self):
self.ui.layer_widget.clear_layers()
self.clear_history()
self.is_saved = False
self._document_name = "Untitled"
self.set_window_title()
Expand Down