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)
Exemplo 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)
Exemplo n.º 3
0
    def __init__(self, parent, title, var, func, args):
        super(VarGrapher, self).__init__(parent)
        self.setFixedSize(700, 600)
        self.setWindowTitle(title)

        # Figure panel
        self._figure = matplotlib.figure.Figure()
        self._canvas = backend.FigureCanvasQTAgg(self._figure)
        self._toolbar = backend.NavigationToolbar2QT(self._canvas, self)

        # Variable panel
        self._variable_widget = QtWidgets.QWidget()

        # Button panel
        self._button_widget = QtWidgets.QWidget()

        # Central widget
        layout = QtWidgets.QVBoxLayout()
        layout.addWidget(self._canvas)
        layout.addWidget(self._toolbar)
        layout.addWidget(self._variable_widget)
        layout.addWidget(self._button_widget)
        self.setLayout(layout)

        # Get function handle, information object
        self._func = func
        self._args = args
        self._var = var

        # Variable ranges
        grid = QtWidgets.QGridLayout()
        self._bounds = {}
        for k, lhs in enumerate(self._args):
            var = lhs.var()
            # Guess appropriate bounds
            if var.label() == 'membrane_potential' or \
                    var.name().lower() in ['v', 'voltage', 'potential']:
                if var.unit() == myokit.units.volt:
                    lohi = (-0.1, 0.1)
                else:
                    lohi = (-100.0, 100.0)
            else:
                v = lhs.eval()
                if v >= 0 and v <= 1:
                    lohi = (0.0, 1.0)
                elif v < 0:
                    lohi = (-50, 50)
                else:
                    lohi = (0, 100)
            # Row and column of first widget in grid
            row = k // 2
            col = (k % 2) * 3
            # Add label
            label = QtWidgets.QLabel(var.qname())
            grid.addWidget(label, row, col)
            # Add lower and upper bound or single value
            if k < 2:
                # Lower
                editlo = QtWidgets.QLineEdit()
                editlo.setValidator(QtGui.QDoubleValidator())
                editlo.setText(str(lohi[0]))
                grid.addWidget(editlo, row, col + 1)
                # Upper
                edithi = QtWidgets.QLineEdit()
                edithi.setValidator(QtGui.QDoubleValidator())
                edithi.setText(str(lohi[1]))
                grid.addWidget(edithi, row, col + 2)
                self._bounds[lhs] = (editlo, edithi)
            else:
                # Single, fixed value
                v = 0.5 * (lohi[0] + lohi[1])
                edit = QtWidgets.QLineEdit(str(v))
                edit.setReadOnly(True)
                grid.addWidget(edit, row, col + 1)
                self._bounds[lhs] = (edit, edit)
        self._variable_widget.setLayout(grid)

        # Buttons
        layout = QtWidgets.QHBoxLayout()

        # Graph button
        button = QtWidgets.QPushButton('Refresh')
        button.clicked.connect(self.action_draw)
        layout.addWidget(button)

        # Close button
        button = QtWidgets.QPushButton('Close')
        button.clicked.connect(self.close)
        layout.addWidget(button)
        self._button_widget.setLayout(layout)

        # Draw!
        self.action_draw()