Пример #1
0
 def __init__(self, buffer):
     self.cleared = False
     self.buffer = buffer
     self.walker = []
     self.unread = 0
     self.count = 0
     self.last_read = 0
     self.page = 1
     self.filter = FilterStatus()
     self.timeline = urwid.ListBox(urwid.SimpleListWalker([]))
Пример #2
0
 def __init__(self, buffer):
     self.cleared = False
     self.buffer = buffer
     self.walker = []
     self.unread = 0
     self.count = 0
     self.last_read = 0
     self.page = 1
     self.filter = FilterStatus()
     self.timeline = urwid.ListBox(urwid.SimpleListWalker([]))
Пример #3
0
 def __init__(self):
     self.statuses = []
     self.unread = 0
     self.count = 0
     self.last_read = 0
     self.current = 0
     self.first = 0
     self.last = 0
     self.page = 1
     self.filter = FilterStatus()
Пример #4
0
 def __init__(self):
     self.statuses = []
     self.walker = []
     self.unread = 0
     self.count = 0
     self.last_read = 0
     self.current = 0
     self.first = 0
     self.last = 0
     self.page = 1
     self.filter = FilterStatus()
     self.timeline = urwid.ListBox(urwid.SimpleListWalker([]))
Пример #5
0
class Timeline(object):
    def __init__(self, buffer):
        self.cleared = False
        self.buffer = buffer
        self.walker = []
        self.unread = 0
        self.count = 0
        self.last_read = 0
        self.page = 1
        self.filter = FilterStatus()
        self.timeline = urwid.ListBox(urwid.SimpleListWalker([]))

    def append_new_statuses(self, retreive):
        retreive = self.filter_statuses(retreive)

        if retreive:
            self.last_read = retreive[0].id

            if len(self.walker) == 0 and not self.cleared:
                self.build_new_walker(retreive)
            else:
                self.add_to_walker(retreive)
            self.add_waterline()

    def add_to_walker(self, retreive):
        size = self.interface.loop.screen_size
        on_top = 'top' in self.timeline.ends_visible(size)
        focus_status, pos = self.walker.get_focus()
        for i, status in enumerate(retreive):
            # New statuses are insert
            if status.id == self.cleared:
                return
            while status.id != self.walker[0 + i].id:
                self.walker.insert(i, StatusWidget(status.id, status))
                if on_top:
                    self.timeline.set_focus(0)
                    self.timeline.set_focus(pos + i + 1)

            # otherwise it just been updated
            self.timeline.set_focus(pos)
            self.walker[i] = StatusWidget(status.id, status)

    def add_waterline(self):
        if self.buffer == 'home' and self.walker[0].id != None:
            div = urwid.Divider('-')
            div.id = None
            self.walker.insert(self.find_waterline(), div)

    def build_new_walker(self, retreive):
        items = []
        for i, status in enumerate(retreive):
            items.append(StatusWidget(status.id, status))
            self.walker = urwid.SimpleListWalker(items)
            self.timeline = urwid.ListBox(self.walker)
            import tyrs
            self.interface = tyrs.container['interface']
            urwid.connect_signal(self.walker, 'modified',
                                 self.interface.lazzy_load)

    def find_waterline(self):
        for i, v in enumerate(self.walker):
            if str(v.id) == self.interface.last_read_home:
                return i
        return 0

    def filter_statuses(self, statuses):
        filters = []
        for i, status in enumerate(statuses):
            if self.filter.filter_status(status):
                filters.append(i)
        filters.reverse()
        for f in filters:
            del statuses[f]

        return statuses

    def update_counter(self):
        self.count_statuses()
        self.count_unread()

    def append_old_statuses(self, statuses):
        if statuses == []:
            pass
        else:
            items = []
            for status in statuses:
                items.append(StatusWidget(status.id, status))
            self.walker.extend(items)
            self.count_statuses()
            self.count_unread()

    def count_statuses(self):
        try:
            self.count = len(self.walker)
        except TypeError:
            self.count = 0

    def count_unread(self):
        try:
            self.unread = 0
            for i in range(len(self.walker)):
                if self.walker[i].id == self.last_read:
                    break
                self.unread += 1
        except TypeError:
            self.unread = 0

    def reset(self):
        self.first = 0
        self.unread = 0

    def clear(self):
        urwid.disconnect_signal(self.walker, 'modified',
                                self.interface.lazzy_load)
        while len(self.walker) > 1:
            pop = self.walker.pop()
            self.cleared = pop.id
        if self.cleared == None:
            self.cleared = True

    def empty(self, buffer):
        self.__init__(buffer)

    def all_read(self):
        if self.count > 0:
            self.last_read = self.walker[0].id

    def go_up(self):
        focus_status, pos = self.walker.get_focus()
        if pos > 0:
            self.timeline.set_focus(pos - 1)

    def go_down(self):
        focus_status, pos = self.walker.get_focus()
        self.timeline.set_focus(pos + 1)
Пример #6
0
class Timeline(object):

    def __init__(self):
        self.statuses = []
        self.unread = 0
        self.count = 0
        self.last_read = 0
        self.current = 0
        self.first = 0
        self.last = 0
        self.page = 1
        self.filter = FilterStatus()

    def append_new_statuses(self, retreive):
        if not retreive:
            pass
        retreive = self.filter_statuses(retreive)
        # Fresh new start.
        if retreive:
            if self.statuses == []:
                self.statuses = retreive
                self.update_counter()
            # This mean there is no new status, we just leave then.
            elif retreive[0].id == self.statuses[0].id:
                pass
            # We may just don't have tweets, in case for DM for example
            elif len(retreive) == 0:
                pass
            # Finally, we append tweets
            else:
                for i in range(len(retreive)):
                    if retreive[i].id == self.statuses[0].id:
                        self.statuses = retreive[:i] + self.statuses
                        self.current += len(retreive[:i])
                self.update_counter()

    def filter_statuses(self, statuses):
        filters = []
        for i, status in enumerate(statuses):
            if self.filter.filter_status(status):
                filters.append(i)
        filters.reverse()
        for f in filters:
            del statuses[f]

        return statuses

    def update_counter(self):
        self.count_statuses()
        self.count_unread()

    def append_old_statuses(self, statuses):
        if statuses == []:
            pass
        else:
            self.statuses += statuses
            self.count_statuses()
            self.count_unread()

    def count_statuses(self):
        try:
            self.count = len(self.statuses)
        except TypeError:
            self.count = 0
            
    def count_unread(self):
        try:
            self.unread = 0
            for i in range(len(self.statuses)):
                if self.statuses[i].id == self.last_read:
                    break
                self.unread += 1
        except TypeError:
            self.unread = 0

    def reset(self):
        self.first = 0
        self.unread = 0

    def empty(self):
        self.__init__()

    def all_read(self):
        if self.count > 0:
            self.last_read = self.statuses[0].id
Пример #7
0
class Timeline(object):

    def __init__(self, buffer):
        self.cleared = False
        self.buffer = buffer
        self.walker = []
        self.unread = 0
        self.count = 0
        self.last_read = 0
        self.page = 1
        self.filter = FilterStatus()
        self.timeline = urwid.ListBox(urwid.SimpleListWalker([]))

    def append_new_statuses(self, retreive):
        retreive = self.filter_statuses(retreive)

        if retreive:
            self.last_read = retreive[0].id

            if len(self.walker) == 0 and not self.cleared:
                self.build_new_walker(retreive)
            else:
                self.add_to_walker(retreive)
            self.add_waterline()

    def add_to_walker(self, retreive):
        size = self.interface.loop.screen_size
        on_top = 'top' in self.timeline.ends_visible(size)
        focus_status, pos = self.walker.get_focus()
        for i, status in enumerate(retreive):
            # New statuses are insert
            if status.id == self.cleared:
                return
            while status.id != self.walker[0+i].id:
                self.walker.insert(i, StatusWidget(status.id, status))
                if on_top:
                    self.timeline.set_focus(0)
                    self.timeline.set_focus(pos+i+1)

            # otherwise it just been updated
            self.timeline.set_focus(pos)
            self.walker[i] = StatusWidget(status.id, status)

    def add_waterline(self):
        if self.buffer == 'home' and self.walker[0].id != None:
            div = urwid.Divider('-')
            div.id = None
            self.walker.insert(self.find_waterline(), div)

    def build_new_walker(self, retreive):
        items = []
        for i, status in enumerate(retreive):
            items.append(StatusWidget(status.id, status))
            self.walker = urwid.SimpleListWalker(items)
            self.timeline = urwid.ListBox(self.walker)
            import tyrs
            self.interface = tyrs.container['interface']
            urwid.connect_signal(self.walker, 'modified', self.interface.lazzy_load)

    def find_waterline(self):
        for i, v in enumerate(self.walker):
            if str(v.id) == self.interface.last_read_home:
                return i
        return 0

    def filter_statuses(self, statuses):
        filters = []
        for i, status in enumerate(statuses):
            if self.filter.filter_status(status):
                filters.append(i)
        filters.reverse()
        for f in filters:
            del statuses[f]

        return statuses

    def update_counter(self):
        self.count_statuses()
        self.count_unread()

    def append_old_statuses(self, statuses):
        if statuses == []:
            pass
        else:
            items = []
            for status in statuses:
                items.append(StatusWidget(status.id, status))
            self.walker.extend(items)
            self.count_statuses()
            self.count_unread()

    def count_statuses(self):
        try:
            self.count = len(self.walker)
        except TypeError:
            self.count = 0

    def count_unread(self):
        try:
            self.unread = 0
            for i in range(len(self.walker)):
                if self.walker[i].id == self.last_read:
                    break
                self.unread += 1
        except TypeError:
            self.unread = 0

    def reset(self):
        self.first = 0
        self.unread = 0

    def clear(self):
        urwid.disconnect_signal(self.walker, 'modified', self.interface.lazzy_load)
        while len(self.walker) > 1:
            pop = self.walker.pop()
            self.cleared = pop.id
        if self.cleared == None:
            self.cleared = True

    def empty(self, buffer):
        self.__init__(buffer)

    def all_read(self):
        if self.count > 0:
            self.last_read = self.walker[0].id

    def go_up(self):
        focus_status, pos = self.walker.get_focus()
        if pos > 0:
            self.timeline.set_focus(pos-1)

    def go_down(self):
        focus_status, pos = self.walker.get_focus()
        self.timeline.set_focus(pos+1)
Пример #8
0
class Timeline(object):

    def __init__(self):
        self.statuses = []
        self.unread = 0
        self.count = 0
        self.last_read = 0
        self.current = 0
        self.first = 0
        self.last = 0
        self.page = 1
        self.filter = FilterStatus()

    def append_new_statuses(self, retreive):
        retreive = self.filter_statuses(retreive)

        if retreive:
            if len(self.statuses) == 0:
                self.statuses = retreive
            else:
                for i, status in enumerate(self.statuses):
                    if retreive[-1].id == status.id:
                        try:
                            self.statuses = retreive + self.statuses[i+1:]
                        except IndexError:
                            self.statuses = retreive
            self.update_counter()

    def filter_statuses(self, statuses):
        filters = []
        for i, status in enumerate(statuses):
            if self.filter.filter_status(status):
                filters.append(i)
        filters.reverse()
        for f in filters:
            del statuses[f]

        return statuses

    def update_counter(self):
        self.count_statuses()
        self.count_unread()

    def append_old_statuses(self, statuses):
        if statuses == []:
            pass
        else:
            self.statuses += statuses
            self.count_statuses()
            self.count_unread()

    def count_statuses(self):
        try:
            self.count = len(self.statuses)
        except TypeError:
            self.count = 0
            
    def count_unread(self):
        try:
            self.unread = 0
            for i in range(len(self.statuses)):
                if self.statuses[i].id == self.last_read:
                    break
                self.unread += 1
        except TypeError:
            self.unread = 0

    def reset(self):
        self.first = 0
        self.unread = 0

    def empty(self):
        self.__init__()

    def all_read(self):
        if self.count > 0:
            self.last_read = self.statuses[0].id
Пример #9
0
class Timeline(object):

    def __init__(self):
        self.statuses = []
        self.walker = []
        self.unread = 0
        self.count = 0
        self.last_read = 0
        self.current = 0
        self.first = 0
        self.last = 0
        self.page = 1
        self.filter = FilterStatus()
        self.timeline = urwid.ListBox(urwid.SimpleListWalker([]))

    def append_new_statuses(self, retreive):
        retreive = self.filter_statuses(retreive)

        if retreive:
            items = []
            if len(self.walker) == 0:
                for i, status in enumerate(retreive):
                    items.append(StatusWidget(status.id, status))
                    self.walker = urwid.SimpleListWalker(items)
                    self.timeline = urwid.ListBox(self.walker)
            else:
                focus_status, pos = self.walker.get_focus()
                for i, status in enumerate(retreive):
                    while status.id != self.walker[0+i].id:
                        self.walker.insert(i, StatusWidget(status.id, status))
                        self.walker.set_focus(pos+i+1)
                    self.walker[i] = StatusWidget(status.id, status)

                #current_id = self.statuses[self.current].id
                #for i, status in enumerate(self.statuses):
                    #if retreive[-1].id == status.id:
                        #try:
                            #self.statuses = retreive + self.statuses[i+1:]
                            #self.find_current(current_id)
                        #except IndexError:
                            #self.statuses = retreive
            self.update_counter()

    def find_current(self, current_id):
        for i, status in enumerate(self.statuses):
            if status.id == current_id:
                self.current = i

    def filter_statuses(self, statuses):
        filters = []
        for i, status in enumerate(statuses):
            if self.filter.filter_status(status):
                filters.append(i)
        filters.reverse()
        for f in filters:
            del statuses[f]

        return statuses

    def update_counter(self):
        self.count_statuses()
        self.count_unread()

    def append_old_statuses(self, statuses):
        if statuses == []:
            pass
        else:
            self.statuses += statuses
            self.count_statuses()
            self.count_unread()

    def count_statuses(self):
        try:
            self.count = len(self.walker)
        except TypeError:
            self.count = 0

    def count_unread(self):
        try:
            self.unread = 0
            for i in range(len(self.walker)):
                if self.walker[i].id == self.last_read:
                    break
                self.unread += 1
        except TypeError:
            self.unread = 0

    def reset(self):
        self.first = 0
        self.unread = 0

    def empty(self):
        self.__init__()

    def all_read(self):
        if self.count > 0:
            self.last_read = self.walker[0].id