22import sys
33
44from PyQt5 import uic
5- from PyQt5 .QtCore import Qt , QTimer , QDir
6- from PyQt5 .QtGui import QCloseEvent
5+ from PyQt5 .QtCore import Qt , QTimer , QDir , QSignalBlocker
6+ from PyQt5 .QtGui import QCloseEvent , QIcon
77from PyQt5 .QtWidgets import (QApplication , QLabel , QCalendarWidget , QFrame , QTreeView ,
8- QTableWidget , QFileSystemModel )
8+ QTableWidget , QFileSystemModel , QPlainTextEdit , QToolBar ,
9+ QWidgetAction , QComboBox , QAction , QSizePolicy , QInputDialog )
910
1011from PyQtAds import QtAds
1112
1213UI_FILE = os .path .join (os .path .dirname (__file__ ), 'mainwindow.ui' )
1314MainWindowUI , MainWindowBase = uic .loadUiType (UI_FILE )
1415
16+ import demo_rc # pyrcc5 demo\demo.qrc -o examples\centralWidget\demo_rc.py
17+
18+
19+ def svg_icon (filename : str ):
20+ '''Helper function to create an SVG icon'''
21+ # This is a workaround, because because in item views SVG icons are not
22+ # properly scaled and look blurry or pixelate
23+ icon = QIcon (filename )
24+ icon .addPixmap (icon .pixmap (92 ))
25+ return icon
26+
1527
1628class MainWindow (MainWindowUI , MainWindowBase ):
1729
@@ -22,12 +34,14 @@ def __init__(self, parent=None):
2234
2335 QtAds .CDockManager .setConfigFlag (QtAds .CDockManager .OpaqueSplitterResize , True )
2436 QtAds .CDockManager .setConfigFlag (QtAds .CDockManager .XmlCompressionEnabled , False )
37+ QtAds .CDockManager .setConfigFlag (QtAds .CDockManager .FocusHighlighting , True )
2538 self .dock_manager = QtAds .CDockManager (self )
2639
2740 # Set central widget
28- calendar = QCalendarWidget ()
41+ text_edit = QPlainTextEdit ()
42+ text_edit .setPlaceholderText ("This is the central editor. Enter your text here." )
2943 central_dock_widget = QtAds .CDockWidget ("CentralWidget" )
30- central_dock_widget .setWidget (calendar )
44+ central_dock_widget .setWidget (text_edit )
3145 central_dock_area = self .dock_manager .setCentralWidget (central_dock_widget )
3246 central_dock_area .setAllowedAreas (QtAds .DockWidgetArea .OuterDockAreas )
3347
@@ -65,7 +79,33 @@ def __init__(self, parent=None):
6579 properties_dock_widget .setMinimumSize (200 ,150 )
6680 self .dock_manager .addDockWidget (QtAds .DockWidgetArea .RightDockWidgetArea , properties_dock_widget , central_dock_area )
6781 self .menuView .addAction (properties_dock_widget .toggleViewAction ())
68-
82+
83+ self .create_perspective_ui ()
84+
85+ def create_perspective_ui (self ):
86+ save_perspective_action = QAction ("Create Perspective" , self )
87+ save_perspective_action .setIcon (svg_icon (":/adsdemo/images/picture_in_picture.svg" ))
88+ save_perspective_action .triggered .connect (self .save_perspective )
89+ perspective_list_action = QWidgetAction (self )
90+ self .perspective_combobox = QComboBox (self )
91+ self .perspective_combobox .setSizeAdjustPolicy (QComboBox .AdjustToContents )
92+ self .perspective_combobox .setSizePolicy (QSizePolicy .Preferred , QSizePolicy .Preferred )
93+ self .perspective_combobox .activated [str ].connect (self .dock_manager .openPerspective )
94+ perspective_list_action .setDefaultWidget (self .perspective_combobox )
95+ self .toolBar .addSeparator ()
96+ self .toolBar .addAction (perspective_list_action )
97+ self .toolBar .addAction (save_perspective_action )
98+
99+ def save_perspective (self ):
100+ perspective_name , ok = QInputDialog .getText (self , "Save Perspective" , "Enter Unique name:" )
101+ if not ok or not perspective_name :
102+ return
103+
104+ self .dock_manager .addPerspective (perspective_name )
105+ blocker = QSignalBlocker (self .perspective_combobox )
106+ self .perspective_combobox .clear ()
107+ self .perspective_combobox .addItems (self .dock_manager .perspectiveNames ())
108+ self .perspective_combobox .setCurrentText (perspective_name )
69109
70110if __name__ == '__main__' :
71111 app = QApplication (sys .argv )
0 commit comments