Skip to content

Commit

Permalink
Merge pull request #74 from Integration-Automation/dev
Browse files Browse the repository at this point in the history
Add save image on generation image
  • Loading branch information
JE-Chen authored Aug 24, 2023
2 parents f1d45da + 3aa7bec commit ae94cec
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 10 deletions.
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

0 comments on commit ae94cec

Please sign in to comment.