Factored tab labels into new class
This commit is contained in:
parent
e68841b71a
commit
f0193d80a8
107
mytwitter.py
107
mytwitter.py
|
@ -162,39 +162,10 @@ class MyTwitter():
|
||||||
|
|
||||||
# This code modified from create_custom_tab in:
|
# This code modified from create_custom_tab in:
|
||||||
# http://www.daa.com.au/pipermail/pygtk/2006-April/012216.html
|
# http://www.daa.com.au/pipermail/pygtk/2006-April/012216.html
|
||||||
#
|
|
||||||
# fixme: this code is pretty heinous, all clumped together like this.
|
|
||||||
# a CloseTabLabel class would be nice, maybe...
|
|
||||||
def add_to_notebook(self, widget, name):
|
def add_to_notebook(self, widget, name):
|
||||||
#create a custom tab for notebook containing a
|
tab_label = CloseTabLabel(name)
|
||||||
#label and a button with STOCK_ICON
|
self.tweet_notebook.append_page(widget, tab_label)
|
||||||
eventBox = gtk.EventBox()
|
tab_label.connect('clicked', self.remove_view, name)
|
||||||
tabBox = gtk.HBox(False, 2)
|
|
||||||
tabLabel = gtk.Label(name)
|
|
||||||
tabButton=gtk.Button()
|
|
||||||
tabButton.connect('clicked', self.remove_view, name)
|
|
||||||
|
|
||||||
#Add a picture on a button
|
|
||||||
iconBox = gtk.HBox(False, 0)
|
|
||||||
image = gtk.Image()
|
|
||||||
image.set_from_stock(gtk.STOCK_CLOSE,gtk.ICON_SIZE_MENU)
|
|
||||||
gtk.Button.set_relief(tabButton,gtk.RELIEF_NONE)
|
|
||||||
settings = gtk.Widget.get_settings(tabButton)
|
|
||||||
(w,h) = gtk.icon_size_lookup_for_settings(settings,gtk.ICON_SIZE_MENU)
|
|
||||||
gtk.Widget.set_size_request(tabButton, w + 4, h + 4);
|
|
||||||
iconBox.pack_start(image, True, False, 0)
|
|
||||||
tabButton.add(iconBox)
|
|
||||||
|
|
||||||
tabBox.pack_start(tabLabel, False)
|
|
||||||
tabBox.pack_start(tabButton, False)
|
|
||||||
|
|
||||||
# needed, otherwise even calling show_all on the notebook won't
|
|
||||||
# make the hbox contents appear.
|
|
||||||
tabBox.show_all()
|
|
||||||
eventBox.add(tabBox)
|
|
||||||
|
|
||||||
# Now, add this convoluted eventBox to the new pane
|
|
||||||
self.tweet_notebook.append_page(widget, eventBox)
|
|
||||||
|
|
||||||
|
|
||||||
### end class MyTwitter
|
### end class MyTwitter
|
||||||
|
@ -220,6 +191,7 @@ class TweetPane(gtk.ScrolledWindow):
|
||||||
# These handle determining which tweets are unread
|
# These handle determining which tweets are unread
|
||||||
self.last_tweet_read = None
|
self.last_tweet_read = None
|
||||||
self.latest_tweet = None
|
self.latest_tweet = None
|
||||||
|
self.num_new_tweets = 0
|
||||||
|
|
||||||
self.tweets = []
|
self.tweets = []
|
||||||
|
|
||||||
|
@ -249,13 +221,13 @@ class TweetPane(gtk.ScrolledWindow):
|
||||||
self.last_tweet_read = statuses[0].id
|
self.last_tweet_read = statuses[0].id
|
||||||
|
|
||||||
# Keep count of the new tweets for posting a status message
|
# Keep count of the new tweets for posting a status message
|
||||||
num_new_tweets = 0
|
self.num_new_tweets = 0
|
||||||
|
|
||||||
for i in range(0, self.mytwitter.num_entries):
|
for i in range(0, self.mytwitter.num_entries):
|
||||||
read = True
|
read = True
|
||||||
if i < len(statuses):
|
if i < len(statuses):
|
||||||
if statuses[i].id > self.last_tweet_read:
|
if statuses[i].id > self.last_tweet_read:
|
||||||
num_new_tweets += 1
|
self.num_new_tweets += 1
|
||||||
read = False
|
read = False
|
||||||
self.tweets[i].set_status(statuses[i], read)
|
self.tweets[i].set_status(statuses[i], read)
|
||||||
else:
|
else:
|
||||||
|
@ -263,9 +235,6 @@ class TweetPane(gtk.ScrolledWindow):
|
||||||
|
|
||||||
self.latest_tweet = statuses[0].id
|
self.latest_tweet = statuses[0].id
|
||||||
|
|
||||||
if num_new_tweets > 0:
|
|
||||||
pass # fixme: change the label here, or maybe in mytwitter?
|
|
||||||
|
|
||||||
|
|
||||||
def get_list_name(self):
|
def get_list_name(self):
|
||||||
return self.list_name
|
return self.list_name
|
||||||
|
@ -279,6 +248,10 @@ class TweetPane(gtk.ScrolledWindow):
|
||||||
def set_tweets_read_callback(self, event):
|
def set_tweets_read_callback(self, event):
|
||||||
self.set_tweets_read()
|
self.set_tweets_read()
|
||||||
|
|
||||||
|
|
||||||
|
def get_num_new_tweets(self):
|
||||||
|
return self.num_new_tweets
|
||||||
|
|
||||||
### end class TweetPane
|
### end class TweetPane
|
||||||
|
|
||||||
|
|
||||||
|
@ -380,10 +353,10 @@ class TweetBox(gtk.VBox):
|
||||||
def set_read(self, read=True):
|
def set_read(self, read=True):
|
||||||
if read:
|
if read:
|
||||||
self.text_eb.modify_bg(gtk.STATE_NORMAL,
|
self.text_eb.modify_bg(gtk.STATE_NORMAL,
|
||||||
gtk.gdk.color_parse("#ffffff"))
|
gtk.gdk.color_parse("#f2f1f0"))
|
||||||
else:
|
else:
|
||||||
self.text_eb.modify_bg(gtk.STATE_NORMAL,
|
self.text_eb.modify_bg(gtk.STATE_NORMAL,
|
||||||
gtk.gdk.color_parse("#ddffdd"))
|
gtk.gdk.color_parse("#"))
|
||||||
|
|
||||||
|
|
||||||
def on_reply_clicked(self, widget):
|
def on_reply_clicked(self, widget):
|
||||||
|
@ -403,10 +376,66 @@ class TweetBox(gtk.VBox):
|
||||||
# end class TweetBox
|
# end class TweetBox
|
||||||
|
|
||||||
|
|
||||||
|
class CloseTabLabel(gtk.EventBox):
|
||||||
|
'''
|
||||||
|
This class holds a label and a button with an 'I' in it. This button causes the CloseTabLabel
|
||||||
|
to emit a clicked signal
|
||||||
|
'''
|
||||||
|
|
||||||
|
def __init__(self, name=None):
|
||||||
|
gtk.EventBox.__init__(self)
|
||||||
|
self.init_widgets(name)
|
||||||
|
|
||||||
|
|
||||||
|
# This code is still heinous, but at least it is
|
||||||
|
# isolated to its own class
|
||||||
|
def init_widgets(self, name):
|
||||||
|
#create a custom tab for notebook containing a
|
||||||
|
#label and a button with STOCK_ICON
|
||||||
|
tabBox = gtk.HBox(False, 2)
|
||||||
|
tabButton=gtk.Button()
|
||||||
|
tabButton.connect('clicked', self.on_clicked)
|
||||||
|
|
||||||
|
self.label = gtk.Label(name)
|
||||||
|
|
||||||
|
#Add a picture on a button
|
||||||
|
iconBox = gtk.HBox(False, 0)
|
||||||
|
image = gtk.Image()
|
||||||
|
image.set_from_stock(gtk.STOCK_CLOSE,gtk.ICON_SIZE_MENU)
|
||||||
|
gtk.Button.set_relief(tabButton,gtk.RELIEF_NONE)
|
||||||
|
settings = gtk.Widget.get_settings(tabButton)
|
||||||
|
(w,h) = gtk.icon_size_lookup_for_settings(settings,gtk.ICON_SIZE_MENU)
|
||||||
|
gtk.Widget.set_size_request(tabButton, w + 4, h + 4);
|
||||||
|
iconBox.pack_start(image, True, False, 0)
|
||||||
|
tabButton.add(iconBox)
|
||||||
|
|
||||||
|
tabBox.pack_start(self.label, False)
|
||||||
|
tabBox.pack_start(tabButton, False)
|
||||||
|
|
||||||
|
# needed, otherwise even calling show_all on the notebook won't
|
||||||
|
# make the hbox contents appear.
|
||||||
|
tabBox.show_all()
|
||||||
|
self.add(tabBox)
|
||||||
|
|
||||||
|
|
||||||
|
def set_label_text(self, new_text):
|
||||||
|
self.label.set_text(new_text)
|
||||||
|
|
||||||
|
|
||||||
|
def on_clicked(self, event):
|
||||||
|
self.emit('clicked')
|
||||||
|
|
||||||
|
|
||||||
|
### end class CloseTabLabel
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# main
|
# main
|
||||||
|
|
||||||
# Create custom events for TweetBox
|
# Create custom events for TweetBox
|
||||||
|
gobject.signal_new("clicked", CloseTabLabel,
|
||||||
|
gobject.SIGNAL_RUN_LAST,
|
||||||
|
gobject.TYPE_NONE, ())
|
||||||
gobject.signal_new("reply", TweetBox,
|
gobject.signal_new("reply", TweetBox,
|
||||||
gobject.SIGNAL_RUN_LAST,
|
gobject.SIGNAL_RUN_LAST,
|
||||||
gobject.TYPE_NONE, ())
|
gobject.TYPE_NONE, ())
|
||||||
|
|
Reference in New Issue
Block a user