root/branch/PacketManipulator/PM/Gui/Core/FallbackPaned.py @ 3500

Revision 3500, 3.0 kB (checked in by nopper, 5 years ago)

rewriting UMPA backend

Line 
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"""
22A simple docking windows fallback replacement based on gtk.Notebook
23"""
24
25import gtk
26
27PANE_CENTER = 'Center'
28PANE_RIGHT = 'Rigth'
29PANE_LEFT = 'Left'
30PANE_TOP = 'Top'
31PANE_BOTTOM = 'Bottom'
32
33class 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        elif pos == gtk.POS_TOP or pos == gtk.POS_BOTTOM:
79            self.vnotebook.append_page(widget, label)
80
81    def remove_view(self, tab):
82        pos = tab.tab_position
83
84        if pos == gtk.POS_RIGHT or pos == gtk.POS_LEFT:
85            nb = self.hnotebook
86        elif pos == gtk.POS_TOP or pos == gtk.POS_BOTTOM:
87            nb = self.vnotebook
88
89        num = nb.page_num(tab.get_toplevel())
90        if num > -1:
91            nb.remove_page(num)
92        else:
93            raise Exception("Cannot found the widget")
94
95if __name__ == "__main__":
96    w = gtk.Window()
97    p = UmitPaned()
98    p.add_view("Top", gtk.Label("miao"))
99    p.add_view("Center", gtk.Label("Center"))
100    p.add_view("Right", gtk.Label("miao"))
101    w.add(p)
102    w.show_all()
103    gtk.main()
Note: See TracBrowser for help on using the browser.