def __init__(self, editor):
     # New style doesn't work:
     QtWidgets.QDialog.__init__(self, editor, Qt.Window)
     self.setWindowTitle('Find and replace')
     self._editor = editor
     # Fix background color of line edits
     self.setStyleSheet('QLineEdit{background: white;}')
     # Create widgets
     self._close_button = QtWidgets.QPushButton('Close')
     self._close_button.clicked.connect(self.action_close)
     self._replace_all_button = QtWidgets.QPushButton('Replace all')
     self._replace_all_button.clicked.connect(self.action_replace_all)
     self._replace_button = QtWidgets.QPushButton('Replace')
     self._replace_button.clicked.connect(self.action_replace)
     self._find_button = QtWidgets.QPushButton('Find')
     self._find_button.clicked.connect(self.action_find)
     self._search_label = QtWidgets.QLabel('Search for')
     self._search_field = QtWidgets.QLineEdit()
     self._replace_label = QtWidgets.QLabel('Replace with')
     self._replace_field = QtWidgets.QLineEdit()
     self._case_check = QtWidgets.QCheckBox('Case sensitive')
     self._whole_check = QtWidgets.QCheckBox('Match whole word only')
     # Create layout
     text_layout = QtWidgets.QGridLayout()
     text_layout.addWidget(self._search_label, 0, 0)
     text_layout.addWidget(self._search_field, 0, 1)
     text_layout.addWidget(self._replace_label, 1, 0)
     text_layout.addWidget(self._replace_field, 1, 1)
     check_layout = QtWidgets.QBoxLayout(QtWidgets.QBoxLayout.TopToBottom)
     check_layout.addWidget(self._case_check)
     check_layout.addWidget(self._whole_check)
     button_layout = QtWidgets.QGridLayout()
     button_layout.addWidget(self._close_button, 0, 0)
     button_layout.addWidget(self._replace_all_button, 0, 1)
     button_layout.addWidget(self._replace_button, 0, 2)
     button_layout.addWidget(self._find_button, 0, 3)
     layout = QtWidgets.QBoxLayout(QtWidgets.QBoxLayout.TopToBottom)
     layout.addLayout(text_layout)
     layout.addLayout(check_layout)
     layout.addLayout(button_layout)
     self.setLayout(layout)
     self._search_field.setEnabled(True)
     self._replace_field.setEnabled(True)
Esempio n. 2
0
    def __init__(self, parent, editor):
        super(FindReplaceWidget, self).__init__(parent)
        self._editor = editor

        # Create widgets
        self._replace_all_button = QtWidgets.QPushButton('Replace all')
        self._replace_all_button.clicked.connect(self.action_replace_all)
        self._replace_button = QtWidgets.QPushButton('Replace')
        self._replace_button.clicked.connect(self.action_replace)
        self._find_button = QtWidgets.QPushButton('Find')
        self._find_button.clicked.connect(self.action_find)
        self._search_label = QtWidgets.QLabel('Search for')
        self._search_field = QtWidgets.QLineEdit()
        self._replace_label = QtWidgets.QLabel('Replace with')
        self._replace_field = QtWidgets.QLineEdit()
        self._case_check = QtWidgets.QCheckBox('Case sensitive')
        self._whole_check = QtWidgets.QCheckBox('Match whole word only')

        # Create layout
        text_layout = QtWidgets.QGridLayout()
        text_layout.addWidget(self._search_label, 0, 0)
        text_layout.addWidget(self._search_field, 0, 1)
        text_layout.addWidget(self._replace_label, 1, 0)
        text_layout.addWidget(self._replace_field, 1, 1)
        check_layout = QtWidgets.QBoxLayout(QtWidgets.QBoxLayout.TopToBottom)
        check_layout.addWidget(self._case_check)
        check_layout.addWidget(self._whole_check)
        button_layout = QtWidgets.QGridLayout()
        button_layout.addWidget(self._replace_all_button, 0, 1)
        button_layout.addWidget(self._replace_button, 0, 2)
        button_layout.addWidget(self._find_button, 0, 3)

        layout = QtWidgets.QBoxLayout(QtWidgets.QBoxLayout.TopToBottom)
        layout.addLayout(text_layout)
        layout.addLayout(check_layout)
        layout.addLayout(button_layout)
        layout.addStretch(1)
        self.setLayout(layout)

        # Accept keyboard focus on search and replace fields
        self._search_field.setEnabled(True)
        self._replace_field.setEnabled(True)