OSDN Git Service

Exit when all windows are destroyed. Add board list window.
authorAiwota Programmer <aiwotaprog@tetteke.tk>
Sun, 20 Aug 2006 13:22:54 +0000 (22:22 +0900)
committerAiwota Programmer <aiwotaprog@tetteke.tk>
Sun, 20 Aug 2006 13:22:54 +0000 (22:22 +0900)
src/Hage1/board_window.py
src/Hage1/brdlist_window.py [new file with mode: 0644]
src/Hage1/windowlist.py [new file with mode: 0644]
src/data/board_window.glade
src/data/brdlist_window.glade [new file with mode: 0644]
src/hage1

index 405df63..87ddf20 100644 (file)
@@ -28,10 +28,28 @@ import thread_window
 import misc
 from threadlistmodel import ThreadListModel
 
+import windowlist
+import brdlist_window
+
 GLADE_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                          "..", "data")
 GLADE_FILENAME = "board_window.glade"
 
+def open_board(bbs, board):
+    if not bbs:
+        raise ValueError, "parameter must not be empty"
+
+    key = "/" + bbs + "/" + board
+    window = windowlist.get_window(key)
+    if window:
+        # already opened
+        window.present()
+        pass
+    else:
+        win_wrap = WinWrap(bbs, board)
+        widget = win_wrap.widget_tree.get_widget("board_window")
+        windowlist.window_created(key, widget)
+
 
 class WinWrap:
 
@@ -42,6 +60,8 @@ class WinWrap:
         glade_path = os.path.join(GLADE_DIR, GLADE_FILENAME)
         self.widget_tree = gtk.glade.XML(glade_path)
 
+        self.window = self.widget_tree.get_widget("board_window")
+
         self.treeview = self.widget_tree.get_widget("treeview")
         self.treeview.set_model(ThreadListModel())
 
@@ -74,6 +94,10 @@ class WinWrap:
                   lambda w,p,v: self.on_open_thread(w),
                   "on_treeview_button_press_event":
                   self.on_treeview_button_press_event,
+                  "on_close_activate":
+                  self.on_close_activate,
+                  "on_show_board_list_activate":
+                  self.on_show_board_list_activate,
                   "on_popup_menu_open_activate": self.on_open_thread}
         self.widget_tree.signal_autoconnect(sigdic)
 
@@ -114,11 +138,17 @@ class WinWrap:
                 "%Y/%m/%d(%a) %H:%M:%S", time.localtime(lastmod)))
 
     def on_board_window_destroy(self, widget):
-        gtk.main_quit()
+        pass
 
     def on_quit_activate(self, widget):
         gtk.main_quit()
 
+    def on_close_activate(self, widget):
+        self.window.destroy()
+
+    def on_show_board_list_activate(self, widget):
+        brdlist_window.open_brdlist(self.bbs)
+
     def on_load_local_activate(self, widget):
         t = board_data.LoadLocal(self.bbs, self.board, self.update_datastore)
         t.start()
diff --git a/src/Hage1/brdlist_window.py b/src/Hage1/brdlist_window.py
new file mode 100644 (file)
index 0000000..6b81642
--- /dev/null
@@ -0,0 +1,112 @@
+# Copyright (C) 2006 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 pygtk
+pygtk.require('2.0')
+import gtk
+import gtk.glade
+import os.path
+import gconf
+
+import windowlist
+import board_window
+import config
+
+GLADE_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)),
+                         "..", "data")
+GLADE_FILENAME = "brdlist_window.glade"
+
+def open_brdlist(bbs):
+    if not bbs:
+        raise ValueError, "parameter must not be empty"
+
+    key = "/" + bbs
+    window = windowlist.get_window(key)
+    if window:
+        window.present()
+    else:
+        win_wrap = WinWrap(bbs)
+        widget = win_wrap.widget_tree.get_widget("brdlist_window")
+        windowlist.window_created(key, widget)
+
+
+class WinWrap:
+
+    def __init__(self, bbs):
+        self.bbs = bbs
+
+        glade_path = os.path.join(GLADE_DIR, GLADE_FILENAME)
+        self.widget_tree = gtk.glade.XML(glade_path)
+
+        self.window = self.widget_tree.get_widget("brdlist_window")
+        self.treeview = self.widget_tree.get_widget("treeview")
+        self.model = gtk.ListStore(str, str, str)
+        self.treeview.set_model(self.model)
+
+        renderer = gtk.CellRendererText()
+        column_names = ["id", "host", "name"]
+        for i in range(3):
+            self.treeviewcolumn = gtk.TreeViewColumn(column_names[i],
+                                                     renderer, text=i)
+            self.treeviewcolumn.set_sort_column_id(i)
+            self.treeviewcolumn.set_resizable(True)
+            self.treeviewcolumn.set_reorderable(True)
+            self.treeview.append_column(self.treeviewcolumn)
+
+        self.treeview.connect("row-activated", self.on_row_activated)
+
+        sigdict = {"on_close_activate": self.on_close_activate,
+                   "on_quit_activate": self.on_quit_activate}
+        self.widget_tree.signal_autoconnect(sigdict)
+
+        self.build_list()
+
+    def build_list(self):
+        key_root = "/apps/" + config.APPNAME.lower() + "/boards/" + self.bbs
+        client = gconf.client_get_default()
+
+        # init
+        for board_dir in client.all_dirs(key_root):
+            bbs_dir, board = os.path.split(board_dir)
+            # host
+            key = board_dir + "/host"
+            host = client.get_string(key)
+            # name
+            key = board_dir + "/name"
+            name = client.get_string(key)
+            if board and host and name:
+                self.modify(board, host, name)
+
+    def modify(self, board, name, host):
+        self.model.append([board, name, host])
+
+    def on_close_activate(self, widget):
+        self.window.destroy()
+
+    def on_quit_activate(self, widget):
+        gtk.main_quit()
+
+    def on_row_activated(self, widget, path, view_column):
+        model = widget.get_model()
+        if model:
+            iter = model.get_iter(path)
+            if iter:
+                board = model.get_value(iter, 0)
+                self.open_board(board)
+
+    def open_board(self, board):
+        board_window.open_board(self.bbs, board)
diff --git a/src/Hage1/windowlist.py b/src/Hage1/windowlist.py
new file mode 100644 (file)
index 0000000..6888919
--- /dev/null
@@ -0,0 +1,54 @@
+# Copyright (C) 2006 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 pygtk
+pygtk.require('2.0')
+import gtk
+
+# key: /bbs/board/thread value: toplevel window widget
+_windows = {}
+
+def get_window(key):
+    if key in _windows:
+        return _windows[key]
+    else:
+        return None
+
+def window_created(key, widget):
+    if not key or not widget:
+        raise ValueError, "parameter must not be empty"
+
+    if key in _windows:
+        return False
+    widget.connect("destroy", on_window_destroy, key)
+    _windows[key] = widget
+    print "regist to _windows", key
+    return True
+
+def on_window_destroy(widget, key):
+    if key not in _windows:
+        return
+
+    del _windows[key]
+    print "unregist from _windows", key
+
+    if not _windows:
+        print "all window unregist"
+        on_all_window_destroy()
+
+def on_all_window_destroy():
+    gtk.main_quit()
index 372bf73..82e2f27 100644 (file)
                    <widget class="GtkMenu" id="file1_menu">
 
                      <child>
+                       <widget class="GtkMenuItem" id="show_board_list">
+                         <property name="visible">True</property>
+                         <property name="label" translatable="yes">Show _Board List</property>
+                         <property name="use_underline">True</property>
+                         <signal name="activate" handler="on_show_board_list_activate" last_modification_time="Sun, 20 Aug 2006 12:50:27 GMT"/>
+                         <accelerator key="B" modifiers="GDK_SHIFT_MASK" signal="activate"/>
+                       </widget>
+                     </child>
+
+                     <child>
                        <widget class="GtkImageMenuItem" id="load_local">
                          <property name="visible">True</property>
                          <property name="label" translatable="yes">_Load Local</property>
@@ -54,7 +64,7 @@
                          <accelerator key="L" modifiers="GDK_CONTROL_MASK" signal="activate"/>
 
                          <child internal-child="image">
-                           <widget class="GtkImage" id="image4">
+                           <widget class="GtkImage" id="image8">
                              <property name="visible">True</property>
                              <property name="stock">gtk-disconnect</property>
                              <property name="icon_size">1</property>
@@ -76,7 +86,7 @@
                          <accelerator key="R" modifiers="GDK_CONTROL_MASK" signal="activate"/>
 
                          <child internal-child="image">
-                           <widget class="GtkImage" id="image5">
+                           <widget class="GtkImage" id="image9">
                              <property name="visible">True</property>
                              <property name="stock">gtk-connect</property>
                              <property name="icon_size">1</property>
                      </child>
 
                      <child>
+                       <widget class="GtkImageMenuItem" id="close">
+                         <property name="visible">True</property>
+                         <property name="stock_item">GNOMEUIINFO_MENU_CLOSE_ITEM</property>
+                         <signal name="activate" handler="on_close_activate" last_modification_time="Sun, 20 Aug 2006 13:00:02 GMT"/>
+                       </widget>
+                     </child>
+
+                     <child>
+                       <widget class="GtkSeparatorMenuItem" id="separator1">
+                         <property name="visible">True</property>
+                       </widget>
+                     </child>
+
+                     <child>
                        <widget class="GtkImageMenuItem" id="quit">
                          <property name="visible">True</property>
                          <property name="stock_item">GNOMEUIINFO_MENU_EXIT_ITEM</property>
diff --git a/src/data/brdlist_window.glade b/src/data/brdlist_window.glade
new file mode 100644 (file)
index 0000000..e9ce42c
--- /dev/null
@@ -0,0 +1,230 @@
+<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
+<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
+
+<glade-interface>
+<requires lib="gnome"/>
+<requires lib="bonobo"/>
+
+<widget class="GnomeApp" id="brdlist_window">
+  <property name="visible">True</property>
+  <property name="title" translatable="yes">brdlist_window</property>
+  <property name="type">GTK_WINDOW_TOPLEVEL</property>
+  <property name="window_position">GTK_WIN_POS_NONE</property>
+  <property name="modal">False</property>
+  <property name="default_width">600</property>
+  <property name="default_height">600</property>
+  <property name="resizable">True</property>
+  <property name="destroy_with_parent">False</property>
+  <property name="decorated">True</property>
+  <property name="skip_taskbar_hint">False</property>
+  <property name="skip_pager_hint">False</property>
+  <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
+  <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
+  <property name="enable_layout_config">True</property>
+
+  <child internal-child="dock">
+    <widget class="BonoboDock" id="bonobodock1">
+      <property name="visible">True</property>
+      <property name="allow_floating">True</property>
+
+      <child>
+       <widget class="BonoboDockItem" id="bonobodockitem1">
+         <property name="visible">True</property>
+         <property name="shadow_type">GTK_SHADOW_NONE</property>
+
+         <child>
+           <widget class="GtkMenuBar" id="menubar1">
+             <property name="visible">True</property>
+
+             <child>
+               <widget class="GtkMenuItem" id="file1">
+                 <property name="visible">True</property>
+                 <property name="stock_item">GNOMEUIINFO_MENU_FILE_TREE</property>
+
+                 <child>
+                   <widget class="GtkMenu" id="file1_menu">
+
+                     <child>
+                       <widget class="GtkImageMenuItem" id="close">
+                         <property name="visible">True</property>
+                         <property name="stock_item">GNOMEUIINFO_MENU_CLOSE_ITEM</property>
+                         <signal name="activate" handler="on_close_activate" last_modification_time="Sun, 20 Aug 2006 13:05:11 GMT"/>
+                       </widget>
+                     </child>
+
+                     <child>
+                       <widget class="GtkSeparatorMenuItem" id="separator4">
+                         <property name="visible">True</property>
+                       </widget>
+                     </child>
+
+                     <child>
+                       <widget class="GtkImageMenuItem" id="quit">
+                         <property name="visible">True</property>
+                         <property name="stock_item">GNOMEUIINFO_MENU_EXIT_ITEM</property>
+                         <signal name="activate" handler="on_quit_activate" last_modification_time="Sun, 20 Aug 2006 13:06:42 GMT"/>
+                       </widget>
+                     </child>
+                   </widget>
+                 </child>
+               </widget>
+             </child>
+
+             <child>
+               <widget class="GtkMenuItem" id="edit1">
+                 <property name="visible">True</property>
+                 <property name="stock_item">GNOMEUIINFO_MENU_EDIT_TREE</property>
+               </widget>
+             </child>
+
+             <child>
+               <widget class="GtkMenuItem" id="view1">
+                 <property name="visible">True</property>
+                 <property name="stock_item">GNOMEUIINFO_MENU_VIEW_TREE</property>
+               </widget>
+             </child>
+
+             <child>
+               <widget class="GtkMenuItem" id="help1">
+                 <property name="visible">True</property>
+                 <property name="stock_item">GNOMEUIINFO_MENU_HELP_TREE</property>
+
+                 <child>
+                   <widget class="GtkMenu" id="help1_menu">
+
+                     <child>
+                       <widget class="GtkImageMenuItem" id="about1">
+                         <property name="visible">True</property>
+                         <property name="stock_item">GNOMEUIINFO_MENU_ABOUT_ITEM</property>
+                         <signal name="activate" handler="on_about1_activate" last_modification_time="Sun, 20 Aug 2006 09:25:15 GMT"/>
+                       </widget>
+                     </child>
+                   </widget>
+                 </child>
+               </widget>
+             </child>
+           </widget>
+         </child>
+       </widget>
+       <packing>
+         <property name="placement">BONOBO_DOCK_TOP</property>
+         <property name="band">0</property>
+         <property name="position">0</property>
+         <property name="offset">0</property>
+         <property name="behavior">BONOBO_DOCK_ITEM_BEH_EXCLUSIVE|BONOBO_DOCK_ITEM_BEH_NEVER_VERTICAL|BONOBO_DOCK_ITEM_BEH_LOCKED</property>
+       </packing>
+      </child>
+
+      <child>
+       <widget class="BonoboDockItem" id="bonobodockitem2">
+         <property name="visible">True</property>
+         <property name="shadow_type">GTK_SHADOW_OUT</property>
+
+         <child>
+           <widget class="GtkToolbar" id="toolbar1">
+             <property name="visible">True</property>
+             <property name="orientation">GTK_ORIENTATION_HORIZONTAL</property>
+             <property name="toolbar_style">GTK_TOOLBAR_BOTH</property>
+             <property name="tooltips">True</property>
+             <property name="show_arrow">True</property>
+
+             <child>
+               <widget class="GtkToolButton" id="toolbutton1">
+                 <property name="visible">True</property>
+                 <property name="tooltip" translatable="yes">New File</property>
+                 <property name="stock_id">gtk-new</property>
+                 <property name="visible_horizontal">True</property>
+                 <property name="visible_vertical">True</property>
+                 <property name="is_important">False</property>
+               </widget>
+               <packing>
+                 <property name="expand">False</property>
+                 <property name="homogeneous">True</property>
+               </packing>
+             </child>
+
+             <child>
+               <widget class="GtkToolButton" id="toolbutton2">
+                 <property name="visible">True</property>
+                 <property name="tooltip" translatable="yes">Open File</property>
+                 <property name="stock_id">gtk-open</property>
+                 <property name="visible_horizontal">True</property>
+                 <property name="visible_vertical">True</property>
+                 <property name="is_important">False</property>
+               </widget>
+               <packing>
+                 <property name="expand">False</property>
+                 <property name="homogeneous">True</property>
+               </packing>
+             </child>
+
+             <child>
+               <widget class="GtkToolButton" id="toolbutton3">
+                 <property name="visible">True</property>
+                 <property name="tooltip" translatable="yes">Save File</property>
+                 <property name="stock_id">gtk-save</property>
+                 <property name="visible_horizontal">True</property>
+                 <property name="visible_vertical">True</property>
+                 <property name="is_important">False</property>
+               </widget>
+               <packing>
+                 <property name="expand">False</property>
+                 <property name="homogeneous">True</property>
+               </packing>
+             </child>
+           </widget>
+         </child>
+       </widget>
+       <packing>
+         <property name="placement">BONOBO_DOCK_TOP</property>
+         <property name="band">1</property>
+         <property name="position">0</property>
+         <property name="offset">0</property>
+         <property name="behavior">BONOBO_DOCK_ITEM_BEH_EXCLUSIVE|BONOBO_DOCK_ITEM_BEH_LOCKED</property>
+       </packing>
+      </child>
+
+      <child>
+       <widget class="GtkScrolledWindow" id="scrolledwindow1">
+         <property name="visible">True</property>
+         <property name="can_focus">True</property>
+         <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+         <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+         <property name="shadow_type">GTK_SHADOW_NONE</property>
+         <property name="window_placement">GTK_CORNER_TOP_LEFT</property>
+
+         <child>
+           <widget class="GtkTreeView" id="treeview">
+             <property name="visible">True</property>
+             <property name="can_focus">True</property>
+             <property name="headers_visible">True</property>
+             <property name="rules_hint">True</property>
+             <property name="reorderable">True</property>
+             <property name="enable_search">True</property>
+           </widget>
+         </child>
+       </widget>
+      </child>
+    </widget>
+    <packing>
+      <property name="padding">0</property>
+      <property name="expand">True</property>
+      <property name="fill">True</property>
+    </packing>
+  </child>
+
+  <child internal-child="appbar">
+    <widget class="GnomeAppBar" id="appbar1">
+      <property name="visible">True</property>
+      <property name="has_progress">True</property>
+      <property name="has_status">True</property>
+    </widget>
+    <packing>
+      <property name="padding">0</property>
+      <property name="expand">True</property>
+      <property name="fill">True</property>
+    </packing>
+  </child>
+</widget>
+
+</glade-interface>
index 8f9b045..2bac2b7 100755 (executable)
--- a/src/hage1
+++ b/src/hage1
@@ -23,8 +23,7 @@ import gtk
 import gnome.ui
 import gobject
 
-from Hage1 import board_data
-from Hage1 import board_window
+from Hage1 import brdlist_window
 from Hage1 import brdlist
 from Hage1 import config
 APPNAME = 'Hage1'
@@ -38,5 +37,5 @@ if __name__ == "__main__":
     config.APPNAME = APPNAME
     # init brdlist after setting config.APPNAME
     brdlist.init()
-    win = board_window.WinWrap(bbs, board)
+    brdlist_window.open_brdlist(bbs)
     gtk.main()