Added functionality to close tabs
This commit is contained in:
parent
f7eb9993dc
commit
e68841b71a
54
mytwitter.py
54
mytwitter.py
|
@ -53,8 +53,7 @@ class MyTwitter():
|
|||
|
||||
# Add the Home tab to the notebook
|
||||
home_pane = TweetPane('Home', self)
|
||||
self.tweet_notebook.append_page(home_pane)
|
||||
self.tweet_notebook.set_tab_label_text(home_pane, 'Home')
|
||||
self.add_to_notebook(home_pane, 'Home')
|
||||
|
||||
# Put Home, @user, and lists in the View menu...
|
||||
lists = self.api.GetUserLists()
|
||||
|
@ -145,12 +144,59 @@ class MyTwitter():
|
|||
|
||||
# Now, add a new tab with this list
|
||||
new_pane = TweetPane(name, self)
|
||||
self.tweet_notebook.append_page(new_pane)
|
||||
self.tweet_notebook.set_tab_label_text(new_pane, name)
|
||||
self.add_to_notebook(new_pane, name)
|
||||
|
||||
# And, to propagate it:
|
||||
self.update_windows()
|
||||
|
||||
|
||||
# Remove one of the views from the tweet notebook.
|
||||
# Called when the close button is clicked on one of the views
|
||||
def remove_view(self, event, name):
|
||||
for i in range(self.tweet_notebook.get_n_pages()):
|
||||
pane = self.tweet_notebook.get_nth_page(i)
|
||||
if (pane.get_list_name() == name):
|
||||
self.tweet_notebook.remove_page(i)
|
||||
return
|
||||
|
||||
|
||||
# This code modified from create_custom_tab in:
|
||||
# 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):
|
||||
#create a custom tab for notebook containing a
|
||||
#label and a button with STOCK_ICON
|
||||
eventBox = gtk.EventBox()
|
||||
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
|
||||
|
||||
|
||||
|
|
Reference in New Issue
Block a user