1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
|
import os
import sys
import logging
from multiprocessing import freeze_support
if '--pyside2' in sys.argv:
from PySide2.QtWidgets import QApplication, QMainWindow, QFileDialog
from PySide2.QtCore import QTimer, Qt, QCoreApplication
from PySide2.QtGui import QIcon
from PySide2.QtUiTools import QUiLoader
elif '--pyside6' in sys.argv:
from PySide6.QtWidgets import QApplication, QMainWindow, QFileDialog
from PySide6.QtCore import QTimer, Qt, QCoreApplication
from PySide6.QtGui import QIcon, QPixmap
from PySide6.QtUiTools import QUiLoader
from __feature__ import snake_case, true_property
elif '--pyqt5' in sys.argv:
from PyQt5.QtWidgets import QApplication, QMainWindow, QFileDialog
from PyQt5.QtCore import QTimer, Qt, QCoreApplication
from PyQt5 import uic, QtWebEngineWidgets
from PyQt5.QtGui import QIcon
elif '--pyqt6' in sys.argv:
from PyQt6.QtWidgets import QApplication, QMainWindow, QFileDialog
from PyQt6.QtCore import QTimer, Qt, QCoreApplication
from PyQt6.QtGui import QIcon
from PyQt6 import uic, QtWebEngineWidgets
from qt_material import apply_stylesheet, QtStyleTools, density
if hasattr(Qt, 'AA_ShareOpenGLContexts'):
try:
QCoreApplication.setAttribute(Qt.AA_ShareOpenGLContexts)
except:
QCoreApplication.set_attribute(Qt.AA_ShareOpenGLContexts)
else:
print("'Qt' object has no attribute 'AA_ShareOpenGLContexts'")
app = QApplication([])
freeze_support()
try:
app.processEvents()
app.setQuitOnLastWindowClosed(False)
app.lastWindowClosed.connect(app.quit)
except:
app.process_events()
app.quit_on_last_window_closed = False
app.lastWindowClosed.connect(app.quit)
# Extra stylesheets
extra = {
# Button colors
'danger': '#dc3545',
'warning': '#ffc107',
'success': '#17a2b8',
# Font
'font_family': 'Roboto',
# Density
'density_scale': '0',
# Button Shape
'button_shape': 'default',
}
# extra['QMenu'] = {
# 'height': 50,
# 'padding': '50px 50px 50px 50px', # top, right, bottom, left
# }
########################################################################
class RuntimeStylesheets(QMainWindow, QtStyleTools):
# ----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
super().__init__()
if '--pyside2' in sys.argv:
self.main = QUiLoader().load('main_window.ui', self)
wt = 'PySide2'
elif '--pyside6' in sys.argv:
self.main = QUiLoader().load('main_window.ui', self)
wt = 'PySide6'
elif '--pyqt5' in sys.argv:
self.main = uic.loadUi('main_window.ui', self)
wt = 'PyQt5'
elif '--pyqt6' in sys.argv:
self.main = uic.loadUi('main_window.ui', self)
wt = 'PyQt6'
else:
logging.error(
'must include --pyside2, --pyside6 or --pyqt5 in args!'
)
sys.exit()
try:
self.main.setWindowTitle(f'{self.main.windowTitle()} - {wt}')
except:
self.main.window_title = f'{self.main.window_title} - {wt}'
self.custom_styles()
self.set_extra(extra)
self.add_menu_theme(self.main, self.main.menuStyles)
self.add_menu_density(self.main, self.main.menuDensity)
self.show_dock_theme(self.main)
logo = QIcon("qt_material:/logo/logo.svg")
logo_frame = QIcon("qt_material:/logo/logo_frame.svg")
try:
self.main.setWindowIcon(logo)
self.main.actionToolbar.setIcon(logo)
[
self.main.listWidget_2.item(i).setIcon(logo_frame)
for i in range(self.main.listWidget_2.count())
]
except:
self.main.window_icon = logo
self.main.actionToolbar.icon = logo
[
setattr(self.main.listWidget_2.item(i), 'icon', logo_frame)
for i in range(self.main.listWidget_2.count)
]
if hasattr(QFileDialog, 'getExistingDirectory'):
self.main.pushButton_file_dialog.clicked.connect(
lambda: QFileDialog.getOpenFileName(self.main)
)
self.main.pushButton_folder_dialog.clicked.connect(
lambda: QFileDialog.getExistingDirectory(self.main)
)
else:
self.main.pushButton_file_dialog.clicked.connect(
lambda: QFileDialog.get_open_file_name(self.main)
)
self.main.pushButton_folder_dialog.clicked.connect(
lambda: QFileDialog.get_existing_directory(self.main)
)
# ----------------------------------------------------------------------
def custom_styles(self):
""""""
for i in range(self.main.toolBar_vertical.layout().count()):
try:
tool_button = (
self.main.toolBar_vertical.layout().itemAt(i).widget()
)
tool_button.setMaximumWidth(150)
tool_button.setMinimumWidth(150)
except:
tool_button = (
self.main.toolBar_vertical.layout().item_at(i).widget()
)
tool_button.maximum_width = 150
tool_button.minimum_width = 150
try:
for r in range(self.main.tableWidget.rowCount()):
self.main.tableWidget.setRowHeight(r, 36)
for r in range(self.main.tableWidget_2.rowCount()):
self.main.tableWidget_2.setRowHeight(r, 36)
except:
for r in range(self.main.tableWidget.row_count):
self.main.tableWidget.set_row_height(r, 36)
for r in range(self.main.tableWidget_2.row_count):
self.main.tableWidget_2.set_row_height(r, 36)
T0 = 1000
if __name__ == "__main__":
# ----------------------------------------------------------------------
def take_screenshot():
pixmap = frame.main.grab()
pixmap.save(os.path.join('screenshots', f'{theme}.png'))
print(f'Saving {theme}')
if len(sys.argv) > 2:
theme = sys.argv[2]
try:
QTimer.singleShot(T0, take_screenshot)
QTimer.singleShot(T0 * 2, app.closeAllWindows)
except:
QTimer.single_shot(T0, take_screenshot)
QTimer.single_shot(T0 * 2, app.closeAllWindows)
else:
theme = 'default'
# Set theme on in itialization
apply_stylesheet(
app,
theme + '.xml',
invert_secondary=('light' in theme and 'dark' not in theme),
extra=extra,
)
frame = RuntimeStylesheets()
try:
frame.main.showMaximized()
except:
frame.main.show_maximized()
if hasattr(app, 'exec'):
app.exec()
else:
app.exec_()
|