File: mw_for_ui_tests.py

package info (click to toggle)
jtdx 2.2.159%2Bimproved-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 75,336 kB
  • sloc: cpp: 38,503; f90: 31,141; python: 27,061; ansic: 11,772; sh: 409; fortran: 353; makefile: 232
file content (75 lines) | stat: -rw-r--r-- 2,399 bytes parent folder | download | duplicates (6)
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
#!python
# -*- coding: utf-8 -*-

"""This module provides a main window for UI tests.
"""

import logging
import sys
import argparse
import qdarkstyle

def get_main_window_app(qt_from='pyqt', no_dark=True):
    """Return main window application."""

    # set log for debug
    logging.basicConfig(level=logging.DEBUG)

    style = ''

    if qt_from == 'pyside':
        # using PySide wrapper
        from PySide.QtGui import QApplication, QMainWindow, QDockWidget
        from PySide.QtCore import QTimer, Qt, QSettings, QByteArray, QPoint, QSize
        # getting style
        style = qdarkstyle.load_stylesheet_pyside()

    elif qt_from == 'pyqt':
        # using PyQt4 wrapper
        from PyQt4.QtGui import QApplication, QMainWindow, QDockWidget
        from PyQt4.QtCore import QTimer, Qt, QSettings, QByteArray, QPoint, QSize
        # getting style
        style = qdarkstyle.load_stylesheet_pyqt()

    elif qt_from == 'pyqt5':
        # using PyQt5 wrapper
        from PyQt5.QtWidgets import QApplication, QMainWindow, QDockWidget
        from PyQt5.QtCore import QTimer, Qt, QSettings, QByteArray, QPoint, QSize
        # getting style
        style = qdarkstyle.load_stylesheet_pyqt5()

    elif qt_from == 'qtpy':
        # using QtPy API
        from qtpy.QtWidgets import QApplication, QMainWindow, QDockWidget
        from qtpy.QtCore import QTimer, Qt, QSettings, QByteArray, QPoint, QSize
        # getting style
        style = qdarkstyle.load_stylesheet_from_environment()

    elif qt_from == 'pyqtgraph':
        # using PyQtGraph API
        from pyqtgraph.Qt import QtGui, QtCore
        # getting style
        style = qdarkstyle.load_stylesheet_from_environment(is_pyqtgraph=True)

    if no_dark:
        style = ''

    # create the application
    app = QApplication(sys.argv)
    app.setOrganizationName('QDarkStyle')
    app.setApplicationName('QDarkStyle Test')
    # setup stylesheet
    app.setStyleSheet(style)
    # create main window
    window = QMainWindow()
    window.setWindowTitle("QDarkStyle v." + qdarkstyle.__version__ +
                          " - TEST - Using " + qt_from)
    # auto quit after 2s when testing on travis-ci
    if "--test" in sys.argv:
        QTimer.singleShot(2000, app.exit)
    # run
    window.showMaximized()
    app.exec_()

    return window