def __init__(self, parent=None, userData=None,inspector = True): QWebView.__init__(self, parent) settings = QWebSettings.globalSettings() settings.setFontFamily(QWebSettings.StandardFont, 'Helvetica') settings.setFontSize(QWebSettings.DefaultFontSize, 12) self.webpage = page = PtWebPage(self) self.setPage(page) self.connect(self, SIGNAL('loadFinished(bool)'), self.onLoadFinished) self.settings().setAttribute( QWebSettings.WebAttribute.DeveloperExtrasEnabled, True) #path = os.getcwd() #self.settings().setUserStyleSheetUrl(QUrl.fromLocalFile(path + "/myCustom.css")) font = QFont("Helvetica") font.setPixelSize(12) self.setFont(font) # or globally: # QWebSettings.globalSettings().setAttribute( # QWebSettings.WebAttribute.DeveloperExtrasEnabled, True) if inspector: self.inspector = QWebInspector() self.inspector.setPage(self.page()) self.inspector.hide() self.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks) self.page().linkClicked.connect(self._on_page_link_clicked)
def paintEvent(self, pe): painter = QPainter(self) painter.save() gradient = QLinearGradient() gradient.setStart(self._grad_start) gradient.setFinalStop(self._grad_end) gradient.setColorAt(0, QColor(230, 230, 230)) gradient.setColorAt(1, QColor(247, 247, 247)) brush = QBrush(gradient) painter.setBrush(brush) pen = QPen(Qt.black) pen.setWidth(1) painter.setPen(pen) painter.drawPath(self._painter_path) painter.restore() font = QFont() font.setFamily("Tahoma") font.setPixelSize(11) font.setBold(True) pen = QPen(Qt.darkGray) painter.setPen(pen) painter.setFont(font) self_rect = QRect(self.rect()) self_rect.moveTo(self._hor_margin, self._ver_margin // 2) painter.drawText(self_rect, Qt.AlignLeft, self._text)
def optionsf(self): self.opt = optdlg(self) self.opt.spinBox.setProperty("value", int(self.fontsize)) font = QFont() font.setPixelSize(int(self.fontsize)) self.opt.sampletxt.setFont(font) if str(self.clipauto) == "True": self.opt.checkclip.setChecked(True) elif str(self.clipauto) == "False": self.opt.checkclip.setChecked(False) if str(self.histdock) == "True": self.opt.checkshowhistdock.setChecked(True) elif str(self.histdock) == "False": self.opt.checkshowhistdock.setChecked(False) if str(self.bkmdock) == "True": self.opt.checkshowbkmdock.setChecked(True) elif str(self.bkmdock) == "False": self.opt.checkshowbkmdock.setChecked(False) self.opt.show() self.connect(self.opt.buttonBox, SIGNAL("accepted()"), self.optok) self.connect(self.opt.buttonBox.button(QDialogButtonBox.Apply), SIGNAL("clicked()"), self.optapply) self.connect(self.opt.checkdelhist, SIGNAL("stateChanged(int)"), self.deleteallhist) self.connect(self.opt.checkshowhistdock, SIGNAL("stateChanged(int)"), self.shownexttime) self.connect(self.opt.checkshowbkmdock, SIGNAL("stateChanged(int)"), self.shownexttime)
def setfontsize(self, i): if i >= 8 or i <= 24: font = QFont() font.setPixelSize(i) self.comboBox.setFont(font) self.searchbtn.setFont(font) self.bkmli.setFont(font) self.histli.setFont(font) self.listview.setFont(font) self.tamtext.setFont(font)
def __init__(self, fixtures_folder, parent=None): QWidget.__init__(self, parent) self.current_fixture = None self.fixtures_folder = fixtures_folder self.setWindowTitle("Frangitron DMX program editor") self.text = QPlainTextEdit() font = QFont("Monospace") font.setStyleHint(QFont.TypeWriter) font.setPixelSize(16) self.text.setFont(font) self.text.setStyleSheet( "color: white; background-color: rgb(30, 30, 30)") self.combo_fixture = QComboBox() self.frame_programs = QWidget() self.checkboxes_programs = list() self.layout_programs = QGridLayout(self.frame_programs) self.spinner_offset = QSpinBox() self.spinner_offset.setMinimum(1) self.spinner_offset.setMaximum(512) self.spinner_offset.setValue(1) self.spinner_offset.valueChanged.connect(self.address_changed) self.doc = QPlainTextEdit() self.doc.setReadOnly(True) self.doc.setFont(font) self.status = QLabel() layout = QGridLayout(self) layout.addWidget(self.combo_fixture, 0, 1) layout.addWidget(self.spinner_offset, 0, 2) layout.addWidget(self.frame_programs, 1, 1) layout.addWidget(self.text, 0, 0, 3, 1) layout.addWidget(self.doc, 2, 1, 1, 2) layout.addWidget(self.status, 3, 0, 1, 3) layout.setColumnStretch(0, 60) layout.setColumnStretch(1, 40) self.resize(1280, 800) self.streamer = Streamer(self.fixtures_folder) self.combo_fixture.addItems(sorted(self.streamer.fixtures)) self.combo_fixture.currentIndexChanged.connect(self.fixture_changed) self.timer = QTimer() self.timer.timeout.connect(self.tick) self.timer.start(500.0 / FRAMERATE) self.should_reload = True self.fixture_changed()
def __init__(self, view, uistack, widget): f = QFont('FreeMono') f.setWeight(QFont.Black) f.setPixelSize(16) self.grids = [] self.colors = [] self._view = view for p in providers: view.colors.addItem(p.name) view.colors.currentIndexChanged.connect(self.colorchange) self._detailview = view.detail self._detailview.scale(10, 10) self._lastdepth = -1 self._detail = None self.add() view.layer.sliderMoved.connect(self.layer) view.detailLayer.sliderMoved.connect(self.detaillayer) self._view.add.pressed.connect(self.add) def detailevent(event): if (isinstance(event, QKeyEvent) and event.text() == u'\t' and event.type() == QEvent.ShortcutOverride): widget.keyPressEvent(QKeyEvent( QEvent.KeyPress, event.key(), event.nativeModifiers(), event.text(), event.isAutoRepeat(), event.count())) return True return QWidget.event(widget, event) widget.event = detailevent widget.keyPressEvent = self.key view.rotation.valueChanged.connect(self.rotate) view.layer.setValue(view.layer.maximum()) self._view.showDetail.pressed.connect(self.showdetail) self._view.hideDetail.pressed.connect(self.hidedetail) self.hidedetail() self._view.pentagon.pressed.connect(self.pentagon) self._uistack = uistack
def getFontMetrics(self, family, pixelSize): """ @param family str @param pixelSize int @return QFontMetrics """ key = pixelSize, family ret = self.fontMetrics.get(key) if not ret: font = QFont(family) font.setPixelSize(pixelSize) ret = self.fontMetrics[key] = QFontMetrics(font) return ret
def CreateFlatButton(action): """ Create a custom flat button and style it so that it will look good on all platforms. """ toolButton = QToolButton() toolButton.setIcon(action.icon()) toolButton.setText(action.text()) toolButton.setAutoRaise(True) toolButton.setIconSize(QSize(32, 32)) toolButton.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) if sys.platform.startswith('darwin'): # Bug for Mac: QToolButtons do not react to setAutoRaise so # can't be made flat when they are not used inside a toolbar. # Setting a custom style sheet with border to none fixes this. # But then it looses all its highlight and pressed visual cues # so some extra styling needs to be done to provide some nice # visual feedback on hover and pressed states. toolButton.setStyleSheet( "QToolButton {" "border: none;" "} " "QToolButton:hover {" "background-color: qradialgradient(cx: 0.5, cy: 0.5," "fx: 0.5, fy: 0.5," "radius: 0.5, " "stop: 0 rgba(255, 255, 255, 100), " "stop: 1 rgba(0, 0, 0, 0));" "}" "QToolButton:pressed {" "background-color: qradialgradient(cx: 0.5, cy: 0.5," "fx: 0.5, fy: 0.5," "radius: 0.5, " "stop: 0 rgba(255, 255, 255, 200), " "stop: 1 rgba(0, 0, 0, 0));" "}") font = QFont() font.setPixelSize(10) toolButton.setFont(font) # Connect the clicked signal to the action trigger def pushed(): toolButton.action.triggered.emit() setattr(toolButton, "pushed", pushed) toolButton.clicked.connect(toolButton.pushed) setattr(toolButton, "action", action) return toolButton
def CreateFlatButton(action): """ Create a custom flat button and style it so that it will look good on all platforms. """ toolButton = QToolButton() toolButton.setIcon(action.icon()) toolButton.setText(action.text()) toolButton.setAutoRaise(True) toolButton.setIconSize(QSize(32, 32)) toolButton.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) if sys.platform.startswith('darwin'): # Bug for Mac: QToolButtons do not react to setAutoRaise so # can't be made flat when they are not used inside a toolbar. # Setting a custom style sheet with border to none fixes this. # But then it looses all its highlight and pressed visual cues # so some extra styling needs to be done to provide some nice # visual feedback on hover and pressed states. toolButton.setStyleSheet("QToolButton {" "border: none;" "} " "QToolButton:hover {" "background-color: qradialgradient(cx: 0.5, cy: 0.5," "fx: 0.5, fy: 0.5," "radius: 0.5, " "stop: 0 rgba(255, 255, 255, 100), " "stop: 1 rgba(0, 0, 0, 0));" "}" "QToolButton:pressed {" "background-color: qradialgradient(cx: 0.5, cy: 0.5," "fx: 0.5, fy: 0.5," "radius: 0.5, " "stop: 0 rgba(255, 255, 255, 200), " "stop: 1 rgba(0, 0, 0, 0));" "}") font = QFont() font.setPixelSize(10) toolButton.setFont(font) # Connect the clicked signal to the action trigger def pushed(): toolButton.action.triggered.emit() setattr(toolButton, "pushed", pushed) toolButton.clicked.connect(toolButton.pushed) setattr(toolButton, "action", action) return toolButton
class StatusWidget(QFrame): """ StatusWidget """ def __init__(self): QFrame.__init__(self) self._color = [220, 220, 220] self._font = QFont() self._font.setPixelSize(10) self._pen = QPen(QColor(100, 100, 100, 255)) self.label = QLabel() self.label.setWordWrap(True) self.label.setFont(self._font) self.label.setMaximumWidth(300) self.label.setMaximumHeight(36) self.label.setMinimumHeight(36) layout = QGridLayout() layout.setSpacing(0) layout.addWidget(self.label) self.setLayout(layout) self.setMinimumWidth(360) self.setMaximumWidth(360) def setText(self, text): self.label.setText(text) def paintEvent(self, ev): size = self.size() height = size.height()-5 width = size.width()-5 offset = 0.5 rect = QRectF(2.0+offset, 2.0+offset, width, height) painter = QPainter(self) painter.setPen(self._pen) painter.setBrush(QColor(self._color[0], self._color[1], self._color[2])) painter.setRenderHint(QPainter.Antialiasing) painter.setRenderHint(QPainter.HighQualityAntialiasing) painter.drawRoundedRect(rect, 4, 4)
class StatusWidget(QFrame): """ StatusWidget """ def __init__(self): QFrame.__init__(self) self._color = [220, 220, 220] self._font = QFont() self._font.setPixelSize(10) self._pen = QPen(QColor(100, 100, 100, 255)) self.label = QLabel() self.label.setWordWrap(True) self.label.setFont(self._font) self.label.setMaximumWidth(300) self.label.setMaximumHeight(36) self.label.setMinimumHeight(36) layout = QGridLayout() layout.setSpacing(0) layout.addWidget(self.label) self.setLayout(layout) self.setMinimumWidth(360) self.setMaximumWidth(360) def setText(self, text): self.label.setText(text) def paintEvent(self, ev): size = self.size() height = size.height() - 5 width = size.width() - 5 offset = 0.5 rect = QRectF(2.0 + offset, 2.0 + offset, width, height) painter = QPainter(self) painter.setPen(self._pen) painter.setBrush(QColor(self._color[0], self._color[1], self._color[2])) painter.setRenderHint(QPainter.Antialiasing) painter.setRenderHint(QPainter.HighQualityAntialiasing) painter.drawRoundedRect(rect, 4, 4)
def buildLabels(self, label): self.label = QLabel(label) self.data = QLabel(constants.DEFAULT_LABEL) # Center the text in the labels self.label.setAlignment(Qt.AlignCenter) self.data.setAlignment(Qt.AlignCenter) # Bold the label label labelFont = QFont() labelFont.setBold(True) # Make the data label font obnoxiously large dataFont = QFont() dataFont.setPixelSize(20) self.label.setFont(labelFont) self.data.setFont(dataFont)
def firstPage(self): for i in range( self.mainLayout.count() ): item = self.mainLayout.itemAt(0) item.widget().setParent( None ) title = QLabel( "<p style='color:rgb( 137,129,120 )'>Welcome to the PingoTools Installer</p>" ) title.setFixedHeight( 50 ) titleFont = QFont() titleFont.setPixelSize( 18 ) titleFont.setBold( True ) titleFont.setFamily( "Helvetica [Cronyx]" ) title.setAlignment( QtCore.Qt.AlignCenter ) title.setFont( titleFont ) description = QLabel() description.setAlignment( QtCore.Qt.AlignCenter ) buttonsWidget = QWidget(); buttonsWidget.setMaximumHeight( 50 ) buttonsLayout = QHBoxLayout( buttonsWidget ) emptyArea = QLabel() buttonNext = QPushButton( 'Next > ' ) buttonCancel = QPushButton( 'Cancel' ) buttonsLayout.addWidget( emptyArea ) buttonsLayout.addWidget( buttonNext ); buttonNext.setFixedWidth( 100 ) buttonsLayout.addWidget( buttonCancel ); buttonCancel.setFixedWidth( 100 ) self.mainLayout.addWidget( title ) self.mainLayout.addWidget( description ) self.mainLayout.addWidget( buttonsWidget ) origWidth = 500 frontImage = QImage() frontImage.load( os.path.dirname( __file__ ) + '/images/pingoTools_main.jpg' ) trValue = QTransform().scale( float(origWidth)/frontImage.width(), float(origWidth)/frontImage.width() ) transformedImage = frontImage.transformed( trValue ) pixmap = QPixmap.fromImage( transformedImage ) description.setPixmap( pixmap ) description.setGeometry( 0,0, transformedImage.width() , transformedImage.height() ) description.paintEvent(QPaintEvent(QtCore.QRect( 0,0,self.width(), self.height() ))) QtCore.QObject.connect( buttonNext, QtCore.SIGNAL( 'clicked()' ), self.secondPage ) QtCore.QObject.connect( buttonCancel, QtCore.SIGNAL( 'clicked()' ), self.cmd_cancel )
def tag_image(source, dest, tag, font, fontsize, x, y, width, height, aspectx, aspecty, red, green, blue, bold=False, italic=False): """docstring for tag_image""" app = QApplication.instance() pixmap = QPixmap(source) color = QColor(red,green,blue) font = QFont(font) font.setPixelSize(int(fontsize*pixmap.height())) font.setItalic(italic) font.setBold(bold) painter = QPainter(pixmap) painter.setPen(color) painter.setFont(font); painter.drawText(x*pixmap.width(),y*pixmap.height(), tag) painter.end() # Resize and save return pixmap.toImage().scaled(width*aspectx, height*aspecty, Qt.KeepAspectRatioByExpanding, Qt.SmoothTransformation).scaled(width, height, Qt.IgnoreAspectRatio, Qt.SmoothTransformation).save(dest)
def PlainText(painter,widget): painter.setPen(widget.textColor()) font = QFont() font.setPixelSize(widget.fontSize()) font.setOverline(widget.overline()) font.setUnderline(widget.underlined()) font.setItalic(widget.italic()) font.setStrikeOut(widget.strikeOut()) font.setWeight(widget.fontWeight()) font.setFamily(widget.fontFamily()) font.setCapitalization( QFont.Capitalization(widget.textTransform()) ) font.setStretch(widget.fontStretch()) font.setLetterSpacing(QFont.SpacingType(widget.letterSpacingType()), widget.letterSpacing()) font.setWordSpacing(widget.wordSpacing()) painter.setFont(font) painter.drawText(0,0,100,100,widget.textAlignment(),widget.text())
def setsampletxt(self, i): font = QFont() font.setPixelSize(i) self.sampletxt.setFont(font)