Exemple #1
0
    def SetSelections(self, sel):
        'Set the selection state of this list. sel must be iterable'

        if not self.SelectionEnabled:
            return

        myclamp = lambda x: clamp(x, 0, len(self.data) - 1)

        torefresh = self._selection.copy()
        self._selection = set(myclamp(x) for x in sel)

        if not len(self.rows): self._selection = set()
        for i in self._selection:
            assert i >= 0 and i < len(self.rows)

        for i in self._selection.difference(torefresh):
            self.emit_selected_event(i)
        for i in torefresh.difference(self._selection):
            self.emit_deselected_event(i)

        if self.delete_button:
            self.delete_button.Enable(bool(self._selection))

        if not self.rows: return

        for i in set(myclamp(x) for x in torefresh.union(self._selection)):
            try:
                if i != myclamp(i): continue
                self.rows[i].Refresh()
            except IndexError, ie:
                import sys
                print >> sys.stderr, 'index:', i
                raise ie
Exemple #2
0
    def SetSelections(self, sel):
        'Set the selection state of this list. sel must be iterable'

        if not self.SelectionEnabled:
            return

        myclamp = lambda x: clamp(x, 0, len(self.data)-1)

        torefresh = self._selection.copy()
        self._selection = set(myclamp(x) for x in sel)

        if not len(self.rows): self._selection = set()
        for i in self._selection: assert i >= 0 and i < len(self.rows)


        for i in self._selection.difference(torefresh):
            self.emit_selected_event(i)
        for i in torefresh.difference(self._selection):
            self.emit_deselected_event(i)

        if self.delete_button:
            self.delete_button.Enable(bool(self._selection))

        if not self.rows: return

        for i in set(myclamp(x) for x in torefresh.union(self._selection)):
            try:
                if i != myclamp(i): continue
                self.rows[i].Refresh()
            except IndexError, ie:
                import sys
                print >> sys.stderr, 'index:', i
                raise ie
Exemple #3
0
 def _rem_clicked(self, e):
     sel = self.list.Selection
     if sel == wx.NOT_FOUND: return
     obj = self.list.data[sel]
     #_str = self.list.GetString(sel)
     self.remove_item(obj)
     first = clamp(sel, 0, len(self.list.data) - 1)
     print first, len(self.list.data) - 1
     if first >= 0:
         self.list.Selections = [first]
Exemple #4
0
 def _rem_clicked(self, e):
     sel = self.list.Selection
     if sel == wx.NOT_FOUND: return
     obj = self.list.data[sel]
     #_str = self.list.GetString(sel)
     self.remove_item(obj)
     first = clamp(sel, 0, len(self.list.data)-1)
     print first, len(self.list.data)-1
     if first >= 0:
         self.list.Selections = [first]
Exemple #5
0
    def fade_tick(self):
        start, end, step = self.range
        self.value += step
        try:
            setalpha(self.window, clamp(self.value, 0, 255))
        except wx.PyDeadObjectError:
            return self.stop()

        if step < 0:
            return self.value > end
        elif step > 0:
            return self.value < end
        else:
            raise AssertionError('FXTimer has a zero step!')
Exemple #6
0
    def fade_tick(self):
        start, end, step = self.range
        self.value += step
        try:
            setalpha(self.window, clamp(self.value, 0, 255))
        except wx.PyDeadObjectError:
            return self.stop()

        if step < 0:
            return self.value > end
        elif step > 0:
            return self.value < end
        else:
            raise AssertionError('FXTimer has a zero step!')
Exemple #7
0
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)
Exemple #8
0
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)