2018-02-20 11:15:47 -05:00
|
|
|
#!python
|
2018-02-06 09:17:25 -05:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2018-02-07 13:32:32 -05:00
|
|
|
"""Example of qdarkstyle use for Python and Qt applications.
|
2018-02-06 09:17:25 -05:00
|
|
|
|
2018-02-07 13:32:32 -05:00
|
|
|
This module a main window with every item that could be created with
|
|
|
|
Qt Design (common ones) in the basic states (enabled/disabled), and
|
|
|
|
(checked/unchecked) for those who has this attribute.
|
2018-02-06 09:17:25 -05:00
|
|
|
|
|
|
|
Requirements:
|
2018-02-07 13:32:32 -05:00
|
|
|
|
2018-02-06 09:17:25 -05:00
|
|
|
- Python 2 or Python 3
|
2018-02-07 13:32:32 -05:00
|
|
|
- PyQt4 or PyQt5 or PySide
|
|
|
|
- QtPy or PyQtGraph (if choosen)
|
|
|
|
|
|
|
|
To run this example using PyQt4, simple do
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
python example.py
|
|
|
|
|
|
|
|
or
|
2018-02-06 09:17:25 -05:00
|
|
|
|
2018-02-07 13:32:32 -05:00
|
|
|
.. code-block:: python
|
2018-02-06 09:17:25 -05:00
|
|
|
|
2018-02-07 13:32:32 -05:00
|
|
|
python example.py --qt_from=pyqt
|
2018-02-06 09:17:25 -05:00
|
|
|
|
2018-02-07 13:32:32 -05:00
|
|
|
Other options for qt_from are: pyqt5, pyside, qtpy and pyqtgraph.
|
2018-02-06 09:17:25 -05:00
|
|
|
|
2018-02-07 13:32:32 -05:00
|
|
|
You also can run the example without dark theme (no_dark), to check for
|
|
|
|
problems.
|
|
|
|
|
|
|
|
.. code-block:: python
|
|
|
|
|
|
|
|
python example.py --qt_from=pyqt --no_dark
|
2018-02-06 09:17:25 -05:00
|
|
|
|
|
|
|
.. note.. :: qdarkstyle does not have to be installed to run the example.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
import logging
|
|
|
|
import sys
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
# make the example runnable without the need to install
|
|
|
|
from os.path import abspath, dirname
|
|
|
|
sys.path.insert(0, abspath(dirname(abspath(__file__)) + '/..'))
|
|
|
|
|
2018-02-20 11:15:47 -05:00
|
|
|
# must be in this place, after setting path, to not need to install
|
2018-02-07 13:32:32 -05:00
|
|
|
import qdarkstyle
|
|
|
|
|
2018-02-06 09:17:25 -05:00
|
|
|
|
|
|
|
def main():
|
|
|
|
"""Execute QDarkStyle example."""
|
|
|
|
parser = argparse.ArgumentParser(description=__doc__,
|
|
|
|
formatter_class=argparse.RawDescriptionHelpFormatter)
|
2018-02-07 13:32:32 -05:00
|
|
|
parser.add_argument('--qt_from', default='pyqt',
|
2018-02-06 09:17:25 -05:00
|
|
|
choices=['pyqt', 'pyqt5', 'pyside', 'qtpy', 'pyqtgraph'],
|
|
|
|
help="Choose which wrapper/framework is to be used to run the example.", type=str)
|
|
|
|
parser.add_argument('--no_dark', action='store_true',
|
2018-02-07 13:32:32 -05:00
|
|
|
help="Exihibts the original window (without qdarkstyle).")
|
2018-02-07 14:01:42 -05:00
|
|
|
parser.add_argument('--test', action='store_true',
|
|
|
|
help="Auto close window after 2s.")
|
2018-02-06 09:17:25 -05:00
|
|
|
# parsing arguments from command line
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
# set log for debug
|
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
|
|
|
|
if args.qt_from == 'pyside':
|
|
|
|
# using PySide wrapper
|
|
|
|
from PySide.QtGui import QApplication, QMainWindow, QDockWidget
|
2018-02-20 11:15:47 -05:00
|
|
|
from PySide.QtCore import QTimer, Qt, QSettings, QByteArray, QPoint, QSize
|
2018-02-06 09:17:25 -05:00
|
|
|
# import examples UI according to wrapper
|
2018-02-20 11:15:47 -05:00
|
|
|
from ui.mw_menus_pyside_ui import Ui_MainWindow as ui_main
|
|
|
|
|
2018-02-06 09:17:25 -05:00
|
|
|
from ui.dw_buttons_pyside_ui import Ui_DockWidget as ui_buttons
|
|
|
|
from ui.dw_displays_pyside_ui import Ui_DockWidget as ui_displays
|
2018-02-20 11:15:47 -05:00
|
|
|
from ui.dw_inputs_fields_pyside_ui import Ui_DockWidget as ui_inputs_fields
|
2018-02-06 09:17:25 -05:00
|
|
|
from ui.dw_inputs_no_fields_pyside_ui import Ui_DockWidget as ui_inputs_no_fields
|
2018-02-20 11:15:47 -05:00
|
|
|
|
|
|
|
from ui.dw_widgets_pyside_ui import Ui_DockWidget as ui_widgets
|
|
|
|
from ui.dw_views_pyside_ui import Ui_DockWidget as ui_views
|
|
|
|
from ui.dw_containers_tabs_pyside_ui import Ui_DockWidget as ui_containers_tabs
|
|
|
|
from ui.dw_containers_no_tabs_pyside_ui import Ui_DockWidget as ui_containers_no_tabs
|
2018-02-06 09:17:25 -05:00
|
|
|
# getting style
|
|
|
|
style = qdarkstyle.load_stylesheet_pyside()
|
|
|
|
|
|
|
|
elif args.qt_from == 'pyqt':
|
|
|
|
# using PyQt4 wrapper
|
|
|
|
from PyQt4.QtGui import QApplication, QMainWindow, QDockWidget
|
2018-02-20 11:15:47 -05:00
|
|
|
from PyQt4.QtCore import QTimer, Qt, QSettings, QByteArray, QPoint, QSize
|
2018-02-06 09:17:25 -05:00
|
|
|
# import examples UI according to wrapper
|
2018-02-20 11:15:47 -05:00
|
|
|
from ui.mw_menus_pyqt_ui import Ui_MainWindow as ui_main
|
|
|
|
|
2018-02-06 09:17:25 -05:00
|
|
|
from ui.dw_buttons_pyqt_ui import Ui_DockWidget as ui_buttons
|
|
|
|
from ui.dw_displays_pyqt_ui import Ui_DockWidget as ui_displays
|
2018-02-20 11:15:47 -05:00
|
|
|
from ui.dw_inputs_fields_pyqt_ui import Ui_DockWidget as ui_inputs_fields
|
2018-02-06 09:17:25 -05:00
|
|
|
from ui.dw_inputs_no_fields_pyqt_ui import Ui_DockWidget as ui_inputs_no_fields
|
2018-02-20 11:15:47 -05:00
|
|
|
|
|
|
|
from ui.dw_widgets_pyqt_ui import Ui_DockWidget as ui_widgets
|
|
|
|
from ui.dw_views_pyqt_ui import Ui_DockWidget as ui_views
|
|
|
|
from ui.dw_containers_tabs_pyqt_ui import Ui_DockWidget as ui_containers_tabs
|
|
|
|
from ui.dw_containers_no_tabs_pyqt_ui import Ui_DockWidget as ui_containers_no_tabs
|
2018-02-06 09:17:25 -05:00
|
|
|
# getting style
|
|
|
|
style = qdarkstyle.load_stylesheet_pyqt()
|
|
|
|
|
|
|
|
elif args.qt_from == 'pyqt5':
|
|
|
|
# using PyQt5 wrapper
|
|
|
|
from PyQt5.QtWidgets import QApplication, QMainWindow, QDockWidget
|
2018-02-20 11:15:47 -05:00
|
|
|
from PyQt5.QtCore import QTimer, Qt, QSettings, QByteArray, QPoint, QSize
|
2018-02-06 09:17:25 -05:00
|
|
|
# import examples UI according to wrapper
|
2018-02-20 11:15:47 -05:00
|
|
|
from ui.mw_menus_pyqt5_ui import Ui_MainWindow as ui_main
|
|
|
|
|
2018-02-06 09:17:25 -05:00
|
|
|
from ui.dw_buttons_pyqt5_ui import Ui_DockWidget as ui_buttons
|
|
|
|
from ui.dw_displays_pyqt5_ui import Ui_DockWidget as ui_displays
|
2018-02-20 11:15:47 -05:00
|
|
|
from ui.dw_inputs_fields_pyqt5_ui import Ui_DockWidget as ui_inputs_fields
|
2018-02-06 09:17:25 -05:00
|
|
|
from ui.dw_inputs_no_fields_pyqt5_ui import Ui_DockWidget as ui_inputs_no_fields
|
2018-02-20 11:15:47 -05:00
|
|
|
|
|
|
|
from ui.dw_widgets_pyqt5_ui import Ui_DockWidget as ui_widgets
|
|
|
|
from ui.dw_views_pyqt5_ui import Ui_DockWidget as ui_views
|
|
|
|
from ui.dw_containers_tabs_pyqt5_ui import Ui_DockWidget as ui_containers_tabs
|
|
|
|
from ui.dw_containers_no_tabs_pyqt5_ui import Ui_DockWidget as ui_containers_no_tabs
|
2018-02-06 09:17:25 -05:00
|
|
|
# getting style
|
|
|
|
style = qdarkstyle.load_stylesheet_pyqt5()
|
|
|
|
|
|
|
|
elif args.qt_from == 'qtpy':
|
|
|
|
# using QtPy API
|
|
|
|
from qtpy.QtWidgets import QApplication, QMainWindow, QDockWidget
|
2018-02-20 11:15:47 -05:00
|
|
|
from qtpy.QtCore import QTimer, Qt, QSettings, QByteArray, QPoint, QSize
|
2018-02-06 09:17:25 -05:00
|
|
|
# import examples UI according to wrapper
|
2018-02-20 11:15:47 -05:00
|
|
|
from ui.mw_menus_qtpy_ui import Ui_MainWindow as ui_main
|
|
|
|
|
2018-02-06 09:17:25 -05:00
|
|
|
from ui.dw_buttons_qtpy_ui import Ui_DockWidget as ui_buttons
|
|
|
|
from ui.dw_displays_qtpy_ui import Ui_DockWidget as ui_displays
|
2018-02-20 11:15:47 -05:00
|
|
|
from ui.dw_inputs_fields_qtpy_ui import Ui_DockWidget as ui_inputs_fields
|
2018-02-06 09:17:25 -05:00
|
|
|
from ui.dw_inputs_no_fields_qtpy_ui import Ui_DockWidget as ui_inputs_no_fields
|
2018-02-20 11:15:47 -05:00
|
|
|
|
|
|
|
from ui.dw_widgets_qtpy_ui import Ui_DockWidget as ui_widgets
|
|
|
|
from ui.dw_views_qtpy_ui import Ui_DockWidget as ui_views
|
|
|
|
from ui.dw_containers_tabs_qtpy_ui import Ui_DockWidget as ui_containers_tabs
|
|
|
|
from ui.dw_containers_no_tabs_qtpy_ui import Ui_DockWidget as ui_containers_no_tabs
|
2018-02-06 09:17:25 -05:00
|
|
|
# getting style
|
|
|
|
style = qdarkstyle.load_stylesheet_from_environment()
|
|
|
|
|
|
|
|
elif args.qt_from == 'pyqtgraph':
|
|
|
|
# using PyQtGraph API
|
2018-02-21 15:27:20 -05:00
|
|
|
from pyqtgraph.Qt.QtGui import QApplication, QMainWindow, QDockWidget
|
|
|
|
from pyqtgraph.Qt.QtCore import QTimer, Qt, QSettings, QByteArray, QPoint, QSize
|
|
|
|
#from pyqtgraph.Qt import QtGui, QtCore
|
2018-02-06 09:17:25 -05:00
|
|
|
# import examples UI according to wrapper
|
2018-02-20 11:15:47 -05:00
|
|
|
from ui.mw_menus_pyqtgraph_ui import Ui_MainWindow as ui_main
|
2018-02-21 15:27:20 -05:00
|
|
|
from ui.dw_buttons_pyqtgraph_ui import Ui_DockWidget as ui_buttons
|
|
|
|
from ui.dw_displays_pyqtgraph_ui import Ui_DockWidget as ui_displays
|
|
|
|
from ui.dw_inputs_fields_pyqtgraph_ui import Ui_DockWidget as ui_inputs_fields
|
|
|
|
from ui.dw_inputs_no_fields_pyqtgraph_ui import Ui_DockWidget as ui_inputs_no_fields
|
2018-02-20 11:15:47 -05:00
|
|
|
from ui.dw_widgets_pyqtgraph_ui import Ui_DockWidget as ui_widgets
|
|
|
|
from ui.dw_views_pyqtgraph_ui import Ui_DockWidget as ui_views
|
|
|
|
from ui.dw_containers_tabs_pyqtgraph_ui import Ui_DockWidget as ui_containers_tabs
|
|
|
|
from ui.dw_containers_no_tabs_pyqtgraph_ui import Ui_DockWidget as ui_containers_no_tabs
|
2018-02-06 09:17:25 -05:00
|
|
|
# getting style
|
|
|
|
style = qdarkstyle.load_stylesheet_from_environment(is_pyqtgraph=True)
|
|
|
|
|
|
|
|
if args.no_dark:
|
|
|
|
style = ''
|
|
|
|
|
2018-02-20 11:15:47 -05:00
|
|
|
def write_settings(window):
|
2018-02-21 15:27:20 -05:00
|
|
|
"""Get window settings and write it into a file."""
|
2018-02-20 11:15:47 -05:00
|
|
|
settings = QSettings('QDarkStyle', 'QDarkStyle Example')
|
|
|
|
settings.setValue('pos', window.pos())
|
|
|
|
settings.setValue('size', window.size())
|
|
|
|
settings.setValue('state', window.saveState())
|
|
|
|
|
|
|
|
def read_settings(window):
|
2018-02-21 15:27:20 -05:00
|
|
|
"""Read and set window settings from a file."""
|
2018-02-20 11:15:47 -05:00
|
|
|
settings = QSettings('QDarkStyle', 'QDarkStyle Example')
|
2018-02-21 15:27:20 -05:00
|
|
|
if args.qt_from == 'pyside':
|
|
|
|
pos = settings.value('pos', window.pos())
|
|
|
|
size = settings.value('size', window.size())
|
|
|
|
state = settings.value('state', window.saveState())
|
|
|
|
else:
|
|
|
|
pos = settings.value('pos', window.pos(), type='QPoint')
|
|
|
|
size = settings.value('size', window.size(), type='QSize')
|
|
|
|
state = settings.value('state', window.saveState(), type='QByteArray')
|
2018-02-20 11:15:47 -05:00
|
|
|
window.restoreState(state)
|
|
|
|
window.resize(size)
|
|
|
|
window.move(pos)
|
|
|
|
|
2018-02-06 09:17:25 -05:00
|
|
|
# create the application
|
|
|
|
app = QApplication(sys.argv)
|
2018-02-20 11:15:47 -05:00
|
|
|
app.setOrganizationName('QDarkStyle')
|
|
|
|
app.setApplicationName('QDarkStyle Example')
|
2018-02-06 09:17:25 -05:00
|
|
|
|
|
|
|
# setup stylesheet
|
|
|
|
app.setStyleSheet(style)
|
|
|
|
|
|
|
|
# create main window
|
|
|
|
window = QMainWindow()
|
2018-02-20 11:15:47 -05:00
|
|
|
window.setObjectName('mainwindow')
|
2018-02-06 09:17:25 -05:00
|
|
|
ui = ui_main()
|
|
|
|
ui.setupUi(window)
|
2018-02-06 14:38:08 -05:00
|
|
|
window.setWindowTitle("QDarkStyle v." + qdarkstyle.__version__ +
|
|
|
|
" - Example - Using " + args.qt_from)
|
2018-02-06 09:17:25 -05:00
|
|
|
|
|
|
|
# create docks for buttons
|
|
|
|
dw_buttons = QDockWidget()
|
2018-02-20 11:15:47 -05:00
|
|
|
dw_buttons.setObjectName('buttons')
|
2018-02-06 09:17:25 -05:00
|
|
|
ui_buttons = ui_buttons()
|
|
|
|
ui_buttons.setupUi(dw_buttons)
|
|
|
|
window.addDockWidget(Qt.RightDockWidgetArea, dw_buttons)
|
|
|
|
|
|
|
|
# create docks for buttons
|
|
|
|
dw_displays = QDockWidget()
|
2018-02-20 11:15:47 -05:00
|
|
|
dw_displays.setObjectName('displays')
|
2018-02-06 09:17:25 -05:00
|
|
|
ui_displays = ui_displays()
|
|
|
|
ui_displays.setupUi(dw_displays)
|
|
|
|
window.addDockWidget(Qt.RightDockWidgetArea, dw_displays)
|
|
|
|
|
|
|
|
# create docks for inputs - fields
|
2018-02-20 11:15:47 -05:00
|
|
|
dw_inputs_fields = QDockWidget()
|
|
|
|
dw_inputs_fields.setObjectName('_fields')
|
|
|
|
ui_inputs_fields = ui_inputs_fields()
|
|
|
|
ui_inputs_fields.setupUi(dw_inputs_fields)
|
|
|
|
window.addDockWidget(Qt.RightDockWidgetArea, dw_inputs_fields)
|
2018-02-06 09:17:25 -05:00
|
|
|
|
|
|
|
# create docks for inputs - no fields
|
2018-02-20 11:15:47 -05:00
|
|
|
dw_inputs_no_fields = QDockWidget()
|
|
|
|
dw_inputs_no_fields.setObjectName('inputs_no_fields')
|
|
|
|
ui_inputs_no_fields = ui_inputs_no_fields()
|
|
|
|
ui_inputs_no_fields.setupUi(dw_inputs_no_fields)
|
|
|
|
window.addDockWidget(Qt.RightDockWidgetArea, dw_inputs_no_fields)
|
|
|
|
|
|
|
|
# create docks for widgets
|
|
|
|
dw_widgets = QDockWidget()
|
|
|
|
dw_widgets.setObjectName('widgets')
|
|
|
|
ui_widgets = ui_widgets()
|
|
|
|
ui_widgets.setupUi(dw_widgets)
|
|
|
|
window.addDockWidget(Qt.LeftDockWidgetArea, dw_widgets)
|
|
|
|
|
|
|
|
# create docks for views
|
|
|
|
dw_views = QDockWidget()
|
|
|
|
dw_views.setObjectName('views')
|
|
|
|
ui_views = ui_views()
|
|
|
|
ui_views.setupUi(dw_views)
|
|
|
|
window.addDockWidget(Qt.LeftDockWidgetArea, dw_views)
|
|
|
|
|
|
|
|
# create docks for containters - tabs
|
|
|
|
dw_containers_tabs = QDockWidget()
|
|
|
|
dw_containers_tabs.setObjectName('containers')
|
|
|
|
ui_containers_tabs = ui_containers_tabs()
|
|
|
|
ui_containers_tabs.setupUi(dw_containers_tabs)
|
|
|
|
window.addDockWidget(Qt.LeftDockWidgetArea, dw_containers_tabs)
|
|
|
|
|
|
|
|
# create docks for containers - no tabs
|
|
|
|
dw_containers_no_tabs = QDockWidget()
|
|
|
|
dw_containers_no_tabs.setObjectName('containers_no_tabs')
|
|
|
|
ui_containers_no_tabs = ui_containers_no_tabs()
|
|
|
|
ui_containers_no_tabs.setupUi(dw_containers_no_tabs)
|
|
|
|
window.addDockWidget(Qt.LeftDockWidgetArea, dw_containers_no_tabs)
|
|
|
|
|
|
|
|
# tabify right docks
|
2018-02-06 09:17:25 -05:00
|
|
|
window.tabifyDockWidget(dw_buttons, dw_displays)
|
2018-02-20 11:15:47 -05:00
|
|
|
window.tabifyDockWidget(dw_displays, dw_inputs_fields)
|
|
|
|
window.tabifyDockWidget(dw_inputs_fields, dw_inputs_no_fields)
|
2018-02-06 09:17:25 -05:00
|
|
|
|
|
|
|
# auto quit after 2s when testing on travis-ci
|
2018-02-07 14:01:42 -05:00
|
|
|
if "--test" in sys.argv:
|
2018-02-06 09:17:25 -05:00
|
|
|
QTimer.singleShot(2000, app.exit)
|
|
|
|
|
|
|
|
# run
|
2018-02-20 11:15:47 -05:00
|
|
|
read_settings(window)
|
2018-02-06 09:17:25 -05:00
|
|
|
window.showMaximized()
|
|
|
|
app.exec_()
|
2018-02-20 11:15:47 -05:00
|
|
|
write_settings(window)
|
|
|
|
|
2018-02-06 09:17:25 -05:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
sys.exit(main())
|