|
| 1 | +import os |
| 2 | +import sys |
| 3 | +import unittest |
| 4 | + |
| 5 | +from PySide6.QtCore import Qt, QTimer |
| 6 | +from PySide6.QtGui import QCloseEvent |
| 7 | +from PySide6.QtWidgets import QApplication, QLabel, QMainWindow, QWidget, QMenuBar, QMenu, QStatusBar |
| 8 | + |
| 9 | +import PySide6QtAds as QtAds |
| 10 | + |
| 11 | + |
| 12 | +class SimpleWindow(QMainWindow): |
| 13 | + """ |
| 14 | + Creates a main window with a dock manager. |
| 15 | + """ |
| 16 | + |
| 17 | + def __init__(self, parent=None): |
| 18 | + super().__init__(parent) |
| 19 | + |
| 20 | + self.setGeometry(0, 0, 400, 21) |
| 21 | + |
| 22 | + self.menu_bar = QMenuBar(self) |
| 23 | + self.menu_view = QMenu(self.menu_bar) |
| 24 | + self.menu_view.setTitle("View") |
| 25 | + |
| 26 | + self.menu_bar.addAction(self.menu_view.menuAction()) |
| 27 | + self.setMenuBar(self.menu_bar) |
| 28 | + |
| 29 | + self.statusBar = QStatusBar(self) |
| 30 | + self.setStatusBar(self.statusBar) |
| 31 | + |
| 32 | + # Create the dock manager. Because the parent parameter is a QMainWindow |
| 33 | + # the dock manager registers itself as the central widget. |
| 34 | + self.dock_manager = QtAds.CDockManager(self) |
| 35 | + |
| 36 | + # Create example content label - this can be any application specific |
| 37 | + # widget |
| 38 | + l = QLabel() |
| 39 | + l.setWordWrap(True) |
| 40 | + l.setAlignment(Qt.AlignTop | Qt.AlignLeft); |
| 41 | + l.setText("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. ") |
| 42 | + |
| 43 | + # Create a dock widget with the title Label 1 and set the created label |
| 44 | + # as the dock widget content |
| 45 | + dock_widget = QtAds.CDockWidget("Label 1") |
| 46 | + dock_widget.setWidget(l) |
| 47 | + |
| 48 | + # Add the toggleViewAction of the dock widget to the menu to give |
| 49 | + # the user the possibility to show the dock widget if it has been closed |
| 50 | + self.menu_view.addAction(dock_widget.toggleViewAction()) |
| 51 | + |
| 52 | + # Add the dock widget to the top dock widget area |
| 53 | + self.dock_manager.addDockWidget(QtAds.TopDockWidgetArea, dock_widget) |
| 54 | + |
| 55 | + |
| 56 | +class TestSimpleWindow(unittest.TestCase): |
| 57 | + """ |
| 58 | + Basic QtAds tests. |
| 59 | + """ |
| 60 | + |
| 61 | + @classmethod |
| 62 | + def setUpClass(cls): |
| 63 | + cls.app = QApplication(sys.argv) |
| 64 | + |
| 65 | + def setUp(self): |
| 66 | + self.window = SimpleWindow() |
| 67 | + self.window.show() |
| 68 | + |
| 69 | + def tearDown(self): |
| 70 | + self.window.close() |
| 71 | + |
| 72 | + def test_window_is_visible(self): |
| 73 | + assert self.window.isVisible() |
| 74 | + |
| 75 | + |
| 76 | +if __name__ == '__main__': |
| 77 | + unittest.main() |
0 commit comments