| 1 |
# -*- coding: utf-8 -*- |
| 2 |
|
| 3 |
"""This module provides a main window for UI tests. |
| 4 |
""" |
| 5 |
|
| 6 |
import logging |
| 7 |
import sys |
| 8 |
import argparse |
| 9 |
import qdarkstyle |
| 10 |
|
| 11 |
def get_main_window_app(qt_from='pyqt', no_dark=True): |
| 12 |
"""Return main window application.""" |
| 13 |
|
| 14 |
# set log for debug |
| 15 |
logging.basicConfig(level=logging.DEBUG) |
| 16 |
|
| 17 |
style = '' |
| 18 |
|
| 19 |
if qt_from == 'pyside': |
| 20 |
# using PySide wrapper |
| 21 |
from PySide.QtGui import QApplication, QMainWindow, QDockWidget |
| 22 |
from PySide.QtCore import QTimer, Qt, QSettings, QByteArray, QPoint, QSize |
| 23 |
# getting style |
| 24 |
style = qdarkstyle.load_stylesheet_pyside() |
| 25 |
|
| 26 |
elif qt_from == 'pyqt': |
| 27 |
# using PyQt4 wrapper |
| 28 |
from PyQt4.QtGui import QApplication, QMainWindow, QDockWidget |
| 29 |
from PyQt4.QtCore import QTimer, Qt, QSettings, QByteArray, QPoint, QSize |
| 30 |
# getting style |
| 31 |
style = qdarkstyle.load_stylesheet_pyqt() |
| 32 |
|
| 33 |
elif qt_from == 'pyqt5': |
| 34 |
# using PyQt5 wrapper |
| 35 |
from PyQt5.QtWidgets import QApplication, QMainWindow, QDockWidget |
| 36 |
from PyQt5.QtCore import QTimer, Qt, QSettings, QByteArray, QPoint, QSize |
| 37 |
# getting style |
| 38 |
style = qdarkstyle.load_stylesheet_pyqt5() |
| 39 |
|
| 40 |
elif qt_from == 'qtpy': |
| 41 |
# using QtPy API |
| 42 |
from qtpy.QtWidgets import QApplication, QMainWindow, QDockWidget |
| 43 |
from qtpy.QtCore import QTimer, Qt, QSettings, QByteArray, QPoint, QSize |
| 44 |
# getting style |
| 45 |
style = qdarkstyle.load_stylesheet_from_environment() |
| 46 |
|
| 47 |
elif qt_from == 'pyqtgraph': |
| 48 |
# using PyQtGraph API |
| 49 |
from pyqtgraph.Qt import QtGui, QtCore |
| 50 |
# getting style |
| 51 |
style = qdarkstyle.load_stylesheet_from_environment(is_pyqtgraph=True) |
| 52 |
|
| 53 |
if no_dark: |
| 54 |
style = '' |
| 55 |
|
| 56 |
# create the application |
| 57 |
app = QApplication(sys.argv) |
| 58 |
app.setOrganizationName('QDarkStyle') |
| 59 |
app.setApplicationName('QDarkStyle Test') |
| 60 |
# setup stylesheet |
| 61 |
app.setStyleSheet(style) |
| 62 |
# create main window |
| 63 |
window = QMainWindow() |
| 64 |
window.setWindowTitle("QDarkStyle v." + qdarkstyle.__version__ + |
| 65 |
" - TEST - Using " + qt_from) |
| 66 |
# auto quit after 2s when testing on travis-ci |
| 67 |
if "--test" in sys.argv: |
| 68 |
QTimer.singleShot(2000, app.exit) |
| 69 |
# run |
| 70 |
window.showMaximized() |
| 71 |
app.exec_() |
| 72 |
|
| 73 |
return window |
| 74 |
|