Exemple #1
0
 def findFont(self, name, fail=None):
     element = self.findChild(name)
     if (element):
         font = QFont()
         font.fromString(element.attribute('value'))
         return font
     elif (fail):
         return fail
     else:
         return QFont()
Exemple #2
0
 def load_presentation(self, config):
     if 'restedit' in config:
         for key, value in config['restedit']:
             if key == 'font':
                 qtfont = QFont()
                 if qtfont.fromString(value):
                     self.setFont(qtfont)
Exemple #3
0
def getFontFromSetting(setting_data, default_font=None):
    import hex.utils as utils

    font = default_font or QFont()
    if isinstance(setting_data, str):
        stored_font = QFont()
        ok = stored_font.fromString(setting_data)
        return stored_font if ok else font
    elif isinstance(setting_data, (tuple, list)):
        for font_data in setting_data:
            if isinstance(font_data, str):
                stored_font = QFont()
                ok = stored_font.fromString(font_data)
                if ok and utils.isFontInstalled(stored_font.family()):
                    return stored_font
    return font
 def startStyle(self, attrs):
     """
     Handler method for the "Style" start tag.
     
     @param attrs list of tag attributes
     """
     self.buffer = ""
     
     if self.lexer is not None:
         style = attrs.get("style")
         if style is not None:
             style = int(style)
             
             color = attrs.get("color")
             if color is None:
                 color = self.lexer.defaultColor(style)
             else:
                 color = QColor(color)
             self.lexer.setColor(color, style)
             
             paper = attrs.get("paper")
             if paper is None:
                 paper = self.lexer.defaultPaper(style)
             else:
                 paper = QColor(paper)
             self.lexer.setPaper(paper, style)
             
             fontStr = attrs.get("font")
             if fontStr is None:
                 font = self.lexer.defaultFont(style)
             else:
                 font = QFont()
                 font.fromString(fontStr)
             self.lexer.setFont(font, style)
             
             eolfill = attrs.get("eolfill")
             if eolfill is None:
                 eolfill = self.lexer.defaulEolFill(style)
             else:
                 eolfill = int(eolfill)
             self.lexer.setEolFill(eolfill, style)
Exemple #5
0
def buildFont( fontAsString ):
    " Converts a string into QFont object "
    fontAsString = fontAsString.strip()
    font = QFont()
    font.fromString( fontAsString )
    return font
Exemple #6
0
def buildFont(fontAsString):
    " Converts saved font into QFont object "
    fontAsString = fontAsString.strip()
    font = QFont()
    font.fromString(fontAsString)
    return font
Exemple #7
0
    def restoreValue(self, fail=None):

        valtype = self.attribute('type')
        value = None

        # Restore a list item
        if (valtype == 'list'):
            value = []
            for child in self.children():
                value.append(child.restoreValue())

        # Restore a dictionary item
        elif (valtype == 'dict'):
            value = {}
            for child in self.children():
                value[child.attribute('key')] = child.restoreValue()

        # Record a qdatetime
        elif (valtype == 'QDateTime'):
            value = QDateTime.fromString(self.attribute('value'),
                                         'yyyy-MM-dd hh:mm:ss')

        # Record a qdate
        elif (valtype == 'QDate'):
            value = QDate.fromString(self.attribute('value'), 'yyyy-MM-dd')

        # Restore a QRect
        elif (valtype == 'QRect'):
            value = self.findRect('rect')

        # Restore a QRectF
        elif (valtype == 'QRectF'):
            value = self.findRectF('rect')

        # Restore a QSize
        elif (valtype == 'QSize'):
            value = self.findSize('size')

        # Restore a QSizeF
        elif (valtype == 'QSizeF'):
            value = self.findSizeF('size')

        # Restore a QPoint
        elif (valtype == 'QPoint'):
            value = self.findPoint('point')

        # Restore a QPointF
        elif (valtype == 'QPointF'):
            value = self.findPointF('point')

        # Restore a QColor
        elif (valtype == 'QColor'):
            value = self.findColor('color')

        # restore a QFont
        elif (valtype == 'QFont'):
            value = QFont()
            value.fromString(self.attribute('value'))

        # Restore a string
        elif (valtype in ('str', 'unicode', 'QString')):
            value = unicode(self.attribute('value'))

        elif (valtype == 'ViewMode'):
            # If treated as a basic value would return fail
            value = int(self.attribute('value'))

        # Restore a QByteArray (Experimental)
        elif (valtype == 'QByteArray'):
            value = QByteArray.fromPercentEncoding(self.attribute('value', ''))

        # Restore a Qt.CheckState
        elif valtype == 'CheckState':
            value = Qt.CheckState(self.attribute('value', 0))

        # Restore a basic value
        else:
            try:
                value = eval('%s(%s)' % (valtype, self.attribute('value')))
            except:
                value = fail

        return value