OSDN Git Service

Window managing auxiliary is added. It shows only same board windows. (#16374)
authorAiwota Programmer <aiwotaprog@tetteke.tk>
Wed, 29 Apr 2009 13:06:10 +0000 (22:06 +0900)
committerAiwota Programmer <aiwotaprog@tetteke.tk>
Wed, 29 Apr 2009 13:06:10 +0000 (22:06 +0900)
src/FukuiNoNamari/board_window.py
src/FukuiNoNamari/bookmark_window.py
src/FukuiNoNamari/session.py
src/FukuiNoNamari/status_icon.py [new file with mode: 0644]
src/FukuiNoNamari/thread_window.py
src/FukuiNoNamari/winwrapbase.py

index 3678de1..d03e684 100644 (file)
@@ -118,6 +118,12 @@ class WinWrap(winwrapbase.WinWrapBase, board_data.BoardData):
     def get_uri(self):
         return self.bbs_type.get_uri_base()
 
+    def show(self):
+        self.window.deiconify()
+
+    def hide(self):
+        self.window.iconify()
+
     def open_thread(self):
         treeselection = self.treeview.get_selection()
         model, iter = treeselection.get_selected()
index 440c702..062ac28 100644 (file)
@@ -110,6 +110,12 @@ class WinWrap(winwrapbase.WinWrapBase):
         self.bookmarklist.set_view(None)
         winwrapbase.WinWrapBase.destroyed(self)
 
+    def show(self):
+        self.window.deiconify()
+
+    def hide(self):
+        self.window.iconify()
+
     def destroy(self):
         self.window.destroy()
 
index 2f8deb2..ae133c7 100644 (file)
@@ -26,6 +26,7 @@ import uri_opener
 from BbsType import bbs_type_judge_uri
 from BbsType import bbs_type_exception
 import config
+import status_icon
 
 # key: /bbs/board/thread value: toplevel window widget
 _windows = {}
@@ -77,6 +78,18 @@ class Gconf:
 
 _gconf = Gconf()
 
+
+def show_window(uri):
+    if uri in _windows:
+        _windows[uri].show()
+
+def hide_window(uri):
+    if uri in _windows:
+        _windows[uri].hide()
+
+def get_windows_uris():
+    return _windows.keys()
+
 def get_window(key):
     if key in _windows:
         return _windows[key]
@@ -148,6 +161,8 @@ def start():
     _gconf.restore()
     if not _windows:
         uri_opener.open_uri("http://dubai.2ch.net/morningcoffee/")
+    icon = gtk.status_icon_new_from_icon_name("")
+    icon.connect("popup-menu", status_icon.on_icon_popup_menu)
     gtk.gdk.threads_enter()
     gtk.main()
     gtk.gdk.threads_leave()
diff --git a/src/FukuiNoNamari/status_icon.py b/src/FukuiNoNamari/status_icon.py
new file mode 100644 (file)
index 0000000..188bee9
--- /dev/null
@@ -0,0 +1,89 @@
+# Copyright (C) 2009 by Aiwota Programmer
+# aiwotaprog@tetteke.tk
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+
+import gtk
+import traceback
+
+from BbsType import bbs_type_judge_uri
+from BbsType import bbs_type_exception
+import session
+
+def on_icon_popup_menu(icon, button, time):
+    menu = StatusIconMenu()
+    menu.show_all()
+    menu.popup(None, None, gtk.status_icon_position_menu,button, time, icon)
+
+
+class StatusIconMenu(gtk.Menu):
+
+    def __init__(self):
+        gtk.Menu.__init__(self)
+        
+        self._bbs_dict = {}
+
+        self._build_bbs_dict()
+        self._build_menu_items()
+
+        item = gtk.MenuItem("show all")
+        item.connect("activate", self.on_menu_item_show_all_activate)
+        self.append(item)
+
+    def _build_menu_items(self):
+        for bbsname, boards in self._bbs_dict.iteritems():
+            for board in boards:
+                label = 'show "' + bbsname + '" "' + board + '" only'
+                item = gtk.MenuItem(label)
+                item.connect("activate", self.on_menu_item_activate,
+                             bbsname, board)
+                self.append(item)
+
+
+    def _build_bbs_dict(self):
+        uris = session.get_windows_uris()
+
+        bbs_dict = {} ## key: bbs_type  value: list of board
+
+        for uri in uris:
+            try:
+                bbs_type = bbs_type_judge_uri.get_type(uri)
+                if bbs_type.bbs_type not in bbs_dict:
+                    bbs_dict[bbs_type.bbs_type] = [bbs_type.board]
+                elif bbs_type.board not in bbs_dict[bbs_type.bbs_type]:
+                    bbs_dict[bbs_type.bbs_type].append(bbs_type.board)
+            except bbs_type_exception.BbsTypeError:
+                pass
+
+        self._bbs_dict = bbs_dict
+
+    def on_menu_item_activate(self, widget, bbsname, board):
+        uris = session.get_windows_uris()
+
+        for uri in uris:
+            try:
+                bbs_type = bbs_type_judge_uri.get_type(uri)
+                if bbs_type.bbs_type == bbsname and bbs_type.board == board:
+                    session.show_window(uri)
+                else:
+                    session.hide_window(uri)
+            except bbs_type_exception.BbsTypeError:
+                pass
+
+    def on_menu_item_show_all_activate(self, widget):
+        uris = session.get_windows_uris()
+        for uri in uris:
+            session.show_window(uri)
index dbc7584..6ce6394 100644 (file)
@@ -203,6 +203,12 @@ class WinWrap(winwrapbase.WinWrapBase):
     def get_uri(self):
         return self.bbs_type.get_thread_uri()
 
+    def show(self):
+        self.window.deiconify()
+
+    def hide(self):
+        self.window.iconify()
+
     def _show_submit_window(self):
         submit_window.open(self.bbs_type.get_thread_uri())
 
index 7bba504..4b44ebc 100644 (file)
@@ -29,6 +29,8 @@ class WinWrapBase:
     def on_thread_idx_updated(self, uri, dict):
         pass
 
+    def show(self): pass
+    def hide(self): pass
 
     def created(self):
         session.regist(self)