diff --git a/default.glade b/default.glade index c62476b..d0ab7c8 100644 --- a/default.glade +++ b/default.glade @@ -133,6 +133,7 @@ True GTK_RELIEF_NORMAL True + 0 @@ -144,7 +145,7 @@ True - Friends + Home False True True @@ -202,7 +203,7 @@ True GTK_RELIEF_NORMAL True - + 0 diff --git a/mytwitter.py b/mytwitter.py index 6b3b356..617d6ff 100755 --- a/mytwitter.py +++ b/mytwitter.py @@ -14,11 +14,18 @@ class MyTwitter(): config.read(os.path.expanduser("~/.mytwitter")) self.username = config.get('global', 'username') self.password = config.get('global', 'password') + self.num_entries = int(config.get('global', 'entries')) + if self.num_entries < 20: + self.num_entries = 20 + self.refresh_time = int(config.get('global', 'refreshtime')) + if self.refresh_time < 10: + self.refresh_time = 10 self.labels = [] self.texts = [] + self.list = None # Authenticate with twitter, set up the API object self.api = twitter.Api(username=self.username, password=self.password) @@ -34,6 +41,7 @@ class MyTwitter(): def init_widgets(self): + self.list_select = self.widget_tree.get_widget('list_select') self.tweet_box = self.widget_tree.get_widget('tweet_box') self.update_entry = self.widget_tree.get_widget('update_entry') self.update_count = self.widget_tree.get_widget('update_count') @@ -53,16 +61,30 @@ class MyTwitter(): self.tweet_box.show_all() + # Fill the ComboBox with entries + self.list_select.append_text('@' + self.username) + lists = self.api.GetUserLists() + for l in lists['lists']: + self.list_select.append_text(l.name) + # Timer to update periodically self.update_window() gobject.timeout_add(self.refresh_time * 100, self.update_window) def update_window(self): + print "debug: update_window()" + timezone = dateutil.tz.gettz() time_format = "%Y.%m.%d %H:%M:%S %Z" - statuses = self.api.GetFriendsTimeline(self.username, count=self.num_entries) + if self.list is None or self.list == 'Home': + statuses = self.api.GetFriendsTimeline(self.username, count=self.num_entries) + elif self.list == '@' + self.username: + statuses = self.api.GetReplies() + else: + statuses = self.api.GetListStatuses(self.list) + for i in range(0, self.num_entries): if i < len(statuses): # Update the label with the user's name and screen name @@ -79,44 +101,21 @@ class MyTwitter(): self.texts[i].set_text(statuses[i].text) + def update_window_callback(self, widget): + self.update_window() + + def update_status(self): text = self.update_entry.get_text() - self.update_entry.set_text(none) + self.update_entry.set_text("") self.api.PostUpdate(text) self.update_window() - # Just calls update_status, here so that things - # that pass an event can be used def update_status_callback(self, widget): self.update_status() - # fixme: convert all of the below to wxPython - - # def scroll_wheel(self, event): - # if event.num == 4: - # self.tweet_view.yview('scroll', -5, 'units'); - # if event.num == 5: - # self.tweet_view.yview('scroll', 5, 'units'); - - - # def page_up(self, event): - # self.tweet_view.yview('scroll', -15, 'units'); - - - # def page_down(self, event): - # self.tweet_view.yview('scroll', 15, 'units'); - - - # def line_up(self, event): - # self.tweet_view.yview('scroll', -5, 'units'); - - - # def line_down(self, event): - # self.tweet_view.yview('scroll', 5, 'units'); - - def char_counter(self, widget): new_count = str(len(self.update_entry.get_text())) + "/140" self.update_count.set_label(new_count) @@ -130,30 +129,13 @@ class MyTwitter(): print "DEBUG: help->about not yet implemented" + def on_list_select_changed(self, widget): + self.list = widget.get_active_text() + self.update_window() + ### end class TwitWindow - -def print_lists(): - data = api.GetUserLists() - for l in data['lists']: - print l.name - -def print_statuses_list(): - statuses = api.GetListStatuses(sys.argv[2]) - print_formatted(statuses) - -def print_statuses(): - statuses = api.GetFriendsTimeline(username) - print_formatted(statuses) - -def print_formatted(statuses): - for s in statuses: - print s.user.name.encode("utf-8"), "(", s.user.screen_name, ") :" - print s.text.encode("utf-8") - print - - # main my_twitter = MyTwitter() gtk.main()