You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ArtNet-Desktop/ArtNet/gui/manual_picture_importer.py

105 lines
3.2 KiB
Python

from PyQt5.QtWidgets import QMainWindow, QWidget, QLabel, QDesktopWidget, QToolBar, QPushButton, QGroupBox, QGridLayout
from PyQt5.QtWidgets import QVBoxLayout
from PyQt5.QtGui import QPixmap
from PyQt5.QtCore import Qt
class PictureImporter(QMainWindow):
def __init__(self, parent=None, max_relative_resize_width: float = 0.8, max_relative_resize_height: float = 0.8,):
super().__init__(parent)
# Menubar
self.__menu_bar = self.menuBar()
self.__menu_bar.addAction("Action1")
self.__menu_bar.addAction("Action2")
# Toolbar
open = QToolBar()
open.addAction("Open")
self.addToolBar(open)
close = QToolBar()
close.addAction("Close")
self.addToolBar(close)
# layout
self.__layout = QGridLayout()
# Central Component Settings
self.__window = QWidget()
self.setCentralWidget(self.__window)
# Statusbar Settings
self.__status_bar = self.statusBar()
self.__status_bar.showMessage("Welcome to ArtNet! :)", 5000)
label = QLabel("ArtNet - v0.1")
self.__status_bar.addPermanentWidget(label)
self.resize(800, 600)
self.setWindowTitle("ArtNet - Picture Importer")
self.center()
def center(self):
"""
Centers the window in the middle of the screen
:return:
"""
screen = QDesktopWidget().screenGeometry()
size = self.geometry()
self.move((screen.width() - size.width()) / 2, (screen.height() - size.height()) / 2)
@DeprecationWarning
def display_geometry(self):
x = self.x()
y = self.y()
print("x: {0}, y: {1}".format(x, y))
x = self.pos().x()
y = self.pos().y()
print("x: {0}, y: {1}".format(x, y))
x = self.frameGeometry().x()
y = self.frameGeometry().y()
print("x: {0}, y: {1}".format(x, y))
x = self.geometry().x()
y = self.geometry().y()
print("x: {0}, y: {1}".format(x, y))
print("geometry: ", self.geometry())
print("frameGeometry: ", self.frameGeometry())
def set_temporary_status_message(self, text: str, duration: int):
"""
Set a temporary status message (bottom left) for the given duration in milliseconds.
:param text:
:param duration:
:return:
"""
self.__status_bar.showMessage("Welcome to ArtNet! :)", 5000)
def display_image(self, full_path: str):
"""
Display an image in the central widget
:param full_path:
:return:
"""
label = QLabel(self)
pixmap = self.__image_resize(QPixmap(full_path))
label.setPixmap(pixmap)
label.setAlignment(Qt.AlignCenter)
self.setCentralWidget(label)
self.center()
def __image_resize(self, pixmap: QPixmap) -> QPixmap:
"""
Resize the given pixmap so that we're not out of the desktop.
:return: new scaled QPixmap
"""
return pixmap
screen_rect = QDesktopWidget().screenGeometry()
print("Resizing pixmap to", int(screen_rect.width()*0.4), int(screen_rect.height()*0.6))
return pixmap.scaled(int(screen_rect.width()*0.6), int(screen_rect.height()*0.7), Qt.KeepAspectRatio)