1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
#!/usr/bin/python
# -*- coding: latin-1 -*-
# Copyright (C) 2007 - Gian Mario Tagliaretti <g.tagliaretti@parafernalia.org>
#
# 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;
#
# 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 Lesser General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
import gtk
import gdl
def create_text_item():
vbox1 = gtk.VBox (False, 0)
scrolledwindow1 = gtk.ScrolledWindow ()
vbox1.pack_start (scrolledwindow1, True, True, 0)
scrolledwindow1.set_policy (gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
scrolledwindow1.set_shadow_type (gtk.SHADOW_ETCHED_IN)
text = gtk.TextView ()
text.props.wrap_mode = gtk.WRAP_WORD
scrolledwindow1.add (text)
return vbox1
def create_item(title):
vbox1 = gtk.VBox (False, 0)
button1 = gtk.Button (title)
vbox1.pack_start (button1, True, True, 0)
return vbox1
def save_layout_cb (widget, layout):
dialog = gtk.Dialog ("New Layout",
None,
gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
(gtk.STOCK_OK, gtk.RESPONSE_OK))
hbox = gtk.HBox (False, 8)
hbox.set_border_width (8)
vbox = dialog.get_child ()
vbox.pack_start (hbox, False, False, 0)
label = gtk.Label ("Name:")
hbox.pack_start (label, False, False, 0)
entry = gtk.Entry ()
hbox.pack_start (entry, True, True, 0)
hbox.show_all ()
response = dialog.run ()
if response == gtk.RESPONSE_OK:
name = entry.get_text ()
layout.save_layout (name)
else:
dialog.destroy ()
def run_layout_manager_cb (widget, layout):
layout.run_manager ()
def button_dump_cb (widget, layout):
layout.save_to_file ("layout.xml")
win = gtk.Window (gtk.WINDOW_TOPLEVEL)
win.connect ("delete_event", gtk.main_quit)
win.set_title ("Docking widget test")
win.set_default_size (400, 400)
''' table '''
table = gtk.VBox (False, 5)
win.add (table)
table.set_border_width (10)
''' create the dock '''
dock = gdl.Dock ()
''' ... and the layout manager '''
layout = gdl.DockLayout (dock)
''' create the dockbar '''
dockbar = gdl.DockBar (dock)
dockbar.set_style(gdl.DOCK_BAR_TEXT)
box = gtk.HBox (False, 5)
table.pack_start (box, True, True, 0)
box.pack_start (dockbar, False, False, 0)
box.pack_end (dock, True, True, 0)
''' create the dock items '''
item1 = gdl.DockItem ("item1", "Item #1", gdl.DOCK_ITEM_BEH_LOCKED);
item1.add (create_text_item ())
dock.add_item (item1, gdl.DOCK_TOP)
item2 = gdl.DockItem ("item2",
"Item #2 has some large title",
gtk.STOCK_EXECUTE,
gdl.DOCK_ITEM_BEH_NORMAL)
item2.props.resize = False
item2.add (create_item ("Button 2"))
item2.show_all ()
dock.add_item (item2, gdl.DOCK_RIGHT)
item3 = gdl.DockItem ("item3", "Item #3 has accented characters (áéíóúñ)",
gtk.STOCK_CONVERT,
gdl.DOCK_ITEM_BEH_NORMAL |
gdl.DOCK_ITEM_BEH_CANT_CLOSE)
item3.add (create_item ("Button 3"))
dock.add_item (item3, gdl.DOCK_BOTTOM)
item = gdl.DockItem ("Item #4", "Item #4",
gtk.STOCK_JUSTIFY_FILL,
gdl.DOCK_ITEM_BEH_NORMAL |
gdl.DOCK_ITEM_BEH_CANT_ICONIFY)
item.add (create_text_item ())
dock.add_item (item, gdl.DOCK_BOTTOM)
for i in range(1, 3):
name = "Item #%s" % (i + 4)
a_item = gdl.DockItem (name,
name,
gtk.STOCK_NEW,
gdl.DOCK_ITEM_BEH_NORMAL)
a_item.add (create_text_item ())
item.dock (a_item, gdl.DOCK_CENTER)
''' tests: manually dock and move around some of the items '''
item3.dock_to (item1, gdl.DOCK_TOP)
item2.dock_to (item3, gdl.DOCK_RIGHT)
item2.dock_to (item3, gdl.DOCK_LEFT)
item2.dock_to (None, gdl.DOCK_FLOATING)
box = gtk.HBox (True, 5)
table.pack_end (box, False, False, 0)
button = gtk.Button (None, gtk.STOCK_SAVE)
button.connect ("clicked", save_layout_cb, layout)
box.pack_end (button, False, True, 0)
button = gtk.Button ("Layout Manager")
button.connect ("clicked", run_layout_manager_cb, layout)
box.pack_end (button, False, True, 0)
button = gtk.Button ("Dump XML")
button.connect ("clicked", button_dump_cb, layout)
box.pack_end (button, False, True, 0)
a = gdl.DockPlaceholder ("ph1", dock, gdl.DOCK_TOP, False)
b = gdl.DockPlaceholder ("ph2", dock, gdl.DOCK_BOTTOM, False)
c = gdl.DockPlaceholder ("ph3", dock, gdl.DOCK_LEFT, False)
d = gdl.DockPlaceholder ("ph4", dock, gdl.DOCK_RIGHT, False)
win.show_all()
gtk.main()
|