def getThemeBlockFormat(themeDatas): bf = QTextBlockFormat() bf.setLineHeight(themeDatas["Spacings/LineSpacing"], QTextBlockFormat.ProportionalHeight) bf.setTextIndent(themeDatas["Spacings/TabWidth"] * 1 if themeDatas["Spacings/IndendFirstLine"] else 0) bf.setTopMargin(themeDatas["Spacings/ParagraphAbove"]) bf.setBottomMargin(themeDatas["Spacings/ParagraphBelow"]) return bf
def readfile(self): self.infodic.clear() filename = QFileDialog.getOpenFileName(self, 'Open File Dialog', 'C:', "Txt files(*.txt)") ch = [] i = 0 f = open(filename[0], 'r') #重置输出框 self.TB1.setText('Grading\n d\tper') #设置TextEdit行高 text_format = QTextBlockFormat() text_format.setBottomMargin(0) text_format.setLineHeight(15, QTextBlockFormat.FixedHeight) text_cursor = self.TB1.textCursor() text_cursor.setBlockFormat(text_format) self.TB1.setTextCursor(text_cursor) try: while True: lines = f.readline() if not lines.strip(): break d_tmp, p_tmp = [float(i) for i in lines.split()] self.TB1.append(str(d_tmp) + '\t' + str(p_tmp) + '\n') self.infodic[d_tmp] = p_tmp f.close() except: QMessageBox.warning(self, 'Warning', 'Invalid Input Format', QMessageBox.Yes) return
def getThemeBlockFormat(themeDatas): bf = QTextBlockFormat() bf.setAlignment(Qt.AlignLeft if themeDatas["Spacings/Alignment"] == 0 else Qt.AlignCenter if themeDatas["Spacings/Alignment"] == 1 else Qt.AlignRight if themeDatas["Spacings/Alignment"] == 2 else Qt.AlignJustify) bf.setLineHeight(themeDatas["Spacings/LineSpacing"], QTextBlockFormat.ProportionalHeight) bf.setTextIndent(themeDatas["Spacings/TabWidth"] * 1 if themeDatas["Spacings/IndentFirstLine"] else 0) bf.setTopMargin(themeDatas["Spacings/ParagraphAbove"]) bf.setBottomMargin(themeDatas["Spacings/ParagraphBelow"]) return bf
def getThemeBlockFormat(themeDatas): bf = QTextBlockFormat() bf.setAlignment(Qt.AlignLeft if themeDatas["Spacings/Alignment"] == 0 else Qt.AlignCenter if themeDatas["Spacings/Alignment"] == 1 else Qt.AlignRight if themeDatas["Spacings/Alignment"] == 2 else Qt.AlignJustify) bf.setLineHeight(themeDatas["Spacings/LineSpacing"], QTextBlockFormat.ProportionalHeight) bf.setTextIndent(themeDatas["Spacings/TabWidth"] * 1 if themeDatas["Spacings/IndentFirstLine"] else 0) bf.setTopMargin(themeDatas["Spacings/ParagraphAbove"]) bf.setBottomMargin(themeDatas["Spacings/ParagraphBelow"]) return bf
def creategridbox(self): self.gridbox = QGroupBox() grid = QGridLayout() ''' self.fig = Figure(figsize=(5, 10), dpi=100) self.canvas=FigureCanvas(self.fig) self.toolbar=MyCostumToolbar(self.canvas,self) btn=QPushButton('Grading Curve') btn.clicked.connect(self.plot) ''' self.btr = QPushButton('Read File') self.btr.clicked.connect(self.readfile) self.bth = QPushButton('Help') self.bth.clicked.connect(self.helpfile) self.TB1 = QTextEdit('Grading') self.TB1.setFixedSize(150, 250) #设置TextEdit行高 text_format = QTextBlockFormat() text_format.setBottomMargin(0) text_format.setLineHeight(15, QTextBlockFormat.FixedHeight) text_cursor = self.TB1.textCursor() text_cursor.setBlockFormat(text_format) self.TB1.setTextCursor(text_cursor) Lbn = QLabel('Particle Number') #不少于100个 self.LEn = QLineEdit('200') Lbr = QLabel('Specimen Slenderness') self.LEr = QLineEdit('2') Lbe = QLabel('Estimated Void Ratio') self.LEe = QLineEdit('0.5') self.LEn.setFixedWidth(100) self.LEr.setFixedWidth(100) self.LEe.setFixedWidth(100) #set the layout grid.addWidget(self.btr, 0, 0, 1, 1) grid.addWidget(self.bth, 0, 6, 1, 1) grid.addWidget(self.TB1, 1, 0, 15, 4) grid.addWidget(Lbn, 1, 5, 1, 1) grid.addWidget(self.LEn, 1, 6, 1, 1) grid.addWidget(Lbr, 2, 5, 1, 1) grid.addWidget(self.LEr, 2, 6, 1, 1) grid.addWidget(Lbe, 3, 5, 1, 1) grid.addWidget(self.LEe, 3, 6, 1, 1) grid.setHorizontalSpacing(15) self.gridbox.setLayout(grid) self.gridbox.setWindowTitle('test')
def spacify(self): lineHeightStyle = QTextBlockFormat() lineHeightStyle.setLineHeight(150, QTextBlockFormat.ProportionalHeight) currentBlock = self.document().begin() while currentBlock.isValid(): cursor = QTextCursor(currentBlock) cursor.setBlockFormat(lineHeightStyle) currentBlock = currentBlock.next()
def loadFontSettings(self): if self._fromTheme or \ not self._index or \ type(self._index.model()) != outlineModel or \ self._column != Outline.text.value: return opt = settings.textEditor f = QFont() f.fromString(opt["font"]) # self.setFont(f) self.setStyleSheet("""QTextEdit{{ background: {bg}; color: {foreground}; font-family: {ff}; font-size: {fs}; }} """.format( bg=opt["background"], foreground=opt["fontColor"], ff=f.family(), fs="{}pt".format(str(f.pointSize())))) cf = QTextCharFormat() # cf.setFont(f) # cf.setForeground(QColor(opt["fontColor"])) bf = QTextBlockFormat() bf.setLineHeight(opt["lineSpacing"], bf.ProportionalHeight) bf.setTextIndent(opt["tabWidth"] * 1 if opt["indent"] else 0) bf.setTopMargin(opt["spacingAbove"]) bf.setBottomMargin(opt["spacingBelow"]) self._defaultCharFormat = cf self._defaultBlockFormat = bf if self.highlighter: self.highlighter.setMisspelledColor(QColor(opt["misspelled"])) self.highlighter.setDefaultCharFormat(self._defaultCharFormat) self.highlighter.setDefaultBlockFormat(self._defaultBlockFormat)
def loadFontSettings(self): if self._fromTheme or \ not self._index or \ type(self._index.model()) != outlineModel or \ self._column != Outline.text.value: return opt = settings.textEditor f = QFont() f.fromString(opt["font"]) # self.setFont(f) self.setStyleSheet("""QTextEdit{{ background: {bg}; color: {foreground}; font-family: {ff}; font-size: {fs}; }} """.format(bg=opt["background"], foreground=opt["fontColor"], ff=f.family(), fs="{}pt".format(str(f.pointSize())))) cf = QTextCharFormat() # cf.setFont(f) # cf.setForeground(QColor(opt["fontColor"])) bf = QTextBlockFormat() bf.setLineHeight(opt["lineSpacing"], bf.ProportionalHeight) bf.setTextIndent(opt["tabWidth"] * 1 if opt["indent"] else 0) bf.setTopMargin(opt["spacingAbove"]) bf.setBottomMargin(opt["spacingBelow"]) self._defaultCharFormat = cf self._defaultBlockFormat = bf if self.highlighter: self.highlighter.setMisspelledColor(QColor(opt["misspelled"])) self.highlighter.setDefaultCharFormat(self._defaultCharFormat) self.highlighter.setDefaultBlockFormat(self._defaultBlockFormat)
def creategridbox(self): self.gridbox = QGroupBox() self.bot_tabs = QTabWidget() self.input_tab = QWidget() self.setting_tab = QWidget() self.output_tab = QWidget() self.bot_tabs.addTab(self.input_tab, 'Input') self.bot_tabs.addTab(self.setting_tab, 'Setting') self.bot_tabs.addTab(self.output_tab, 'Output') #set the layout for input tab grid1 = QGridLayout() self.t_ch_box = QCheckBox('Scan Thickness') self.t_ch_box.setChecked(False) self.t_ch_box.stateChanged.connect(self.if_scan) self.m_ch_box = QCheckBox('Metal Material') self.m_ch_box.setChecked(True) self.e_ch_box = QCheckBox('Draw ε') self.e_ch_box.setChecked(True) self.m_ch_box.stateChanged.connect(self.if_metal) self.lb_t = QLabel('Thickness (nm)') self.le_t = QLineEdit('10') self.le_t.setFixedWidth(100) self.le_t.setToolTip('scan and fit thickness if leave it blank') self.lb_t_min = QLabel('min Thickness (nm)') self.le_t_min = QLineEdit('') self.le_t_min.setFixedWidth(100) self.lb_t_tol = QLabel('Thickness Tolerance (nm)') self.le_t_tol = QLineEdit('') self.le_t_tol.setFixedWidth(100) lb_R = QLabel('Reflectance (%s)' % chr(248)) #use ASCII to get the icon self.le_R = QLineEdit('0 50 60') #hide sth self.lb_t_min.hide() self.le_t_min.hide() self.lb_t_tol.hide() self.le_t_tol.hide() lb_T = QLabel('Transmittance (%s)' % chr(248)) self.le_T = QLineEdit('0') lb_upload = QLabel('Upload Files') hbox = QHBoxLayout() btn_load_R = QPushButton('Reflectance') btn_load_R.setFixedWidth(120) btn_load_R.clicked.connect(self.readfile) btn_load_T = QPushButton('Transmittance') btn_load_T.setFixedWidth(120) btn_load_T.clicked.connect(self.readfile) btn_load_nk = QPushButton('nk file') btn_load_nk.setFixedWidth(120) btn_load_nk.clicked.connect(self.readfile) hbox.addWidget(btn_load_R, Qt.AlignLeft) hbox.addStretch(1) hbox.addWidget(btn_load_T, Qt.AlignHCenter) hbox.addStretch(1) hbox.addWidget(btn_load_nk, Qt.AlignRight) grid1.addWidget(self.t_ch_box, 0, 0, 1, 1) grid1.addWidget(self.m_ch_box, 0, 2, 1, 1) grid1.addWidget(self.e_ch_box, 0, 4, 1, 1) grid1.addWidget(self.lb_t, 1, 0, 1, 1) grid1.addWidget(self.le_t, 1, 1, 1, 1) grid1.addWidget(self.lb_t_min, 1, 2, 1, 1) grid1.addWidget(self.le_t_min, 1, 3, 1, 1) grid1.addWidget(self.lb_t_tol, 1, 4, 1, 1) grid1.addWidget(self.le_t_tol, 1, 5, 1, 1) grid1.addWidget(lb_R, 2, 0, 1, 1) grid1.addWidget(self.le_R, 2, 1, 1, 5) grid1.addWidget(lb_T, 3, 0, 1, 1) grid1.addWidget(self.le_T, 3, 1, 1, 5) grid1.addWidget(lb_upload, 4, 0, 1, 1) grid1.setRowStretch(3, 20) grid1.setColumnMinimumWidth(1, 200) grid1.setColumnMinimumWidth(3, 200) grid1.setColumnMinimumWidth(5, 100) grid1.addLayout(hbox, 5, 0, 1, 6) self.input_tab.setLayout(grid1) #set the layout for setting tab grid3 = QGridLayout() lb_tol = QLabel('tolerance') self.le_tol = QLineEdit('0.00001') self.le_tol.setFixedWidth(100) lb_thes_min = QLabel('threshold_min') self.le_thes_min = QLineEdit('0.001') self.le_thes_min.setFixedWidth(100) lb_thes_max = QLabel('threshold_max') self.le_thes_max = QLineEdit('0.01') self.le_thes_max.setFixedWidth(100) lb_lam_min = QLabel('lamda_min (nm)') self.le_lam_min = QLineEdit() self.le_lam_min.setFixedWidth(100) lb_lam_max = QLabel('lamda_max (nm)') self.le_lam_max = QLineEdit() self.le_lam_max.setFixedWidth(100) grid3.addWidget(lb_tol, 2, 0, 1, 1) grid3.addWidget(self.le_tol, 2, 1, 1, 1) grid3.addWidget(lb_thes_min, 1, 0, 1, 1) grid3.addWidget(self.le_thes_min, 1, 1, 1, 1) grid3.addWidget(lb_thes_max, 1, 2, 1, 1) grid3.addWidget(self.le_thes_max, 1, 3, 1, 1) grid3.addWidget(lb_lam_min, 0, 0, 1, 1) grid3.addWidget(self.le_lam_min, 0, 1, 1, 1) grid3.addWidget(lb_lam_max, 0, 2, 1, 1) grid3.addWidget(self.le_lam_max, 0, 3, 1, 1) grid3.setColumnMinimumWidth(1, 200) grid3.setColumnMinimumWidth(3, 200) grid3.setRowMinimumHeight(1, 60) grid3.setColumnStretch(4, 1) grid3.setRowStretch(2, 1) self.setting_tab.setLayout(grid3) #set the layout for output tab grid2 = QGridLayout() self.TB1 = QTextEdit('') #set the height of QTextEdit text_format = QTextBlockFormat() text_format.setBottomMargin(0) text_format.setLineHeight(15, QTextBlockFormat.FixedHeight) text_cursor = self.TB1.textCursor() text_cursor.setBlockFormat(text_format) self.TB1.setTextCursor(text_cursor) self.TB1.verticalScrollBar().rangeChanged.connect(self.tb_scroll) #self.TB1.moveCursor(QTextCursor.End) self.bth = QPushButton('Help') self.bth.clicked.connect(self.helpfile) hbox2 = QHBoxLayout() hbox2.addStretch(1) #hbox2.addWidget(self.bth) grid2.addWidget(self.TB1, 0, 0, 10, 2) grid2.addLayout(hbox2, 10, 0, 1, 2) grid2.setVerticalSpacing(10) grid2.setHorizontalSpacing(15) self.output_tab.setLayout(grid2) vbox = QVBoxLayout() vbox.addWidget(self.bot_tabs) self.gridbox.setLayout(vbox)
def loadFontSettings(self): if self._fromTheme or \ not self._index or \ type(self._index.model()) != outlineModel or \ self._column != Outline.text.value: return opt = settings.textEditor f = QFont() f.fromString(opt["font"]) background = opt["background"] if not opt["backgroundTransparent"] else "transparent" foreground = opt["fontColor"] if not opt["backgroundTransparent"] else S.text # self.setFont(f) self.setStyleSheet("""QTextEdit{{ background: {bg}; color: {foreground}; font-family: {ff}; font-size: {fs}; margin: {mTB}px {mLR}px; {maxWidth} }} """.format( bg=background, foreground=foreground, ff=f.family(), fs="{}pt".format(str(f.pointSize())), mTB = opt["marginsTB"], mLR = opt["marginsLR"], maxWidth = "max-width: {}px;".format(opt["maxWidth"]) if opt["maxWidth"] else "", ) ) # We set the parent background to the editor's background in case # there are margins. We check that the parent class is a QWidget because # if textEditView is used in fullScreenEditor, then we don't want to # set the background. if self.parent().__class__ == QWidget: self.parent().setStyleSheet(""" QWidget#{name}{{ background: {bg}; }}""".format( # We style by name, otherwise all heriting widgets get the same # colored background, for example context menu. name=self.parent().objectName(), bg=background, )) cf = QTextCharFormat() # cf.setFont(f) # cf.setForeground(QColor(opt["fontColor"])) self.setCursorWidth(opt["cursorWidth"]) bf = QTextBlockFormat() bf.setLineHeight(opt["lineSpacing"], bf.ProportionalHeight) bf.setTextIndent(opt["tabWidth"] * 1 if opt["indent"] else 0) bf.setTopMargin(opt["spacingAbove"]) bf.setBottomMargin(opt["spacingBelow"]) bf.setAlignment(Qt.AlignLeft if opt["textAlignment"] == 0 else Qt.AlignCenter if opt["textAlignment"] == 1 else Qt.AlignRight if opt["textAlignment"] == 2 else Qt.AlignJustify) self._defaultCharFormat = cf self._defaultBlockFormat = bf if self.highlighter: self.highlighter.setMisspelledColor(QColor(opt["misspelled"])) self.highlighter.setDefaultCharFormat(self._defaultCharFormat) self.highlighter.setDefaultBlockFormat(self._defaultBlockFormat)
def loadFontSettings(self): if self._fromTheme or \ not self._index or \ type(self._index.model()) != outlineModel or \ self._column != Outline.text: return opt = settings.textEditor f = QFont() f.fromString(opt["font"]) background = (opt["background"] if not opt["backgroundTransparent"] else "transparent") foreground = opt["fontColor"] # if not opt["backgroundTransparent"] # else S.text # self.setFont(f) self.setStyleSheet("""QTextEdit{{ background: {bg}; color: {foreground}; font-family: {ff}; font-size: {fs}; margin: {mTB}px {mLR}px; {maxWidth} }} """.format( bg=background, foreground=foreground, ff=f.family(), fs="{}pt".format(str(f.pointSize())), mTB = opt["marginsTB"], mLR = opt["marginsLR"], maxWidth = "max-width: {}px;".format(opt["maxWidth"]) if opt["maxWidth"] else "", ) ) self._defaultFontSize = f.pointSize() # We set the parent background to the editor's background in case # there are margins. We check that the parent class is a QWidget because # if textEditView is used in fullScreenEditor, then we don't want to # set the background. if self.parent().__class__ == QWidget: self.parent().setStyleSheet(""" QWidget#{name}{{ background: {bg}; }}""".format( # We style by name, otherwise all inheriting widgets get the same # colored background, for example context menu. name=self.parent().objectName(), bg=background, )) cf = QTextCharFormat() # cf.setFont(f) # cf.setForeground(QColor(opt["fontColor"])) self.setCursorWidth(opt["cursorWidth"]) bf = QTextBlockFormat() bf.setLineHeight(opt["lineSpacing"], bf.ProportionalHeight) bf.setTextIndent(opt["tabWidth"] * 1 if opt["indent"] else 0) bf.setTopMargin(opt["spacingAbove"]) bf.setBottomMargin(opt["spacingBelow"]) bf.setAlignment(Qt.AlignLeft if opt["textAlignment"] == 0 else Qt.AlignCenter if opt["textAlignment"] == 1 else Qt.AlignRight if opt["textAlignment"] == 2 else Qt.AlignJustify) self._defaultCharFormat = cf self._defaultBlockFormat = bf if self.highlighter: self.highlighter.updateColorScheme() self.highlighter.setMisspelledColor(QColor(opt["misspelled"])) self.highlighter.setDefaultCharFormat(self._defaultCharFormat) self.highlighter.setDefaultBlockFormat(self._defaultBlockFormat)