Beispiel #1
0
    def update_label_font_display(self, newLabelFont):
        """ Update the displayed font properties for a newly
        selected label font.

        Updated properties are font style, size, example text.

        """

        # block signals from to avoid that update_current_label_font
        # is called multiple times. We'll call it once at the end
        self.labelStyleComboBox.blockSignals(True)
        self.labelSizeComboBox.blockSignals(True)

        fontFamily = newLabelFont.family()
        fontDatabase = QFontDatabase()

        availableStyles  = fontDatabase.styles(fontFamily)
        targetStyle      = fontDatabase.styleString(newLabelFont)
        targetStyleIndex = 0

        # FIXME: There seems to be a bug in Qt 4.8
        # "Normal" styleStrings are "Regular" in styles leading to
        # a mismatch below
        if QT_VERSION >= 0x040800:
            if targetStyle == "Normal":
                targetStyle = "Regular"

        self.labelStyleComboBox.clear()
        for (index, style) in enumerate(availableStyles):
            self.labelStyleComboBox.addItem(style)

            if targetStyle == style:
                targetStyleIndex = index

        self.labelStyleComboBox.setCurrentIndex(targetStyleIndex)

        availableSizes  = fontDatabase.pointSizes(fontFamily)
        targetSize      = newLabelFont.pointSize()
        targetSizeIndex = 0
        self.labelSizeComboBox.clear()
        for (index, size) in enumerate(availableSizes):
            self.labelSizeComboBox.addItem(str(size))

            if targetSize == size:
                targetSizeIndex = index

        self.labelSizeComboBox.setCurrentIndex(targetSizeIndex)

        self.update_current_label_font()

        # turn signals back on
        self.labelStyleComboBox.blockSignals(False)
        self.labelSizeComboBox.blockSignals(False)
    def update_label_font_display(self, newLabelFont):
        """ Update the displayed font properties for a newly
        selected label font.

        Updated properties are font style, size, example text.

        """

        # block signals from to avoid that update_current_label_font
        # is called multiple times. We'll call it once at the end
        self.labelStyleComboBox.blockSignals(True)
        self.labelSizeComboBox.blockSignals(True)

        fontFamily = newLabelFont.family()
        fontDatabase = QFontDatabase()

        availableStyles = fontDatabase.styles(fontFamily)
        targetStyle = fontDatabase.styleString(newLabelFont)
        targetStyleIndex = 0

        # FIXME: There seems to be a bug in Qt 4.8
        # "Normal" styleStrings are "Regular" in styles leading to
        # a mismatch below
        if QT_VERSION >= 0x040800:
            if targetStyle == "Normal":
                targetStyle = "Regular"

        self.labelStyleComboBox.clear()
        for (index, style) in enumerate(availableStyles):
            self.labelStyleComboBox.addItem(style)

            if targetStyle == style:
                targetStyleIndex = index

        self.labelStyleComboBox.setCurrentIndex(targetStyleIndex)

        availableSizes = fontDatabase.pointSizes(fontFamily)
        targetSize = newLabelFont.pointSize()
        targetSizeIndex = 0
        self.labelSizeComboBox.clear()
        for (index, size) in enumerate(availableSizes):
            self.labelSizeComboBox.addItem(str(size))

            if targetSize == size:
                targetSizeIndex = index

        self.labelSizeComboBox.setCurrentIndex(targetSizeIndex)

        self.update_current_label_font()

        # turn signals back on
        self.labelStyleComboBox.blockSignals(False)
        self.labelSizeComboBox.blockSignals(False)