Example #1
0
    def find_convo(self, name=(), count=(), type=(), f=None):
        '''
        Finds all conversation such that:
            All names in the sequence 'name' are also in the conversation, and vice versa
            the number of buddies is in the sequence 'count'
            the type of the conversation is in the sequence 'type'
            f(conversation) is True

        If an argument is not provided, it is ignored.

        A list is returned. (Empty if no conversations match)
        '''
        result = []

        if f is None:
            f = lambda x: True

        if not funcs.isiterable(name):
            name = name,
        if not funcs.isiterable(type):
            type = type,
        if not funcs.isiterable(count):
            count = count,

        functions = [f]

        def namechecker(c):
            mynames = set(name)
            cnames = set(c.buddies)

            mynames.discard(self.self_buddy.name)
            cnames.discard(self.self_buddy.name)

            return mynames == cnames

        if name: functions.append(namechecker)

        def typechecker(c):
            return c.type in type

        if type: functions.append(typechecker)

        def countchecker(c):
            return len(c.room_list) in count

        if count: functions.append(countchecker)

        import inspect
        log.debug('find_convo: name=%s,count=%s,type=%s,f=%s', name, count,
                  type,
                  inspect.getsource(f).strip())
        for conv in self._convs.values():
            log.debug('%r: names=%r,count=%s,type=%s,id=%s', conv,
                      conv.buddies, len(conv.room_list), conv.type, id(conv))
            if all(_f(conv) for _f in functions):
                result.append(conv)

        return result
Example #2
0
    def find_convo(self, name=(), count=(), type=(), f=None):
        '''
        Finds all conversation such that:
            All names in the sequence 'name' are also in the conversation, and vice versa
            the number of buddies is in the sequence 'count'
            the type of the conversation is in the sequence 'type'
            f(conversation) is True

        If an argument is not provided, it is ignored.

        A list is returned. (Empty if no conversations match)
        '''
        result = []

        if f is None:
            f = lambda x:True

        if not funcs.isiterable(name):
            name = name,
        if not funcs.isiterable(type):
            type = type,
        if not funcs.isiterable(count):
            count = count,

        functions = [f]

        def namechecker(c):
            mynames = set(name)
            cnames  = set(c.buddies)

            mynames.discard(self.self_buddy.name)
            cnames. discard(self.self_buddy.name)

            return mynames == cnames

        if name: functions.append(namechecker)

        def typechecker(c):
            return c.type in type

        if type: functions.append(typechecker)

        def countchecker(c):
            return len(c.room_list) in count

        if count: functions.append(countchecker)

        import inspect
        log.debug('find_convo: name=%s,count=%s,type=%s,f=%s',
                    name,count,type, inspect.getsource(f).strip())
        for conv in self._convs.values():
            log.debug('%r: names=%r,count=%s,type=%s,id=%s',
                        conv, conv.buddies, len(conv.room_list), conv.type, id(conv))
            if all(_f(conv) for _f in functions):
                result.append(conv)

        return result
Example #3
0
    def Draw( self, dc, rect, selected, obj, depth, expanded, index, hover ):
        s = self.skin

        # apply margins
        rect = rect.AddMargins(wx.Rect(*s.margins)).AddMargins(wx.Rect(0, s.padding.y, 0, s.padding.y))

        # Group font is drawn with the same as the buddies.
        fontface = self.font_face
        font = safefont(fontface, try_this(lambda: int(self.font_size), 10), bold = True)
        dc.SetFont( font )

        # indent for depth
        rect = rect.Subtract(left = self.group_indent * depth)

        # Expander triangles.
        if isiterable( obj ):
            triangle = self.get_expander(selected, expanded, hover)

            if triangle is not None:
                dc.DrawBitmap(triangle, rect.x, rect.VCenter(triangle), True)
                rect = rect.Subtract(left = triangle.Width + s.padding.x)

        # decide on a foreground text color
        if selected: fg = s.fontcolors.groupselected
        elif hover:  fg = s.fontcolors.grouphover
        else:        fg = s.fontcolors.group
        dc.SetTextForeground( fg )

        # the actual text label
        dc.DrawTruncatedText(obj.display_string, rect, alignment = lmiddle)
Example #4
0
    def __init__(self, parent, start=0, stop=None, step=1, value=0):
        if isiterable(start):
            values = start
        else:
            if stop is None:
                start, stop = 0, start

            if start > stop and step > 0:
                step *= -1

            values = range(start, stop, step)

        max_ = max(values)
        min_ = min(values)
        reverse = step < 0

        self.start = start
        self.step = step

        style = wx.SL_HORIZONTAL  #| wx.SL_AUTOTICKS | wx.SL_LABELS
        style |= wx.SL_INVERSE * reverse

        wx.Slider.__init__(self,
                           value=value,
                           minValue=min_,
                           maxValue=max_,
                           parent=parent,
                           style=style)
        self.SetTickFreq(step, start)
Example #5
0
def _flatten(L, forbidden = ()):
    # some loop variables
    i, size = 0, len(L)

    while i < size:
        if isiterable(L[i]) and not isinstance(L[i], forbidden):
            L[i:i+1] = L[i]
            size = len(L)
        else:
            i += 1

    return L
Example #6
0
    def on_sck_connect(self, s):

        old_s = self.socket
        self.socket = s

        if old_s not in (self.socket, None):
            self.close_transport(old_s)

        self.socket.unbind('on_connect', self.on_sck_connect)
        self.socket.bind('on_message', self.on_message)

        from common import pref
        user_vers = pref('msn.versions', None)

        if user_vers is not None and isiterable(user_vers) and len(user_vers) > 0:
            self.versions = user_vers

        self.init_ns_connection(self.versions)
Example #7
0
    def on_sck_connect(self, s):

        old_s = self.socket
        self.socket = s

        if old_s not in (self.socket, None):
            self.close_transport(old_s)

        self.socket.unbind('on_connect', self.on_sck_connect)
        self.socket.bind('on_message', self.on_message)

        from common import pref
        user_vers = pref('msn.versions', None)

        if user_vers is not None and isiterable(
                user_vers) and len(user_vers) > 0:
            self.versions = user_vers

        self.init_ns_connection(self.versions)
Example #8
0
    def __init__(self, parent, start=0, stop=None, step=1, value=0):
        if isiterable(start):
            values = start
        else:
            if stop is None:
                start, stop = 0, start

            if start > stop and step > 0:
                step *= -1

            values = range(start, stop, step)

        max_ = max(values)
        min_ = min(values)
        reverse = step < 0

        self.start = start
        self.step = step

        style = wx.SL_HORIZONTAL #| wx.SL_AUTOTICKS | wx.SL_LABELS
        style |= wx.SL_INVERSE * reverse

        wx.Slider.__init__(self, value=value, minValue=min_, maxValue=max_, parent=parent, style = style)
        self.SetTickFreq(step, start)
Example #9
0
 def num_online(self):
     from Contact import Contact
     if isiterable(self) and not isinstance(self, Contact):
         return sum(elt.num_online for elt in self)
     else:
         return int(self.online)
Example #10
0
 def num_online(self):
     from Contact import Contact
     if isiterable(self) and not isinstance(self, Contact):
         return sum(elt.num_online for elt in self)
     else:
         return int(self.online)