OSDN Git Service

Refactoring menu items and toolbuttons commands in ThreadWindow.
authorAiwota Programmer <aiwotaprog@tetteke.tk>
Sun, 19 Apr 2009 07:18:50 +0000 (16:18 +0900)
committerAiwota Programmer <aiwotaprog@tetteke.tk>
Sun, 19 Apr 2009 07:18:50 +0000 (16:18 +0900)
src/FukuiNoNamari/thread_window.py
src/data/thread_window.glade

index 2a81afa..dbc7584 100644 (file)
@@ -51,6 +51,7 @@ import bookmark_list
 import bookmark_window
 import thread_view
 import thread_popup
+import submit_window
 
 GLADE_FILENAME = "thread_window.glade"
 
@@ -140,11 +141,10 @@ class WinWrap(winwrapbase.WinWrapBase):
 
         glade_path = os.path.join(config.glade_dir, GLADE_FILENAME)
         self.widget_tree = gtk.glade.XML(glade_path)
-        self.window = self.widget_tree.get_widget("thread_window")
-        self.toolbar = self.widget_tree.get_widget("toolbar")
+        self._get_widgets()
+        self.widget_tree.signal_autoconnect(self)
+
         self.toolbar.unset_style()
-        self.statusbar = self.widget_tree.get_widget("statusbar")
-        self.vbox = self.widget_tree.get_widget("vbox")
 
         self.threadview = thread_view.ThreadView()
         self.threadpopup = thread_popup.ThreadPopup(self.bbs_type)
@@ -153,15 +153,31 @@ class WinWrap(winwrapbase.WinWrapBase):
         self.vbox.reorder_child(self.threadview, 2)
         self.window.set_focus(self.threadview.drawingarea)
 
-        self.threadview.connect("uri-clicked-event", self.on_threadview_uri_clicked)
+        self._get_popupmenu_widgets()
+
+        self.threadview.connect(
+            "uri-clicked-event", self.on_thread_view_uri_clicked)
         self.threadpopup.connect(
-            "uri-clicked-event",
-            lambda widget, threadview, uri: self.on_threadview_uri_clicked(threadview, uri))
+            "uri-clicked-event", self.on_thread_popup_uri_clicked)
 
         self.statusbar_context_id = self.statusbar.get_context_id(
             "Thread Window Status")
         self.statusbar.push(self.statusbar_context_id, "OK.")
 
+        self.initialize_buffer()
+
+        self.restore()
+        self.window.show_all()
+
+        self.created()
+
+    def _get_widgets(self):
+        self.window = self.widget_tree.get_widget("thread_window")
+        self.toolbar = self.widget_tree.get_widget("toolbar")
+        self.statusbar = self.widget_tree.get_widget("statusbar")
+        self.vbox = self.widget_tree.get_widget("vbox")
+
+    def _get_popupmenu_widgets(self):
         self.threadview.popupmenu = self.widget_tree.get_widget(
             "popup_threadview_menu")
         self.threadview.menu_openuri = self.widget_tree.get_widget(
@@ -177,40 +193,6 @@ class WinWrap(winwrapbase.WinWrapBase):
         self.threadview.menu_separator_selection = self.widget_tree.get_widget(
             "popup_threadview_menu_separator_selection")
 
-        self.initialize_buffer()
-
-        sigdic = {"on_refresh_activate": self.update,
-                  "on_compose_activate": self.on_compose_clicked,
-                  "on_toolbar_activate": self.on_toolbar_activate,
-                  "on_statusbar_activate": self.on_statusbar_activate,
-                  "on_refresh_activate": self.update,
-                  "on_close_activate": self.on_close_activate,
-                  "on_quit_activate": self.on_quit_activate,
-                  "on_show_board_activate": self.on_show_board_activate,
-                  "on_delete_activate": self.on_delete_activate,
-                  "on_thread_window_delete_event":
-                  self.on_thread_window_delete_event,
-                  "on_add_bookmark_activate": self.on_add_bookmark_activate,
-                  "on_manage_bookmarks_activate": \
-                  self.on_manage_bookmarks_activate,
-                  "on_popup_threadview_menu_openuri_activate":
-                  self.on_popup_threadview_menu_openuri_activate,
-                  "on_popup_threadview_menu_copylinkaddress_activate":
-                  self.on_popup_threadview_menu_copylinkaddress_activate,
-                  "on_popup_threadview_menu_copyselection_activate":
-                  self.on_popup_threadview_menu_copyselection_activate,
-                  "on_popup_threadview_menu_openasuri_activate":
-                  self.on_popup_threadview_menu_openasuri_activate,
-                  "on_popup_threadview_menu_refresh_activate":
-                  self.on_popup_threadview_menu_refresh_activate,
-                  "on_thread_window_destroy": self.on_thread_window_destroy}
-        self.widget_tree.signal_autoconnect(sigdic)
-
-        self.restore()
-        self.window.show_all()
-
-        self.created()
-
     def initialize_buffer(self):
         self.threadview.initialize_buffer()
 
@@ -221,46 +203,38 @@ class WinWrap(winwrapbase.WinWrapBase):
     def get_uri(self):
         return self.bbs_type.get_thread_uri()
 
-    def on_compose_clicked(self, widget):
-        import submit_window
+    def _show_submit_window(self):
         submit_window.open(self.bbs_type.get_thread_uri())
 
-    def on_toolbar_activate(self, widget):
+    def _toggle_toolbar(self):
         if self.toolbar.get_property("visible"):
             self.toolbar.hide()
         else:
             self.toolbar.show()
 
-    def on_statusbar_activate(self, widget):
+    def _toggle_statusbar(self):
         if self.statusbar.get_property("visible"):
             self.statusbar.hide()
         else:
             self.statusbar.show()
 
-    def on_close_activate(self, widget):
+    def _close_window(self):
         self.destroy()
 
-    def on_thread_window_delete_event(self, widget, event):
-        self.save()
-        return False
-        
-    def on_thread_window_destroy(self, widget):
-        self.destroyed()
-
-    def on_quit_activate(self, widget):
+    def _quit_session(self):
         session.main_quit()
 
-    def on_add_bookmark_activate(self, widget):
+    def _regist_as_bookmark(self):
         bookmark_list.bookmark_list.add_bookmark_with_edit(
             name=self.title, uri=self.bbs_type.uri)
 
-    def on_manage_bookmarks_activate(self, widget):
+    def _manage_bookmarks(self):
         bookmark_window.open()
 
-    def on_show_board_activate(self, widget):
+    def _show_board(self):
         board_window.open_board(self.bbs_type.get_uri_base())
 
-    def on_delete_activate(self, widget):
+    def _delete_log(self):
         try:
             dat_path = misc.get_thread_dat_path(self.bbs_type)
             os.remove(dat_path)
@@ -277,8 +251,7 @@ class WinWrap(winwrapbase.WinWrapBase):
         except OSError:
             traceback.print_exc()
 
-    def on_threadview_uri_clicked(self, widget, uri):
-
+    def _open_uri(self, uri):
         if not uri.startswith("http://"):
             # maybe a relative uri.
             uri = urlparse.urljoin(self.bbs_type.get_uri_base(), uri)
@@ -288,29 +261,17 @@ class WinWrap(winwrapbase.WinWrapBase):
         except bbs_type_exception.BbsTypeError:
             # not supported, show with the web browser.
             gnome.url_show(uri)
-            
-    def on_popup_threadview_menu_openuri_activate(self, widget):
-        self.on_threadview_uri_clicked(widget.uri)
 
-    def on_popup_threadview_menu_copylinkaddress_activate(self, widget):
-        clip = gtk.Clipboard()
-        clip.set_text(widget.uri, len(widget.uri))
-
-    def on_popup_threadview_menu_copyselection_activate(self, widget):
-        text = self.threadview.get_selected_text()
+    def _copy_text_to_clipboard(self, text):
         if text and len(text) > 0:
             clip = gtk.Clipboard()
             text = text.encode("utf8")
             clip.set_text(text, len(text))
 
-    def on_popup_threadview_menu_openasuri_activate(self, widget):
-        text = self.threadview.get_selected_text()
-        if not text.startswith("http://"):
-            text = "http://" + text
-        self.on_threadview_uri_clicked(text)
-
-    def on_popup_threadview_menu_refresh_activate(self, widget):
-        self.update(widget)
+    def _modify_uri(self, uri):
+        if not uri.startswith("http://"):
+            uri = "http://" + uri
+        return uri
 
     def http_get_dat(self, on_get_res):
         datfile_url = self.bbs_type.get_dat_uri()
@@ -389,7 +350,7 @@ class WinWrap(winwrapbase.WinWrapBase):
                 gobject.idle_add(session.thread_idx_updated,
                                  self.bbs_type.get_thread_uri(), idx_dic)
 
-    def update(self, widget=None):
+    def update(self):
 
         self.jump_request_num = 0
 
@@ -675,3 +636,94 @@ class WinWrap(winwrapbase.WinWrapBase):
                                  priority=gobject.PRIORITY_HIGH)
         except:
             traceback.print_exc()
+
+
+    # signal handlers
+    
+    def on_thread_view_uri_clicked(self, widget, uri):
+        self._open_uri(uri)
+
+    def on_thread_popup_uri_clicked(self, widget, threadview, uri):
+        self._open_uri(uri)
+
+    def on_thread_window_delete_event(self, widget, event):
+        self.save()
+        return False
+
+    def on_thread_window_destroy(self, widget):
+        self.destroyed()
+
+
+
+
+    # menu commands
+
+    # menu file
+
+    def on_menu_file_show_board_activate(self, widget):
+        self._show_board()
+
+    def on_menu_file_compose_activate(self, widget):
+        self._show_submit_window()
+
+    def on_menu_file_delete_activate(self, widget):
+        self._delete_log()
+
+    def on_menu_file_close_activate(self, widget):
+        self._close_window()
+
+    def on_menu_file_quit_activate(self, widget):
+        self._quit_session()
+
+    # menu view
+    
+    def on_menu_view_refresh_activate(self, widget):
+        self.update()
+
+    def on_menu_view_toolbar_activate(self, widget):
+        self._toggle_toolbar()
+
+    def on_menu_view_statusbar_activate(self, widget):
+        self._toggle_statusbar()
+
+    # menu bookmarks
+
+    def on_menu_bookmarks_bookmarkthispage_activate(self, widget):
+        self._regist_as_bookmark()
+
+    def on_menu_bookmarks_showbookmarks_activate(self, widget):
+        self._manage_bookmarks()
+
+    # toolbuttons
+    
+    def on_toolbutton_refresh_activate(self, widget):
+        self.update()
+
+    def on_toolbutton_showboard_activate(self, widget):
+        self._show_board()
+
+    def on_toolbutton_compose_activate(self, widget):
+        self._show_submit_window()
+
+    def on_toolbutton_delete_activate(self, widget):
+        self._delete_log()
+
+    # popup menus
+    
+    def on_popup_threadview_menu_openuri_activate(self, widget):
+        self._open_uri(widget.uri)
+
+    def on_popup_threadview_menu_copylinkaddress_activate(self, widget):
+        self._copy_text_to_clipboard(widget.uri)
+
+    def on_popup_threadview_menu_copyselection_activate(self, widget):
+        text = self.threadview.get_selected_text()
+        self._copy_text_to_clipboard(text)
+
+    def on_popup_threadview_menu_openasuri_activate(self, widget):
+        text = self.threadview.get_selected_text()
+        uri = self._modify_uri(text)
+        self._open_uri(uri)
+
+    def on_popup_threadview_menu_refresh_activate(self, widget):
+        self.update()
index e3841ed..aa50147 100644 (file)
@@ -30,7 +30,7 @@
                         <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                         <property name="label" translatable="yes">Show Board</property>
                         <property name="use_underline">True</property>
-                        <signal name="activate" handler="on_show_board_activate"/>
+                        <signal name="activate" handler="on_menu_file_show_board_activate"/>
                         <child internal-child="image">
                           <widget class="GtkImage" id="menu-item-image11">
                             <property name="stock">gtk-go-up</property>
@@ -44,7 +44,7 @@
                         <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                         <property name="label" translatable="yes">_Compose Message</property>
                         <property name="use_underline">True</property>
-                        <signal name="activate" handler="on_compose_activate"/>
+                        <signal name="activate" handler="on_menu_file_compose_activate"/>
                         <accelerator key="S" modifiers="GDK_CONTROL_MASK" signal="activate"/>
                         <child internal-child="image">
                           <widget class="GtkImage" id="menu-item-image12">
@@ -60,7 +60,7 @@
                         <property name="label" translatable="yes">gtk-delete</property>
                         <property name="use_underline">True</property>
                         <property name="use_stock">True</property>
-                        <signal name="activate" handler="on_delete_activate"/>
+                        <signal name="activate" handler="on_menu_file_delete_activate"/>
                       </widget>
                     </child>
                     <child>
@@ -76,7 +76,7 @@
                         <property name="label" translatable="yes">gtk-close</property>
                         <property name="use_underline">True</property>
                         <property name="use_stock">True</property>
-                        <signal name="activate" handler="on_close_activate"/>
+                        <signal name="activate" handler="on_menu_file_close_activate"/>
                       </widget>
                     </child>
                     <child>
@@ -92,7 +92,7 @@
                         <property name="label" translatable="yes">gtk-quit</property>
                         <property name="use_underline">True</property>
                         <property name="use_stock">True</property>
-                        <signal name="activate" handler="on_quit_activate"/>
+                        <signal name="activate" handler="on_menu_file_quit_activate"/>
                       </widget>
                     </child>
                   </widget>
                         <property name="label" translatable="yes">gtk-refresh</property>
                         <property name="use_underline">True</property>
                         <property name="use_stock">True</property>
-                        <signal name="activate" handler="on_refresh_activate"/>
+                        <signal name="activate" handler="on_menu_view_refresh_activate"/>
                         <accelerator key="R" modifiers="GDK_CONTROL_MASK" signal="activate"/>
                       </widget>
                     </child>
                         <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                         <property name="label" translatable="yes">_Toolbar</property>
                         <property name="use_underline">True</property>
-                        <signal name="activate" handler="on_toolbar_activate"/>
+                        <signal name="activate" handler="on_menu_view_toolbar_activate"/>
                       </widget>
                     </child>
                     <child>
                         <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                         <property name="label" translatable="yes">_Statusbar</property>
                         <property name="use_underline">True</property>
-                        <signal name="activate" handler="on_statusbar_activate"/>
+                        <signal name="activate" handler="on_menu_view_statusbar_activate"/>
                       </widget>
                     </child>
                   </widget>
                         <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                         <property name="label" translatable="yes">Bookmark This Page</property>
                         <property name="use_underline">True</property>
-                        <signal name="activate" handler="on_add_bookmark_activate"/>
+                        <signal name="activate" handler="on_menu_bookmarks_bookmarkthispage_activate"/>
                       </widget>
                     </child>
                     <child>
                         <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
                         <property name="label" translatable="yes">_Show Bookmarks</property>
                         <property name="use_underline">True</property>
-                        <signal name="activate" handler="on_manage_bookmarks_activate"/>
+                        <signal name="activate" handler="on_menu_bookmarks_showbookmarks_activate"/>
                       </widget>
                     </child>
                   </widget>
               <widget class="GtkToolButton" id="toolbutton_refresh">
                 <property name="visible">True</property>
                 <property name="stock_id">gtk-refresh</property>
-                <signal name="clicked" handler="on_refresh_activate"/>
+                <signal name="clicked" handler="on_toolbutton_refresh_activate"/>
               </widget>
               <packing>
                 <property name="expand">False</property>
                 <property name="label" translatable="yes">Board</property>
                 <property name="use_underline">True</property>
                 <property name="stock_id">gtk-go-up</property>
-                <signal name="clicked" handler="on_show_board_activate"/>
+                <signal name="clicked" handler="on_toolbutton_showboard_activate"/>
               </widget>
               <packing>
                 <property name="expand">False</property>
                 <property name="label" translatable="yes">Compose</property>
                 <property name="use_underline">True</property>
                 <property name="stock_id">gnome-stock-mail-new</property>
-                <signal name="clicked" handler="on_compose_activate"/>
+                <signal name="clicked" handler="on_toolbutton_compose_activate"/>
               </widget>
               <packing>
                 <property name="expand">False</property>
               <widget class="GtkToolButton" id="toolbutton_delete">
                 <property name="visible">True</property>
                 <property name="stock_id">gtk-delete</property>
-                <signal name="clicked" handler="on_delete_activate"/>
+                <signal name="clicked" handler="on_toolbutton_delete_activate"/>
               </widget>
               <packing>
                 <property name="expand">False</property>