Пример #1
0
    def __init__(self):
        key,secret = self.load_auth()
        self.api = twoauth.api(CONSUMER_KEY,CONSUMER_SECRET,key,secret)
        self.me = self.api.verify_credentials()
        self.my_name = self.me.screen_name
        pynotify.init("Silfatter")
        self.statuses = {}

        self.iconstore = IconStore()
        self.reply_getter = InReplyGetter(self)
        self.twtool = twittertool.TwitterTool()

        self.window = ClientWindow()

        self.accelgroup = gtk.AccelGroup()
        self.window.add_accel_group(self.accelgroup)
        stream = StreamingThread(self)
        rest = RestThread(self)

        main_vbox = gtk.VBox()

        self.lines_note_book = gtk.Notebook()
        self.home_timeline_sw = Timelinesw(self,"home")
        self.mention_timeline_sw = Timelinesw(self,"mention")
        self.event_timeline_sw = Eventlinesw(self)

        stream.add_timeline(self.home_timeline_sw.view)
        stream.add_timeline(self.mention_timeline_sw.view)
        stream.add_eventline(self.event_timeline_sw.view)

        rest.add(self.home_timeline_sw.view)
        rest.add(self.mention_timeline_sw.view)

        self.post_window = PostWindow(self)
        self.url_window = UrlWindow(self)

        self.lines_note_book.append_page(self.home_timeline_sw,gtk.Label("Home"))
        self.lines_note_book.append_page(self.mention_timeline_sw,gtk.Label("Mention"))
        self.lines_note_book.append_page(self.event_timeline_sw,gtk.Label("Event"))

        self.window.add(main_vbox)
        self.window.set_size_request(300,300)

        main_vbox.pack_start(self.lines_note_book,expand=True,fill=True)

        stream.start()
        rest.start()
        self.window.show_all()
Пример #2
0
class Timeline(gtk.ScrolledWindow):
    twitter = None
    
    def __init__(self):
        gtk.ScrolledWindow.__init__(self)
        self.timeline = None
        self.stream = None

        # Add treeview to scrolledwindow
        self.view = StatusView()
        self.add(self.view)
        
        # Scrollbar policy
        self.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)
        self.set_shadow_type(gtk.SHADOW_IN)
        self.connect("destroy", self.on_destroy)
        
        # Auto scroll to top setup
        vadj = self.get_vadjustment()
        self.vadj_upper = vadj.upper
        self.vadj_lock = False
        vadj.connect("changed", self.on_vadjustment_changed)
        vadj.connect("value-changed", self.on_vadjustment_value_changed)
    
    # Start Sync Timeline (new twitter timeline thread create)
    def set_timeline(self, method, interval, counts, args, kwargs):
        self.timeline = TimelineThread(method, interval, counts, args, kwargs)

    def set_stream(self, method, kwargs = {}):
        self.stream = StreamingThread(method, kwargs = kwargs)
    
    def start_timeline(self):
        if self.timeline and not self.timeline.is_alive():
            # Set Event Hander (exec in every get timeline
            self.timeline.on_received_status = self.on_received_statuses
            # Start Timeline sync thread
            self.timeline.start()
        
    def start_stream(self):
        if self.stream and not self.stream.is_alive():
            self.stream.on_received_status = self.on_received_statuses
            self.stream.start()
    
    # Reload Timeline
    def reload(self):
        if self.timeline != None and not self.timeline.lock.isSet():
            # lock flag set (unlock)
            self.timeline.lock.set()
    
    # Get timeline ids
    def get_timeline_ids(self):
        timeline = self.timeline.timeline if self.timeline != None else set()
        stream = self.stream.timeline if self.stream != None else set()
        
        return timeline.union(stream)

    # FIXME for notify event
    def get_processing_ids(self):
        timeline = self.timeline._processing if self.timeline != None else set()
        stream = self.stream._processing if self.stream != None else set()
        
        return timeline.union(stream)
    
    def on_received_statuses(self, ids):
        statuses = ids.difference(self.get_timeline_ids())
        self.view.prepend_new_statuses(statuses)
        
        if not self.timeline or not self.timeline._initial_load:
            for i in statuses:
                self.on_status_added(i)
    
    def on_status_added(self, ids): pass
    
    ########################################
    # Gtk Signal Events
    
    # Scroll to top if upper(list length) changed Event
    def on_vadjustment_changed(self, adj):
        if not self.vadj_lock and self.vadj_upper < adj.upper:
            if len(self.view.store):
                self.view.scroll_to_cell((0,))
                self.view.added = False
        
        self.vadj_upper = adj.upper
        self.vadj_len = len(self.view.store)
    
    def on_vadjustment_value_changed(self, adj):
        if adj.value == 0.0:
            self.vadj_lock = False
        elif self.vadj_upper == adj.upper and not self.view.added:
            self.vadj_lock = True
    
    def on_destroy(self, widget):
        if self.timeline != None:
            self.timeline.destroy()
        if self.stream != None:
            self.stream.destroy()
        self.view.destroy()