[Ocfs2-tools-commits] manish commits r547 - trunk/ocfs2tool

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Mon Jan 10 20:10:19 CST 2005


Author: manish
Date: 2005-01-10 20:10:17 -0600 (Mon, 10 Jan 2005)
New Revision: 547

Added:
   trunk/ocfs2tool/toolbar.py
Modified:
   trunk/ocfs2tool/interface.py
Log:
Replace action area with toolbar


Modified: trunk/ocfs2tool/interface.py
===================================================================
--- trunk/ocfs2tool/interface.py	2005-01-08 02:23:40 UTC (rev 546)
+++ trunk/ocfs2tool/interface.py	2005-01-11 02:10:17 UTC (rev 547)
@@ -15,8 +15,6 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 021110-1307, USA.
 
-import sys
-
 import gtk
 
 import ocfs2
@@ -24,6 +22,7 @@
 from guiutil import set_props, error_box, query_text
 
 from menu import Menu
+from toolbar import Toolbar
 from about import about
 from process import Process
 from format import format_partition
@@ -193,28 +192,6 @@
         frame.add(info(device, pv.advanced).widget)
         frame.show_all()
 
-def create_action_area(pv):
-    vbbox = gtk.VButtonBox()
-    set_props(vbbox, layout_style=gtk.BUTTONBOX_START,
-                     spacing=5,
-                     border_width=5)
-
-    button = gtk.Button('Mount')
-    vbbox.add(button)
-    button.connect('clicked', mount, pv)
-    pv.mount_button = button
-
-    button = gtk.Button('Unmount')
-    vbbox.add(button)
-    button.connect('clicked', unmount, pv)
-    pv.unmount_button = button
-
-    button = gtk.Button('Refresh')
-    vbbox.add(button)
-    button.connect('clicked', refresh, pv)
-
-    return vbbox
-
 def format(pv):
     format_partition(pv.toplevel, pv.get_device(), pv.advanced)
     pv.refresh_partitions()
@@ -247,27 +224,24 @@
     menubar = menu.get_widget(window, pv)
     vbox.pack_start(menubar, expand=False, fill=False)
 
+    toolbar = Toolbar(mount=mount, unmount=unmount, refresh=refresh)
+
+    tb, buttons = toolbar.get_widgets(pv)
+    vbox.pack_start(tb, expand=False, fill=False)
+
+    for k, v in buttons.iteritems():
+        setattr(pv, k + '_button', v)
+ 
     vpaned = gtk.VPaned()
     vpaned.set_border_width(4)
     vbox.pack_start(vpaned, expand=True, fill=True)
 
-    hbox = gtk.HBox(spacing=4)
-    vpaned.pack1(hbox)
-
     scrl_win = gtk.ScrolledWindow()
     set_props(scrl_win, hscrollbar_policy=gtk.POLICY_AUTOMATIC,
-                        vscrollbar_policy=gtk.POLICY_AUTOMATIC,
-                        parent=hbox)
-
+                        vscrollbar_policy=gtk.POLICY_AUTOMATIC)
     scrl_win.add(pv)
+    vpaned.pack1(scrl_win)
 
-    frame = gtk.Frame()
-    frame.set_shadow_type(gtk.SHADOW_IN)
-    hbox.pack_end(frame, expand=False, fill=False)
-
-    vbbox = create_action_area(pv)
-    frame.add(vbbox)
-
     notebook = gtk.Notebook()
     notebook.set_tab_pos(gtk.POS_TOP)
     vpaned.pack2(notebook)

Added: trunk/ocfs2tool/toolbar.py
===================================================================
--- trunk/ocfs2tool/toolbar.py	2005-01-08 02:23:40 UTC (rev 546)
+++ trunk/ocfs2tool/toolbar.py	2005-01-11 02:10:17 UTC (rev 547)
@@ -0,0 +1,74 @@
+# OCFS2Tool - GUI frontend for OCFS2 management and debugging
+# Copyright (C) 2005 Oracle.  All rights reserved.
+#
+# 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., 59 Temple Place - Suite 330, Boston, MA 021110-1307, USA.
+
+import gtk
+
+toolbar_data = (
+    ('Mount', gtk.STOCK_EXECUTE, 'mount'),
+    ('Unmount', gtk.STOCK_STOP, 'unmount'),
+    ('Refresh', gtk.STOCK_REFRESH, 'refresh')
+)
+
+class Toolbar:
+    def __init__(self, **callbacks):
+        self.callbacks = callbacks
+
+    def get_widgets(self, data=None):
+        toolbar = gtk.Toolbar()
+        items = {}
+
+        for i in toolbar_data:
+            def make_cb():
+                callback = self.callbacks[i[2]]
+
+                def cb(w, d=None):
+                    callback(d)
+
+                return cb
+
+            icon = gtk.Image()
+            icon.set_from_stock(i[1], gtk.ICON_SIZE_BUTTON)
+            items[i[2]] = toolbar.append_item(i[0], i[0], None, icon,
+                                              make_cb(), data)
+
+        return toolbar, items
+
+
+def main():
+    def dummy(*args):
+        gtk.main_quit()
+
+    cb = {}
+    for i in toolbar_data:
+        cb[i[2]] = dummy
+
+    toolbar = Toolbar(**cb)
+
+    window = gtk.Window()
+    window.connect('delete_event', dummy)
+
+    vbox = gtk.VBox()
+    window.add(vbox)
+
+    vbox.add(toolbar.get_widgets()[0])
+
+    window.show_all()
+
+    gtk.main()
+
+if __name__ == '__main__':
+    main()



More information about the Ocfs2-tools-commits mailing list