2
2
import sys
3
3
4
4
from 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
7
7
from PyQt5 .QtWidgets import (QApplication , QLabel , QCalendarWidget , QFrame , QTreeView ,
8
- QTableWidget , QFileSystemModel )
8
+ QTableWidget , QFileSystemModel , QPlainTextEdit , QToolBar ,
9
+ QWidgetAction , QComboBox , QAction , QSizePolicy , QInputDialog )
9
10
10
11
from PyQtAds import QtAds
11
12
12
13
UI_FILE = os .path .join (os .path .dirname (__file__ ), 'mainwindow.ui' )
13
14
MainWindowUI , MainWindowBase = uic .loadUiType (UI_FILE )
14
15
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
+
15
27
16
28
class MainWindow (MainWindowUI , MainWindowBase ):
17
29
@@ -22,12 +34,14 @@ def __init__(self, parent=None):
22
34
23
35
QtAds .CDockManager .setConfigFlag (QtAds .CDockManager .OpaqueSplitterResize , True )
24
36
QtAds .CDockManager .setConfigFlag (QtAds .CDockManager .XmlCompressionEnabled , False )
37
+ QtAds .CDockManager .setConfigFlag (QtAds .CDockManager .FocusHighlighting , True )
25
38
self .dock_manager = QtAds .CDockManager (self )
26
39
27
40
# Set central widget
28
- calendar = QCalendarWidget ()
41
+ text_edit = QPlainTextEdit ()
42
+ text_edit .setPlaceholderText ("This is the central editor. Enter your text here." )
29
43
central_dock_widget = QtAds .CDockWidget ("CentralWidget" )
30
- central_dock_widget .setWidget (calendar )
44
+ central_dock_widget .setWidget (text_edit )
31
45
central_dock_area = self .dock_manager .setCentralWidget (central_dock_widget )
32
46
central_dock_area .setAllowedAreas (QtAds .DockWidgetArea .OuterDockAreas )
33
47
@@ -65,7 +79,33 @@ def __init__(self, parent=None):
65
79
properties_dock_widget .setMinimumSize (200 ,150 )
66
80
self .dock_manager .addDockWidget (QtAds .DockWidgetArea .RightDockWidgetArea , properties_dock_widget , central_dock_area )
67
81
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 )
69
109
70
110
if __name__ == '__main__' :
71
111
app = QApplication (sys .argv )
0 commit comments