import os
import sys
from os import path
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QWidget, QDesktopWidget, QTabWidget, QGridLayout, QDialog, QDialogButtonBox, QVBoxLayout, QLabel
from PyQt5 import QtCore
import PyQt5
import traceback
from titania.QtGUI.error_tab import ErrorQtTab
if hasattr(QtCore.Qt, 'AA_EnableHighDpiScaling'):
PyQt5.QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True)
if hasattr(QtCore.Qt, 'AA_UseHighDpiPixmaps'):
PyQt5.QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps, True)
[docs]class MainWindow(QWidget):
def __init__(self, height=None, width=None, tab_config=None):
super().__init__()
self.height = height
self.width = width
self.init_ui()
grid_layout = QGridLayout()
self.setLayout(grid_layout)
# self.setWindowFlags(Qt.FramelessWindowHint)
dirname = os.path.dirname(__file__)
filename = os.path.join(dirname, '../resources/main_window.css')
file = open(filename)
self.setStyleSheet(file.read())
file.close()
self.top_tab = QTabWidget(self)
self.widgets = tab_config
self.set_widgets()
grid_layout.addWidget(self.top_tab, 0, 1, 1, 3)
[docs] def set_widgets(self):
for widget in self.widgets:
self.top_tab.addTab(WidgetCreator(widget, parent=self, config=self.widgets),
widget)
[docs] def init_ui(self):
if self.width is not None and self.height is not None:
self.resize(self.width - 100, self.height - 100)
self.center()
self.setWindowTitle('Titania')
dirname = os.path.dirname(__file__)
filename = os.path.join(dirname, '../../resources/cern.gif')
self.setWindowIcon(QIcon(filename))
[docs] def center(self):
qr = self.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
[docs] def resource_path(self, relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
if hasattr(sys, '_MEIPASS'):
return path.join(sys._MEIPASS, relative_path)
return path.join(path.abspath(""), relative_path)
[docs]class TitaniaErrorDialog(QDialog):
def __init__(self, tab_name, exception):
super().__init__()
self.setWindowTitle("Error!")
QBtn = QDialogButtonBox.Ok
self.buttonBox = QDialogButtonBox(QBtn)
self.buttonBox.accepted.connect(self.accept)
self.layout = QVBoxLayout()
message_txt = """
During the creation of the =={}== tab the following error occured:
\n
{}
""".format(tab_name, exception)
message = QLabel(message_txt)
self.layout.addWidget(message)
self.layout.addWidget(self.buttonBox)
self.setLayout(self.layout)