def copy(self, row=None):
        # select entire row
        if row is None:
            list_row = self.o_selection.get_list_row()
            if len(list_row) > 1:
                self.parent.ui.statusbar.setStyleSheet("color: red")
                self.parent.ui.statusbar.showMessage(
                    "Please select only 1 row!",
                    self.parent.statusbar_display_time)
                return
            elif len(list_row) == 0:
                self.parent.ui.statusbar.setStyleSheet("color: red")
                self.parent.ui.statusbar.showMessage(
                    "Please select a row to copy from!",
                    self.parent.statusbar_display_time)
                return

            row = list_row[0]

        self.parent.copied_row = row

        _table_ui = self.table_ui
        nbr_col = _table_ui.columnCount()
        _row_selection = QTableWidgetSelectionRange(row, 0, row, nbr_col - 1)
        _table_ui.setRangeSelected(_row_selection, True)
        self.parent.ui.statusbar.setStyleSheet("color: green")
        self.parent.ui.statusbar.showMessage(
            "Select another row to copy the current selected row to!",
            self.parent.statusbar_display_time)

        self.parent.master_table_cells_copy['temp'] = []
        self.parent.master_table_cells_copy['list_column'] = []
        self.parent.master_table_cells_copy['row'] = row
    def paste(self, row=None):
        if row is None:
            list_to_row = self.o_selection.get_list_row()
            nbr_col = self.table_ui.columnCount()
            _row_selection = QTableWidgetSelectionRange(
                list_to_row[0], 0, list_to_row[-1], nbr_col - 1)
            self.table_ui.setRangeSelected(_row_selection, True)

            list_to_row = self.o_selection.get_list_row()

        else:
            list_to_row = [row]
        from_row = self.parent.master_table_cells_copy['row']
        nbr_col = self.table_ui.columnCount()
        o_copy = CopyCells(parent=self.parent)
        list_column_copy = np.arange(0, nbr_col)
        msg = "No row(s) selected. Highlight any cell(s) in row(s) to duplicate followed by right click."
        if not rows_selected(list_to_row, msg):
            self.parent.ui.statusbar.setStyleSheet("color: red")
            self.parent.ui.statusbar.showMessage(
                msg, self.parent.statusbar_display_time)
            return
        for _row in list_to_row:
            for _column in list_column_copy:
                o_copy.copy_from_to(from_row=from_row,
                                    from_col=_column,
                                    to_row=_row)
Exemple #3
0
 def select_all(self, status=True):
     nbr_row = self.parent.table.rowCount()
     nbr_column = self.parent.table.columnCount()
     selected_range = self.parent_no_ui.ui.table.selectedRanges()
     _full_range = QTableWidgetSelectionRange(0, 0, nbr_row - 1,
                                              nbr_column - 1)
     self.parent.table.setRangeSelected(_full_range, status)
    def _fill_table(self, table_contents):
        self.table.setRowCount(len(table_contents))

        for nr, row in enumerate(table_contents):
            for nc, entry in enumerate(row):
                s = textwrap.fill(entry, width=40)
                item = QTableWidgetItem(s)
                item.setFlags(item.flags() & ~Qt.ItemIsEditable)
                if not nc:
                    item.setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
                self.table.setItem(nr, nc, item)
        self.table.resizeRowsToContents()

        brightness = 220
        for nr in range(self.table.rowCount()):
            for nc in range(self.table.columnCount()):
                self.table.item(nr, nc)
                if nr % 2:
                    color = QColor(255, brightness, brightness)
                else:
                    color = QColor(brightness, 255, brightness)
                self.table.item(nr, nc).setBackground(QBrush(color))

        try:
            index = self._qe_param.index(self._qe_standard_selected)
            self.selected_standard_index = index
            n_columns = self.table.columnCount()
            self.table.setRangeSelected(QTableWidgetSelectionRange(index, 0, index, n_columns - 1), True)
        except ValueError:
            pass
Exemple #5
0
 def __set_selected_ranges(self, selections: Sequence[int], *,
                           is_continue: bool, un_select: bool):
     """Different mode of select function."""
     selected_rows = self.selected_rows()
     if not is_continue:
         self.clearSelection()
     self.setCurrentCell(selections[-1], 0)
     for row in selections:
         is_selected = (row not in selected_rows) if un_select else True
         self.setRangeSelected(
             QTableWidgetSelectionRange(row, 0, row,
                                        self.columnCount() - 1),
             is_selected)
         self.scrollToItem(self.item(row, 0))
Exemple #6
0
def test_symbol_editor(qtbot, monkeypatch):
    """
    Test the rules editor in general.

    Parameters
    ----------
    qtbot : fixture
        pytest-qt window for widget test
    monkeypatch : fixture
        To override dialog behaviors
    """
    # Create the base widget
    widget = PyDMSymbol()
    qtbot.addWidget(widget)

    # Ensure that no rules are set
    assert len(widget._state_images) == 0

    # Create a rule editor for this widget
    empty = SymbolEditor(widget)
    qtbot.addWidget(empty)

    empty.show()

    # Abort the changes
    empty.cancelChanges()

    # Create the rules data for the widget
    symbol_dict = {"1": "goodbye.jpg"}

    # Add the rules to the widget
    widget.imageFiles = json.dumps(symbol_dict)

    # Create a new Editor Window
    se = SymbolEditor(widget)
    qtbot.addWidget(se)
    se.show()

    assert se.tbl_symbols.rowCount() == 1
    assert not se.frm_edit.isEnabled()

    se.tbl_symbols.setCurrentCell(0, 0)
    assert se.frm_edit.isEnabled()
    assert se.txt_state.text() == "1"
    assert se.txt_file.text() == "goodbye.jpg"

    qtbot.mouseClick(se.btn_add_symbol, QtCore.Qt.LeftButton)
    assert se.txt_state.text() == "New State"
    assert se.txt_file.text() == "New File"
    assert se.lbl_image.text() == "Could not load image \nNew File"
    assert se.frm_edit.isEnabled()

    qtbot.keyClicks(se.txt_state, "-Test")
    qtbot.keyClick(se.txt_state, QtCore.Qt.Key_Return)
    assert se.txt_state.text() == "New State-Test"
    assert "New State-Test" in se.symbols
    assert se.symbols["New State-Test"] == "New File"

    qtbot.keyClick(se.txt_file, "!")
    assert se.txt_file.text() == "New File!"
    assert se.symbols["New State-Test"] == "New File!"

    # Test Delete Symbol with Confirm - NO
    assert se.tbl_symbols.rowCount() == 2
    se.tbl_symbols.setRangeSelected(QTableWidgetSelectionRange(1, 0, 1, 1),
                                    True)
    monkeypatch.setattr(QMessageBox, 'question', lambda *args: QMessageBox.No)
    qtbot.mouseClick(se.btn_del_symbol, QtCore.Qt.LeftButton)
    assert se.tbl_symbols.rowCount() == 2
    assert se.frm_edit.isEnabled()

    # Test Delete Symbol with Confirm - YES
    se.tbl_symbols.setRangeSelected(QTableWidgetSelectionRange(1, 0, 1, 1),
                                    True)
    monkeypatch.setattr(QMessageBox, 'question', lambda *args: QMessageBox.Yes)
    qtbot.mouseClick(se.btn_del_symbol, QtCore.Qt.LeftButton)
    assert se.tbl_symbols.rowCount() == 1
    assert len(se.symbols) == 1
    assert se.frm_edit.isEnabled() is False

    # Test Delete Symbol with No Selection
    se.tbl_symbols.clearSelection()
    monkeypatch.setattr(QMessageBox, 'question', lambda *args: QMessageBox.Yes)
    qtbot.mouseClick(se.btn_del_symbol, QtCore.Qt.LeftButton)
    assert se.tbl_symbols.rowCount() == 1
    assert len(se.symbols) == 1
    assert se.frm_edit.isEnabled() is False
Exemple #7
0
 def select_first_row(self):
     _nbr_column = self.get_number_of_columns()
     selection_first_row = QTableWidgetSelectionRange(
         0, 0, 0, _nbr_column - 1)
     self.parent.ui.tableView_fitSummary.setRangeSelected(
         selection_first_row, True)
Exemple #8
0
 def select_row(self, row=-1, status=True):
     nbr_column = self.parent.table.columnCount()
     _range = QTableWidgetSelectionRange(row, 0, row, nbr_column - 1)
     self.parent.table.setRangeSelected(_range, status)
Exemple #9
0
def test_rules_editor(qtbot, monkeypatch):
    """
    Test the rules editor in general.

    Parameters
    ----------
    qtbot : fixture
        pytest-qt window for widget test
    monkeypatch : fixture
        To override dialog behaviors
    """

    # Create the base widget
    widget = DummyWidget()

    # Ensure that no rules are set
    assert widget.rules is None

    # Create a rule editor for this widget
    empty = RulesEditor(widget)
    qtbot.addWidget(empty)

    empty.show()

    qtbot.waitExposed(empty, timeout=5000)

    # Abort the changes
    empty.cancelChanges()

    # Create the rules data for the widget
    rules_list = [{
        'name':
        'Rule #1',
        'property':
        'Enable',
        'initial_value':
        'False',
        'expression':
        'ch[0] > 1',
        'channels': [{
            'channel': 'ca://MTEST:Float',
            'trigger': True
        }]
    }]

    # Add the rules to the widget
    widget.rules = json.dumps(rules_list)

    # Create a new Editor Window
    re = RulesEditor(widget)
    qtbot.addWidget(re)
    re.show()

    qtbot.waitExposed(re, timeout=5000)

    assert re.lst_rules.count() == 1
    assert not re.frm_edit.isEnabled()

    re.lst_rules.setCurrentRow(0)
    re.load_from_list()
    assert re.frm_edit.isEnabled()
    assert re.txt_name.text() == 'Rule #1'
    assert re.cmb_property.currentText() == 'Enable'
    assert re.tbl_channels.rowCount() == 1
    assert re.tbl_channels.item(0, 0).text() == 'ca://MTEST:Float'
    assert re.tbl_channels.item(0, 1).checkState() == QtCore.Qt.Checked
    assert re.lbl_expected_type.text() == 'bool'
    assert re.txt_expression.text() == 'ch[0] > 1'
    assert re.txt_initial_value.text() == 'False'

    qtbot.keyClicks(re.txt_name, '-Test')
    qtbot.keyClick(re.txt_name, QtCore.Qt.Key_Return)
    assert re.txt_name.text() == 'Rule #1-Test'
    assert re.rules[0]['name'] == 'Rule #1-Test'

    qtbot.mouseClick(re.btn_add_channel, QtCore.Qt.LeftButton)
    re.tbl_channels.item(1, 0).setText("ca://TEST")
    assert re.rules[0]['channels'][1]['channel'] == 'ca://TEST'
    assert re.rules[0]['channels'][1]['trigger'] is False

    re.txt_expression.clear()
    qtbot.keyClicks(re.txt_expression, 'ch[0] < 1')
    qtbot.keyClick(re.txt_expression, QtCore.Qt.Key_Return)
    assert re.txt_expression.text() == 'ch[0] < 1'
    assert re.rules[0]['expression'] == 'ch[0] < 1'

    re.txt_initial_value.clear()
    qtbot.keyClicks(re.txt_initial_value, 'True')
    qtbot.keyClick(re.txt_initial_value, QtCore.Qt.Key_Return)
    assert re.txt_initial_value.text() == 'True'
    assert re.rules[0]['initial_value'] == 'True'

    # Test Delete with Confirm - NO
    assert re.tbl_channels.rowCount() == 2
    re.tbl_channels.setRangeSelected(QTableWidgetSelectionRange(1, 0, 1, 1),
                                     True)
    monkeypatch.setattr(QMessageBox, 'question', lambda *args: QMessageBox.No)
    qtbot.mouseClick(re.btn_del_channel, QtCore.Qt.LeftButton)
    assert re.tbl_channels.rowCount() == 2

    # Test Delete with Confirm - YES
    re.tbl_channels.setRangeSelected(QTableWidgetSelectionRange(1, 0, 1, 1),
                                     True)
    monkeypatch.setattr(QMessageBox, 'question', lambda *args: QMessageBox.Yes)
    qtbot.mouseClick(re.btn_del_channel, QtCore.Qt.LeftButton)
    assert re.tbl_channels.rowCount() == 1
    assert len(re.rules[0]['channels']) == 1

    # Test Delete with Invalid Selection
    re.tbl_channels.setRangeSelected(QTableWidgetSelectionRange(1, 0, 1, 1),
                                     True)
    monkeypatch.setattr(QMessageBox, 'question', lambda *args: QMessageBox.Yes)
    qtbot.mouseClick(re.btn_del_channel, QtCore.Qt.LeftButton)
    assert re.tbl_channels.rowCount() == 1
    assert len(re.rules[0]['channels']) == 1

    qtbot.mouseClick(re.btn_add_rule, QtCore.Qt.LeftButton)
    assert re.lst_rules.count() == 2
    assert re.frm_edit.isEnabled()
    assert re.txt_name.text() == 'New Rule'
    assert re.cmb_property.currentText() == widget.DEFAULT_RULE_PROPERTY
    assert re.tbl_channels.rowCount() == 0
    assert re.txt_expression.text() == ''

    qtbot.mouseClick(re.btn_add_channel, QtCore.Qt.LeftButton)
    assert re.tbl_channels.item(0, 0).text() == ''
    assert re.tbl_channels.item(0, 1).checkState() == QtCore.Qt.Checked

    qtbot.mouseClick(re.btn_add_channel, QtCore.Qt.LeftButton)
    assert re.tbl_channels.item(1, 0).text() == ''
    assert re.tbl_channels.item(1, 1).checkState() == QtCore.Qt.Unchecked

    # Switch between the rules
    re.lst_rules.setCurrentRow(0)
    re.lst_rules.setCurrentRow(1)

    # Delete Rule 1 - Confirm - NO
    monkeypatch.setattr(QMessageBox, 'question', lambda *args: QMessageBox.No)
    qtbot.mouseClick(re.btn_del_rule, QtCore.Qt.LeftButton)
    assert re.lst_rules.count() == 2

    # Delete Rule 1 - Confirm - YES
    monkeypatch.setattr(QMessageBox, 'question', lambda *args: QMessageBox.Yes)
    qtbot.mouseClick(re.btn_del_rule, QtCore.Qt.LeftButton)
    assert re.frm_edit.isEnabled() is False
    assert re.lst_rules.count() == 1

    re.lst_rules.setCurrentRow(0)
    monkeypatch.setattr(QMessageBox, 'question', lambda *args: QMessageBox.Yes)
    qtbot.mouseClick(re.btn_del_rule, QtCore.Qt.LeftButton)
    assert re.frm_edit.isEnabled() is False
    assert re.lst_rules.count() == 0

    # Delete Empty List - Confirm - YES
    monkeypatch.setattr(QMessageBox, 'question', lambda *args: QMessageBox.Yes)
    qtbot.mouseClick(re.btn_del_rule, QtCore.Qt.LeftButton)
    assert re.frm_edit.isEnabled() is False
    assert re.lst_rules.count() == 0
    re.cancelChanges()