Now support viewing lists, some general code cleanup also done.
This commit is contained in:
parent
5dae37a260
commit
55546a9a5e
|
@ -133,6 +133,7 @@
|
||||||
<property name="use_underline">True</property>
|
<property name="use_underline">True</property>
|
||||||
<property name="relief">GTK_RELIEF_NORMAL</property>
|
<property name="relief">GTK_RELIEF_NORMAL</property>
|
||||||
<property name="focus_on_click">True</property>
|
<property name="focus_on_click">True</property>
|
||||||
|
<signal name="activate" handler="update_window_callback" last_modification_time="Thu, 08 Apr 2010 21:02:59 GMT"/>
|
||||||
</widget>
|
</widget>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="padding">0</property>
|
<property name="padding">0</property>
|
||||||
|
@ -144,7 +145,7 @@
|
||||||
<child>
|
<child>
|
||||||
<widget class="GtkComboBoxEntry" id="list_select">
|
<widget class="GtkComboBoxEntry" id="list_select">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="items" translatable="yes">Friends</property>
|
<property name="items" translatable="yes">Home</property>
|
||||||
<property name="add_tearoffs">False</property>
|
<property name="add_tearoffs">False</property>
|
||||||
<property name="has_frame">True</property>
|
<property name="has_frame">True</property>
|
||||||
<property name="focus_on_click">True</property>
|
<property name="focus_on_click">True</property>
|
||||||
|
@ -202,7 +203,7 @@
|
||||||
<property name="use_underline">True</property>
|
<property name="use_underline">True</property>
|
||||||
<property name="relief">GTK_RELIEF_NORMAL</property>
|
<property name="relief">GTK_RELIEF_NORMAL</property>
|
||||||
<property name="focus_on_click">True</property>
|
<property name="focus_on_click">True</property>
|
||||||
<signal name="activate" handler="update_status_callback" last_modification_time="Thu, 08 Apr 2010 19:44:59 GMT"/>
|
<signal name="activate" handler="update_status_callback" last_modification_time="Thu, 08 Apr 2010 21:03:06 GMT"/>
|
||||||
</widget>
|
</widget>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="padding">0</property>
|
<property name="padding">0</property>
|
||||||
|
|
82
mytwitter.py
82
mytwitter.py
|
@ -14,11 +14,18 @@ class MyTwitter():
|
||||||
config.read(os.path.expanduser("~/.mytwitter"))
|
config.read(os.path.expanduser("~/.mytwitter"))
|
||||||
self.username = config.get('global', 'username')
|
self.username = config.get('global', 'username')
|
||||||
self.password = config.get('global', 'password')
|
self.password = config.get('global', 'password')
|
||||||
|
|
||||||
self.num_entries = int(config.get('global', 'entries'))
|
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'))
|
self.refresh_time = int(config.get('global', 'refreshtime'))
|
||||||
|
if self.refresh_time < 10:
|
||||||
|
self.refresh_time = 10
|
||||||
|
|
||||||
self.labels = []
|
self.labels = []
|
||||||
self.texts = []
|
self.texts = []
|
||||||
|
self.list = None
|
||||||
|
|
||||||
# Authenticate with twitter, set up the API object
|
# Authenticate with twitter, set up the API object
|
||||||
self.api = twitter.Api(username=self.username, password=self.password)
|
self.api = twitter.Api(username=self.username, password=self.password)
|
||||||
|
@ -34,6 +41,7 @@ class MyTwitter():
|
||||||
|
|
||||||
|
|
||||||
def init_widgets(self):
|
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.tweet_box = self.widget_tree.get_widget('tweet_box')
|
||||||
self.update_entry = self.widget_tree.get_widget('update_entry')
|
self.update_entry = self.widget_tree.get_widget('update_entry')
|
||||||
self.update_count = self.widget_tree.get_widget('update_count')
|
self.update_count = self.widget_tree.get_widget('update_count')
|
||||||
|
@ -53,16 +61,30 @@ class MyTwitter():
|
||||||
|
|
||||||
self.tweet_box.show_all()
|
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
|
# Timer to update periodically
|
||||||
self.update_window()
|
self.update_window()
|
||||||
gobject.timeout_add(self.refresh_time * 100, self.update_window)
|
gobject.timeout_add(self.refresh_time * 100, self.update_window)
|
||||||
|
|
||||||
|
|
||||||
def update_window(self):
|
def update_window(self):
|
||||||
|
print "debug: update_window()"
|
||||||
|
|
||||||
timezone = dateutil.tz.gettz()
|
timezone = dateutil.tz.gettz()
|
||||||
time_format = "%Y.%m.%d %H:%M:%S %Z"
|
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):
|
for i in range(0, self.num_entries):
|
||||||
if i < len(statuses):
|
if i < len(statuses):
|
||||||
# Update the label with the user's name and screen name
|
# 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)
|
self.texts[i].set_text(statuses[i].text)
|
||||||
|
|
||||||
|
|
||||||
|
def update_window_callback(self, widget):
|
||||||
|
self.update_window()
|
||||||
|
|
||||||
|
|
||||||
def update_status(self):
|
def update_status(self):
|
||||||
text = self.update_entry.get_text()
|
text = self.update_entry.get_text()
|
||||||
self.update_entry.set_text(none)
|
self.update_entry.set_text("")
|
||||||
self.api.PostUpdate(text)
|
self.api.PostUpdate(text)
|
||||||
self.update_window()
|
self.update_window()
|
||||||
|
|
||||||
|
|
||||||
# Just calls update_status, here so that things
|
|
||||||
# that pass an event can be used
|
|
||||||
def update_status_callback(self, widget):
|
def update_status_callback(self, widget):
|
||||||
self.update_status()
|
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):
|
def char_counter(self, widget):
|
||||||
new_count = str(len(self.update_entry.get_text())) + "/140"
|
new_count = str(len(self.update_entry.get_text())) + "/140"
|
||||||
self.update_count.set_label(new_count)
|
self.update_count.set_label(new_count)
|
||||||
|
@ -130,30 +129,13 @@ class MyTwitter():
|
||||||
print "DEBUG: help->about not yet implemented"
|
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
|
### 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
|
# main
|
||||||
my_twitter = MyTwitter()
|
my_twitter = MyTwitter()
|
||||||
gtk.main()
|
gtk.main()
|
||||||
|
|
Reference in New Issue
Block a user