| 1 | #!/usr/bin/env python |
|---|
| 2 | # -*- coding: utf-8 -*- |
|---|
| 3 | # Copyright (C) 2008 Adriano Monteiro Marques |
|---|
| 4 | # |
|---|
| 5 | # Author: Francesco Piccinno <stack.box@gmail.com> |
|---|
| 6 | # |
|---|
| 7 | # This program is free software; you can redistribute it and/or modify |
|---|
| 8 | # it under the terms of the GNU General Public License as published by |
|---|
| 9 | # the Free Software Foundation; either version 2 of the License, or |
|---|
| 10 | # (at your option) any later version. |
|---|
| 11 | # |
|---|
| 12 | # This program is distributed in the hope that it will be useful, |
|---|
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | # GNU General Public License for more details. |
|---|
| 16 | # |
|---|
| 17 | # You should have received a copy of the GNU General Public License |
|---|
| 18 | # along with this program; if not, write to the Free Software |
|---|
| 19 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 20 | |
|---|
| 21 | """ |
|---|
| 22 | A simple docking windows fallback replacement based on gtk.Notebook |
|---|
| 23 | """ |
|---|
| 24 | |
|---|
| 25 | import gtk |
|---|
| 26 | |
|---|
| 27 | PANE_CENTER = 'Center' |
|---|
| 28 | PANE_RIGHT = 'Rigth' |
|---|
| 29 | PANE_LEFT = 'Left' |
|---|
| 30 | PANE_TOP = 'Top' |
|---|
| 31 | PANE_BOTTOM = 'Bottom' |
|---|
| 32 | |
|---|
| 33 | class UmitPaned(gtk.VBox): |
|---|
| 34 | """Fallback UmitPaned based on gtk.Paned |
|---|
| 35 | """ |
|---|
| 36 | |
|---|
| 37 | def __init__(self): |
|---|
| 38 | super(UmitPaned, self).__init__(2, False) |
|---|
| 39 | |
|---|
| 40 | self.hpaned = gtk.HPaned() |
|---|
| 41 | self.vpaned = gtk.VPaned() |
|---|
| 42 | |
|---|
| 43 | self.hnotebook = gtk.Notebook() |
|---|
| 44 | self.vnotebook = gtk.Notebook() |
|---|
| 45 | |
|---|
| 46 | self.vnotebook.set_tab_pos(gtk.POS_BOTTOM) |
|---|
| 47 | |
|---|
| 48 | self.pack_start(self.vpaned) |
|---|
| 49 | self.vpaned.pack2(self.vnotebook, False, True) # bottom |
|---|
| 50 | |
|---|
| 51 | self.vpaned.add1(self.hpaned) |
|---|
| 52 | self.hpaned.pack1(self.hnotebook, False, True) # left |
|---|
| 53 | |
|---|
| 54 | self.show_all() |
|---|
| 55 | |
|---|
| 56 | def add_view(self, tab, unused=False): |
|---|
| 57 | widget = tab.get_toplevel() |
|---|
| 58 | |
|---|
| 59 | if not tab.tab_position: |
|---|
| 60 | if not self.hpaned.get_child2(): |
|---|
| 61 | self.hpaned.pack2(widget, True, False) |
|---|
| 62 | return |
|---|
| 63 | |
|---|
| 64 | label = gtk.HBox() |
|---|
| 65 | |
|---|
| 66 | image = gtk.image_new_from_stock(tab.icon_name, gtk.ICON_SIZE_MENU) |
|---|
| 67 | |
|---|
| 68 | pos = tab.tab_position |
|---|
| 69 | |
|---|
| 70 | label.pack_start(image, False, False) |
|---|
| 71 | label.pack_start(gtk.Label(tab.label_text)) |
|---|
| 72 | label.show_all() |
|---|
| 73 | |
|---|
| 74 | #print "Adding widget", widget, "to", pos |
|---|
| 75 | |
|---|
| 76 | if pos == gtk.POS_RIGHT or pos == gtk.POS_LEFT: |
|---|
| 77 | self.hnotebook.append_page(widget, label) |
|---|
| 78 | self.hnotebook.set_tab_reorderable(widget, True) |
|---|
| 79 | elif pos == gtk.POS_TOP or pos == gtk.POS_BOTTOM: |
|---|
| 80 | self.vnotebook.append_page(widget, label) |
|---|
| 81 | self.vnotebook.set_tab_reorderable(widget, True) |
|---|
| 82 | |
|---|
| 83 | def remove_view(self, tab): |
|---|
| 84 | pos = tab.tab_position |
|---|
| 85 | |
|---|
| 86 | if pos == gtk.POS_RIGHT or pos == gtk.POS_LEFT: |
|---|
| 87 | nb = self.hnotebook |
|---|
| 88 | elif pos == gtk.POS_TOP or pos == gtk.POS_BOTTOM: |
|---|
| 89 | nb = self.vnotebook |
|---|
| 90 | |
|---|
| 91 | num = nb.page_num(tab.get_toplevel()) |
|---|
| 92 | if num > -1: |
|---|
| 93 | nb.remove_page(num) |
|---|
| 94 | else: |
|---|
| 95 | raise Exception("Cannot found the widget") |
|---|
| 96 | |
|---|
| 97 | if __name__ == "__main__": |
|---|
| 98 | w = gtk.Window() |
|---|
| 99 | p = UmitPaned() |
|---|
| 100 | p.add_view("Top", gtk.Label("miao")) |
|---|
| 101 | p.add_view("Center", gtk.Label("Center")) |
|---|
| 102 | p.add_view("Right", gtk.Label("miao")) |
|---|
| 103 | w.add(p) |
|---|
| 104 | w.show_all() |
|---|
| 105 | gtk.main() |
|---|