def insertCalendar(self): self.editor.clear() cursor = self.editor.textCursor() cursor.beginEditBlock() date = QDate(self.selectedDate.year(), self.selectedDate.month(), 1) tableFormat = QTextTableFormat() tableFormat.setAlignment(Qt.AlignHCenter) tableFormat.setBackground(QColor("#e0e0e0")) tableFormat.setCellPadding(2) tableFormat.setCellSpacing(4) constraints = [ QTextLength(QTextLength.PercentageLength, 14), QTextLength(QTextLength.PercentageLength, 14), QTextLength(QTextLength.PercentageLength, 14), QTextLength(QTextLength.PercentageLength, 14), QTextLength(QTextLength.PercentageLength, 14), QTextLength(QTextLength.PercentageLength, 14), QTextLength(QTextLength.PercentageLength, 14), ] tableFormat.setColumnWidthConstraints(constraints) table = cursor.insertTable(1, 7, tableFormat) frame = cursor.currentFrame() frameFormat = frame.frameFormat() frameFormat.setBorder(1) frame.setFrameFormat(frameFormat) format = cursor.charFormat() format.setFontPointSize(self.fontSize) boldFormat = QTextCharFormat(format) boldFormat.setFontWeight(QFont.Bold) highlightedFormat = QTextCharFormat(boldFormat) highlightedFormat.setBackground(Qt.yellow) for weekDay in range(1, 8): cell = table.cellAt(0, weekDay - 1) cellCursor = cell.firstCursorPosition() cellCursor.insertText(QDate.longDayName(weekDay), boldFormat) table.insertRows(table.rows(), 1) while date.month() == self.selectedDate.month(): weekDay = date.dayOfWeek() cell = table.cellAt(table.rows() - 1, weekDay - 1) cellCursor = cell.firstCursorPosition() if date == QDate.currentDate(): cellCursor.insertText(str(date.day()), highlightedFormat) else: cellCursor.insertText(str(date.day()), format) date = date.addDays(1) if weekDay == 7 and date.month() == self.selectedDate.month(): table.insertRows(table.rows(), 1) cursor.endEditBlock() self.setWindowTitle( "Calendar for %s %d" % (QDate.longMonthName(self.selectedDate.month()), self.selectedDate.year()) )
def insertCalendar(self): self.editor.clear() cursor = self.editor.textCursor() cursor.beginEditBlock() date = QDate(self.selectedDate.year(), self.selectedDate.month(), 1) tableFormat = QTextTableFormat() tableFormat.setAlignment(Qt.AlignHCenter) tableFormat.setBackground(QColor('#e0e0e0')) tableFormat.setCellPadding(2) tableFormat.setCellSpacing(4) constraints = [QTextLength(QTextLength.PercentageLength, 14), QTextLength(QTextLength.PercentageLength, 14), QTextLength(QTextLength.PercentageLength, 14), QTextLength(QTextLength.PercentageLength, 14), QTextLength(QTextLength.PercentageLength, 14), QTextLength(QTextLength.PercentageLength, 14), QTextLength(QTextLength.PercentageLength, 14)] tableFormat.setColumnWidthConstraints(constraints) table = cursor.insertTable(1, 7, tableFormat) frame = cursor.currentFrame() frameFormat = frame.frameFormat() frameFormat.setBorder(1) frame.setFrameFormat(frameFormat) format = cursor.charFormat() format.setFontPointSize(self.fontSize) boldFormat = QTextCharFormat(format) boldFormat.setFontWeight(QFont.Bold) highlightedFormat = QTextCharFormat(boldFormat) highlightedFormat.setBackground(Qt.yellow) for weekDay in range(1, 8): cell = table.cellAt(0, weekDay-1) cellCursor = cell.firstCursorPosition() cellCursor.insertText(QDate.longDayName(weekDay), boldFormat) table.insertRows(table.rows(), 1) while date.month() == self.selectedDate.month(): weekDay = date.dayOfWeek() cell = table.cellAt(table.rows()-1, weekDay-1) cellCursor = cell.firstCursorPosition() if date == QDate.currentDate(): cellCursor.insertText(str(date.day()), highlightedFormat) else: cellCursor.insertText(str(date.day()), format) date = date.addDays(1) if weekDay == 7 and date.month() == self.selectedDate.month(): table.insertRows(table.rows(), 1) cursor.endEditBlock() self.setWindowTitle("Calendar for %s %d" % (QDate.longMonthName(self.selectedDate.month()), self.selectedDate.year()))
def interp(self): self.reset() curve = self.curveCombobox.currentText().strip() if self.view is None: return if curve not in self.view.pointObjs or len( self.view.pointObjs[curve]) < 2: return xs = [] ys = [] for item in self.view.pointObjs[curve]: xs.append(item.pos().x()) ys.append(item.pos().y()) xs, ys = self.view.pointToCoord(xs, ys) xmin = None xmax = None xstep = None if self.minXTextBox.text().strip(): xmin = str2num(self.minXTextBox.text().strip()) self.view.proj.fitx[0] = xmin if xmin is None: xmin = min(xs) if self.maxXTextBox.text().strip(): xmax = str2num(self.maxXTextBox.text().strip()) self.view.proj.fitx[1] = xmax if xmax is None: xmax = max(xs) if self.stepXTextBox.text().strip(): xstep = str2num(self.stepXTextBox.text().strip()) self.view.proj.fitx[2] = xstep if xstep is None: xstep = (xmax - xmin) / 15 xnew = np.arange(xmin, xmax + xstep / 2, xstep) degree = int(self.degreeComboBox.currentText()) self.view.proj.degree = degree self.view.proj.precision = self.presicion ynew = interp(xs, ys, xnew, degree) xpos, ypos = self.view.coordToPoint(xnew, ynew) for i in range(1, len(xpos)): line = QGraphicsLineItem(xpos[i - 1], ypos[i - 1], xpos[i], ypos[i]) line.setZValue(10) line.setPen(QPen(Qt.yellow, 2, Qt.SolidLine)) self.interpCurveObjs.append(line) self.view.scene.addItem(line) self.minXTextBox.setText(str(xmin)) self.maxXTextBox.setText(str(xmax)) self.stepXTextBox.setText(str(xstep)) text = "interpolation points:\n\n" self.outTextBox.setText(text) cursor = QTextCursor(self.outTextBox.textCursor()) cursor.movePosition(QTextCursor.End) # move the end of documents ttf = QTextTableFormat() # 创建表格对象格式 ttf.setCellPadding(2) # 单元格内文本和边框距离 ttf.setCellSpacing(0) # 单元格线宽 ttf.setAlignment(Qt.AlignLeft) # 表格对齐模式 ttf.setBorder(0.5) # ttf.setColumnWidthConstraints( # (QTextLength(QTextLength.PercentageLength, 50), QTextLength(QTextLength.PercentageLength, 50))) # 百分比定义列宽 ttf.setColumnWidthConstraints( (QTextLength(QTextLength.FixedLength, 75), QTextLength(QTextLength.FixedLength, 75))) # 像素定义列宽 table = cursor.insertTable(len(xnew) + 1, 2, ttf) table.cellAt(0, 0).firstCursorPosition().insertHtml("<b>x</b>") table.cellAt(0, 1).firstCursorPosition().insertHtml("<b>y</b>") for i in range(len(xnew)): table.cellAt(i + 1, 0).firstCursorPosition().insertText( str(round(xnew[i], self.presicion))) table.cellAt(i + 1, 1).firstCursorPosition().insertText( str(round(ynew[i], self.presicion))) self.view.sigModified.emit(True)
def insertCalendar(self): self.editor.clear() cursor = self.editor.textCursor() cursor.beginEditBlock() #self.editor.setStyleSheet("QTextTableFormat {border-color:white}") date = QDate(self.selectedDate.year(), self.selectedDate.month(), 1) tableFormat = QTextTableFormat() self.setStyleSheet( "selection-color: yellow;" "selection-background-color: black;" "border-width: 1px;border-style: solid;border-color: white;") tableFormat.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter) tableFormat.setBackground(QColor('#ffffff')) tableFormat.setCellPadding(1) tableFormat.setCellSpacing(0) constraints = [ QTextLength(QTextLength.PercentageLength, 7), QTextLength(QTextLength.PercentageLength, 7), QTextLength(QTextLength.PercentageLength, 7), QTextLength(QTextLength.PercentageLength, 7), QTextLength(QTextLength.PercentageLength, 7), QTextLength(QTextLength.PercentageLength, 7), QTextLength(QTextLength.PercentageLength, 7) ] tableFormat.setColumnWidthConstraints(constraints) table = cursor.insertTable(1, 7, tableFormat) # frame = cursor.currentFrame() # frameFormat = frame.frameFormat() # frameFormat.setBorder(2) # frame.setFrameFormat(frameFormat) format = cursor.charFormat() format.setFontPointSize(self.fontSize) boldFormat = QTextCharFormat(format) boldFormat.setFontWeight(QFont.Bold) dayFormat = QTextCharFormat(format) #self.editor.setStyleSheet("color:red;") dayFormat.setForeground(QColor('#f44336')) highlightedFormat = QTextCharFormat(boldFormat) highlightedFormat.setBackground(Qt.yellow) highlightedFormat.setFontUnderline(True) highlightedFormat.setUnderlineColor(QColor('#f44336')) # highlightedFormat.setColor(Qt.white) for weekDay in range(1, 8): cell = table.cellAt(0, weekDay - 1) cellCursor = cell.firstCursorPosition() cellCursor.insertText(day[weekDay - 1], dayFormat) table.insertRows(table.rows(), 1) while date.month() == self.selectedDate.month(): weekDay = date.dayOfWeek() cell = table.cellAt(table.rows() - 1, weekDay - 1) cellCursor = cell.firstCursorPosition() if date == QDate.currentDate(): cellCursor.insertText(str(date.day()), highlightedFormat) else: cellCursor.insertText(str(date.day()), format) date = date.addDays(1) if weekDay == 7 and date.month() == self.selectedDate.month(): table.insertRows(table.rows(), 1) cursor.endEditBlock() self.setWindowTitle("Calendar for %s %d" % (QDate.longMonthName( self.selectedDate.month()), self.selectedDate.year()))