gtk.gdk.threads_init()
gobject.threads_init()
+ # Twitter class instance
+ self.twitter = twitterapi(keys, maxn)
+
# GtkBuilder instance
builder = gtk.Builder()
self.builder = builder
# init icon store
self.icons = IconStore(iconmode)
-
+
# set tools
self.twtools = twittertools.TwitterTools()
- init = threading.Thread(target=self.initialize, args=(keys, maxn))
- init.start()
+ self.initialize(keys, maxn)
def main(self):
gtk.gdk.threads_enter()
print >>sys.stderr, "[Warning] Allocation not defined"
window.show_all()
-
+
# Start gtk main loop
gtk.main()
gtk.gdk.threads_leave()
- # Initialize Twitter API and Tabs (in another thread)
+ # Initialize Tabs (in another thread)
def initialize(self, keys, maxn):
- gtk.gdk.threads_enter()
- # Twitter class instance
- self.twitter = twitterapi(keys, maxn)
-
- # Set statusbar (Show API Remaining)
- self.label_apilimit = gtk.Label()
-
- sbar = self.builder.get_object("statusbar1")
- sbar.pack_start(
- self.label_apilimit, expand = False, padding = 10)
- sbar.show_all()
-
# Set Status Views
for i in (("Home", "home_timeline", 30),
("Mentions", "mentions", 300)):
# create new timeline and tab view
self.new_timeline(*i)
- # insert little delay
- time.sleep(random.random())
+
+ # Set statusbar (Show API Remaining)
+ self.label_apilimit = gtk.Label()
+ sbar = self.builder.get_object("statusbar1")
+ sbar.pack_start(
+ self.label_apilimit, expand = False, padding = 10)
+ sbar.show_all()
# Users tab append
users = UserSelection()
self.icons.add_store(users.store, 1)
users.set_userdict(self.twitter.users, self.icons)
self.new_tab(users, "Users")
-
+
notebook = self.builder.get_object("notebook1")
notebook.set_current_page(0)
- gtk.gdk.threads_leave()
# Window close event
def close(self, widget):
########################################
- # Original Events
+ # Original Events
# status added event
def on_status_added(self, i):
import time
import webbrowser
+import threading
class timeline:
def __init__(self, api, icons, iconmode = True):
it = self.store.get_iter(path[0])
sid = self.store.get_value(it, 2)
return self.twitter.statuses[sid]
-
- # Color status
- def color_status(self, status = None):
- myname = self.twitter.myname
- myid = self.twitter.me.id if self.twitter.me != None else -1
+
+ # Replace & -> &
+ def _replace_amp(self, string):
+ amp = string.find('&')
+ if amp == -1: return string
- # if not set target status
- if status == None:
- status = self.get_selected_status()
+ entity_match = self.noent_amp.finditer(string)
- i = self.store.get_iter_first()
- while i:
- bg = None
-
- id = self.store.get_value(i, 2)
- s = self.twitter.statuses[id]
- u = s.user
-
- if u.id == myid:
- # My status (Blue)
- bg = "#CCCCFF"
- elif s.in_reply_to_user_id == myid or \
- s.text.find("@%s" % myname) != -1:
- # Reply to me (Red)
- bg = "#FFCCCC"
-
- if status:
- if s.id == status.in_reply_to_status_id:
- # Reply to (Orange)
- bg = "#FFCC99"
- elif u.id == status.in_reply_to_user_id:
- # Reply to other (Yellow)
- bg = "#FFFFCC"
- elif u.id == status.user.id:
- # Selected user (Green)
- bg = "#CCFFCC"
-
- self.store.set_value(i, 4, bg)
- i = self.store.iter_next(i)
+ for i, e in enumerate(entity_match):
+ string = "%s&%s" % (
+ string[:e.start() + (4 * i)],
+ string[e.start() + (4 * i) + 1:])
+
+ return string
+ ########################################
+ # Execute in Background Thread Methods
+
# Prepend new statuses
def prepend_new_statuses(self, new_ids):
# Auto scroll lock if adjustment changed manually
vadj = self.scrwin.get_vadjustment()
self.vadj_lock = True if vadj.value != 0.0 else False
- gtk.gdk.threads_enter()
# Insert New Status
for i in new_ids:
self.add_status(i)
- gtk.gdk.threads_leave()
self.color_status()
text = self._replace_amp(text)
if status.user.id in self.twitter.followers:
- # Bold screen_name if follwer
+ # Bold screen_name if follower
tmpl = "<b>%s</b>\n%s"
else:
# or gray
status.user.screen_name, text)
# New Status Prepend to Liststore (Add row)
+ gtk.gdk.threads_enter()
+
self.store.prepend(
(self.icons.get(status.user),
message,
long(status.id), long(status.user.id),
background))
-
self.on_status_added(i)
-
- # Replace & -> &
- def _replace_amp(self, string):
- amp = string.find('&')
- if amp == -1: return string
- entity_match = self.noent_amp.finditer(string)
+ gtk.gdk.threads_leave()
+
+ # Color status
+ def color_status(self, status = None):
+ t = threading.Thread(target=self.color_status_in_thread, args=(status,))
+ t.start()
+
+ def color_status_in_thread(self, status = None):
+ myname = self.twitter.myname
+ myid = self.twitter.me.id if self.twitter.me != None else -1
- for i, e in enumerate(entity_match):
- string = "%s&%s" % (
- string[:e.start() + (4 * i)],
- string[e.start() + (4 * i) + 1:])
+ # if not set target status
+ if status == None:
+ status = self.get_selected_status()
- return string
-
+ i = self.store.get_iter_first()
+ while i:
+ bg = None
+
+ id = self.store.get_value(i, 2)
+ s = self.twitter.statuses[id]
+ u = s.user
+
+ if u.id == myid:
+ # My status (Blue)
+ bg = "#CCCCFF"
+ elif s.in_reply_to_user_id == myid or \
+ s.text.find("@%s" % myname) != -1:
+ # Reply to me (Red)
+ bg = "#FFCCCC"
+
+ if status:
+ if s.id == status.in_reply_to_status_id:
+ # Reply to (Orange)
+ bg = "#FFCC99"
+ elif u.id == status.in_reply_to_user_id:
+ # Reply to other (Yellow)
+ bg = "#FFFFCC"
+ elif u.id == status.user.id:
+ # Selected user (Green)
+ bg = "#CCFFCC"
+
+ gtk.gdk.threads_enter()
+ self.store.set_value(i, 4, bg)
+ gtk.gdk.threads_leave()
+
+ i = self.store.iter_next(i)
+
# dummy events and methods
def on_status_added(self, *args, **kwargs): pass
def on_status_selection_changed(self, *args, **kwargs): pass