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

Add save image on generation image #74

Merged
merged 1 commit into from
Aug 24, 2023
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
4 changes: 2 additions & 2 deletions stable.toml → dev.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[project]
name = "frontengine"
version = "0.0.42"
name = "frontengine_dev"
version = "0.0.44"
authors = [
{ name = "JE-Chen", email = "[email protected]" },
]
Expand Down
35 changes: 32 additions & 3 deletions frontengine/show/image_generation/image_generation_show.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,43 @@
from PySide6.QtGui import QPixmap
from PySide6.QtWidgets import QWidget, QLabel, QGridLayout
from pathlib import Path

import PySide6
from PySide6.QtGui import QPixmap, QAction, Qt
from PySide6.QtWidgets import QWidget, QLabel, QGridLayout, QFileDialog, QMenu

from frontengine.utils.multi_language.language_wrapper import language_wrapper


class ImageGenerateShow(QWidget):

def __init__(self, pixmap: QPixmap):
def __init__(self, pixmap: QPixmap, title: str):
super().__init__()
self.setWindowTitle(title)
self.pixmap = pixmap
self.label = QLabel()
self.label.setPixmap(pixmap)
self.grid_layout = QGridLayout(self)
self.grid_layout.setContentsMargins(0, 0, 0, 0)
self.grid_layout.addWidget(self.label)
self.setLayout(self.grid_layout)

# Menubar
self.menu = QMenu(self)
self.save_image_action = QAction(language_wrapper.language_word_dict.get("save_generation_image"))
self.save_image_action.triggered.connect(self.save_image)
self.menu.addAction(self.save_image_action)

def save_image(self):
file_path = QFileDialog().getSaveFileName(
parent=self,
dir=str(Path.cwd()),
filter="Images (*.png;*.jpg;*.webp)"
)[0]
file_path = Path(file_path)
if file_path.is_file():
self.pixmap.save(str(file_path))

def mousePressEvent(self, event: PySide6.QtGui.QMouseEvent) -> None:
if event.button() == Qt.MouseButton.RightButton:
self.menu.move(self.x() + event.x(), self.y() + event.y())
self.menu.show()
super().mousePressEvent(event)
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def get_image(self):
image_response = requests.get(image_link)
image = QPixmap()
image.loadFromData(image_response.content)
image_show = ImageGenerateShow(image)
image_show = ImageGenerateShow(image, image_link)
self.show_list.append(image_show)
image_show.show()
self.image_panel.appendPlainText(image_link)
Expand All @@ -59,4 +59,3 @@ def close(self) -> bool:
for widget in self.show_list:
widget.close()
return super().close()

3 changes: 2 additions & 1 deletion frontengine/utils/multi_language/english.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,6 @@
# Image Generation
"image_generation_tab": "Image generation",
"start_generate_image": "Star generate",
"input_error": "Please input something"
"input_error": "Please input something",
"save_generation_image": "Save Image",
}
3 changes: 2 additions & 1 deletion frontengine/utils/multi_language/traditional_chinese.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,6 @@
# Image Generation
"image_generation_tab": "圖片產生",
"start_generate_image": "開始產生圖片",
"input_error": "請勿無輸入或空格"
"input_error": "請勿無輸入或空格",
"save_generation_image": "儲存圖片",
}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[project]
name = "frontengine_dev"
name = "frontengine"
version = "0.0.43"
authors = [
{ name = "JE-Chen", email = "[email protected]" },
Expand Down