1
2#############################################################################
3##
4## Copyright (C) 2013 Riverbank Computing Limited.
5## Copyright (C) 2016 The Qt Company Ltd.
6## Contact: http://www.qt.io/licensing/
7##
8## This file is part of the Qt for Python examples of the Qt Toolkit.
9##
10## $QT_BEGIN_LICENSE:BSD$
11## You may use this file under the terms of the BSD license as follows:
12##
13## "Redistribution and use in source and binary forms, with or without
14## modification, are permitted provided that the following conditions are
15## met:
16##   * Redistributions of source code must retain the above copyright
17##     notice, this list of conditions and the following disclaimer.
18##   * Redistributions in binary form must reproduce the above copyright
19##     notice, this list of conditions and the following disclaimer in
20##     the documentation and/or other materials provided with the
21##     distribution.
22##   * Neither the name of The Qt Company Ltd nor the names of its
23##     contributors may be used to endorse or promote products derived
24##     from this software without specific prior written permission.
25##
26##
27## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28## "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29## LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30## A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31## OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
38##
39## $QT_END_LICENSE$
40##
41#############################################################################
42
43"""PySide2 port of the widgets/dialogs/extension example from Qt v5.x"""
44
45from PySide2 import QtCore, QtWidgets
46
47
48class FindDialog(QtWidgets.QDialog):
49    def __init__(self, parent=None):
50        super(FindDialog, self).__init__(parent)
51
52        label = QtWidgets.QLabel("Find &what:")
53        lineEdit = QtWidgets.QLineEdit()
54        label.setBuddy(lineEdit)
55
56        caseCheckBox = QtWidgets.QCheckBox("Match &case")
57        fromStartCheckBox = QtWidgets.QCheckBox("Search from &start")
58        fromStartCheckBox.setChecked(True)
59
60        findButton = QtWidgets.QPushButton("&Find")
61        findButton.setDefault(True)
62
63        moreButton = QtWidgets.QPushButton("&More")
64        moreButton.setCheckable(True)
65        moreButton.setAutoDefault(False)
66
67        buttonBox = QtWidgets.QDialogButtonBox(QtCore.Qt.Vertical)
68        buttonBox.addButton(findButton, QtWidgets.QDialogButtonBox.ActionRole)
69        buttonBox.addButton(moreButton, QtWidgets.QDialogButtonBox.ActionRole)
70
71        extension = QtWidgets.QWidget()
72
73        wholeWordsCheckBox = QtWidgets.QCheckBox("&Whole words")
74        backwardCheckBox = QtWidgets.QCheckBox("Search &backward")
75        searchSelectionCheckBox = QtWidgets.QCheckBox("Search se&lection")
76
77        moreButton.toggled.connect(extension.setVisible)
78
79        extensionLayout = QtWidgets.QVBoxLayout()
80        extensionLayout.setContentsMargins(0, 0, 0, 0)
81        extensionLayout.addWidget(wholeWordsCheckBox)
82        extensionLayout.addWidget(backwardCheckBox)
83        extensionLayout.addWidget(searchSelectionCheckBox)
84        extension.setLayout(extensionLayout)
85
86        topLeftLayout = QtWidgets.QHBoxLayout()
87        topLeftLayout.addWidget(label)
88        topLeftLayout.addWidget(lineEdit)
89
90        leftLayout = QtWidgets.QVBoxLayout()
91        leftLayout.addLayout(topLeftLayout)
92        leftLayout.addWidget(caseCheckBox)
93        leftLayout.addWidget(fromStartCheckBox)
94        leftLayout.addStretch(1)
95
96        mainLayout = QtWidgets.QGridLayout()
97        mainLayout.setSizeConstraint(QtWidgets.QLayout.SetFixedSize)
98        mainLayout.addLayout(leftLayout, 0, 0)
99        mainLayout.addWidget(buttonBox, 0, 1)
100        mainLayout.addWidget(extension, 1, 0, 1, 2)
101        self.setLayout(mainLayout)
102
103        self.setWindowTitle("Extension")
104        extension.hide()
105
106
107if __name__ == '__main__':
108
109    import sys
110
111    app = QtWidgets.QApplication(sys.argv)
112    dialog = FindDialog()
113    sys.exit(dialog.exec_())
114