def onAltFontChange(self, propagate=True): font = QFont(self.altFontComboBox.currentFont()) font.setPointSize(self.altFontSizeSpinBox.value()) if propagate and bool(self.state.model): self.state.model.setConfig(Gconf.Key.AltFont, font.family()) self.state.model.setConfig(Gconf.Key.AltFontSize, font.pointSize())
def __init__(self, parent, text='', hyperlink=None): ''' Smaller font than normal text ''' super(SignalList, self).__init__(parent, text) self.setFont(QFont('Ubuntu', pointSize=8))
def __init__(self, parent): super(TimeReportView, self).__init__(parent) self.title_font = QFont("Arial", 12, QFont.Normal)
def setObjectText(self, strng): """ TOWRITE :param `strng`: TOWRITE :type `strng`: QString """ self.objText = strng textPath = QPainterPath() font = QFont() font.setFamily(self.objTextFont) font.setPointSizeF(self.objTextSize) font.setBold(self.objTextBold) font.setItalic(self.objTextItalic) font.setUnderline(self.objTextUnderline) font.setStrikeOut(self.objTextStrikeOut) font.setOverline(self.objTextOverline) textPath.addText(0., 0., font, strng) # Translate the path based on the justification. jRect = textPath.boundingRect() # QRectF if self.objTextJustify == "Left": textPath.translate(-jRect.left(), 0) elif self.objTextJustify == "Center": textPath.translate(-jRect.center().x(), 0) elif self.objTextJustify == "Right": textPath.translate(-jRect.right(), 0) elif self.objTextJustify == "Aligned": pass # TODO: TextSingleObject Aligned Justification elif self.objTextJustify == "Middle": textPath.translate(-jRect.center()) elif self.objTextJustify == "Fit": pass # TODO: TextSingleObject Fit Justification elif self.objTextJustify == "Top Left": textPath.translate(-jRect.topLeft()) elif self.objTextJustify == "Top Center": textPath.translate(-jRect.center().x(), -jRect.top()) elif self.objTextJustify == "Top Right": textPath.translate(-jRect.topRight()) elif self.objTextJustify == "Middle Left": textPath.translate(-jRect.left(), -jRect.top() / 2.0) elif self.objTextJustify == "Middle Center": textPath.translate(-jRect.center().x(), -jRect.top() / 2.0) elif self.objTextJustify == "Middle Right": textPath.translate(-jRect.right(), -jRect.top() / 2.0) elif self.objTextJustify == "Bottom Left": textPath.translate(-jRect.bottomLeft()) elif self.objTextJustify == "Bottom Center": textPath.translate(-jRect.center().x(), -jRect.bottom()) elif self.objTextJustify == "Bottom Right": textPath.translate(-jRect.bottomRight()) # Backward or Upside Down. if self.objTextBackward or self.objTextUpsideDown: horiz = 1.0 # qreal vert = 1.0 # qreal if self.objTextBackward: horiz = -1.0 if self.objTextUpsideDown: vert = -1.0 flippedPath = QPainterPath() element = QPainterPath.Element P2 = QPainterPath.Element P3 = QPainterPath.Element P4 = QPainterPath.Element for i in range(0, textPath.elementCount( )): # for(int i = 0; i < textPath.elementCount(); ++i) element = textPath.elementAt(i) if element.isMoveTo(): flippedPath.moveTo(horiz * element.x, vert * element.y) elif element.isLineTo(): flippedPath.lineTo(horiz * element.x, vert * element.y) elif element.isCurveTo(): # start point P1 is not needed P2 = textPath.elementAt(i) # control point P3 = textPath.elementAt(i + 1) # control point P4 = textPath.elementAt(i + 2) # end point flippedPath.cubicTo(horiz * P2.x, vert * P2.y, horiz * P3.x, vert * P3.y, horiz * P4.x, vert * P4.y) objTextPath = flippedPath else: objTextPath = textPath # Add the grip point to the shape path. gripPath = objTextPath # QPainterPath gripPath.connectPath(objTextPath) gripPath.addRect(-0.00000001, -0.00000001, 0.00000002, 0.00000002) self.setObjectPath(gripPath)
def __init__(self, parent=None): super(MainWindow, self).__init__(parent) # Set window Icon self.setWindowTitle(__appname__) iconImage = QImage(iconByteArray) iconPixmap = QPixmap(iconImage) self.setWindowIcon(QIcon(iconPixmap)) # Set up private key format widgets privateKeyFormatLayout = QHBoxLayout() privateKeyFormatLabel = QLabel('Select Key Format: ') self.privateKeyTypeCombobox = QComboBox() self.privateKeyTypeCombobox.addItems(privateKeyFormats) self.privateKeyLengthLabel = QLabel('0') privateKeyFormatLayout.addWidget(privateKeyFormatLabel) privateKeyFormatLayout.addWidget(self.privateKeyTypeCombobox) privateKeyFormatLayout.addWidget(self.privateKeyLengthLabel) # Set up private key text widgets privateKeyLayout = QVBoxLayout() privateKeyButtonsLayout = QHBoxLayout() generatePrivateKeyButton = QPushButton('Generate Key') generatePrivateKeyButton.clicked.connect(self.get_private_key) self.copyPrivateKeyButton = QPushButton('Copy Key') self.copyPrivateKeyButton.setDisabled(True) self.copyPrivateKeyButton.clicked.connect(self.copy_private_key) privateKeyButtonsLayout.addWidget(generatePrivateKeyButton) privateKeyButtonsLayout.addWidget(self.copyPrivateKeyButton) self.privateKeyEdit = GrowingTextEdit() self.privateKeyEdit.setFont(QFont('Courier')) self.privateKeyEdit.textChanged.connect( self.private_key_or_code_changed) privateKeyLayout.addLayout(privateKeyButtonsLayout) privateKeyLayout.addWidget(self.privateKeyEdit) # Set up cypher code widgets codeLayout = QHBoxLayout() codeLabel = QLabel('Select Cypher Code: ') self.codeSelect = QSpinBox() self.codeSelect.setValue(10) self.codeSelect.setMinimum(2) self.codeSelect.setDisabled(True) self.codeSelect.valueChanged.connect(self.private_key_or_code_changed) codeLayout.addWidget(codeLabel) codeLayout.addWidget(self.codeSelect) # Set up cypher text widgets cypherLayout = QVBoxLayout() cypherButtonsLayout = QHBoxLayout() cardButtonsLayout = QHBoxLayout() self.generateCypherButton = QPushButton('Generate Cypher') self.generateCypherButton.clicked.connect(self.get_cypher) self.generateCypherButton.setDisabled(True) self.copyCypherButton = QPushButton('Copy Cypher') self.copyCypherButton.setDisabled(True) self.copyCypherButton.clicked.connect(self.copy_cypher) cypherButtonsLayout.addWidget(self.generateCypherButton) cypherButtonsLayout.addWidget(self.copyCypherButton) self.cypherEdit = GrowingTextEdit() self.cypherEdit.setFont(QFont('Courier')) self.cypherEdit.setReadOnly(True) self.cypherEdit.setVisible(False) self.cypherEdit.textChanged.connect(self.resize_window) self.cypherPreviewLabel = QLabel('-CYPHER PREVIEW-') self.cypherPreviewLabel.setAlignment(Qt.AlignCenter) self.cypherPreviewLabel.setVisible(False) self.cypherPreview = GrowingTextEdit() self.cypherPreview.setFont(QFont('Courier')) self.cypherPreview.setAlignment(Qt.AlignHCenter) self.cypherPreview.setWordWrapMode(QTextOption.NoWrap) self.cypherPreview.setReadOnly(True) self.cypherPreview.setVisible(False) self.cypherCardsPrintButton = QPushButton('Print Cypher Cards') self.cypherCardsPrintButton.setVisible(False) self.cypherCardsPrintButton.clicked.connect(partial(self.cards, True)) self.cypherCardsCopyButton = QPushButton('Copy Cypher Cards') self.cypherCardsCopyButton.setVisible(False) self.cypherCardsCopyButton.clicked.connect(partial(self.cards, False)) cardButtonsLayout.addWidget(self.cypherCardsPrintButton) cardButtonsLayout.addWidget(self.cypherCardsCopyButton) cypherLayout.addLayout(cypherButtonsLayout) cypherLayout.addWidget(self.cypherEdit) cypherLayout.addWidget(self.cypherPreviewLabel) cypherLayout.addWidget(self.cypherPreview) cypherLayout.addLayout(cardButtonsLayout) # Set up donation widgets donationsLayout = QVBoxLayout() separater = QFrame() separater.setFrameShape(QFrame.HLine) self.donationButton = QPushButton('Donate') self.donationButton.setVisible(False) self.donationButton.clicked.connect(self.donate) self.copyEthAddressButton = QPushButton('ETH: Copy Address') self.copyEthAddressButton.clicked.connect( self.copy_eth_donation_address) self.copyEthAddressButton.setVisible(False) self.copyBtcAddressButton = QPushButton('BTC: Copy Address') self.copyBtcAddressButton.clicked.connect( self.copy_btc_donation_address) self.copyBtcAddressButton.setVisible(False) donationsLayout.addWidget(separater) donationsLayout.addWidget(self.donationButton) donationsLayout.addWidget(self.copyEthAddressButton) donationsLayout.addWidget(self.copyBtcAddressButton) # Add all widgets and sub-layouts to the master layout self.master_layout = QVBoxLayout() self.master_layout.addLayout(privateKeyFormatLayout) self.master_layout.addLayout(privateKeyLayout) self.master_layout.addLayout(codeLayout) self.master_layout.addLayout(cypherLayout) self.master_layout.addLayout(donationsLayout) self.master_widget = QWidget() self.master_widget.setLayout(self.master_layout) self.setCentralWidget(self.master_widget) # Start and connect the window resizing thread self.worker = Worker() self.worker.updateWindowSize.connect(self.resize_window)
def __init__(self, robocare_serial): self.__robocare_serial = robocare_serial QWidget.__init__(self) layout = QGridLayout() self.setLayout(layout) self.__line1 = QLineEdit() self.__line1.setPlaceholderText("03 F3 F3 ...") self.__line1.setFont(QFont(u"나눔고딕", 20, weight=QFont.Bold)) layout.addWidget(self.__line1, 0, 0, 1, 3) button = QPushButton(u'한번 보내기', self) button.setFont(QFont(u"나눔고딕", 15, weight=QFont.Bold)) button.clicked.connect(self.clicked_custom_once) layout.addWidget(button, 1, 0, 1, 1) button = QPushButton(u'100번 보내기', self) button.setFont(QFont(u"나눔고딕", 15, weight=QFont.Bold)) button.clicked.connect(self.clicked_custom_repeat) layout.addWidget(button, 1, 1, 1, 1) # button = QPushButton(u'인코더 읽기',self) # button.setFont(QFont(u"나눔고딕",15,weight=QFont.Bold)) # button.clicked.connect(self.clicked_encoder) # layout.addWidget(button, 1, 2, 1, 1) self.__line2 = QLineEdit() self.__line2.setPlaceholderText("03 F3 F3 ...") self.__line2.setFont(QFont(u"나눔고딕", 20, weight=QFont.Bold)) layout.addWidget(self.__line2, 2, 0, 1, 3) button = QPushButton(u'버전 체크', self) button.setFont(QFont(u"나눔고딕", 15, weight=QFont.Bold)) button.clicked.connect(self.clicked_version) layout.addWidget(button, 3, 0, 1, 1) button = QPushButton(u'스톱', self) button.setFont(QFont(u"나눔고딕", 15, weight=QFont.Bold)) button.clicked.connect(self.clicked_stop) layout.addWidget(button, 3, 1, 1, 1) button = QPushButton(u'인코더 읽기', self) button.setFont(QFont(u"나눔고딕", 15, weight=QFont.Bold)) button.clicked.connect(self.clicked_encoder) layout.addWidget(button, 3, 2, 1, 1) button = QPushButton(u'좌회전', self) button.setFont(QFont(u"나눔고딕", 15, weight=QFont.Bold)) button.clicked.connect(self.clicked_lt) layout.addWidget(button, 4, 0, 1, 1) button = QPushButton(u'전진', self) button.setFont(QFont(u"나눔고딕", 15, weight=QFont.Bold)) button.clicked.connect(self.clicked_foward) layout.addWidget(button, 4, 1, 1, 1) button = QPushButton(u'우회전', self) button.setFont(QFont(u"나눔고딕", 15, weight=QFont.Bold)) button.clicked.connect(self.clicked_rt) layout.addWidget(button, 4, 2, 1, 1) button = QPushButton(u'왼쪽 이동', self) button.setFont(QFont(u"나눔고딕", 15, weight=QFont.Bold)) button.clicked.connect(self.clicked_left) layout.addWidget(button, 5, 0, 1, 1) button = QPushButton(u'후진', self) button.setFont(QFont(u"나눔고딕", 15, weight=QFont.Bold)) button.clicked.connect(self.clicked_back) layout.addWidget(button, 5, 1, 1, 1) button = QPushButton(u'오른쪽 이동', self) button.setFont(QFont(u"나눔고딕", 15, weight=QFont.Bold)) button.clicked.connect(self.clicked_right) layout.addWidget(button, 5, 2, 1, 1)
def print_(self, printer): painter = QPainter(printer) pageRect = printer.pageRect() w = pageRect.width() * 0.85 h = pageRect.height() painter.drawPixmap(0, 0, w, h, './template/image.png') sansFont = QFont("Helvetica", 10) painter.setFont(sansFont) fm = QFontMetrics(sansFont) height = fm.height() + 10 vmargin = 40 x0 = w + 1 y = 25 width = fm.width(u"测试编号") + 25 x1 = x0 + width painter.drawText(x0, y, u"报告编号") painter.drawText(x1, y, self.report['SERIAL']) y += height painter.drawText(x0, y, u"测试类型") painter.drawText(x1, y, self.report['TYPE']) y += height painter.drawText(x0, y, u"触发方式") painter.drawText(x1, y, self.report['TRIGGER']) y += height painter.drawText(x0, y, u"测试人员") painter.drawText(x1, y, self.report['PERSON']) y += height painter.drawText(x0, y, u"测试日期") painter.drawText(x1, y, self.report['DATE']) y += vmargin width = fm.width(u"通道1") + 50 x1 = x0 + width space = 0 painter.drawText(x0 + 20, y, u"压力通道(Mpa)") for i, j in enumerate(self.group_press): if j[1]: y += height if j[0]: painter.drawText(x0, y, j[0]) else: painter.drawText(x0, y, '通道%d'.decode("utf-8") % (i + 1)) painter.drawText(x1, y, self.report['PRESS'][i + 1]) else: space += height y += (vmargin + space) width = fm.width(u"通道计量1") + 15 x1 = x0 + width #x2 = x1 + width painter.drawText(x0 + 20, y, u"数字量计时通道(s)") y += height painter.drawText(x0, y, u"通道") painter.drawText(x1, y, u"开启时间") #painter.drawText(x2, y, u"关闭") space = 0 for i, j in enumerate(self.group_digital): if j[1]: y += height if j[0]: painter.drawText(x0, y, j[0]) else: painter.drawText(x0, y, '通道%d'.decode("utf-8") % (i + 1)) painter.drawText(x1, y, self.report['DIGITAL'][i + 1][0]) #painter.drawText(x2, y, self.report['DIGITAL'][i + 1][1]) else: space += height y += (vmargin + space) width = fm.width(u"出管速度(m/s)") + 25 x1 = x0 + width painter.drawText(x0, y, u"加速度(g)") painter.drawText(x1, y, self.report['ACCELERATION']) y += height painter.drawText(x0, y, u"出管速度(m/s)") painter.drawText(x1, y, self.report['SPEED']) y += height painter.drawText(x0, y, u"延迟时间(s)") painter.drawText(x1, y, self.report['DELAY']) y += height painter.drawText(x0, y, u"发射时间(s)") painter.drawText(x1, y, self.report['SHOOT']) y += height painter.drawText(x0, y, u"发射深度(s)") painter.drawText(x1, y, self.report['DEEP']) width = fm.width(u"泄放装置泄放时间(s)") + 5 y += height painter.drawText(x0, y, u"泄放阀开启时机(m)") x1 = x0 + width painter.drawText(x1, y, self.report['BLEED']) y += height painter.drawText(x0, y, u"泄放阀开启时间(s)") x1 = x0 + width + 1 painter.drawText(x1, y, self.report['OPEN'])
def paint( self, painter, option, index, ): '''Paint our tweet''' (x1, y1, x2, y2) = option.rect.getCoords() # Ugly hack ? if y1 < 0 and y2 < 0: return # Init Font : One time is enough if not self.fm: self.normFont = QFont(option.font) self.normFont.setPointSizeF(option.font.pointSizeF() * self.fsize) if not self.minifm: self.miniFont = QFont(option.font) self.miniFont.setPointSizeF(option.font.pointSizeF() * 0.8 * self.fsize) # Query data tweet = to_str(index.data(Qt.DisplayRole)) screenname = to_str(index.data(SCREENNAMEROLE)) retweet_of = index.data(RETWEETOFROLE) timestamp = to_str(index.data(role=TIMESTAMPROLE)) reply_name = to_str(index.data(role=REPLYTOSCREENNAMEROLE)) reply_text = to_str(index.data(role=REPLYTEXTROLE)) is_new = index.data(role=ISNEWROLE) painter.save() # Draw alternate ? if index.row() % 2 == 0: color = self.bg_color else: color = self.bg_alternate_color painter.fillRect(option.rect, color) # highlight selected items if option.state & QStyle.State_Selected: painter.fillRect(option.rect, option.palette.highlight()) # Draw icon icon = index.data(Qt.DecorationRole) if type(icon) == QPixmap: try: painter.drawPixmap(x1 + 10, y1 + 10, 50, 50, icon) except Exception: logging.exception("Drawing icon") # Draw screenname painter.setFont(self.miniFont) painter.setPen(self.user_color) nrect = painter.drawText(option.rect.adjusted(70, 5, -4, -9), int(Qt.AlignTop) | int(Qt.AlignLeft), screenname) # Reply icon if reply_name: painter.drawPixmap(x1 + 74 + nrect.width(), y1, 26, 26, self.reply_icon) painter.setFont(self.miniFont) painter.setPen(self.replyto_color) painter.drawText( option.rect.adjusted(109 + nrect.width(), 5, -4, -9), int(Qt.AlignTop) | int(Qt.AlignLeft), reply_name) # Retweet icon if retweet_of: painter.drawPixmap(x1 + 74 + nrect.width(), y1, 32, 32, self.retweet_icon) painter.setFont(self.miniFont) painter.setPen(self.replyto_color) painter.drawText( option.rect.adjusted(110 + nrect.width(), 5, -4, -9), int(Qt.AlignTop) | int(Qt.AlignLeft), retweet_of.user.screen_name) # Draw tweet painter.setFont(self.normFont) painter.setPen(self.text_color) new_rect = painter.drawText( option.rect.adjusted(70, nrect.height() + 5, -4, 0), int(Qt.AlignTop) | int(Qt.AlignLeft) | int(Qt.TextWordWrap), tweet) # Draw Timeline painter.setFont(self.miniFont) painter.setPen(self.time_color) painter.drawText(option.rect.adjusted(70, 5, -4, -9), int(Qt.AlignTop) | int(Qt.AlignRight), timestamp) # Draw reply if reply_text: painter.setFont(self.miniFont) painter.setPen(self.replyto_color) painter.drawText( option.rect.adjusted(70, nrect.height() + new_rect.height() + 5, -4, -9), int(Qt.AlignTop) | int(Qt.AlignLeft) | int(Qt.TextWordWrap), reply_text) # Draw line separator painter.setPen(self.separator_color) painter.drawLine(x1, y2, x2, y2) #Use a little tips to say that's a new tweet if is_new: painter.fillRect(x1, y1, 8, y2, self.new_bg_alternate_color) # restore painter painter.restore()
def __init__(self, parent=None): super(MassAttribute_UI, self).__init__(parent) # Abstract self.applier = self.Applikator(self) self.selection = [] self.callback = None self.ctx = None # storing found attributes' types to avoid double check self.solved = {} self.setLocale(QLocale.C) self.setAttribute(Qt.WA_DeleteOnClose) self.setAttribute(Qt.WA_QuitOnClose) self.setFixedWidth(300) self.setWindowTitle('Massive Attribute Modifier') # UI L_main = QVBoxLayout() self.WV_title = QLabel('') self.WV_title.setVisible(False) self.WV_title.setFont(QFont('Verdana', 10)) self.WV_title.setContentsMargins(0, 0, 0, 7) self.WB_select = QPushButton('Select') self.WB_select.setVisible(False) self.WB_select.setFixedWidth(50) self.WB_select.clicked.connect(lambda: cmds.select(self.selection)) self.WB_update = QPushButton('Update') self.WB_update.setFixedWidth(50) self.WB_update.clicked.connect( lambda: self.update_attributes(cmds.ls(sl=True))) self.WV_search = Filter() self.WV_search.textChanged.connect(self.filter) self.WC_cases = QCheckBox('Case sensitive') self.WC_cases.stateChanged.connect(self.filter) self.WC_types = QCheckBox('Type filtering') self.WL_attrtype = QComboBox() self.WL_attrtype.setEnabled(False) for i, ctx in enumerate(sorted(self.ctx_wide)): self.WL_attrtype.addItem(ctx.title()) self.WL_attrtype.setItemIcon(i, self.ctx_icons[ctx]) L_attrtype = line(self.WC_types, self.WL_attrtype) self.WC_types.stateChanged.connect( partial(self.update_attributes, self.selection)) self.WC_types.stateChanged.connect(self.WL_attrtype.setEnabled) self.WL_attrtype.currentIndexChanged.connect(self.filter) self.WC_liveu = QCheckBox('Live') self.WC_liveu.stateChanged.connect(self.WB_update.setDisabled) self.WC_liveu.stateChanged.connect(self.set_callback) self.WC_histo = QCheckBox('Load history') self.WC_histo.setChecked(True) self.WC_histo.stateChanged.connect( partial(self.update_attributes, self.selection)) self.WC_child = QCheckBox('Children') self.WC_child.stateChanged.connect( partial(self.update_attributes, self.selection)) options = group( 'Options', line(self.WC_cases, L_attrtype), line(self.WC_child, self.WC_histo, self.WC_liveu, self.WB_update)) options.layout().setSpacing(2) self.WL_attributes = QTreeWidget() self.WL_attributes.setStyleSheet( 'QTreeView {alternate-background-color: #1b1b1b;}') self.WL_attributes.setAlternatingRowColors(True) self.WL_attributes.setHeaderHidden(True) self.WL_attributes.setRootIsDecorated(False) self.objs_attr = set() self.shps_attr = set() self.W_EDI_float = FloatBox() self.W_EDI_int = IntBox() self.W_EDI_enum = QComboBox() self.W_EDI_bool = QCheckBox() self.W_EDI_str = QLineEdit() self.W_EDI_d3 = Double3() self.W_EDI_d4 = Double4() self.W_EDI_color = ColorPicker() # Final layout L_title = line(self.WV_title, self.WB_select) L_title.setStretch(0, 1) L_main.addLayout(L_title) L_main.setAlignment(Qt.AlignLeft) L_main.addWidget(self.WV_search) L_main.addWidget(options) L_main.addWidget(self.WL_attributes) L_edits = col(self.W_EDI_bool, self.W_EDI_int, self.W_EDI_float, self.W_EDI_enum, self.W_EDI_str, self.W_EDI_d3, self.W_EDI_d4, self.W_EDI_color) L_edits.setContentsMargins(0, 8, 0, 0) L_main.addLayout(L_edits) L_main.setStretch(3, 1) L_main.setSpacing(2) self.appliers = { 'float': self.applier.apply_float, 'enum': self.applier.apply_enum, 'bool': self.applier.apply_bool, 'time': self.applier.apply_float, 'byte': self.applier.apply_int, 'angle': self.applier.apply_float, 'string': self.applier.apply_str, 'float3': self.applier.apply_d3, 'float4': self.applier.apply_d4, 'color': self.applier.apply_color } self.setLayout(L_main) # final settings self.WL_attributes.itemSelectionChanged.connect(self.update_setter) self.applier.unset_editors()
from PySide.QtCore import QRect from PySide.QtGui import QGraphicsItem, QPainter from PySide.QtGui import QColor from PySide.QtGui import QPen from PySide.QtGui import QFontMetrics from PySide.QtGui import QFont from PySide.QtGui import QBrush nodes_font = QFont("Impact", 19) class ClassyNode(QGraphicsItem): def __init__(self, name): QGraphicsItem.__init__(self) self.label = name self.edges_in = [] self.edges_out = [] self.metrics = QFontMetrics(nodes_font) self._b_width = 0 self._b_height = 0 self._x = 0 self._y = 0 self.margin = 5 self.node_pen = QPen(QColor(30, 30, 30)) self.selected_pen = QPen(QColor(200, 200, 30)) self.node_brush = QBrush(QColor(120, 120, 30))
def initUI(self): QToolTip.setFont(QFont('SansSerif', 10)) self.setGeometry(300, 200, 810, 430) self.setWindowTitle('Transformation on Human Face') #Method choose combobox self.comboAffineLabel = QLabel(self) self.comboAffineLabel.setText('Transformation Method:') self.comboAffineLabel.setGeometry(60, 270, 230, 30) self.comboAffine = QComboBox(self) self.comboAffine.addItem("Local Affine Transformation") self.comboAffine.addItem("Moving Least Squares") self.comboAffine.addItem("Morphing") self.comboAffine.setGeometry(22, 290, 225, 30) self.comboAffine.activated[str].connect(self.affineChoiceChange) #The button to choose the original figure self.oriBtn = QPushButton('Choose Original Picture', self) self.oriBtn.setToolTip('Choose Original Picture') self.oriBtn.setGeometry(20, 330, 230, 30) self.oriBtn.clicked.connect(self.showOriDialog) #The button to choose the proto figure self.protoBtn = QPushButton('Choose Proto Picture', self) self.protoBtn.setToolTip('Choose Proto Picture') self.protoBtn.setGeometry(20, 365, 230, 30) self.protoBtn.clicked.connect(self.showProtoDialog) #The distance function choose combobox self.comboLabel = QLabel(self) self.comboLabel.setText('Distance Fun:') self.comboLabel.setGeometry(310, 280, 200, 30) self.comboDis = QComboBox(self) self.comboDis.addItem("L2") self.comboDis.addItem("L1") self.comboDis.setGeometry(410, 280, 80, 30) self.comboDis.activated[str].connect(self.distanceChoiceChange) #E choose slider self.eLabel = QLabel(self) self.eLabel.setText('E Value:0.00') self.eLabel.setGeometry(310, 320, 200, 30) self.eSld = QSlider(Qt.Horizontal, self) self.eSld.setRange(0, 10**5) self.eSld.setFocusPolicy(Qt.NoFocus) self.eSld.setGeometry(390, 320, 120, 30) self.eSld.valueChanged[int].connect(self.changeEValue) #alpha choose slider self.aLabel = QLabel(self) self.aLabel.setText('Alpha Value:0.00') self.aLabel.setGeometry(310, 360, 200, 30) self.aSld = QSlider(Qt.Horizontal, self) self.aSld.setRange(0, 10**5) self.aSld.setFocusPolicy(Qt.NoFocus) self.aSld.setGeometry(410, 360, 100, 30) self.aSld.valueChanged[int].connect(self.changeAlphaValue) # Picture show self.oriTextLabel = QLabel(self) self.protoTextLabel = QLabel(self) self.transTextLabel = QLabel(self) self.oriTextLabel.setText('The Orginal Picture') self.protoTextLabel.setText('The Proto Picture') self.transTextLabel.setText('The Picture after Transformation') self.oriTextLabel.move(70, 5) self.protoTextLabel.move(350, 5) self.transTextLabel.move(580, 5) self.oriLabel = QLabel(self) self.protoLabel = QLabel(self) self.transLabel = QLabel(self) pixmap = QPixmap(self.oriPath) pixmap2 = QPixmap(self.protoPath) self.oriLabel.setPixmap(pixmap) self.protoLabel.setPixmap(pixmap2) self.transLabel.setPixmap(pixmap) #Position setting self.oriLabel.setGeometry(20, 20, 230, 230) self.protoLabel.setGeometry(290, 20, 230, 230) self.transLabel.setGeometry(560, 20, 230, 230) self.oriLabel.setScaledContents(True) self.protoLabel.setScaledContents(True) self.transLabel.setScaledContents(True) #Load button self.loadOriBtn = QPushButton('Load Ori Points', self) self.loadOriBtn.setToolTip('Load Control Points From Txt File') self.loadOriBtn.setGeometry(550, 280, 130, 30) self.loadOriBtn.clicked.connect(self.showLoadOriDialog) self.loadProtoBtn = QPushButton('Load Proto Points', self) self.loadProtoBtn.setToolTip('Load Control Points From Txt File') self.loadProtoBtn.setGeometry(680, 280, 130, 30) self.loadProtoBtn.clicked.connect(self.showLoadProtoDialog) #Face ++ button self.faceBtn = QPushButton('Face++ Keypoint', self) self.faceBtn.setToolTip('Save the Face++ Keypoints') self.faceBtn.setGeometry(550, 315, 130, 30) self.faceBtn.clicked.connect(self.detectKeyPoints) #Load region Button self.loadRegionBtn = QPushButton('Load Regions', self) self.loadRegionBtn.setToolTip('Load Regions From Txt File') self.loadRegionBtn.setGeometry(680, 315, 130, 30) self.loadRegionBtn.clicked.connect(self.showLoadRegionDialog) #Save Button setting self.saveBtn = QPushButton('Save', self) self.saveBtn.setToolTip( 'Transform this picture to the shape of Baboon') self.saveBtn.setGeometry(560, 350, 110, 40) self.saveBtn.clicked.connect(self.saveImg) #Transform action button self.confirmBtn = QPushButton('Generate', self) self.confirmBtn.setToolTip('Generate') self.confirmBtn.setGeometry(680, 350, 110, 40) self.confirmBtn.clicked.connect(self.transformAction) self.show()
def fresh(self): self.t1 += 1 self.t2 += 1 self.t3 += 1 self.t4 += 1 if self.t1 == 10: self.data_model.setItem(1, 1, QtGui.QStandardItem("0")) self.data_model.setItem(2, 1, QtGui.QStandardItem("0")) self.data_model.setItem(3, 1, QtGui.QStandardItem("0")) if self.t2 == 10: self.data_model.setItem(1, 2, QtGui.QStandardItem("0")) self.data_model.setItem(2, 2, QtGui.QStandardItem("0")) self.data_model.setItem(3, 2, QtGui.QStandardItem("0")) if self.t3 == 10: self.data_model.setItem(1, 3, QtGui.QStandardItem("0")) self.data_model.setItem(2, 3, QtGui.QStandardItem("0")) self.data_model.setItem(3, 3, QtGui.QStandardItem("0")) if self.t4 == 10: self.data_model.setItem(1, 4, QtGui.QStandardItem("0")) self.data_model.setItem(2, 4, QtGui.QStandardItem("0")) self.data_model.setItem(3, 4, QtGui.QStandardItem("0")) # 设置水平居中 self.data_model.item(1, 1).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(2, 1).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(3, 1).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(1, 2).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(2, 2).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(3, 2).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(1, 3).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(2, 3).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(3, 3).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(1, 4).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(2, 4).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(3, 4).setTextAlignment(QtCore.Qt.AlignCenter) # 设置字号和粗细 self.data_model.item(1, 1).setFont(QFont("Times", 12, QFont.Light)) self.data_model.item(2, 1).setFont(QFont("Times", 12, QFont.Light)) self.data_model.item(3, 1).setFont(QFont("Times", 12, QFont.Light)) self.data_model.item(1, 2).setFont(QFont("Times", 12, QFont.Light)) self.data_model.item(2, 2).setFont(QFont("Times", 12, QFont.Light)) self.data_model.item(3, 2).setFont(QFont("Times", 12, QFont.Light)) self.data_model.item(1, 3).setFont(QFont("Times", 12, QFont.Light)) self.data_model.item(2, 3).setFont(QFont("Times", 12, QFont.Light)) self.data_model.item(3, 3).setFont(QFont("Times", 12, QFont.Light)) self.data_model.item(1, 4).setFont(QFont("Times", 12, QFont.Light)) self.data_model.item(2, 4).setFont(QFont("Times", 12, QFont.Light)) self.data_model.item(3, 4).setFont(QFont("Times", 12, QFont.Light)) if self.text: self.textEdit_2.insertPlainText(self.text) self.text = "" v = self.textEdit_2.verticalScrollBar() v.setSliderPosition(v.maximum()) if self.result: self.showData()
def showData(self): # 实时显示各节点测量数据 for l1 in range(len(self.result)): if self.result[l1][0] == 'F': if self.result[l1][1] == '1': self.datat1.pop(0) self.datat1.append(float(self.result[l1 + 1])) self.datah1.pop(0) self.datah1.append(float(self.result[l1 + 2])) self.datal1.pop(0) self.datal1.append(float(self.result[l1 + 3])) self.data_model.setItem( 1, 1, QtGui.QStandardItem(self.result[l1 + 1])) self.data_model.setItem( 2, 1, QtGui.QStandardItem(self.result[l1 + 2])) self.data_model.setItem( 3, 1, QtGui.QStandardItem(self.result[l1 + 3])) self.t1 = 0 time1 = time.strftime('%Y-%m-%d %H:%M:%S') self.datas1 = [ time1, self.result[l1 + 1], self.result[l1 + 2], self.result[l1 + 3] ] self.data1.append(self.datas1) if self.result[l1][1] == '2': self.datat2.pop(0) self.datat2.append(float(self.result[l1 + 1])) self.datah2.pop(0) self.datah2.append(float(self.result[l1 + 2])) self.datal2.pop(0) self.datal2.append(float(self.result[l1 + 3])) self.data_model.setItem( 1, 2, QtGui.QStandardItem(self.result[l1 + 1])) self.data_model.setItem( 2, 2, QtGui.QStandardItem(self.result[l1 + 2])) self.data_model.setItem( 3, 2, QtGui.QStandardItem(self.result[l1 + 3])) self.t2 = 0 time2 = time.strftime('%Y-%m-%d %H:%M:%S') self.datas2 = [ time2, self.result[l1 + 1], self.result[l1 + 2], self.result[l1 + 3] ] self.data2.append(self.datas2) if self.result[l1][1] == '3': self.datat3.pop(0) self.datat3.append(float(self.result[l1 + 1])) self.datah3.pop(0) self.datah3.append(float(self.result[l1 + 2])) self.datal3.pop(0) self.datal3.append(float(self.result[l1 + 3])) self.data_model.setItem( 1, 3, QtGui.QStandardItem(self.result[l1 + 1])) self.data_model.setItem( 2, 3, QtGui.QStandardItem(self.result[l1 + 2])) self.data_model.setItem( 3, 3, QtGui.QStandardItem(self.result[l1 + 3])) self.t3 = 0 time3 = time.strftime('%Y-%m-%d %H:%M:%S') self.datas3 = [ time3, self.result[l1 + 1], self.result[l1 + 2], self.result[l1 + 3] ] self.data3.append(self.datas3) if self.result[l1][1] == '4': self.datat4.pop(0) self.datat4.append(float(self.result[l1 + 1])) self.datah4.pop(0) self.datah4.append(float(self.result[l1 + 2])) self.datal4.pop(0) self.datal4.append(float(self.result[l1 + 3])) self.data_model.setItem( 1, 4, QtGui.QStandardItem(self.result[l1 + 1])) self.data_model.setItem( 2, 4, QtGui.QStandardItem(self.result[l1 + 2])) self.data_model.setItem( 3, 4, QtGui.QStandardItem(self.result[l1 + 3])) self.t4 = 0 time4 = time.strftime('%Y-%m-%d %H:%M:%S') self.datas4 = [ time4, self.result[l1 + 1], self.result[l1 + 2], self.result[l1 + 3] ] self.data4.append(self.datas4) # 设置水平居中 self.data_model.item(1, 1).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(2, 1).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(3, 1).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(1, 2).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(2, 2).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(3, 2).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(1, 3).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(2, 3).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(3, 3).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(1, 4).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(2, 4).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(3, 4).setTextAlignment(QtCore.Qt.AlignCenter) # 设置字号和粗细 self.data_model.item(1, 1).setFont(QFont("Times", 12, QFont.Light)) self.data_model.item(2, 1).setFont(QFont("Times", 12, QFont.Light)) self.data_model.item(3, 1).setFont(QFont("Times", 12, QFont.Light)) self.data_model.item(1, 2).setFont(QFont("Times", 12, QFont.Light)) self.data_model.item(2, 2).setFont(QFont("Times", 12, QFont.Light)) self.data_model.item(3, 2).setFont(QFont("Times", 12, QFont.Light)) self.data_model.item(1, 3).setFont(QFont("Times", 12, QFont.Light)) self.data_model.item(2, 3).setFont(QFont("Times", 12, QFont.Light)) self.data_model.item(3, 3).setFont(QFont("Times", 12, QFont.Light)) self.data_model.item(1, 4).setFont(QFont("Times", 12, QFont.Light)) self.data_model.item(2, 4).setFont(QFont("Times", 12, QFont.Light)) self.data_model.item(3, 4).setFont(QFont("Times", 12, QFont.Light)) # elif not self.result[0] == "F4": # self.t4 += 1 self.test1._change(self.datal1, self.datat1, self.datah1) self.test1.set_diagram(1) self.test2._change(self.datal2, self.datat2, self.datah2) self.test2.set_diagram(2) self.test3._change(self.datal3, self.datat3, self.datah3) self.test3.set_diagram(3) self.test4._change(self.datal4, self.datat4, self.datah4) self.test4.set_diagram(4) self.result = []
def setTable2(self): self.t1 = 0 self.t2 = 0 self.t3 = 0 self.t4 = 0 self.datat1 = [0] * 100 self.datah1 = [0] * 100 self.datal1 = [0] * 100 self.datat2 = [0] * 100 self.datah2 = [0] * 100 self.datal2 = [0] * 100 self.datat3 = [0] * 100 self.datah3 = [0] * 100 self.datal3 = [0] * 100 self.datat4 = [0] * 100 self.datah4 = [0] * 100 self.datal4 = [0] * 100 # 隐藏表头 self.tableView_2.verticalHeader().hide() self.tableView_2.horizontalHeader().hide() # self.tableView_2.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers) self.data_model = QtGui.QStandardItemModel() # self.tableView_2.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers) # 设置每列的标题 self.data_model.setItem(0, 0, QtGui.QStandardItem("测量参数")) self.data_model.setItem(0, 1, QtGui.QStandardItem("F1")) self.data_model.setItem(0, 2, QtGui.QStandardItem("F2")) self.data_model.setItem(0, 3, QtGui.QStandardItem("F3")) self.data_model.setItem(0, 4, QtGui.QStandardItem("F4")) self.data_model.setItem(1, 0, QtGui.QStandardItem("温度(℃)")) self.data_model.setItem(2, 0, QtGui.QStandardItem("湿度(%RH)")) self.data_model.setItem(3, 0, QtGui.QStandardItem("光照强度(lx)")) self.data_model.setItem(0, 0, QtGui.QStandardItem("测量参数")) self.data_model.setItem(1, 1, QtGui.QStandardItem("0")) self.data_model.setItem(2, 1, QtGui.QStandardItem("0")) self.data_model.setItem(3, 1, QtGui.QStandardItem("0")) self.data_model.setItem(1, 2, QtGui.QStandardItem("0")) self.data_model.setItem(2, 2, QtGui.QStandardItem("0")) self.data_model.setItem(3, 2, QtGui.QStandardItem("0")) self.data_model.setItem(1, 3, QtGui.QStandardItem("0")) self.data_model.setItem(2, 3, QtGui.QStandardItem("0")) self.data_model.setItem(3, 3, QtGui.QStandardItem("0")) self.data_model.setItem(1, 4, QtGui.QStandardItem("0")) self.data_model.setItem(2, 4, QtGui.QStandardItem("0")) self.data_model.setItem(3, 4, QtGui.QStandardItem("0")) # 设置参数水平居中 self.data_model.item(0, 0).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(0, 1).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(0, 2).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(0, 3).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(0, 4).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(1, 0).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(2, 0).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(3, 0).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(1, 1).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(2, 1).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(3, 1).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(1, 2).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(2, 2).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(3, 2).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(1, 3).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(2, 3).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(3, 3).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(1, 4).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(2, 4).setTextAlignment(QtCore.Qt.AlignCenter) self.data_model.item(3, 4).setTextAlignment(QtCore.Qt.AlignCenter) # 设置表格的默认行高 # self.tableView_2.verticalHeader().setDefaultSectionSize(60) self.data_model.item(0, 0).setFont(QFont("Times", 13, QFont.Black)) self.data_model.item(0, 1).setFont(QFont("Times", 13, QFont.Black)) self.data_model.item(0, 2).setFont(QFont("Times", 13, QFont.Black)) self.data_model.item(0, 3).setFont(QFont("Times", 13, QFont.Black)) self.data_model.item(0, 4).setFont(QFont("Times", 13, QFont.Black)) self.data_model.item(1, 0).setFont(QFont("Times", 13, QFont.Black)) self.data_model.item(2, 0).setFont(QFont("Times", 13, QFont.Black)) self.data_model.item(3, 0).setFont(QFont("Times", 13, QFont.Black)) # 设置自适应列宽 self.tableView_2.horizontalHeader().setResizeMode(QHeaderView.Stretch) self.tableView_2.verticalHeader().setResizeMode(QHeaderView.Stretch) # 关联tableView_2 self.tableView_2.setModel(self.data_model) self.tableView_2.show()
def fontChange(self): (font, ok) = QFontDialog.getFont(QFont("Helvetica [Cronyx]", 10), self) if ok: self.textEdit.setCurrentFont(font)
def updateDisplayFonts(self): self.setFont(QFont(self.state.stdFontFamily, self.state.stdFontSize))
if WEARECODING: try: os.remove('log.txt') except: pass if not DEBUG: # Redirect `sys.stderr` and `sys.stdout` to a file # when building for release. sys.stderr = sys.stdout = open('log.txt', 'a') f = sys.stdout class F(): def write(self, data): if data.strip(): # Only attach a timestamp to non whitespace prints. data = '{0} {1}'.format(dt.utcnow().strftime('%Y-%m-%d %H:%M:%S'), data) f.write(data) f.flush() sys.stderr = sys.stdout = F() app=QApplication.instance() # checks if QApplication already exists if not app: # create QApplication if it doesnt exist app = QApplication(sys.argv) window = SyncWindow() font = QFont(View.fontFamily, 12, 50, False) app.setFont(font) window.show() sys.exit(app.exec_())
def __init__(self, *args): super(HooverBar, self).__init__(*args) self.setAcceptHoverEvents(True) self.gi = None self.description = [""] self.base_font = QFont()
def __init__(self, parent=None, filePath=''): """Default class constructor.""" super(MDISubWindow_TextEdit, self).__init__(parent) print(filePath) self.filePath = filePath self.fileName = os.path.basename(os.path.abspath(filePath)) self.fileExt = os.path.splitext(self.fileName)[1] if not filePath: self.setWindowTitle('Untitled[*]') parent.setWindowIcon(QIcon(gIconDir + os.sep + 'new.png')) else: f = open(filePath, 'r') txt = f.read() f.close() self.setText(txt) self.setWindowTitle('%s[*]' % self.fileName) # TODO: This is changing all the subwindows icons. We want individual icons based on filetype...? if self.fileExt in ('.py', '.pyw'): parent.setWindowIcon(QIcon(gIconDir + os.sep + 'pyscript.png')) else: parent.setWindowIcon(QIcon(gIconDir + os.sep + 'new.png')) monoFont = QFont('Courier New') monoFont.setFixedPitch(True) self.setFont(monoFont) self.setWordWrapMode(QTextOption.NoWrap) ## self.setTextBackgroundColor(QColor('#000000')) ## self.setTextColor(QColor('#FFFFFF')) self.setCursorWidth(2) self.CreateActions() self.zoomLevel = 0 gMainWin.action_Edit_Cut.setEnabled(False) gMainWin.action_Edit_Copy.setEnabled(False) self.copyAvailable.connect(gMainWin.action_Edit_Cut.setEnabled) self.copyAvailable.connect(gMainWin.action_Edit_Copy.setEnabled) # Handle the Context Menu Entries Also. self.action_Edit_Undo.setEnabled(False) self.action_Edit_Redo.setEnabled(False) self.action_Edit_Cut.setEnabled(False) self.action_Edit_Copy.setEnabled(False) self.undoAvailable.connect(self.action_Edit_Undo.setEnabled) self.redoAvailable.connect(self.action_Edit_Redo.setEnabled) self.copyAvailable.connect(self.action_Edit_Cut.setEnabled) self.copyAvailable.connect(self.action_Edit_Copy.setEnabled) self.document().contentsChanged.connect(self.TheDocumentWasModified) # self.show() # self.showMaximized() # self.setFocusPolicy(Qt.WheelFocus) ##### self.setFocus() # This makes the MDIArea go into SubWindowView...? self.gCornerWidget = QToolButton(self) # self.gCornerWidgetToolTip = QToolTip() QToolTip.setFont(QFont('SansSerif', 10)) br = QBrush(QPixmap(gImgDir + os.sep + 'texture-spirals.png')) pal = QPalette() # pal.setBrush(QPalette.Active, QPalette.Base, br) # pal.setColor(QPalette.Background, QColor('#FF8000')) pal.setColor(QPalette.ColorGroup.Inactive, QPalette.ColorRole.ToolTipBase, QColor(EMBROIDERBLUE2)) QToolTip.setPalette(QPalette(pal)) self.action_Edit_SelectAll.setToolTip( 'This is a <b>QWidget</b> widget') self.gCornerWidget.setDefaultAction(self.action_Edit_SelectAll) self.setCornerWidget(self.gCornerWidget) # We want to show the corner widget no matter what so... self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOn) self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
def setUp(self): super(QFontMetricsTest, self).setUp() self.font = QFont() self.metrics = QFontMetrics(self.font)
def add_labels_internal(self, gl, render_state, draw_to_canvas, labels): ''' call to add a list of labels ''' text_paint = QPainter() if draw_to_canvas: text_paint.begin(self.bitmap) text_paint.setRenderHints(QPainter.Antialiasing) u = 0 v = 0 line_height = 0 for label in labels: ascent = 0 descent = 0 measured_text_width = 0 height = 0 width = 0 font_size = label.font_size while True: metrics = None if draw_to_canvas: mask = 0x000000FF b = (label.color >> 16) & mask g = (label.color >> 8) & mask r = label.color & mask ######################################################################## LINE CHANGED text_paint.setPen(QColor(0, 0, 0)) #text_paint.setPen(QColor(r, g, b)) # The value 0.75 is hard coded representing phone pixel density text_paint.setFont(QFont('Veranda', font_size * 0.75)) # Paint.ascent is negative, so negate it. metrics = text_paint.fontMetrics() else: # The value 0.75 is hard coded representing phone pixel density metrics = QFontMetrics(QFont('Veranda', font_size * 0.75)) ascent = math.ceil(metrics.ascent()) descent = math.ceil(metrics.descent()) measured_text_width = math.ceil(metrics.boundingRect(label.string).width()) height = int(ascent) + int(descent) width = int(measured_text_width) # If it's wider than the screen, try it again with a font size of 1 # smaller. font_size -= 1 if font_size < 0 or width < render_state.screen_width: break next_u = 0 # Is there room for this string on the current line? if u + width > self.strike_width: # No room, go to the next line: u = 0 next_u = width v += line_height line_height = 0 else: next_u = u + width line_height = max(line_height, height) if (v + line_height > self.strike_height) and draw_to_canvas: raise Exception("out of texture space.") v_base = v + ascent if draw_to_canvas: text_paint.drawText(int(u), int(v_base), label.string) label.set_texture_data(width, height, u, v + height, width, -height, self.texel_width, self.texel_height) u = next_u if draw_to_canvas: text_paint.end() return v + line_height
def __init__(self, robocare_serial): self.__is_xtion_type = True self.__robocare_serial = robocare_serial QWidget.__init__(self) layout = QGridLayout() self.setLayout(layout) self.__line1 = QLineEdit() if self.__is_xtion_type: self.__line1.setPlaceholderText( "08 F8 F8 05 00 64 00 00 00 00 00 64 00 00 00 00 00 00 00 00 00 00 10 10 00 00 00 00 00 00 00 E8" ) else: self.__line1.setPlaceholderText( "08 F8 F8 05 00 64 00 00 00 00 00 64 00 00 00 00 00 00 00 00 10 10 00 00 00 00 00 00 E8" ) self.__line1.setFont(QFont(u"나눔고딕", 8, weight=QFont.Bold)) layout.addWidget(self.__line1, 0, 0, 1, 4) button = QPushButton(u'보내기', self) button.setFont(QFont(u"나눔고딕", 15, weight=QFont.Bold)) button.clicked.connect(self.clicked_custom_once) layout.addWidget(button, 1, 0, 1, 1) button = QPushButton(u'홈위치', self) button.setFont(QFont(u"나눔고딕", 15, weight=QFont.Bold)) button.clicked.connect(self.clicked_home) layout.addWidget(button, 1, 1, 1, 1) button = QPushButton(u'홈위치 변경', self) button.setFont(QFont(u"나눔고딕", 15, weight=QFont.Bold)) button.clicked.connect(self.clicked_set_home) layout.addWidget(button, 1, 2, 1, 1) button = QPushButton(u'버전 체크', self) button.setFont(QFont(u"나눔고딕", 15, weight=QFont.Bold)) button.clicked.connect(self.clicked_version) layout.addWidget(button, 1, 3, 1, 1) # button = QPushButton(u'인코더 읽기',self) # button.setFont(QFont(u"나눔고딕",15,weight=QFont.Bold)) # button.clicked.connect(self.clicked_encoder) # layout.addWidget(button, 1, 2, 1, 1) self.__line2 = QLineEdit() if self.__is_xtion_type: self.__line1.setPlaceholderText( "08 F8 F8 05 00 64 00 00 00 00 00 64 00 00 00 00 00 00 00 00 00 00 10 10 00 00 00 00 00 00 00 E8" ) else: self.__line1.setPlaceholderText( "08 F8 F8 05 00 64 00 00 00 00 00 64 00 00 00 00 00 00 00 00 10 10 00 00 00 00 00 00 E8" ) self.__line2.setFont(QFont(u"나눔고딕", 8, weight=QFont.Bold)) layout.addWidget(self.__line2, 2, 0, 1, 4) button = QPushButton(u'팔 위치 1', self) button.setFont(QFont(u"나눔고딕", 15, weight=QFont.Bold)) button.clicked.connect(self.clicked_a1) layout.addWidget(button, 3, 0, 1, 1) button = QPushButton(u'팔 위치 2', self) button.setFont(QFont(u"나눔고딕", 15, weight=QFont.Bold)) button.clicked.connect(self.clicked_a2) layout.addWidget(button, 3, 1, 1, 1) button = QPushButton(u'팔 위치 3', self) button.setFont(QFont(u"나눔고딕", 15, weight=QFont.Bold)) button.clicked.connect(self.clicked_a3) layout.addWidget(button, 3, 2, 1, 1) button = QPushButton(u'팔 위치 4', self) button.setFont(QFont(u"나눔고딕", 15, weight=QFont.Bold)) button.clicked.connect(self.clicked_a4) layout.addWidget(button, 3, 3, 1, 1) button = QPushButton(u'팔 위치 5', self) button.setFont(QFont(u"나눔고딕", 15, weight=QFont.Bold)) button.clicked.connect(self.clicked_a5) layout.addWidget(button, 4, 0, 1, 1) button = QPushButton(u'팔 위치 6', self) button.setFont(QFont(u"나눔고딕", 15, weight=QFont.Bold)) button.clicked.connect(self.clicked_a6) layout.addWidget(button, 4, 1, 1, 1) button = QPushButton(u'머리 위치 1', self) button.setFont(QFont(u"나눔고딕", 15, weight=QFont.Bold)) button.clicked.connect(self.clicked_h1) layout.addWidget(button, 4, 2, 1, 1) button = QPushButton(u'머리 위치 2', self) button.setFont(QFont(u"나눔고딕", 15, weight=QFont.Bold)) button.clicked.connect(self.clicked_h2) layout.addWidget(button, 4, 3, 1, 1)
def updateDisplayFonts(self): self.pane.setFont( QFont(self.state.stdFontFamily, self.state.stdFontSize)) self.refresh()
def settext(self, txt): font = QFont(u'微软雅黑', 10) self.txt.setFont(font) self.txt.setText(txt)
def tab_options(self): """ Everything inside the Options tab gets created here. """ # self.options # This section is for selecting output dir # Creates the output dir label self.output_dir_lbl = QLabel(self.options) self.output_dir_lbl.setGeometry(10, 10, 125, 15) self.output_dir_lbl.setText('Change Output Directory: ') # Creates the output dir button self.select_output_dir_btn = QPushButton(self.options) self.select_output_dir_btn.setGeometry(137, 8, 30, 20) self.select_output_dir_btn.setText('...') # Creates the output dir currentdir Lineedit self.output_cur_dir_lbl = QLineEdit(self.options) self.output_cur_dir_lbl.setGeometry(170, 6, 210, 25) self.output_cur_dir_lbl.setReadOnly(True) self.output_cur_dir_lbl.setText( Constants.CONFIG.get('directories', 'current_song')) # when the '...' button is clicked, show a dialog (fire func # disp_dialog) QObject.connect(self.select_output_dir_btn, SIGNAL("clicked()"), self.disp_dialog) # This section is for selecting what players you use # The box with all the active players self.active_items_list = QListWidget(self.options) self.active_items_list.setGeometry(10, 40, 150, 100) # The box with all the inactive players self.inactive_items_list = QListWidget(self.options) self.inactive_items_list.setGeometry(230, 40, 150, 100) # Populate the two boxes with active and inactive items for item in Constants.ACTIVEITEMS: if item == '__name__' or item == 'active': continue self.active_items_list.addItem(item) for item in Constants.INACTIVEITEMS: if item == '__name__' or item == 'active': continue self.inactive_items_list.addItem(item) # The buttons responsible for switching # off button self.switch_active_item_button_off = QPushButton(self.options) self.switch_active_item_button_off.setText('->'.decode('utf-8')) # Makes the -> readable and clear self.switch_active_item_button_off.setFont(QFont('SansSerif', 17)) self.switch_active_item_button_off.setGeometry(175, 55, 40, 30) # on button self.switch_active_item_button_on = QPushButton(self.options) self.switch_active_item_button_on.setText('<-'.decode('utf-8')) # makes <- readable and clear self.switch_active_item_button_on.setFont(QFont('SansSerif', 17)) self.switch_active_item_button_on.setGeometry(175, 90, 40, 30) QObject.connect(self.switch_active_item_button_on, SIGNAL("clicked()"), self.switch_item_on) QObject.connect(self.switch_active_item_button_off, SIGNAL("clicked()"), self.switch_item_off) # A button to toggle the split output in half option. It's a temporary # fix for the Foobar double output problem. self.switch_output_split_btn = QCheckBox(self.options) self.switch_output_split_btn.setCheckState(Qt.CheckState.Unchecked) self.switch_output_split_btn.setGeometry(10, 140, 40, 30) self.switch_output_split_btn.stateChanged.connect(self.toggle_split) # The label for the split toggle self.switch_output_split_lbl = QLabel(self.options) self.switch_output_split_lbl.setText( "Split the output text in half (don't use this if you don't need it)" ) self.switch_output_split_lbl.setGeometry(30, 140, 300, 30)
def __init__(self, parent=None): super(Truss, self).__init__(parent) self.resize(800, 600) self.filename = None self.filetuple = None self.dirty = False # Refers to Data Page only. centralwidget = QWidget(self) gridLayout = QGridLayout(centralwidget) self.tabWidget = QTabWidget(centralwidget) self.tab = QWidget() font = QFont() font.setFamily("Courier 10 Pitch") font.setPointSize(12) self.tab.setFont(font) gridLayout_3 = QGridLayout(self.tab) self.plainTextEdit = QPlainTextEdit(self.tab) gridLayout_3.addWidget(self.plainTextEdit, 0, 0, 1, 1) self.tabWidget.addTab(self.tab, "") self.tab_2 = QWidget() self.tab_2.setFont(font) gridLayout_2 = QGridLayout(self.tab_2) self.plainTextEdit_2 = QPlainTextEdit(self.tab_2) gridLayout_2.addWidget(self.plainTextEdit_2, 0, 0, 1, 1) self.tabWidget.addTab(self.tab_2, "") gridLayout.addWidget(self.tabWidget, 0, 0, 1, 1) self.setCentralWidget(centralwidget) menubar = QMenuBar(self) menubar.setGeometry(QRect(0, 0, 800, 29)) menu_File = QMenu(menubar) self.menu_Solve = QMenu(menubar) self.menu_Help = QMenu(menubar) self.setMenuBar(menubar) self.statusbar = QStatusBar(self) self.setStatusBar(self.statusbar) self.action_New = QAction(self) self.actionSave_As = QAction(self) self.action_Save = QAction(self) self.action_Open = QAction(self) self.action_Quit = QAction(self) self.action_About = QAction(self) self.actionShow_CCPL = QAction(self) self.action_Solve = QAction(self) self.action_CCPL = QAction(self) self.action_Help = QAction(self) menu_File.addAction(self.action_New) menu_File.addAction(self.action_Open) menu_File.addAction(self.actionSave_As) menu_File.addAction(self.action_Save) menu_File.addSeparator() menu_File.addAction(self.action_Quit) self.menu_Solve.addAction(self.action_Solve) self.menu_Help.addAction(self.action_About) self.menu_Help.addAction(self.action_CCPL) self.menu_Help.addAction(self.action_Help) menubar.addAction(menu_File.menuAction()) menubar.addAction(self.menu_Solve.menuAction()) menubar.addAction(self.menu_Help.menuAction()) self.setWindowTitle("Main Window") self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab),\ "Data Page") self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2),\ "Solution Page") menu_File.setTitle("&File") self.menu_Solve.setTitle("&Solve") self.menu_Help.setTitle("&Help") self.tabWidget.setCurrentIndex(0) self.action_New.setText("&New") self.action_Open.setText("&Open") self.actionSave_As.setText("Save &As") self.action_Save.setText("&Save") self.action_Quit.setText("&Quit") self.action_Solve.setText("&Solve") self.action_About.setText("&About") self.action_CCPL.setText("&CCPL") self.action_Help.setText("&Help") self.action_Quit.triggered.connect(self.close) allToolBar = self.addToolBar("AllToolBar") allToolBar.setObjectName("AllToolBar") self.addActions(allToolBar, (self.action_Open, self.actionSave_As,\ self.action_Save, self.action_Solve,\ self.action_Quit )) self.action_New.triggered.connect(self.fileNew) self.action_Open.triggered.connect(self.fileOpen) self.actionSave_As.triggered.connect(self.fileSaveAs) self.action_Save.triggered.connect(self.fileSave) self.action_Solve.triggered.connect(self.trussSolve) self.action_About.triggered.connect(self.aboutBox) self.action_CCPL.triggered.connect(self.displayCCPL) self.action_Help.triggered.connect(self.help) self.plainTextEdit.textChanged.connect(self.setDirty) self.action_New = self.editAction(self.action_New, None,\ 'ctrl+N', 'filenew', 'New File.') self.action_Open = self.editAction(self.action_Open, None, 'ctrl+O', 'fileopen', 'Open File.') self.actionSave_As = self.editAction(self.actionSave_As,\ None, 'ctrl+A', 'filesaveas',\ 'Save and Name File.') self.action_Save = self.editAction(self.action_Save, None, 'ctrl+S', 'filesave', 'Save File.') self.action_Solve = self.editAction(self.action_Solve, None, 'ctrl+L', 'solve', 'Solve Structure.') self.action_About = self.editAction(self.action_About, None, 'ctrl+B', 'about', 'Pop About Box.') self.action_CCPL = self.editAction(self.action_CCPL, None, 'ctrl+G', 'licence', 'Show Licence') self.action_Help = self.editAction(self.action_Help, None, 'ctrl+H', 'help', 'Show Help Page.') self.action_Quit = self.editAction(self.action_Quit, None, 'ctrl+Q', 'quit', 'Quit the program.') self.plainTextEdit_2.setReadOnly(True)
def setupFont(self): """ Setup the Font """ self.font = QFont() self.font.setPointSize(14)
def __init__(self, text): super(label, self).__init__() self.setText(text) self.setFont(QFont("", 10)) self.setFixedHeight(35)
def _updateDataTable(self, data): ''' Updates the data table with data from the last integration. ''' #prepare data self.dataTableHeaders = [] self.dataTableColumnData = [] self.dataTableRowCount = -1 self.dataTableRowHeaders = None self.maxValue = -1 for (entity, entityDataList) in data.items(): for entityData in entityDataList: dataDescriptors = entityData.dataDescriptors if not self.dataTableRowHeaders: self._setRowHeaders(dataDescriptors) elif len(self.dataTableRowHeaders) != len(dataDescriptors): logging.debug( "Different number of time points for two Species. Last Species (%s) will be skipped." % entity) continue # set header for first column (dataDescriptor/Timepoint col) # in first iteration if len(self.dataTableHeaders) == 0: dataDescriptorName = entityData.dataDescriptorName dataDescriptorUnit = entityData.dataDescriptorUnit if not dataDescriptorUnit and "timepoint" in str( dataDescriptorName).lower(): dataDescriptorUnit = self.host.optionTimeUnit firstColHeader = "" if dataDescriptorName: if self.showUnits: firstColHeader = "%s [%s]" % (dataDescriptorName, dataDescriptorUnit) elif dataDescriptorName: firstColHeader = "%s" % dataDescriptorName self.dataTableHeaders.append(firstColHeader) #self.dataTableHeaders.append("Time species %s [%s]" % (str(speciesID), self.lineEditTimeUnit.text())) #self.dataTableColumnData.append(timepoints) if len(dataDescriptors) > self.dataTableRowCount: self.dataTableRowCount = len(dataDescriptors) #datapoints = entityData.datapoints datapoints = [] # shorten datapoints for i, datapoint in enumerate(entityData.datapoints): try: #datapoints.append(round(float(datapoint), 4)) # valueString = "%g" % (float(datapoint)) floatValue = float( datapoint) # will jump to except if no float valueString = "N/A" if math.isnan( floatValue) else ' {0:-.4f}'.format(floatValue) datapoints.append(valueString) # preparing color computation # logging.debug(entityData.dataDescriptorName) # logging.debug(entityData.dataDescriptors[i] == settingsandvalues.SUBCONDITION_HEADER_ABSOLUTE) if self._mode == MODE_SUBCONDITIONS\ and entityData.dataDescriptors[i] == settingsandvalues.SUBCONDITION_HEADER_ABSOLUTE\ and floatValue > self.maxValue\ and floatValue < self.colorThreshold: self.maxValue = floatValue except: # datapoints.append(round(float("nan"), 4)) datapoints.append(str(datapoint)) # logging.debug("TableWidgetController - datapoints: %s" % datapoints) # too much overhead #self.dataTableHeaders.append("Data species %s [%s]" % (str(speciesID), entityData.getUnit())) if self.showUnits: # if type(entity) == str: # self.dataTableHeaders.append("%s" % entity) # else: self.dataTableHeaders.append( "%s [%s]" % (entity.getCombinedId(), entityData.getUnit())) else: self.dataTableHeaders.append("%s" % entity.getCombinedId()) self.dataTableColumnData.append(datapoints) # if len(datapoints) > self.dataTableRowCount: # self.dataTableRowCount = len(datapoints) # Put those labels into the actual data that would be the vertical/row labels. # We can't use .setVerticalHeaderLabers() because those labels don't get sorted together with the data. # Very weird but that seems to be the intended behaviour of Qt. if self.orientation == ORIENTATION_VERTICAL: #self.dataTableColumnData.insert(0, self.dataTableHeaders) # handle as if it were data so that sorting works self.dataTableHeaders = self.dataTableHeaders[ 1:] # remove unnecessary dataDescriptor name for i in xrange(len(self.dataTableColumnData)): entry = self.dataTableColumnData[i] entry.insert(0, self.dataTableHeaders[i]) self.dataTableRowHeaders.insert(0, "") else: self.dataTableColumnData.insert(0, self.dataTableRowHeaders) #self.dataTableHeaders.insert(0,"") if not self.dataTableWidget: # create for the first time tableLayout = QVBoxLayout(self.tableWrapper) self.dataTableWidget = QTableWidget(self) tableLayout.addWidget(self.dataTableWidget) #prepare table self.dataTableWidget.setSortingEnabled( True ) # do here to avoid performance penalty (this actually does one sorting run) if self.orientation == ORIENTATION_HORIZONTAL: self.dataTableWidget.setColumnCount(len(self.dataTableHeaders)) self.dataTableWidget.setRowCount(self.dataTableRowCount) self.dataTableWidget.setHorizontalHeaderLabels( self.dataTableHeaders) # self.dataTableWidget.setVerticalHeaderLabels( # self.dataTableRowHeaders) # has to be called after setRowCount? elif self.orientation == ORIENTATION_VERTICAL: self.dataTableWidget.setRowCount(len(self.dataTableHeaders)) self.dataTableWidget.setColumnCount(len(self.dataTableRowHeaders)) # self.dataTableWidget.setVerticalHeaderLabels(self.dataTableHeaders) self.dataTableWidget.setHorizontalHeaderLabels( self.dataTableRowHeaders ) # has to be called after setRowCount? #put data into table for col in xrange(len(self.dataTableColumnData)): for row in xrange(len(self.dataTableColumnData[col])): try: value = self.dataTableColumnData[col][ row] # don't touch "values"; they could be pre-formatted strings newItem = SortedTableWidgetItem() # use custom item class newItem.setData(Qt.DisplayRole, value) newItem.setTextAlignment(Qt.AlignRight) newItem.setFont(QFont("Fixed")) if self.isColored: if not (self._mode == MODE_SUBCONDITIONS and row != 2 ): #color only row 2 of subcondition tables color = self._computeColor(value) if color: newItem.setBackground(QBrush(color)) except Exception, e: logging.debug( "TableWidgetController._updateDataTable(): Could not put value into widget item: %s\nError: %s" % (value, e)) # newItem = SortedTableWidgetItem(str(self.dataTableColumnData[col][row])) # newItem.setTextAlignment(Qt.AlignRight) # newItem.setFont(QFont("Fixed")) if self.orientation == ORIENTATION_HORIZONTAL: self.dataTableWidget.setItem(row, col, newItem) elif self.orientation == ORIENTATION_VERTICAL: self.dataTableWidget.setItem(col, row, newItem)
def draw(self): glUseProgram(0) glLoadIdentity() glColor3f(0.0, 0.0, 0.0) self.viewer.renderText(self.x, self.y, self.text, QFont('Ubuntu', 36))