Ejemplo n.º 1
0
    def __clean_and_load_bookings__(self, working_date: str=None):
        """
        Cleans booking table when switch working day.

        :param working_date:
        :return:
        """
        row = 0
        t: QTableWidget = self.ui.table_bookings
        clean_table(t)
        bookings = list()
        if working_date is not None:
            bookings = self.time_capture_service.load_bookings(working_date)
        else:
            bookings = self.__convert_entities_to_bookings__()
        for b in bookings:
            t.insertRow(row)

            qcb = QCheckBox(self.ui.table_bookings)
            qcb.setChecked(b[bk.BOOKED])
            t.setCellWidget(row, B_BOOKED, qcb)

            qcb = QCheckBox(self.ui.table_bookings)
            qcb.setChecked(b[bk.LOGGED])
            t.setCellWidget(row, B_LOGGED, qcb)

            qdsb = QDoubleSpinBox(self.ui.table_bookings)
            qdsb.setValue(b[bk.HOURS])
            t.setCellWidget(row, B_HOURS, qdsb)

            t.setItem(row, B_ORDER, QTableWidgetItem(b[bk.ORDER]))
            t.setItem(row, B_COMMENT, QTableWidgetItem(b[bk.COMMENT]))
            t.resizeRowsToContents()
            row += 1
Ejemplo n.º 2
0
    def __clean_and_load_entries__(self, working_date: str):
        """
        Cleans entry table when switch working day.

        :param working_date:
        :return:
        """
        row = 0
        entries = self.time_capture_service.load_working_entries(working_date)

        clean_table(self.ui.table_times)

        for e in entries:
            self.ui.table_times.insertRow(row)
            qte = QTimeEdit(self.ui.table_times)
            qte.setTime(e[wek.START_TIME])
            self.ui.table_times.setCellWidget(row, E_START_TIME_COL, qte)

            qte = QTimeEdit(self.ui.table_times)
            qte.setTime(e[wek.END_TIME])
            self.ui.table_times.setCellWidget(row, E_END_TIME_COL, qte)

            self.ui.table_times.setItem(row, E_ORDER_COL, QTableWidgetItem(e[wek.ORDER]))
            self.ui.table_times.setItem(row, E_COMMENT_COL, QTableWidgetItem(e[wek.COMMENT]))
            row += 1
            self.ui.table_times.resizeRowsToContents()
Ejemplo n.º 3
0
 def createEditor(self, parent, option, index):
     ws = option.rect.width()
     hs = option.rect.height() + 4
     xs = option.rect.x()
     ys = option.rect.y() - 2
     if index.column() in [2]:
         filt = "CGNS Files (*.hdf *.cgns)"
         filename = str(QFileDialog.getOpenFileName(self._table,
                                                    "Select file",
                                                    filter=filt)[0])
         (dname, fname) = os.path.split(filename)
         if not dname or not fname:
             return None
         itf = QTableWidgetItem(fname)
         itd = QTableWidgetItem(dname)
         self._table.setItem(index.row(), 2, itf)
         self._table.setItem(index.row(), 4, itd)
         return None
     if index.column() in [1, 3]:
         editor = QLineEdit(parent)
         editor.transgeometry = (xs, ys, ws, hs)
         editor.installEventFilter(self)
         self.setEditorData(editor, index)
         return editor
     return None
Ejemplo n.º 4
0
    def set_data_2d(self,
                    data: 'Iterable',
                    rows: int = None,
                    columns: int = None):

        if not hasattr(data, '__len__'):
            item = QTableWidgetItem(str(data))
            self.setItem(0, 0, item)
            return
        if rows is None or columns is None:
            rows = len(data)
            max_cols = 0
            for row_contents in data:
                if hasattr(row_contents, '__iter__'):
                    col_span = len(row_contents)
                else:
                    col_span = 1
                if col_span > max_cols:
                    max_cols = col_span
            columns = max_cols
        self.setColumnCount(columns)
        self.setRowCount(rows)
        self.setSelectionBehavior(QAbstractItemView.SelectRows)
        for row, row_content in enumerate(data):
            if hasattr(row_content, '__iter__'):
                for col, content in enumerate(row_content):
                    item = QTableWidgetItem(str(data[row][col]))
                    self.setItem(row, col, item)
            else:
                item = QTableWidgetItem(str(data[row]))
                self.setItem(row, 0, item)
 def refresh_view(self):
     self.measurements_storage.change_expand(self.expand_mode.isChecked())
     self.info_field.clear()
     save_orientation = self.horizontal_measurement_present.isChecked()
     columns, rows = self.measurements_storage.get_size(save_orientation)
     if self.file_names.get_value() == FileNamesEnum.No:
         rows -= 1
         shift = 1
     else:
         shift = 0
     self.info_field.setColumnCount(columns)
     self.info_field.setRowCount(rows)
     self.info_field.setHorizontalHeaderLabels(self.measurements_storage.get_header(save_orientation))
     self.info_field.setVerticalHeaderLabels(self.measurements_storage.get_rows(save_orientation))
     if self.file_names.get_value() == FileNamesEnum.Full:
         for y in range(columns):
             self.info_field.setItem(
                 0, y, QTableWidgetItem(self.measurements_storage.get_val_as_str(0, y, save_orientation))
             )
     elif self.file_names.get_value() == FileNamesEnum.Short:
         for y in range(columns):
             self.info_field.setItem(
                 0,
                 y,
                 QTableWidgetItem(
                     os.path.basename(self.measurements_storage.get_val_as_str(0, y, save_orientation))
                 ),
             )
     for x in range(1, rows + shift):
         for y in range(columns):
             self.info_field.setItem(
                 x - shift, y, QTableWidgetItem(self.measurements_storage.get_val_as_str(x, y, save_orientation))
             )
Ejemplo n.º 6
0
 def display_ranks(self):
     if self.ranks is None:
         return
     # https://stackoverflow.com/questions/7960505/strange-qtablewidget-behavior-not-all-cells-populated-after-sorting-followed-b
     self.ranks_tbl.setSortingEnabled(False)
     nrow, ncol = self.ranks.shape
     irow = 0
     for index, row in self.ranks.iterrows():
         pcell = QTableWidgetItem()
         pcell.setText(index)
         self.ranks_tbl.setItem(irow, 0, pcell)
         for icol in range(ncol):
             cell = QTableWidgetItem()
             val = row.iloc[icol]
             #if icol in [0, 1]:
             #    val = str(int(val))
             #else:
             #    val = "{0:.3f}".format(val)
             #cell.setText(val)
             if icol in [0, 1]:
                 val = int(val)
             else:
                 val = "{0:.3f}".format(val)
             cell.setData(Qt.EditRole, QVariant(val))
             self.ranks_tbl.setItem(irow, icol + 1, cell)
         irow += 1
     self.ranks_tbl.setSortingEnabled(True)
Ejemplo n.º 7
0
def table_to_widget(table: dict) -> QTableWidget:
    view = QTableWidget(len(next(iter(table.values()))), len(table))
    for i, column in enumerate(table.keys()):
        view.setItem(0, i, QTableWidgetItem(column))
        for j, value in enumerate(table.get(column)):
            view.setItem(j + 1, i, QTableWidgetItem(str(value)))
    return view
Ejemplo n.º 8
0
    def test_onClickOpenSelectedInScriptWindow(self):
        self.prw.ui.tableWidget.selectedItems.return_value = \
            [QTableWidgetItem("1"), QTableWidgetItem("2"), QTableWidgetItem("No")]
        self.prw.onClickOpenSelectedInScriptWindow()

        self.prw.presenter.open_selected_checkpoint_in_editor.assert_called_with(
            "1")
Ejemplo n.º 9
0
 def reset(self):
     tlvcols = 4
     tlvcolsnames = ['S', 'Pattern', 'P', 'Comment']
     v = self.patternTable
     v.setColumnCount(tlvcols)
     lh = v.horizontalHeader()
     lv = v.verticalHeader()
     h = tlvcolsnames
     n = len(h)
     for i in range(n):
         hi = QTableWidgetItem(h[i])
         v.setHorizontalHeaderItem(i, hi)
     for profkey in self._profiles:
         prof = self._profiles[profkey]
         for k in prof:
             pentry = prof[k]
             v.setRowCount(v.rowCount() + 1)
             r = v.rowCount() - 1
             it1 = QTableWidgetItem(self.IC(QW.I_EMPTY), '')
             it2 = QTableWidgetItem(k)
             it2.setFont(QFont("Courier"))
             it3 = QTableWidgetItem(profkey)
             it4 = QTableWidgetItem(pentry[2])
             v.setItem(r, 0, it1)
             v.setItem(r, 1, it2)
             v.setItem(r, 2, it3)
             v.setItem(r, 3, it4)
     self.patternTable.resizeColumnsToContents()
     self.patternTable.resizeRowsToContents()
     plist = []
     for i in range(len(plist)):
         v.resizeColumnToContents(i)
     for i in range(v.rowCount()):
         v.resizeRowToContents(i)
     self._initialized = True
Ejemplo n.º 10
0
    def _set_table_item(self, json=None, metadata_filter={}, row=-1, col=-1):
        """Populate the filter metadada table from the oncat json file of only the arguments specified in
        the config.json file (oncat_metadata_filters)"""

        table_ui = self.table_ui

        def _format_proton_charge(raw_proton_charge):
            _proton_charge = raw_proton_charge / 1e12
            return "{:.3}".format(_proton_charge)

        title = metadata_filter['title']
        list_args = metadata_filter["path"]
        argument_value = json_extractor(json=json,
                                        list_args=copy.deepcopy(list_args))

        # if title is "Proton Charge" change format of value displayed
        if title == "Proton Charge (C)":
            argument_value = _format_proton_charge(argument_value)

        if table_ui is None:
            table_ui = self.ui.tableWidget_filter_result

        if self.parent.first_time_filling_table:
            table_ui.insertColumn(col)
            _item_title = QTableWidgetItem(title)
            table_ui.setHorizontalHeaderItem(col, _item_title)
            width = metadata_filter["column_width"]
            table_ui.setColumnWidth(col, width)

        _item = QTableWidgetItem("{}".format(argument_value))
        table_ui.setItem(row, col, _item)
Ejemplo n.º 11
0
 def set_expr(self, es: EStack, unsolved: Sequence[int]):
     """Set the table items for new coming expression."""
     exprs = es.as_list()
     if exprs != self.exprs:
         self.clear()
         self.setRowCount(len(exprs) + len(unsolved))
     row = 0
     for expr in exprs:
         # Target
         self.setItem(row,
                      self.columnCount() - 1, QTableWidgetItem(expr[-1]))
         # Parameters
         for column, text in enumerate(expr[:-1]):
             item = QTableWidgetItem(text)
             item.setToolTip(text)
             self.setItem(row, column, item)
         row += 1
     for p in unsolved:
         # Declaration
         self.setItem(row, 0, QTableWidgetItem("Unsolved"))
         # Target
         self.setItem(row,
                      self.columnCount() - 1, QTableWidgetItem(f"P{p}"))
         row += 1
     self.exprs = exprs
Ejemplo n.º 12
0
    def on_create_super_group(self):
        inames = [
            iname for iname, check in enumerate(self.checks)
            if bool(check.checkState())
        ]

        if not len(inames):
            # TODO: add logging
            print('nothing is checked...')
            return
        if inames[0] == 0:
            # TODO: add logging
            print("cannot include 'ALL' in supergroup...")
            return

        name = 'SuperGroup'
        # popup gui and get a name

        irow = self.table.rowCount()
        self.table.insertRow(irow)

        check = QTableWidgetItem()
        check.setCheckState(False)
        name_text = QTableWidgetItem(str(name))

        self.names.extend(name)
        self.names_text.append(name_text)
        self.checks.append(check)

        self.table.setItem(irow, 0, check)
        self.table.setItem(irow, 1, name_text)
Ejemplo n.º 13
0
    def reload(self):
        """Reload the tracks features from the layers to the table widget"""
        particles = self.viewer.layers[self.layer_name].data
        features = self.viewer.layers[self.layer_name].metadata
        headers = ['track_id']
        for key in features:
            if isinstance(features[key], dict):
                headers.append(key)
        self.tableWidget.setColumnCount(len(headers))
        self.tableWidget.setHorizontalHeaderLabels(headers)
        self.tableWidget.setRowCount(len(np.unique(particles[:, 0])))

        features_dict = dict()
        tracks_ids = np.unique(particles[:, 0])
        for id_ in tracks_ids:
            features_dict[id_] = list()

        for key in features:
            if isinstance(features[key], dict):
                feature_dict = features[key]
                for f_key in feature_dict:
                    if f_key in features_dict:
                        features_dict[f_key].append(str(feature_dict[f_key]))

        line = -1
        for key in features_dict:
            line += 1
            # track_id = key
            self.tableWidget.setItem(line, 0, QTableWidgetItem(str(key)))
            # add each feature per column
            col = 0
            for feature in features_dict[key]:
                col += 1
                self.tableWidget.setItem(line, col, QTableWidgetItem(feature))
Ejemplo n.º 14
0
    def refresh_table(self, job_list):
        for _row in range(self.ui.tableWidget.rowCount()):
            self.ui.tableWidget.removeRow(0)

        nbr_row = len(job_list)
        for _row in range(nbr_row):
            _row_job = job_list[_row]

            self.ui.tableWidget.insertRow(_row)

            # job name
            _item = QTableWidgetItem(_row_job['job_name'])
            self.ui.tableWidget.setItem(_row, 0, _item)

            # time
            _item = QTableWidgetItem(_row_job['time'])
            self.ui.tableWidget.setItem(_row, 1, _item)

            # action
            _pid = _row_job['pid']
            process = psutil.Process(_pid)
            if not process.is_running():
                _item = QTableWidgetItem("Done!")
                self.ui.tableWidget.setItem(_row, 2, _item)
            else:
                if _row_job['status'] == 'processing':
                    _widget = QPushButton()
                    _widget.setText("Abort!")
                    _widget.clicked.connect(lambda row=_row:
                                            self.parent.kill_job(row))
                    self.ui.tableWidget.setCellWidget(_row, 2, _widget)
                else:
                    _item = QTableWidgetItem("Killed!")
                    self.ui.tableWidget.setItem(_row, 2, _item)
Ejemplo n.º 15
0
    def write_info(self, data_stream):
        if len(data_stream) < 1:
            return
        if len(data_stream[0]) > 40:
            return
        rcount = self.rxtable.rowCount()
        ####pprint.pprint(data_stream)
        cntr = 0
        hexstr = ''
        intstr = ''
        txt = ''
        decimals = ''
        str_int_digits = []
        str_hex_digits = []
        str_ampere = ''
        for ttx in data_stream:
            for itx in ttx:
                txt += '{:02X} '.format(int(itx))
                cntr += 1
                if cntr > 2:
                    intstr += '{:04d} '.format(int(hexstr, 16))
                    str_int_digits.append('{:04d}'.format(int(hexstr, 16)))
                    hexstr = ''
                    cntr = 1

                hexstr += '{:02X}'.format(int(itx))
                str_hex_digits.append(hexstr)

        if len(str_int_digits) > 7:
            try:
                #pprint.pprint(str_int_digits)

                self.lcddcout.display(str(int(str_int_digits[5])))
                self.lcddcin.display(str(int(str_int_digits[6])))
                str_ampere = str(
                    int(str_hex_digits[3][-2:], 16) - 128
                )  # + '.' + str_hex_digits[2][-1] + str_hex_digits[1][-1]
                print('Amp : ' + str_hex_digits[3][-2:])
                self.lcddcamp.display(float(str_ampere))
                #pprint.pprint(str_hex_digits)
                print('KWh : ' + str_hex_digits[9][-2:]
                      )  #+ str(int(str_hex_digits[5][-2:], 16)))
                self.lcdkwhob.display(int(str_hex_digits[9][-2:], 16))

                self.outback_dcout = str(int(str_int_digits[5]))
                self.outback_dcin = str(int(str_int_digits[6]))
                self.outback_current = str(
                    int(str_hex_digits[3][-2:], 16) - 128)
                self.outback_kwh = str(int(str_hex_digits[9][-2:], 16))
            except Exception as e:
                print('exc - lcddcamp : ' + str_hex_digits[3] + ' : ' + str(e))

        self.rxtable.insertRow(rcount)
        self.rxtable.setItem(rcount, 0, QTableWidgetItem(txt))
        self.rxtable.setItem(rcount, 1, QTableWidgetItem(intstr))
        if self.isAutoScroll:
            self.rxtable.scrollToBottom()
        self.rxtable.resizeColumnsToContents()
        self.rxtable.resizeRowsToContents()
Ejemplo n.º 16
0
 def updateStatus(self, param):
     self.status[param["device"]] = "{}".format(param["status"])
     idx = 0
     self.deviceStatus.setRowCount(len(self.status))
     for k, v in self.status.items():
         self.deviceStatus.setItem(idx, 0, QTableWidgetItem(k))
         self.deviceStatus.setItem(idx, 1, QTableWidgetItem(v))
         idx += 1
Ejemplo n.º 17
0
    def _populate_table(self):
        """Add row for each extension to reader mapping in settings"""
        self._extension_col = 0
        self._reader_col = 1

        header_strs = [trans._('Extension'), trans._('Reader Plugin')]

        self._table.setColumnCount(2)
        self._table.setColumnWidth(self._extension_col, 100)
        self._table.setColumnWidth(self._reader_col, 150)
        self._table.verticalHeader().setVisible(False)
        self._table.setMinimumHeight(120)

        extension2reader = get_settings().plugins.extension2reader
        if len(extension2reader) > 0:
            self._table.setRowCount(len(extension2reader))
            self._table.horizontalHeader().setStretchLastSection(True)
            self._table.horizontalHeader().setStyleSheet(
                'border-bottom: 2px solid white;'
            )
            self._table.setHorizontalHeaderLabels(header_strs)

            for row, (extension, plugin_name) in enumerate(
                extension2reader.items()
            ):
                item = QTableWidgetItem(extension)
                item.setFlags(Qt.NoItemFlags)
                self._table.setItem(row, self._extension_col, item)

                plugin_widg = QWidget()
                # need object name to easily find row
                plugin_widg.setObjectName(f'{extension}')
                plugin_widg.setLayout(QHBoxLayout())
                plugin_widg.layout().setContentsMargins(0, 0, 0, 0)

                plugin_label = QLabel(plugin_name)
                # need object name to easily work out which button was clicked
                remove_btn = QPushButton('x', objectName=f'{extension}')
                remove_btn.setFixedWidth(30)
                remove_btn.setStyleSheet('margin: 4px;')
                remove_btn.setToolTip(
                    trans._('Remove this extension to reader association')
                )
                remove_btn.clicked.connect(self._remove_extension_assignment)

                plugin_widg.layout().addWidget(plugin_label)
                plugin_widg.layout().addWidget(remove_btn)
                self._table.setCellWidget(row, self._reader_col, plugin_widg)
        else:
            # Display that there are no extensions with reader associations
            self._table.setRowCount(1)
            self._table.setHorizontalHeaderLabels(header_strs)

            self._table.setColumnHidden(self._reader_col, True)
            self._table.setColumnWidth(self._extension_col, 200)
            item = QTableWidgetItem(trans._('No extensions found.'))
            item.setFlags(Qt.NoItemFlags)
            self._table.setItem(0, 0, item)
Ejemplo n.º 18
0
    def reset_headers(self):
        """Update the column and row numbering in the headers."""
        rows = self.rowCount()
        cols = self.columnCount()

        for r in range(rows):
            self.setVerticalHeaderItem(r, QTableWidgetItem(str(r)))
        for c in range(cols):
            self.setHorizontalHeaderItem(c, QTableWidgetItem(str(c)))
            self.setColumnWidth(c, 40)
Ejemplo n.º 19
0
    def set_values(self, values: dict) -> None:
        """Populate the table with keys and values.

        values : dict
            Populate with these keys and values.
        """
        self.setRowCount(len(values))
        self.setColumnCount(2)
        for i, (key, value) in enumerate(values.items()):
            self.setItem(i, 0, QTableWidgetItem(key))
            self.setItem(i, 1, QTableWidgetItem(value))
Ejemplo n.º 20
0
 def populate_plugin_list(self):
     col_labels = ["Protocol", "File"]
     self.ui.dataPluginsTableWidget.setColumnCount(len(col_labels))
     self.ui.dataPluginsTableWidget.setHorizontalHeaderLabels(col_labels)
     self.ui.dataPluginsTableWidget.horizontalHeader().setStretchLastSection(True)
     self.ui.dataPluginsTableWidget.verticalHeader().setVisible(False)
     for (protocol, plugin) in pydm.data_plugins.plugin_modules.items():
         protocol_item = QTableWidgetItem(protocol)
         file_item = QTableWidgetItem(inspect.getfile(plugin.__class__))
         new_row = self.ui.dataPluginsTableWidget.rowCount()
         self.ui.dataPluginsTableWidget.insertRow(new_row)
         self.ui.dataPluginsTableWidget.setItem(new_row, 0, protocol_item)
         self.ui.dataPluginsTableWidget.setItem(new_row, 1, file_item)
Ejemplo n.º 21
0
 def _checking_status_of_jobs(self):
     _job_list = self.parent.job_list
     for _row, _job in enumerate(_job_list):
         _pid = _job['pid']
         process = psutil.Process(_pid)
         if process is None:
             self.job_monitor_interafce.ui.tableWidget.removeCellWidget(_row, 2)
             _item = QTableWidgetItem("Done!")
             self.job_monitor_interafce.ui.tableWidget.setItem(_row, 2, _item)
         else:
             if not process.status() == 'sleeping':
                 self.job_monitor_interafce.ui.tableWidget.removeCellWidget(_row, 2)
                 _item = QTableWidgetItem("Done!")
                 self.job_monitor_interafce.ui.tableWidget.setItem(_row, 2, _item)
Ejemplo n.º 22
0
    def reload(self):
        """Reload the particles properties from the layers to the table widget"""
        particles = self.viewer.layers[self.layer_name].data
        print(particles)
        properties = self.viewer.layers[self.layer_name].properties
        headers = []
        if particles.shape[1] == 3:
            headers = ['T', 'Y', 'X']
        elif particles.shape[1] == 4:
            headers = ['T', 'Z', 'Y', 'X']

        for key in properties:
            headers.append(key)
        self.tableWidget.setColumnCount(len(headers))
        self.tableWidget.setHorizontalHeaderLabels(headers)
        self.tableWidget.setRowCount(particles.shape[0])

        col = 0
        for line in range(particles.shape[0]):
            col = -1

            # T
            if particles.shape[1] == 4:
                col += 1
                self.tableWidget.setItem(line, col,
                                         QTableWidgetItem(
                                             str(particles[line, col])))
            # T or Z
            if particles.shape[1] >= 3:
                col += 1
                self.tableWidget.setItem(line, col,
                                         QTableWidgetItem(
                                             str(particles[line, col])))
            # Y
            col += 1
            self.tableWidget.setItem(line, col,
                                     QTableWidgetItem(
                                         str(particles[line, col])))
            # X
            col += 1
            self.tableWidget.setItem(line, col,
                                     QTableWidgetItem(
                                         str(particles[line, col])))
        # properties
        for key in properties:
            col += 1
            prop = properties[key]
            for line in range(len(prop)):
                self.tableWidget.setItem(line, col,
                                         QTableWidgetItem(str(prop[line])))
Ejemplo n.º 23
0
    def actualizeTable(self):
        self.ui.tablePossibilities.clearContents()
        r = 0
        for p in self.__possibilities__:
            if 'first_air_date' not in p.__dict__ or 'name' not in p.__dict__:
                self.__possibilities__.remove(p)
                continue
            self.ui.tablePossibilities.setRowCount(r + 1)
            self.ui.tablePossibilities.setItem(r, 0, QTableWidgetItem(p.name))
            self.ui.tablePossibilities.setItem(
                r, 1, QTableWidgetItem(p.first_air_date[:4]))
            r += 1

        self.ui.tablePossibilities.clearSelection()
Ejemplo n.º 24
0
 def add_tools_to_list(self, tools):
     for (name, tool) in tools.items():
         if isinstance(tool, dict):
             self.add_tools_to_list(tool)
         else:
             tool_info = tool.get_info()
             name_item = QTableWidgetItem(tool_info.get("name","None"))
             group_item = QTableWidgetItem(tool_info.get("group","None"))
             author_item = QTableWidgetItem(tool_info.get("author","None"))
             file_item = QTableWidgetItem(tool_info.get("file","None"))
             new_row = self.ui.externalToolsTableWidget.rowCount()
             self.ui.externalToolsTableWidget.insertRow(new_row)
             self.ui.externalToolsTableWidget.setItem(new_row, 0, name_item)
             self.ui.externalToolsTableWidget.setItem(new_row, 1, group_item)
             self.ui.externalToolsTableWidget.setItem(new_row, 2, author_item)
             self.ui.externalToolsTableWidget.setItem(new_row, 3, file_item)
Ejemplo n.º 25
0
 def _add_data_to_table(self):
     # This table's size was generated for 5 which is the default but will take the value given by the presenter
     number_of_rows = self.presenter.get_number_of_checkpoints()
     for ii in range(0, number_of_rows):
         row = self.presenter.get_row(ii)
         for jj in range(0, len(row)):
             self.ui.tableWidget.setItem(ii, jj, QTableWidgetItem(row[jj]))
Ejemplo n.º 26
0
    def __init__(self, row: int, parent: QWidget) -> None:
        super(BaseTableWidget, self).__init__(parent)
        self.setSizePolicy(
            QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding))
        self.setStatusTip(
            "This table will show about the entities items in current view mode."
        )
        self.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.setVerticalScrollMode(QAbstractItemView.ScrollPerPixel)
        self.setHorizontalScrollMode(QAbstractItemView.ScrollPerPixel)

        self.setRowCount(row)
        self.setColumnCount(len(self.headers))
        for i, e in enumerate(self.headers):
            self.setHorizontalHeaderItem(i, QTableWidgetItem(e))

        # Table widget column width.
        header = self.horizontalHeader()
        header.setSectionResizeMode(QHeaderView.ResizeToContents)

        @Slot()
        def emit_selection_changed() -> None:
            self.row_selection_changed.emit(self.selected_rows())

        self.itemSelectionChanged.connect(emit_selection_changed)
Ejemplo n.º 27
0
    def value_changed(self, new_waveform):
        """
        Callback invoked when the Channel value is changed.

        Parameters
        ----------
        new_waveform : np.ndarray
            The new waveform value from the channel.
        """
        PyDMWritableWidget.value_changed(self, new_waveform)
        self._valueBeingSet = True
        self.waveform = new_waveform
        col_count = self.columnCount()
        len_wave = len(new_waveform)
        row_count = len_wave // col_count + (1 if len_wave % col_count else 0)
        self.setRowCount(row_count)
        for ind, element in enumerate(new_waveform):
            i, j = ind // col_count, ind % col_count
            value_cell = QTableWidgetItem(str(element))
            value_cell.setFlags(self._itemsFlags)
            self.setItem(i, j, value_cell)

        self.setVerticalHeaderLabels(self._rowHeaders)
        self.setHorizontalHeaderLabels(self._columnHeaders)
        self._valueBeingSet = False
Ejemplo n.º 28
0
    def set_peaks_workspaces(self, names_and_statuses):
        """
        :param names_and_statuses: a list of 2-tuples where each tuple contains (workspace name:str, checked status :bool)
        """
        table = self._table
        table.clearContents()

        for row, (name, checked) in enumerate(names_and_statuses):
            table.insertRow(row)
            name_item = QTableWidgetItem(name)
            name_item.setFlags(Qt.ItemIsEnabled)
            table.setItem(row, self.NAME_COLUMN_INDEX, name_item)
            overlay_item = QTableWidgetItem()
            overlay_item.setFlags(Qt.ItemIsEnabled | Qt.ItemIsUserCheckable)
            overlay_item.setCheckState(Qt.Checked if checked else Qt.Unchecked)
            table.setItem(row, self.CHECKED_COLUMN_INDEX, overlay_item)
Ejemplo n.º 29
0
 def test_eraseCell(self):
     self.assertIsNone(self.table.item(0, 0))
     cell = QTableWidgetItem("test")
     self.table.setItem(0, 0, cell)
     self.assertIsNotNone(self.table.item(0, 0))
     self.table.eraseCell(0, 0)
     self.assertIsNone(self.table.item(0, 0))
Ejemplo n.º 30
0
    def dropEvent(self, event):
        if not event.isAccepted() and event.source() == self:
            self.blockSignals(True)
            drop_row = self.drop_on(event)

            rows = sorted(set(item.row() for item in self.selectedItems()))
            rows_to_move = [[
                QTableWidgetItem(self.item(row_index, column_index))
                for column_index in range(self.columnCount())
            ] for row_index in rows]
            for row_index in reversed(rows):
                self.removeRow(row_index)
                if row_index < drop_row:
                    drop_row -= 1

            for row_index, data in enumerate(rows_to_move):
                row_index += drop_row
                self.insertRow(row_index)
                for column_index, column_data in enumerate(data):
                    self.setItem(row_index, column_index, column_data)
            event.accept()
            for row_index in range(len(rows_to_move)):
                self.item(drop_row + row_index, 0).setSelected(True)
                self.item(drop_row + row_index, 1).setSelected(True)

            drop_row = self.drop_on(event)
            self.blockSignals(False)
            self.rowMoved.emit(drop_row, rows)

        super(TableWidgetDragRows, self).dropEvent(event)