MCPcopy Create free account
hub / github.com/cztomczak/cefpython / MainWindow

Class MainWindow

examples/qt.py:132–200  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

130
131
132class MainWindow(QMainWindow):
133 def __init__(self):
134 # noinspection PyArgumentList
135 super(MainWindow, self).__init__(None)
136 # Avoids crash when shutting down CEF (issue #360)
137 if PYSIDE:
138 self.setAttribute(Qt.WA_DeleteOnClose, True)
139 self.cef_widget = None
140 self.navigation_bar = None
141 if PYQT4:
142 self.setWindowTitle("PyQt4 example")
143 elif PYQT5:
144 self.setWindowTitle("PyQt5 example")
145 elif PYSIDE:
146 self.setWindowTitle("PySide example")
147 elif PYSIDE2:
148 self.setWindowTitle("PySide2 example")
149 self.setFocusPolicy(Qt.StrongFocus)
150 self.setupLayout()
151
152 def setupLayout(self):
153 self.resize(WIDTH, HEIGHT)
154 self.cef_widget = CefWidget(self)
155 self.navigation_bar = NavigationBar(self.cef_widget)
156 layout = QGridLayout()
157 # noinspection PyArgumentList
158 layout.addWidget(self.navigation_bar, 0, 0)
159 # noinspection PyArgumentList
160 layout.addWidget(self.cef_widget, 1, 0)
161 layout.setContentsMargins(0, 0, 0, 0)
162 layout.setSpacing(0)
163 layout.setRowStretch(0, 0)
164 layout.setRowStretch(1, 1)
165 # noinspection PyArgumentList
166 frame = QFrame()
167 frame.setLayout(layout)
168 self.setCentralWidget(frame)
169
170 if (PYSIDE2 or PYQT5) and WINDOWS:
171 # On Windows with PyQt5 main window must be shown first
172 # before CEF browser is embedded, otherwise window is
173 # not resized and application hangs during resize.
174 self.show()
175
176 # Browser can be embedded only after layout was set up
177 self.cef_widget.embedBrowser()
178
179 if (PYSIDE2 or PYQT5) and LINUX:
180 # On Linux with PyQt5 the QX11EmbedContainer widget is
181 # no more available. An equivalent in Qt5 is to create
182 # a hidden window, embed CEF browser in it and then
183 # create a container for that hidden window and replace
184 # cef widget in the layout with the container.
185 # noinspection PyUnresolvedReferences, PyArgumentList
186 self.container = QWidget.createWindowContainer(
187 self.cef_widget.hidden_window, parent=self)
188 # noinspection PyArgumentList
189 layout.addWidget(self.container, 1, 0)

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected