Skip to content

Commit

Permalink
GUI: make dropzone rounded
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Laurent committed Dec 25, 2024
1 parent 6078cdc commit 09441a7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions fmu_manipulation_toolbox/gui.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os.path
import sys
from .version import __version__ as version
from PyQt6.QtCore import Qt, QObject, QUrl, pyqtSignal, QDir
from PyQt6.QtCore import Qt, QObject, QUrl, pyqtSignal, QDir, QSize, QRect
from PyQt6.QtWidgets import (QApplication, QWidget, QGridLayout, QLabel, QLineEdit, QPushButton, QFileDialog,
QTextBrowser, QInputDialog, QMenu)
from PyQt6.QtGui import (QPixmap, QImage, QFont, QTextCursor, QIcon, QDesktopServices, QAction)
from PyQt6.QtGui import (QPixmap, QImage, QFont, QTextCursor, QIcon, QDesktopServices, QAction, QPainter, QColor)
import textwrap
from functools import partial
from typing import Optional
Expand Down Expand Up @@ -70,11 +70,23 @@ def set_image(self, filename=None):
elif not os.path.isfile(filename):
filename = os.path.join(os.path.dirname(__file__), "resources", "fmu.png")

image = QImage(filename).scaled(self.WIDTH, self.HEIGHT, Qt.AspectRatioMode.IgnoreAspectRatio,
Qt.TransformationMode.SmoothTransformation)
pixmap = QPixmap.fromImage(image)
base_image = QImage(filename).scaled(self.WIDTH, self.HEIGHT, Qt.AspectRatioMode.IgnoreAspectRatio,
Qt.TransformationMode.SmoothTransformation)
mask_filename = os.path.join(os.path.dirname(__file__), "resources", "mask.png")
mask_image = QImage(mask_filename).scaled(self.WIDTH, self.HEIGHT, Qt.AspectRatioMode.IgnoreAspectRatio,
Qt.TransformationMode.SmoothTransformation)
rounded = QImage(QSize(self.WIDTH, self.HEIGHT), QImage.Format.Format_ARGB32)
rounded.fill(QColor(0, 0, 0, 0))
painter = QPainter()
painter.begin(rounded)
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
painter.drawImage(QRect(0, 0, self.WIDTH, self.HEIGHT), base_image)
painter.drawImage(QRect(0, 0, self.WIDTH, self.HEIGHT), mask_image)
painter.end()
pixmap = QPixmap.fromImage(rounded)
self.setPixmap(pixmap)


def set_fmu(self, filename):
try:
self.last_directory = os.path.dirname(filename)
Expand Down Expand Up @@ -203,6 +215,9 @@ def __init__(self, *args, **kwargs):

# set the grid layout
self.layout = QGridLayout()
self.layout.setVerticalSpacing(4)
self.layout.setHorizontalSpacing(4)
self.layout.setContentsMargins(10, 10, 10, 10)
self.setLayout(self.layout)

self.dropped_fmu = DropZoneWidget()
Expand Down Expand Up @@ -424,8 +439,8 @@ class Application(QApplication):
"""
Analyse and modify your FMUs.
Note: modifying the modelDescription.xml can damage your FMU ! Communicating with the FMU-developer and adapting the
way the FMU is generated, is preferable when possible.
Note: modifying the modelDescription.xml can damage your FMU !
Communicating with the FMU-developer and adapting the way the FMU is generated, is preferable when possible.
"""
def __init__(self, *args, **kwargs):
Expand Down
Binary file modified fmu_manipulation_toolbox/resources/drop_fmu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fmu_manipulation_toolbox/resources/mask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 09441a7

Please sign in to comment.