fixed x11 and wayland popup display
This commit is contained in:
parent
fb6360309a
commit
cf817a62d0
1 changed files with 46 additions and 26 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
from PyQt6.QtWidgets import QComboBox, QButtonGroup, QLineEdit, QMainWindow, QLabel, QWidget, QStackedWidget, QApplication, QPushButton, QTextEdit, QFrame, QHBoxLayout, QVBoxLayout, QScrollArea, QSystemTrayIcon, QMessageBox, QGraphicsDropShadowEffect, QGridLayout, QCheckBox, QStackedLayout, QGroupBox, QDialog, QPlainTextEdit, QListWidget, QListWidgetItem
|
from PyQt6.QtWidgets import QComboBox, QButtonGroup, QLineEdit, QMainWindow, QLabel, QWidget, QStackedWidget, QApplication, QPushButton, QTextEdit, QFrame, QHBoxLayout, QVBoxLayout, QScrollArea, QSystemTrayIcon, QMessageBox, QGraphicsDropShadowEffect, QGridLayout, QCheckBox, QStackedLayout, QGroupBox, QDialog, QPlainTextEdit, QListWidget, QListWidgetItem
|
||||||
from PyQt6.QtGui import QIcon, QPixmap, QTransform, QPainter, QColor, QFont, QFontDatabase
|
from PyQt6.QtGui import QIcon, QPixmap, QTransform, QPainter, QColor, QFont, QFontDatabase, QGuiApplication
|
||||||
from PyQt6 import QtGui
|
from PyQt6 import QtGui
|
||||||
from PyQt6 import QtCore
|
from PyQt6 import QtCore
|
||||||
from PyQt6.QtCore import Qt, QSize, QThread, pyqtSignal, QTimer, QPointF, QRect, QMutex, QMutexLocker, QObject
|
from PyQt6.QtCore import Qt, QSize, QThread, pyqtSignal, QTimer, QPointF, QRect, QMutex, QMutexLocker, QObject
|
||||||
|
|
@ -8966,19 +8966,23 @@ class ConfirmationPopup(QWidget):
|
||||||
self.oldPos = event.globalPosition().toPoint()
|
self.oldPos = event.globalPosition().toPoint()
|
||||||
|
|
||||||
|
|
||||||
class TicketDataLossPopup(QWidget):
|
class TicketDataLossPopup(QDialog):
|
||||||
finished = pyqtSignal()
|
|
||||||
|
|
||||||
def __init__(self, parent=None, ticket_number="", billing_code=""):
|
def __init__(self, parent=None, ticket_number="", billing_code=""):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self.parent_window = parent
|
self.parent_window = parent
|
||||||
|
self._use_parent_local_geometry = QGuiApplication.platformName().lower().startswith("wayland")
|
||||||
self.ticket_number = str(ticket_number)
|
self.ticket_number = str(ticket_number)
|
||||||
self.billing_code = str(billing_code)
|
self.billing_code = str(billing_code)
|
||||||
self.initUI()
|
self.initUI()
|
||||||
|
|
||||||
def initUI(self):
|
def initUI(self):
|
||||||
self.setFixedSize(640, 380)
|
self.setFixedSize(640, 380)
|
||||||
self.setWindowFlags(Qt.WindowType.FramelessWindowHint)
|
if self._use_parent_local_geometry:
|
||||||
|
if self.parent_window is not None:
|
||||||
|
self.setParent(self.parent_window)
|
||||||
|
self.setWindowFlags(Qt.WindowType.Widget)
|
||||||
|
else:
|
||||||
|
self.setWindowFlags(Qt.WindowType.Dialog | Qt.WindowType.FramelessWindowHint)
|
||||||
self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground)
|
self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground)
|
||||||
|
|
||||||
outer = QVBoxLayout(self)
|
outer = QVBoxLayout(self)
|
||||||
|
|
@ -9116,11 +9120,11 @@ class TicketDataLossPopup(QWidget):
|
||||||
button_row.addStretch()
|
button_row.addStretch()
|
||||||
content.addLayout(button_row)
|
content.addLayout(button_row)
|
||||||
|
|
||||||
|
if not self._use_parent_local_geometry:
|
||||||
self.setWindowModality(Qt.WindowModality.ApplicationModal)
|
self.setWindowModality(Qt.WindowModality.ApplicationModal)
|
||||||
|
|
||||||
def _on_acknowledge(self):
|
def _on_acknowledge(self):
|
||||||
self.finished.emit()
|
self.accept()
|
||||||
self.close()
|
|
||||||
|
|
||||||
def _on_copy_billing_code(self):
|
def _on_copy_billing_code(self):
|
||||||
QApplication.clipboard().setText(self.billing_code)
|
QApplication.clipboard().setText(self.billing_code)
|
||||||
|
|
@ -9132,22 +9136,37 @@ class TicketDataLossPopup(QWidget):
|
||||||
self.copy_button.setText("Copy Billing Code")
|
self.copy_button.setText("Copy Billing Code")
|
||||||
self.copy_button.setStyleSheet(self._copy_button_default_style)
|
self.copy_button.setStyleSheet(self._copy_button_default_style)
|
||||||
|
|
||||||
|
def show(self):
|
||||||
|
self._center_on_parent()
|
||||||
|
super().show()
|
||||||
|
|
||||||
def showEvent(self, event):
|
def showEvent(self, event):
|
||||||
super().showEvent(event)
|
super().showEvent(event)
|
||||||
self._center_on_parent()
|
self._center_on_parent()
|
||||||
|
QTimer.singleShot(0, self._center_on_parent)
|
||||||
|
|
||||||
def _center_on_parent(self):
|
def _center_on_parent(self):
|
||||||
parent = self.parent_window
|
parent = self.parent_window
|
||||||
if parent is None:
|
if parent is None:
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
self.adjustSize()
|
if not hasattr(parent, 'mapToGlobal') or not hasattr(parent, 'rect'):
|
||||||
parent_geom = parent.frameGeometry() if hasattr(parent, 'frameGeometry') else None
|
|
||||||
if parent_geom is None or parent_geom.isEmpty():
|
|
||||||
return
|
return
|
||||||
my_rect = self.frameGeometry()
|
parent_local_rect = parent.rect()
|
||||||
my_rect.moveCenter(parent_geom.center())
|
if parent_local_rect.isEmpty():
|
||||||
target = my_rect.topLeft()
|
return
|
||||||
|
my_size = self.size()
|
||||||
|
if my_size.isEmpty() or my_size.width() <= 0 or my_size.height() <= 0:
|
||||||
|
my_size = self.sizeHint()
|
||||||
|
if self._use_parent_local_geometry:
|
||||||
|
target_x = parent_local_rect.x() + (parent_local_rect.width() - my_size.width()) // 2
|
||||||
|
target_y = parent_local_rect.y() + (parent_local_rect.height() - my_size.height()) // 2
|
||||||
|
target_x = max(parent_local_rect.left(), min(target_x, parent_local_rect.right() - my_size.width() + 1))
|
||||||
|
target_y = max(parent_local_rect.top(), min(target_y, parent_local_rect.bottom() - my_size.height() + 1))
|
||||||
|
else:
|
||||||
|
parent_center = parent.mapToGlobal(parent_local_rect.center())
|
||||||
|
target_x = parent_center.x() - my_size.width() // 2
|
||||||
|
target_y = parent_center.y() - my_size.height() // 2
|
||||||
screen = None
|
screen = None
|
||||||
if hasattr(parent, 'screen'):
|
if hasattr(parent, 'screen'):
|
||||||
try:
|
try:
|
||||||
|
|
@ -9156,11 +9175,12 @@ class TicketDataLossPopup(QWidget):
|
||||||
screen = None
|
screen = None
|
||||||
if screen is not None:
|
if screen is not None:
|
||||||
avail = screen.availableGeometry()
|
avail = screen.availableGeometry()
|
||||||
tx = max(avail.left(), min(target.x(), avail.right() - my_rect.width()))
|
target_x = max(avail.left(), min(target_x, avail.right() - my_size.width()))
|
||||||
ty = max(avail.top(), min(target.y(), avail.bottom() - my_rect.height()))
|
target_y = max(avail.top(), min(target_y, avail.bottom() - my_size.height()))
|
||||||
self.move(tx, ty)
|
self.setGeometry(target_x, target_y, my_size.width(), my_size.height())
|
||||||
else:
|
if self._use_parent_local_geometry:
|
||||||
self.move(target)
|
self.raise_()
|
||||||
|
self.setFocus(Qt.FocusReason.PopupFocusReason)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue