Fukui no Namari
Revision | ae595951dfb27bddcdde33ab4d4af0c902de5ff9 (tree) |
---|---|
Time | 2009-04-19 16:18:50 |
Author | Aiwota Programmer <aiwotaprog@tett...> |
Commiter | Aiwota Programmer |
Refactoring menu items and toolbuttons commands in ThreadWindow.
@@ -51,6 +51,7 @@ import bookmark_list | ||
51 | 51 | import bookmark_window |
52 | 52 | import thread_view |
53 | 53 | import thread_popup |
54 | +import submit_window | |
54 | 55 | |
55 | 56 | GLADE_FILENAME = "thread_window.glade" |
56 | 57 |
@@ -140,11 +141,10 @@ class WinWrap(winwrapbase.WinWrapBase): | ||
140 | 141 | |
141 | 142 | glade_path = os.path.join(config.glade_dir, GLADE_FILENAME) |
142 | 143 | self.widget_tree = gtk.glade.XML(glade_path) |
143 | - self.window = self.widget_tree.get_widget("thread_window") | |
144 | - self.toolbar = self.widget_tree.get_widget("toolbar") | |
144 | + self._get_widgets() | |
145 | + self.widget_tree.signal_autoconnect(self) | |
146 | + | |
145 | 147 | self.toolbar.unset_style() |
146 | - self.statusbar = self.widget_tree.get_widget("statusbar") | |
147 | - self.vbox = self.widget_tree.get_widget("vbox") | |
148 | 148 | |
149 | 149 | self.threadview = thread_view.ThreadView() |
150 | 150 | self.threadpopup = thread_popup.ThreadPopup(self.bbs_type) |
@@ -153,15 +153,31 @@ class WinWrap(winwrapbase.WinWrapBase): | ||
153 | 153 | self.vbox.reorder_child(self.threadview, 2) |
154 | 154 | self.window.set_focus(self.threadview.drawingarea) |
155 | 155 | |
156 | - self.threadview.connect("uri-clicked-event", self.on_threadview_uri_clicked) | |
156 | + self._get_popupmenu_widgets() | |
157 | + | |
158 | + self.threadview.connect( | |
159 | + "uri-clicked-event", self.on_thread_view_uri_clicked) | |
157 | 160 | self.threadpopup.connect( |
158 | - "uri-clicked-event", | |
159 | - lambda widget, threadview, uri: self.on_threadview_uri_clicked(threadview, uri)) | |
161 | + "uri-clicked-event", self.on_thread_popup_uri_clicked) | |
160 | 162 | |
161 | 163 | self.statusbar_context_id = self.statusbar.get_context_id( |
162 | 164 | "Thread Window Status") |
163 | 165 | self.statusbar.push(self.statusbar_context_id, "OK.") |
164 | 166 | |
167 | + self.initialize_buffer() | |
168 | + | |
169 | + self.restore() | |
170 | + self.window.show_all() | |
171 | + | |
172 | + self.created() | |
173 | + | |
174 | + def _get_widgets(self): | |
175 | + self.window = self.widget_tree.get_widget("thread_window") | |
176 | + self.toolbar = self.widget_tree.get_widget("toolbar") | |
177 | + self.statusbar = self.widget_tree.get_widget("statusbar") | |
178 | + self.vbox = self.widget_tree.get_widget("vbox") | |
179 | + | |
180 | + def _get_popupmenu_widgets(self): | |
165 | 181 | self.threadview.popupmenu = self.widget_tree.get_widget( |
166 | 182 | "popup_threadview_menu") |
167 | 183 | self.threadview.menu_openuri = self.widget_tree.get_widget( |
@@ -177,40 +193,6 @@ class WinWrap(winwrapbase.WinWrapBase): | ||
177 | 193 | self.threadview.menu_separator_selection = self.widget_tree.get_widget( |
178 | 194 | "popup_threadview_menu_separator_selection") |
179 | 195 | |
180 | - self.initialize_buffer() | |
181 | - | |
182 | - sigdic = {"on_refresh_activate": self.update, | |
183 | - "on_compose_activate": self.on_compose_clicked, | |
184 | - "on_toolbar_activate": self.on_toolbar_activate, | |
185 | - "on_statusbar_activate": self.on_statusbar_activate, | |
186 | - "on_refresh_activate": self.update, | |
187 | - "on_close_activate": self.on_close_activate, | |
188 | - "on_quit_activate": self.on_quit_activate, | |
189 | - "on_show_board_activate": self.on_show_board_activate, | |
190 | - "on_delete_activate": self.on_delete_activate, | |
191 | - "on_thread_window_delete_event": | |
192 | - self.on_thread_window_delete_event, | |
193 | - "on_add_bookmark_activate": self.on_add_bookmark_activate, | |
194 | - "on_manage_bookmarks_activate": \ | |
195 | - self.on_manage_bookmarks_activate, | |
196 | - "on_popup_threadview_menu_openuri_activate": | |
197 | - self.on_popup_threadview_menu_openuri_activate, | |
198 | - "on_popup_threadview_menu_copylinkaddress_activate": | |
199 | - self.on_popup_threadview_menu_copylinkaddress_activate, | |
200 | - "on_popup_threadview_menu_copyselection_activate": | |
201 | - self.on_popup_threadview_menu_copyselection_activate, | |
202 | - "on_popup_threadview_menu_openasuri_activate": | |
203 | - self.on_popup_threadview_menu_openasuri_activate, | |
204 | - "on_popup_threadview_menu_refresh_activate": | |
205 | - self.on_popup_threadview_menu_refresh_activate, | |
206 | - "on_thread_window_destroy": self.on_thread_window_destroy} | |
207 | - self.widget_tree.signal_autoconnect(sigdic) | |
208 | - | |
209 | - self.restore() | |
210 | - self.window.show_all() | |
211 | - | |
212 | - self.created() | |
213 | - | |
214 | 196 | def initialize_buffer(self): |
215 | 197 | self.threadview.initialize_buffer() |
216 | 198 |
@@ -221,46 +203,38 @@ class WinWrap(winwrapbase.WinWrapBase): | ||
221 | 203 | def get_uri(self): |
222 | 204 | return self.bbs_type.get_thread_uri() |
223 | 205 | |
224 | - def on_compose_clicked(self, widget): | |
225 | - import submit_window | |
206 | + def _show_submit_window(self): | |
226 | 207 | submit_window.open(self.bbs_type.get_thread_uri()) |
227 | 208 | |
228 | - def on_toolbar_activate(self, widget): | |
209 | + def _toggle_toolbar(self): | |
229 | 210 | if self.toolbar.get_property("visible"): |
230 | 211 | self.toolbar.hide() |
231 | 212 | else: |
232 | 213 | self.toolbar.show() |
233 | 214 | |
234 | - def on_statusbar_activate(self, widget): | |
215 | + def _toggle_statusbar(self): | |
235 | 216 | if self.statusbar.get_property("visible"): |
236 | 217 | self.statusbar.hide() |
237 | 218 | else: |
238 | 219 | self.statusbar.show() |
239 | 220 | |
240 | - def on_close_activate(self, widget): | |
221 | + def _close_window(self): | |
241 | 222 | self.destroy() |
242 | 223 | |
243 | - def on_thread_window_delete_event(self, widget, event): | |
244 | - self.save() | |
245 | - return False | |
246 | - | |
247 | - def on_thread_window_destroy(self, widget): | |
248 | - self.destroyed() | |
249 | - | |
250 | - def on_quit_activate(self, widget): | |
224 | + def _quit_session(self): | |
251 | 225 | session.main_quit() |
252 | 226 | |
253 | - def on_add_bookmark_activate(self, widget): | |
227 | + def _regist_as_bookmark(self): | |
254 | 228 | bookmark_list.bookmark_list.add_bookmark_with_edit( |
255 | 229 | name=self.title, uri=self.bbs_type.uri) |
256 | 230 | |
257 | - def on_manage_bookmarks_activate(self, widget): | |
231 | + def _manage_bookmarks(self): | |
258 | 232 | bookmark_window.open() |
259 | 233 | |
260 | - def on_show_board_activate(self, widget): | |
234 | + def _show_board(self): | |
261 | 235 | board_window.open_board(self.bbs_type.get_uri_base()) |
262 | 236 | |
263 | - def on_delete_activate(self, widget): | |
237 | + def _delete_log(self): | |
264 | 238 | try: |
265 | 239 | dat_path = misc.get_thread_dat_path(self.bbs_type) |
266 | 240 | os.remove(dat_path) |
@@ -277,8 +251,7 @@ class WinWrap(winwrapbase.WinWrapBase): | ||
277 | 251 | except OSError: |
278 | 252 | traceback.print_exc() |
279 | 253 | |
280 | - def on_threadview_uri_clicked(self, widget, uri): | |
281 | - | |
254 | + def _open_uri(self, uri): | |
282 | 255 | if not uri.startswith("http://"): |
283 | 256 | # maybe a relative uri. |
284 | 257 | uri = urlparse.urljoin(self.bbs_type.get_uri_base(), uri) |
@@ -288,29 +261,17 @@ class WinWrap(winwrapbase.WinWrapBase): | ||
288 | 261 | except bbs_type_exception.BbsTypeError: |
289 | 262 | # not supported, show with the web browser. |
290 | 263 | gnome.url_show(uri) |
291 | - | |
292 | - def on_popup_threadview_menu_openuri_activate(self, widget): | |
293 | - self.on_threadview_uri_clicked(widget.uri) | |
294 | 264 | |
295 | - def on_popup_threadview_menu_copylinkaddress_activate(self, widget): | |
296 | - clip = gtk.Clipboard() | |
297 | - clip.set_text(widget.uri, len(widget.uri)) | |
298 | - | |
299 | - def on_popup_threadview_menu_copyselection_activate(self, widget): | |
300 | - text = self.threadview.get_selected_text() | |
265 | + def _copy_text_to_clipboard(self, text): | |
301 | 266 | if text and len(text) > 0: |
302 | 267 | clip = gtk.Clipboard() |
303 | 268 | text = text.encode("utf8") |
304 | 269 | clip.set_text(text, len(text)) |
305 | 270 | |
306 | - def on_popup_threadview_menu_openasuri_activate(self, widget): | |
307 | - text = self.threadview.get_selected_text() | |
308 | - if not text.startswith("http://"): | |
309 | - text = "http://" + text | |
310 | - self.on_threadview_uri_clicked(text) | |
311 | - | |
312 | - def on_popup_threadview_menu_refresh_activate(self, widget): | |
313 | - self.update(widget) | |
271 | + def _modify_uri(self, uri): | |
272 | + if not uri.startswith("http://"): | |
273 | + uri = "http://" + uri | |
274 | + return uri | |
314 | 275 | |
315 | 276 | def http_get_dat(self, on_get_res): |
316 | 277 | datfile_url = self.bbs_type.get_dat_uri() |
@@ -389,7 +350,7 @@ class WinWrap(winwrapbase.WinWrapBase): | ||
389 | 350 | gobject.idle_add(session.thread_idx_updated, |
390 | 351 | self.bbs_type.get_thread_uri(), idx_dic) |
391 | 352 | |
392 | - def update(self, widget=None): | |
353 | + def update(self): | |
393 | 354 | |
394 | 355 | self.jump_request_num = 0 |
395 | 356 |
@@ -675,3 +636,94 @@ class WinWrap(winwrapbase.WinWrapBase): | ||
675 | 636 | priority=gobject.PRIORITY_HIGH) |
676 | 637 | except: |
677 | 638 | traceback.print_exc() |
639 | + | |
640 | + | |
641 | + # signal handlers | |
642 | + | |
643 | + def on_thread_view_uri_clicked(self, widget, uri): | |
644 | + self._open_uri(uri) | |
645 | + | |
646 | + def on_thread_popup_uri_clicked(self, widget, threadview, uri): | |
647 | + self._open_uri(uri) | |
648 | + | |
649 | + def on_thread_window_delete_event(self, widget, event): | |
650 | + self.save() | |
651 | + return False | |
652 | + | |
653 | + def on_thread_window_destroy(self, widget): | |
654 | + self.destroyed() | |
655 | + | |
656 | + | |
657 | + | |
658 | + | |
659 | + # menu commands | |
660 | + | |
661 | + # menu file | |
662 | + | |
663 | + def on_menu_file_show_board_activate(self, widget): | |
664 | + self._show_board() | |
665 | + | |
666 | + def on_menu_file_compose_activate(self, widget): | |
667 | + self._show_submit_window() | |
668 | + | |
669 | + def on_menu_file_delete_activate(self, widget): | |
670 | + self._delete_log() | |
671 | + | |
672 | + def on_menu_file_close_activate(self, widget): | |
673 | + self._close_window() | |
674 | + | |
675 | + def on_menu_file_quit_activate(self, widget): | |
676 | + self._quit_session() | |
677 | + | |
678 | + # menu view | |
679 | + | |
680 | + def on_menu_view_refresh_activate(self, widget): | |
681 | + self.update() | |
682 | + | |
683 | + def on_menu_view_toolbar_activate(self, widget): | |
684 | + self._toggle_toolbar() | |
685 | + | |
686 | + def on_menu_view_statusbar_activate(self, widget): | |
687 | + self._toggle_statusbar() | |
688 | + | |
689 | + # menu bookmarks | |
690 | + | |
691 | + def on_menu_bookmarks_bookmarkthispage_activate(self, widget): | |
692 | + self._regist_as_bookmark() | |
693 | + | |
694 | + def on_menu_bookmarks_showbookmarks_activate(self, widget): | |
695 | + self._manage_bookmarks() | |
696 | + | |
697 | + # toolbuttons | |
698 | + | |
699 | + def on_toolbutton_refresh_activate(self, widget): | |
700 | + self.update() | |
701 | + | |
702 | + def on_toolbutton_showboard_activate(self, widget): | |
703 | + self._show_board() | |
704 | + | |
705 | + def on_toolbutton_compose_activate(self, widget): | |
706 | + self._show_submit_window() | |
707 | + | |
708 | + def on_toolbutton_delete_activate(self, widget): | |
709 | + self._delete_log() | |
710 | + | |
711 | + # popup menus | |
712 | + | |
713 | + def on_popup_threadview_menu_openuri_activate(self, widget): | |
714 | + self._open_uri(widget.uri) | |
715 | + | |
716 | + def on_popup_threadview_menu_copylinkaddress_activate(self, widget): | |
717 | + self._copy_text_to_clipboard(widget.uri) | |
718 | + | |
719 | + def on_popup_threadview_menu_copyselection_activate(self, widget): | |
720 | + text = self.threadview.get_selected_text() | |
721 | + self._copy_text_to_clipboard(text) | |
722 | + | |
723 | + def on_popup_threadview_menu_openasuri_activate(self, widget): | |
724 | + text = self.threadview.get_selected_text() | |
725 | + uri = self._modify_uri(text) | |
726 | + self._open_uri(uri) | |
727 | + | |
728 | + def on_popup_threadview_menu_refresh_activate(self, widget): | |
729 | + self.update() |
@@ -30,7 +30,7 @@ | ||
30 | 30 | <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property> |
31 | 31 | <property name="label" translatable="yes">Show Board</property> |
32 | 32 | <property name="use_underline">True</property> |
33 | - <signal name="activate" handler="on_show_board_activate"/> | |
33 | + <signal name="activate" handler="on_menu_file_show_board_activate"/> | |
34 | 34 | <child internal-child="image"> |
35 | 35 | <widget class="GtkImage" id="menu-item-image11"> |
36 | 36 | <property name="stock">gtk-go-up</property> |
@@ -44,7 +44,7 @@ | ||
44 | 44 | <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property> |
45 | 45 | <property name="label" translatable="yes">_Compose Message</property> |
46 | 46 | <property name="use_underline">True</property> |
47 | - <signal name="activate" handler="on_compose_activate"/> | |
47 | + <signal name="activate" handler="on_menu_file_compose_activate"/> | |
48 | 48 | <accelerator key="S" modifiers="GDK_CONTROL_MASK" signal="activate"/> |
49 | 49 | <child internal-child="image"> |
50 | 50 | <widget class="GtkImage" id="menu-item-image12"> |
@@ -60,7 +60,7 @@ | ||
60 | 60 | <property name="label" translatable="yes">gtk-delete</property> |
61 | 61 | <property name="use_underline">True</property> |
62 | 62 | <property name="use_stock">True</property> |
63 | - <signal name="activate" handler="on_delete_activate"/> | |
63 | + <signal name="activate" handler="on_menu_file_delete_activate"/> | |
64 | 64 | </widget> |
65 | 65 | </child> |
66 | 66 | <child> |
@@ -76,7 +76,7 @@ | ||
76 | 76 | <property name="label" translatable="yes">gtk-close</property> |
77 | 77 | <property name="use_underline">True</property> |
78 | 78 | <property name="use_stock">True</property> |
79 | - <signal name="activate" handler="on_close_activate"/> | |
79 | + <signal name="activate" handler="on_menu_file_close_activate"/> | |
80 | 80 | </widget> |
81 | 81 | </child> |
82 | 82 | <child> |
@@ -92,7 +92,7 @@ | ||
92 | 92 | <property name="label" translatable="yes">gtk-quit</property> |
93 | 93 | <property name="use_underline">True</property> |
94 | 94 | <property name="use_stock">True</property> |
95 | - <signal name="activate" handler="on_quit_activate"/> | |
95 | + <signal name="activate" handler="on_menu_file_quit_activate"/> | |
96 | 96 | </widget> |
97 | 97 | </child> |
98 | 98 | </widget> |
@@ -124,7 +124,7 @@ | ||
124 | 124 | <property name="label" translatable="yes">gtk-refresh</property> |
125 | 125 | <property name="use_underline">True</property> |
126 | 126 | <property name="use_stock">True</property> |
127 | - <signal name="activate" handler="on_refresh_activate"/> | |
127 | + <signal name="activate" handler="on_menu_view_refresh_activate"/> | |
128 | 128 | <accelerator key="R" modifiers="GDK_CONTROL_MASK" signal="activate"/> |
129 | 129 | </widget> |
130 | 130 | </child> |
@@ -140,7 +140,7 @@ | ||
140 | 140 | <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property> |
141 | 141 | <property name="label" translatable="yes">_Toolbar</property> |
142 | 142 | <property name="use_underline">True</property> |
143 | - <signal name="activate" handler="on_toolbar_activate"/> | |
143 | + <signal name="activate" handler="on_menu_view_toolbar_activate"/> | |
144 | 144 | </widget> |
145 | 145 | </child> |
146 | 146 | <child> |
@@ -149,7 +149,7 @@ | ||
149 | 149 | <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property> |
150 | 150 | <property name="label" translatable="yes">_Statusbar</property> |
151 | 151 | <property name="use_underline">True</property> |
152 | - <signal name="activate" handler="on_statusbar_activate"/> | |
152 | + <signal name="activate" handler="on_menu_view_statusbar_activate"/> | |
153 | 153 | </widget> |
154 | 154 | </child> |
155 | 155 | </widget> |
@@ -172,7 +172,7 @@ | ||
172 | 172 | <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property> |
173 | 173 | <property name="label" translatable="yes">Bookmark This Page</property> |
174 | 174 | <property name="use_underline">True</property> |
175 | - <signal name="activate" handler="on_add_bookmark_activate"/> | |
175 | + <signal name="activate" handler="on_menu_bookmarks_bookmarkthispage_activate"/> | |
176 | 176 | </widget> |
177 | 177 | </child> |
178 | 178 | <child> |
@@ -181,7 +181,7 @@ | ||
181 | 181 | <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property> |
182 | 182 | <property name="label" translatable="yes">_Show Bookmarks</property> |
183 | 183 | <property name="use_underline">True</property> |
184 | - <signal name="activate" handler="on_manage_bookmarks_activate"/> | |
184 | + <signal name="activate" handler="on_menu_bookmarks_showbookmarks_activate"/> | |
185 | 185 | </widget> |
186 | 186 | </child> |
187 | 187 | </widget> |
@@ -224,7 +224,7 @@ | ||
224 | 224 | <widget class="GtkToolButton" id="toolbutton_refresh"> |
225 | 225 | <property name="visible">True</property> |
226 | 226 | <property name="stock_id">gtk-refresh</property> |
227 | - <signal name="clicked" handler="on_refresh_activate"/> | |
227 | + <signal name="clicked" handler="on_toolbutton_refresh_activate"/> | |
228 | 228 | </widget> |
229 | 229 | <packing> |
230 | 230 | <property name="expand">False</property> |
@@ -236,7 +236,7 @@ | ||
236 | 236 | <property name="label" translatable="yes">Board</property> |
237 | 237 | <property name="use_underline">True</property> |
238 | 238 | <property name="stock_id">gtk-go-up</property> |
239 | - <signal name="clicked" handler="on_show_board_activate"/> | |
239 | + <signal name="clicked" handler="on_toolbutton_showboard_activate"/> | |
240 | 240 | </widget> |
241 | 241 | <packing> |
242 | 242 | <property name="expand">False</property> |
@@ -248,7 +248,7 @@ | ||
248 | 248 | <property name="label" translatable="yes">Compose</property> |
249 | 249 | <property name="use_underline">True</property> |
250 | 250 | <property name="stock_id">gnome-stock-mail-new</property> |
251 | - <signal name="clicked" handler="on_compose_activate"/> | |
251 | + <signal name="clicked" handler="on_toolbutton_compose_activate"/> | |
252 | 252 | </widget> |
253 | 253 | <packing> |
254 | 254 | <property name="expand">False</property> |
@@ -258,7 +258,7 @@ | ||
258 | 258 | <widget class="GtkToolButton" id="toolbutton_delete"> |
259 | 259 | <property name="visible">True</property> |
260 | 260 | <property name="stock_id">gtk-delete</property> |
261 | - <signal name="clicked" handler="on_delete_activate"/> | |
261 | + <signal name="clicked" handler="on_toolbutton_delete_activate"/> | |
262 | 262 | </widget> |
263 | 263 | <packing> |
264 | 264 | <property name="expand">False</property> |