コード例 #1
0
ファイル: skinparse.py プロジェクト: AlexUlrich/digsby
def makeBorder(borderdesc):

    vals = borderdesc.split()

    if not vals: return wx.TRANSPARENT_PEN

    if vals[0].lower() == 'border':
        vals = vals[1:]

    d = S()
    for elem in vals:
        elem = elem.lower()
        if elem.endswith('px') and isint(elem[:-2]):
            d.size = int(elem[:-2])
        elif isint(elem):
            d.size = int(elem)
        else:
            penstyle = penstyle_aliases.get(elem, elem)
            if penstyle in penstyles:
                d.style = penstyle
            else:
                try: d.color = colorfor(elem)
                except ValueError: pass

    return _pen_from_dict(d)
コード例 #2
0
ファイル: skinparse.py プロジェクト: sgricci/digsby
def makeBorder(borderdesc):

    vals = borderdesc.split()

    if not vals: return wx.TRANSPARENT_PEN

    if vals[0].lower() == 'border':
        vals = vals[1:]

    d = S()
    for elem in vals:
        elem = elem.lower()
        if elem.endswith('px') and isint(elem[:-2]):
            d.size = int(elem[:-2])
        elif isint(elem):
            d.size = int(elem)
        else:
            penstyle = penstyle_aliases.get(elem, elem)
            if penstyle in penstyles:
                d.style = penstyle
            else:
                try:
                    d.color = colorfor(elem)
                except ValueError:
                    pass

    return _pen_from_dict(d)
コード例 #3
0
ファイル: skinparse.py プロジェクト: sgricci/digsby
def _pen_from_dict(d):
    '''
    Give {color: 'blue', width:5, style:'dot'}, makes the appropriate
    wxPen object.
    '''

    color = colorfor(d.get('color', 'black'))

    width = int(d.get('size', 1))

    style = d.get('style', 'solid')

    if not style: style = 'solid'

    if not style in penstyles:
        raise SkinException('invalid pen style: "%s"' % style)

    import wx
    style = getattr(wx, style.upper())

    if not isinstance(color, wx.Colour):
        raise TypeError('not a color: %r' % color)

    return wx.Pen(color, width, style)
コード例 #4
0
ファイル: skinparse.py プロジェクト: AlexUlrich/digsby
def _pen_from_dict(d):
    '''
    Give {color: 'blue', width:5, style:'dot'}, makes the appropriate
    wxPen object.
    '''

    color = colorfor(d.get('color', 'black'))

    width = int(d.get('size', 1))

    style = d.get('style', 'solid')

    if not style: style = 'solid'

    if not style in penstyles:
        raise SkinException('invalid pen style: "%s"' % style)

    import wx
    style = getattr(wx, style.upper())

    if not isinstance(color, wx.Colour):
        raise TypeError('not a color: %r' % color)

    return wx.Pen(color, width, style)
コード例 #5
0
ファイル: skinparse.py プロジェクト: sgricci/digsby
def makeBrush(brushdesc):
    '''
    Makes a rectangular skin brush given strings like

    red
    red white blue
    vertical green white
    red rounded
    red rounded 10
    blue shadow
    0xffffee 0x123456
    '''

    if isinstance(brushdesc, list):
        return SkinStack(makeBrush(e) for e in brushdesc)
    elif isinstance(brushdesc, int):
        return SkinColor(colorfor(brushdesc))
    elif brushdesc is None:
        return None

    elems = brushdesc.split()

    try:
        b = elems.index('border')
    except ValueError:
        border = None
    else:
        border = makeBorder(' '.join(elems[b:]))
        elems = elems[:b]

    first = elems[0]
    if any(first.endswith(e) for e in image_exts):
        return makeImage(brushdesc)

    shadow = highlight = rounded = False
    colors = []
    direction = 'vertical'

    for i, elem in enumerate(elems):
        elem = elem.lower()

        if elem in ('h', 'v', 'horizontal', 'vertical'):
            direction = {'h': 'horizontal', 'v': 'vertical'}.get(elem, elem)
        elif elem == 'rounded':
            if len(elems) > i + 1 and isint(elems[i + 1]):
                rounded = float(elems[i + 1])
            else:
                rounded = DEFAULT_ROUNDED_RADIUS
        elif elem == 'highlight':
            highlight = True
        elif elem == 'shadow':
            shadow = True
        elif elem.endswith('%') and isint(elem[:-1]) and colors:
            # replace the last wxColor in colors with the same color and
            # a new alpha value, so strings like "blue red 40%" produce
            # [wx.Colour(0, 0, 255, 255), wx.Colour(255, 0, 0, 102)]
            #
            # (I know there is a wxColour.Set method but it didn't work for me)
            alpha_value = clamp(float(elem[:-1]) / 100.00 * 255.0, 0, 255)
            rgba = tuple(colors[-1])[:3] + (alpha_value, )
            colors[-1] = wx.Colour(*rgba)
        else:
            try:
                colors.append(colorfor(elem))
            except ValueError:
                pass

    kwargs = dict(rounded=rounded,
                  shadow=shadow,
                  highlight=highlight,
                  border=border)

    if len(colors) == 0:
        raise SkinException('no colors specified in "%s"' % brushdesc)
    elif len(colors) == 1:
        # one color -> SkinColor
        return SkinColor(colors[0], **kwargs)
    else:
        # multiple colors -> SkinGradient
        return SkinGradient(direction, colors, **kwargs)
コード例 #6
0
ファイル: skintransform.py プロジェクト: sgricci/digsby
def r_fontcolor(v):
    return colorfor(v)
コード例 #7
0
ファイル: skintransform.py プロジェクト: sgricci/digsby
def r_color(v):
    return wx.Brush(colorfor(v))
コード例 #8
0
ファイル: skintransform.py プロジェクト: sgricci/digsby
def er_color(v):
    return colorfor(v)
コード例 #9
0
ファイル: skintransform.py プロジェクト: sgricci/digsby
def er_colors(v):
    for colorname, color in v.iteritems():
        v[colorname] = colorfor(color)
    return v
コード例 #10
0
ファイル: skintransform.py プロジェクト: AlexUlrich/digsby
def r_fontcolor(v):
    return colorfor(v)
コード例 #11
0
ファイル: skintransform.py プロジェクト: AlexUlrich/digsby
def r_color(v):
    return wx.Brush(colorfor(v))
コード例 #12
0
ファイル: skintransform.py プロジェクト: AlexUlrich/digsby
def er_color(v):
    return colorfor(v)
コード例 #13
0
ファイル: skintransform.py プロジェクト: AlexUlrich/digsby
def er_colors(v):
    for colorname, color in v.iteritems():
        v[colorname] = colorfor(color)
    return v
コード例 #14
0
ファイル: skinparse.py プロジェクト: AlexUlrich/digsby
def makeBrush(brushdesc):
    '''
    Makes a rectangular skin brush given strings like

    red
    red white blue
    vertical green white
    red rounded
    red rounded 10
    blue shadow
    0xffffee 0x123456
    '''

    if isinstance(brushdesc, list):
        return SkinStack(makeBrush(e) for e in brushdesc)
    elif isinstance(brushdesc, int):
        return SkinColor(colorfor(brushdesc))
    elif brushdesc is None:
        return None

    elems = brushdesc.split()

    try:
        b = elems.index('border')
    except ValueError:
        border = None
    else:
        border = makeBorder(' '.join(elems[b:]))
        elems = elems[:b]

    first = elems[0]
    if any(first.endswith(e) for e in image_exts):
        return makeImage(brushdesc)

    shadow = highlight = rounded = False
    colors = []
    direction = 'vertical'

    for i, elem in enumerate(elems):
        elem = elem.lower()

        if elem in ('h','v', 'horizontal', 'vertical'):
            direction = {'h': 'horizontal',
                         'v': 'vertical'}.get(elem, elem)
        elif elem == 'rounded':
            if len(elems) > i + 1 and isint(elems[i+1]):
                rounded = float(elems[i+1])
            else:
                rounded = DEFAULT_ROUNDED_RADIUS
        elif elem == 'highlight': highlight = True
        elif elem == 'shadow':    shadow = True
        elif elem.endswith('%') and isint(elem[:-1]) and colors:
            # replace the last wxColor in colors with the same color and
            # a new alpha value, so strings like "blue red 40%" produce
            # [wx.Colour(0, 0, 255, 255), wx.Colour(255, 0, 0, 102)]
            #
            # (I know there is a wxColour.Set method but it didn't work for me)
            alpha_value = clamp(float(elem[:-1])/100.00 * 255.0, 0, 255)
            rgba = tuple(colors[-1])[:3] + (alpha_value,)
            colors[-1] = wx.Colour(*rgba)
        else:
            try: colors.append(colorfor(elem))
            except ValueError: pass

    kwargs = dict(rounded = rounded, shadow = shadow,
                  highlight = highlight, border = border)

    if len(colors) == 0:
        raise SkinException('no colors specified in "%s"' % brushdesc)
    elif len(colors) == 1:
        # one color -> SkinColor
        return SkinColor(colors[0], **kwargs)
    else:
        # multiple colors -> SkinGradient
        return SkinGradient(direction, colors, **kwargs)