diff --git a/default.glade b/default.glade index 8df5bad..5d6a757 100644 --- a/default.glade +++ b/default.glade @@ -98,6 +98,56 @@ </packing> </child> + <child> + <widget class="GtkHBox" id="search_box"> + <property name="visible">True</property> + <property name="homogeneous">False</property> + <property name="spacing">0</property> + + <child> + <widget class="GtkEntry" id="search_entry"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="editable">True</property> + <property name="visibility">True</property> + <property name="max_length">0</property> + <property name="text" translatable="yes"></property> + <property name="has_frame">True</property> + <property name="invisible_char">•</property> + <property name="activates_default">False</property> + <signal name="activate" handler="on_search" last_modification_time="Mon, 12 Apr 2010 21:30:26 GMT"/> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">True</property> + <property name="fill">True</property> + </packing> + </child> + + <child> + <widget class="GtkButton" id="search_button"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="label" translatable="yes">Search</property> + <property name="use_underline">True</property> + <property name="relief">GTK_RELIEF_NORMAL</property> + <property name="focus_on_click">True</property> + <signal name="clicked" handler="on_search" last_modification_time="Mon, 12 Apr 2010 21:29:55 GMT"/> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">False</property> + <property name="fill">False</property> + </packing> + </child> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">False</property> + <property name="fill">True</property> + </packing> + </child> + <child> <widget class="GtkNotebook" id="tweet_notebook"> <property name="visible">True</property> diff --git a/mytwitter.py b/mytwitter.py index f097ebb..523060f 100755 --- a/mytwitter.py +++ b/mytwitter.py @@ -47,6 +47,8 @@ class MyTwitter(): self.update_entry = self.widget_tree.get_widget('update_entry') self.update_count = self.widget_tree.get_widget('update_count') self.status_bar = self.widget_tree.get_widget('status_bar') + self.search_entry = self.widget_tree.get_widget('search_entry') + self.context_id = self.status_bar.get_context_id('message') self.tweet_notebook.remove_page(0) # kill the page that glade makes us have @@ -55,8 +57,7 @@ class MyTwitter(): self.tweet_notebook.connect('switch_page', self.on_tab_change) # Add the Home tab to the notebook - home_pane = TweetPane('Home', self) - self.add_to_notebook(home_pane, 'Home') + self.add_to_notebook('Home') # Put Home, @user, and lists in the View menu... lists = self.api.GetUserLists() @@ -86,9 +87,9 @@ class MyTwitter(): statuses = self.api.GetHomeTimeline(count=self.num_entries) elif list_name == '@' + self.username: statuses = self.api.GetMentions(count=self.num_entries) - elif re.search('user: ', list_name): - statuses = self.api.GetUserTimeline(re.sub('^user: ', '', list_name), count=self.num_entries) - elif re.search('#', list_name): + elif re.match(r'user: ', list_name): + statuses = self.api.GetUserTimeline(re.sub(r'^user: ', r'', list_name), count=self.num_entries) + elif re.match(r'#', list_name): statuses = self.api.Search(list_name, rpp=self.num_entries) else: statuses = self.api.GetListStatuses(list_name, per_page=self.num_entries) @@ -159,8 +160,7 @@ class MyTwitter(): return # Now, add a new tab with this list - new_pane = TweetPane(name, self) - self.add_to_notebook(new_pane, name) + self.add_to_notebook(name) # And, to propagate it: self.update_windows() @@ -178,9 +178,11 @@ class MyTwitter(): # This code modified from create_custom_tab in: # http://www.daa.com.au/pipermail/pygtk/2006-April/012216.html - def add_to_notebook(self, widget, name): + def add_to_notebook(self, name): + new_pane = TweetPane(name, self) + tab_label = CloseTabLabel(name) - self.tweet_notebook.append_page(widget, tab_label) + self.tweet_notebook.append_page(new_pane, tab_label) tab_label.connect('clicked', self.remove_view, name) self.tweet_notebook.set_current_page(-1) # switch to the new pane @@ -192,6 +194,19 @@ class MyTwitter(): pane.set_tweets_read() tab_label.set_label_text(pane.get_list_name()) + + def on_search(self, event): + search_string = self.search_entry.get_text() + self.search_entry.set_text('') + if re.match(r'#', search_string): + self.add_to_notebook(search_string) + else: + # Assume this is a user name we want to lookup + self.add_to_notebook('user: ' + search_string) + + self.update_windows() + + ### end class MyTwitter