OSDN Git Service

Multithreads are abandoned. Alternatly, The asyncore substitutes.(#16776)
[fukui-no-namari/fukui-no-namari.git] / src / FukuiNoNamari / status_icon.py
1 # Copyright (C) 2009 by Aiwota Programmer
2 # aiwotaprog@tetteke.tk
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18
19 import gtk
20 import traceback
21
22 from BbsType import bbs_type_judge_uri
23 from BbsType import bbs_type_exception
24 import session
25
26 def on_icon_popup_menu(icon, button, time):
27     menu = StatusIconMenu()
28     menu.show_all()
29     menu.popup(None, None, gtk.status_icon_position_menu,button, time, icon)
30
31
32 class StatusIconMenu(gtk.Menu):
33
34     def __init__(self):
35         gtk.Menu.__init__(self)
36         
37         self._bbs_dict = {}
38
39         self._build_bbs_dict()
40         self._build_menu_items()
41
42         item = gtk.MenuItem("show all")
43         item.connect("activate", self.on_menu_item_show_all_activate)
44         self.append(item)
45
46     def _build_menu_items(self):
47         for bbsname, boards in self._bbs_dict.iteritems():
48             for board in boards:
49                 label = 'show "' + bbsname + '" "' + board + '" only'
50                 item = gtk.MenuItem(label)
51                 item.connect("activate", self.on_menu_item_activate,
52                              bbsname, board)
53                 self.append(item)
54
55
56     def _build_bbs_dict(self):
57         uris = session.get_windows_uris()
58
59         bbs_dict = {} ## key: bbs_type  value: list of board
60
61         for uri in uris:
62             try:
63                 bbs_type = bbs_type_judge_uri.get_type(uri)
64                 if bbs_type.bbs_type not in bbs_dict:
65                     bbs_dict[bbs_type.bbs_type] = [bbs_type.board]
66                 elif bbs_type.board not in bbs_dict[bbs_type.bbs_type]:
67                     bbs_dict[bbs_type.bbs_type].append(bbs_type.board)
68             except bbs_type_exception.BbsTypeError:
69                 pass
70
71         self._bbs_dict = bbs_dict
72
73     def on_menu_item_activate(self, widget, bbsname, board):
74         uris = session.get_windows_uris()
75
76         for uri in uris:
77             try:
78                 bbs_type = bbs_type_judge_uri.get_type(uri)
79                 if bbs_type.bbs_type == bbsname and bbs_type.board == board:
80                     session.show_window(uri)
81                 else:
82                     session.hide_window(uri)
83             except bbs_type_exception.BbsTypeError:
84                 pass
85
86     def on_menu_item_show_all_activate(self, widget):
87         uris = session.get_windows_uris()
88         for uri in uris:
89             session.show_window(uri)