def update_current_position(self, coords: Sequence[Union[_Coord, Tuple[_Coord, _Coord]]]): """Update the current coordinate for a point.""" for i, c in enumerate(coords): if type(c[0]) == float: text = f"({c[0]:.06f}, {c[1]:.06f})" else: text = "; ".join(f"({x:.06f}, {y:.06f})" for x, y in c) item = QTableWidgetItem(text) item.setToolTip(text) self.setItem(i, 6, item)
def setExpr(self, exprs: List[Tuple[str]]): if exprs == self.exprs: return self.clear() self.setRowCount(len(exprs)) for row, expr in enumerate(exprs): self.setItem(row, 5, QTableWidgetItem(expr[-1])) for column, e in enumerate(expr[:-1]): self.setItem(row, column, QTableWidgetItem(e)) self.exprs = exprs
def updateCurrentPosition(self, coords: Tuple[Tuple[Tuple[float, float]]]): """Update the current coordinate for a point.""" for i, c in enumerate(coords): if type(c[0]) == float: text = "({}, {})".format(*c) else: text = "; ".join("({}, {})".format(x, y) for x, y in c) item = QTableWidgetItem(text) item.setToolTip(text) self.setItem(i, 6, item)
def updateCurrentPosition(self, coords: Sequence[Tuple[float, float]]): """Update the current coordinate for a point.""" for i, c in enumerate(coords): if type(c[0]) == float: text = f"({c[0]}, {c[1]})" else: text = "; ".join(f"({x}, {y})" for x, y in c) item = QTableWidgetItem(text) item.setToolTip(text) self.setItem(i, 6, item)
def addCommit(self, commit: CommitModel): """Add commit data to all widgets. + Commit ID + Date + Description + Author + Previous commit + Branch + Add to table widget. """ row = self.CommitTable.rowCount() self.CommitTable.insertRow(row) self.commit_current_id.setValue(commit.id) button = LoadCommitButton(commit.id, self) button.loaded.connect(self.loadCommitID) self.load_id.connect(button.isLoaded) self.CommitTable.setCellWidget(row, 0, button) date = ("{t.year:02d}-{t.month:02d}-{t.day:02d} " + "{t.hour:02d}:{t.minute:02d}:{t.second:02d}").format( t=commit.date) self.CommitTable.setItem(row, 2, QTableWidgetItem(commit.description)) author_name = commit.author.name all_authors = [ self.AuthorList.item(row).text() for row in range(self.AuthorList.count()) ] if author_name not in all_authors: self.AuthorList.addItem(author_name) if commit.previous: previous_id = "#{}".format(commit.previous.id) else: previous_id = "None" branch_name = commit.branch.name all_branchs = [ self.BranchList.item(row).text() for row in range(self.BranchList.count()) ] if branch_name not in all_branchs: self.BranchList.addItem(branch_name) self.branch_current.setText(branch_name) for i, text in enumerate( [date, commit.description, author_name, previous_id, branch_name]): item = QTableWidgetItem(text) item.setToolTip(text) self.CommitTable.setItem(row, i + 1, item)
def __setProfile(self, profile_name: str, params: Dict[str, Any]): """Set profile to sub-widgets.""" self.__clearSettings() self.profile_name.setText(profile_name) self.Expression.setText(params['Expression']) self.Link_Expression.setText(params['Link_Expression']) for name in sorted(params['Target']): self.target_points.addItem(name) path = params['Target'][name] if path: self.path[name] = path.copy() else: self.path[name] = [] if self.target_points.count(): self.target_points.setCurrentRow(0) gj = {} for key in ('Driver', 'Follower'): gj.update(params[key]) self.ground_joints.setRowCount(0) self.ground_joints.setRowCount(len(gj)) def spinbox(v: float, prefix: bool = False): s = QDoubleSpinBox(self) s.setMinimum(-1000000.0) s.setMaximum(1000000.0) s.setSingleStep(10.0) s.setValue(v) if prefix: s.setPrefix("±") return s for row, name in enumerate(sorted(gj)): coord = gj[name] self.ground_joints.setItem(row, 0, QTableWidgetItem(name)) if name in params['Driver']: role = 'Driver' else: role = 'Follower' self.ground_joints.setItem(row, 1, QTableWidgetItem(role)) x, y = params['pos'][int(name.replace('P', ''))] s1 = spinbox(coord[0] if coord else x) s2 = spinbox(coord[1] if coord else y) s3 = spinbox(coord[2] if coord else 50., True) self.ground_joints.setCellWidget(row, 2, s1) self.ground_joints.setCellWidget(row, 3, s2) self.ground_joints.setCellWidget(row, 4, s3) for s in (s1, s2, s3): s.valueChanged.connect(self.updateRange) self.PreviewCanvas.from_profile(params) self.mech_params = params self.updateRange() self.__ableToGenerate()
def __rename(self, arg1: Sequence[str], arg2: Sequence[str]): """Adjust link name in all dependents, if link name are changed. """ if arg2[0] == arg1[0]: return for index in _no_empty_string(arg2[2].split(',')): row = int(index.replace('Point', '')) new_links = self.point_table.item(row, 1).text().split(',') item = QTableWidgetItem(','.join( _no_empty_string( w.replace(arg2[0], arg1[0]) for w in new_links))) item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) self.point_table.setItem(row, 1, item)
def set_profile(self): """Set profile to sub-widgets.""" params = self.mechanismParams self.path.clear() self.target_points.clear() for name in sorted(params['Target']): self.target_points.addItem(name) path = params['Target'][name] if path: self.path[name] = path.copy() else: self.path[name] = [] if self.target_points.count(): self.target_points.setCurrentRow(0) gj = {} for key in ('Driver', 'Follower'): gj.update(params[key]) self.ground_joints.setRowCount(0) self.ground_joints.setRowCount(len(gj)) def spinbox(v, prefix=False): s = QDoubleSpinBox(self) s.setMinimum(-1000000.0) s.setMaximum(1000000.0) s.setSingleStep(10.0) s.setValue(v) if prefix: s.setPrefix("±") return s nd = {k: int(v.replace('P', '')) for k, v in params['name_dict'].items()} for row, name in enumerate(sorted(gj)): coord = gj[name] self.ground_joints.setItem(row, 0, QTableWidgetItem(name)) self.ground_joints.setItem(row, 1, QTableWidgetItem('Driver' if name in params['Driver'] else 'Follower') ) self.ground_joints.setCellWidget(row, 2, spinbox(coord[0] if coord else params['pos'][nd[name]][0]) ) self.ground_joints.setCellWidget(row, 3, spinbox(coord[1] if coord else params['pos'][nd[name]][1]) ) self.ground_joints.setCellWidget(row, 4, spinbox(coord[2] if coord else 50., True) ) for row in range(self.ground_joints.rowCount()): for column in range(2, 5): self.ground_joints.cellWidget(row, column).valueChanged.connect(self.updateRange) self.updateRange() self.PreviewCanvas.from_profile(self.mechanismParams)
def rename(self, Args1: Tuple[str], Args2: Tuple[str]): """Adjust link name in all dependents, if link name are changed. """ if Args2[0] == Args1[0]: return for index in noNoneString(Args2[2].split(',')): row = int(index.replace('Point', '')) newLinks = self.PointTable.item(row, 1).text().split(',') item = QTableWidgetItem(','.join(noNoneString([ w.replace(Args2[0], Args1[0]) for w in newLinks ]))) item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) self.PointTable.setItem(row, 1, item)
def undo(self): """Rename again then insert a empty row.""" if self.is_rename: self.table.rename(self.row) self.table.insertRow(self.row) for column in range(self.table.columnCount()): self.table.setItem(self.row, column, QTableWidgetItem(''))
def writeTable(Integers: List[Tuple[str, str, str]], Floats: List[Tuple[str, str, str]]): """Use to write table data.""" i = 0 for Types, box, maxV in zip([Integers, Floats], [QSpinBox, QDoubleSpinBox], [9, 10.]): for name, vname, tooltip in Types: self.APTable.insertRow(i) name_cell = QTableWidgetItem(name) name_cell.setToolTip(tooltip) self.APTable.setItem(i, 0, name_cell) spinbox = box() spinbox.setMaximum(maxV) spinbox.setToolTip(vname) self.APTable.setCellWidget(i, 1, spinbox) i += 1
def __add_commit(self, commit: CommitModel): """Add commit data to all widgets. + Commit ID + Date + Description + Author + Previous commit + Branch + Add to table widget. """ row = self.CommitTable.rowCount() self.CommitTable.insertRow(row) self.commit_current_id.setValue(commit.id) button = LoadCommitButton(commit.id, self) button.loaded.connect(self.__load_commit_id) self.load_id.connect(button.set_loaded) self.CommitTable.setCellWidget(row, 0, button) self.CommitTable.setItem(row, 2, QTableWidgetItem(commit.description)) author_name = commit.author.name for row in range(self.AuthorList.count()): if author_name == self.AuthorList.item(row).text(): break else: self.AuthorList.addItem(author_name) branch_name = commit.branch.name for row in range(self.BranchList.count()): if branch_name == self.BranchList.item(row).text(): break else: self.BranchList.addItem(branch_name) self.branch_current.setText(branch_name) t = commit.date for i, text in enumerate( (f"{t.year:02d}-{t.month:02d}-{t.day:02d} " f"{t.hour:02d}:{t.minute:02d}:{t.second:02d}", commit.description, author_name, f"#{commit.previous.id}" if commit.previous else "None", branch_name)): item = QTableWidgetItem(text) item.setToolTip(text) self.CommitTable.setItem(row, i + 1, item)
def writeTable(Length: List[Tuple[str, str, str]], Degrees: List[Tuple[str, str, str]]): """Use to write table data.""" i = 0 for Types, maxV, minV in zip([Length, Degrees], [1000., 360.], [0.1, 0.]): for name, vname, tooltip in Types: self.PLTable.insertRow(i) name_cell = QTableWidgetItem(name) name_cell.setToolTip(tooltip) self.PLTable.setItem(i, 0, name_cell) spinbox = QDoubleSpinBox() spinbox.setMaximum(maxV) spinbox.setMinimum(minV) spinbox.setToolTip(vname) self.PLTable.setCellWidget(i, 1, spinbox) i += 1
def adjust_request(item: QTableWidgetItem): """This function is use to change link length without to drag the points. """ if item: self.free_move_request.emit(item.text().startswith('L')) else: self.free_move_request.emit(False)
def redo(self): """Add a empty row and add empty text strings into table items. """ row = self.table.rowCount() self.table.insertRow(row) for column in range(row): self.table.setItem(row, column, QTableWidgetItem(''))
def write_table(integers: Optional[List[Tuple[str, str, str]]] = None, floats: Optional[List[Tuple[str, str, str]]] = None): """Use to write table data.""" if integers is None: integers = [] if floats is None: floats = [] i = 0 for options, box, max_value in ((integers, QSpinBox, 9), (floats, QDoubleSpinBox, 10.)): for name, tooltip, tooltip in options: self.alg_table.insertRow(i) name_cell = QTableWidgetItem(name) name_cell.setToolTip(tooltip) self.alg_table.setItem(i, 0, name_cell) spinbox = box() spinbox.setMaximum(max_value) spinbox.setToolTip(tooltip) self.alg_table.setCellWidget(i, 1, spinbox) i += 1
def editLink(self, row: int, name: str, color: str, points: str): """Edit a link.""" for i, e in enumerate((name, color, points)): item = QTableWidgetItem(e) item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) if i == 1: item.setIcon(color_icon(e)) self.setItem(row, i, item)
def edit_point(self, row: int, links: str, type_str: str, color: str, x: str, y: str): """Edit a point.""" for i, e in enumerate([f'Point{row}', links, type_str, color, x, y, f"({x}, {y})"]): item = QTableWidgetItem(str(e)) item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) if i == 3: item.setIcon(color_icon(e)) self.setItem(row, i, item)
def __init__(self, RowCount: int, HorizontalHeaderItems: Tuple[str], parent=None): super(BaseTableWidget, self).__init__(parent) self.setSizePolicy( QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)) self.setEditTriggers(QAbstractItemView.NoEditTriggers) self.setSelectionBehavior(QAbstractItemView.SelectRows) self.setVerticalScrollMode(QAbstractItemView.ScrollPerPixel) self.setHorizontalScrollMode(QAbstractItemView.ScrollPerPixel) self.setRowCount(RowCount) self.setColumnCount(len(HorizontalHeaderItems) + 1) for i, e in enumerate(('Name', ) + HorizontalHeaderItems): self.setHorizontalHeaderItem(i, QTableWidgetItem(e))
def editArgs(self, row: int, Links: str, Type: str, Color: str, x: float, y: float): """Edite a point.""" for i, e in enumerate([ 'Point{}'.format(row), Links, Type, Color, x, y, "({}, {})".format(x, y) ]): item = QTableWidgetItem(str(e)) item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) if i == 3: item.setIcon(colorIcons(e)) self.setItem(row, i, item)
def __init__(self, filename, tag, parent=None): super(Dialog, self).__init__(parent) self.setupUi(self) self.tag = tag if tag == 'signal': self.sigform() wb = open_workbook(filename) table = wb.sheet_by_index(0) self.ts_edit.setValidator(QDoubleValidator(0, 10, 6, self)) self.tableWidget.setColumnCount(table.ncols) self.tableWidget.setRowCount(table.nrows) for row in range(table.nrows): for col in range(table.ncols): self.tableWidget.setItem(row, col, QTableWidgetItem(str(table.cell(row,col).value))) self.data = [] self.fftchose = False
def __init__(self, row: int, headers: Sequence[str], parent: QWidget): 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(headers)) for i, e in enumerate(headers): self.setHorizontalHeaderItem(i, QTableWidgetItem(e)) self.itemSelectionChanged.connect(self.__emitSelectionChanged)
def writeRows(self, items1: Sequence[int], items2: Sequence[int] ): """Write table function. + Append the point that relate with these links. + Remove the point that irrelevant with these links. """ for row in items1: newPoints = self.LinkTable.item(row, 2).text().split(',') newPoints.append('Point{}'.format(self.row)) item = QTableWidgetItem(','.join(noNoneString(newPoints))) item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) self.LinkTable.setItem(row, 2, item) for row in items2: newPoints = self.LinkTable.item(row, 2).text().split(',') newPoints.remove('Point{}'.format(self.row)) item = QTableWidgetItem(','.join(noNoneString(newPoints))) item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) self.LinkTable.setItem(row, 2, item)
def writeRows(self, name: str, items1: Sequence[int], items2: Sequence[int] ): """Write table function. + Append the link that relate with these points. + Remove the link that irrelevant with these points. """ for row in items1: newLinks = self.PointTable.item(row, 1).text().split(',') newLinks.append(name) item = QTableWidgetItem(','.join(noNoneString(newLinks))) item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) self.PointTable.setItem(row, 1, item) for row in items2: newLinks = self.PointTable.item(row, 1).text().split(',') if name: newLinks.remove(name) item = QTableWidgetItem(','.join(noNoneString(newLinks))) item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) self.PointTable.setItem(row, 1, item)
def set_expr( self, exprs: ExpressionStack, data_dict: Dict[str, Union[Coordinate, float]], unsolved: Tuple[int, ...] ): """Set the table items for new coming expression.""" exprs = exprs.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, e in enumerate(expr[:-1]): if e in data_dict: if type(data_dict[e]) == float: # Pure digit text = f"{e}:{data_dict[e]:.02f}" else: # Coordinate c = data_dict[e] text = f"{e}:({c.x:.02f}, {c.y:.02f})" else: # Function name text = e 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
def setCell(self, row: int, links: List[str]): item = QTableWidgetItem(','.join(noNoneString(links))) item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) self.PointTable.setItem(row, 1, item)
def __set_cell(self, row: int, links: List[str]): item = QTableWidgetItem(','.join(_no_empty_string(links))) item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) self.point_table.setItem(row, 1, item)
def rename(self, row: int): """When index changed, the points need to rename.""" for j in range(row, self.rowCount()): self.setItem(j, 0, QTableWidgetItem(f'Point{j}'))
def rename(self, row): """When index changed, the points need to rename.""" for j in range(row, self.rowCount()): self.setItem(j, 0, QTableWidgetItem(self.name+str(j)))
def setCell(self, row: int, points: List): item = QTableWidgetItem(','.join(noNoneString(points))) item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) self.LinkTable.setItem(row, 2, item)