comparison tools/editor/scripts/gui/faketabwidget.py @ 378:64738befdf3b

bringing in the changes from the build_system_rework branch in preparation for the 0.3.0 release. This commit will require the Jan2010 devkit. Clients will also need to be modified to the new way to import fife.
author vtchill@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 11 Jan 2010 23:34:52 +0000
parents
children
comparison
equal deleted inserted replaced
377:fe6fb0e0ed23 378:64738befdf3b
1 # -*- coding: utf-8 -*-
2
3 # ####################################################################
4 # Copyright (C) 2005-2009 by the FIFE team
5 # http://www.fifengine.de
6 # This file is part of FIFE.
7 #
8 # FIFE is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2.1 of the License, or (at your option) any later version.
12 #
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 # Lesser General Public License for more details.
17 #
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this library; if not, write to the
20 # Free Software Foundation, Inc.,
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 # ####################################################################
23
24 from fife.extensions.pychan import widgets
25 from fife.extensions.pychan.tools import callbackWithArguments as cbwa
26 from resizablebase import ResizableBase
27
28 import scripts
29
30 class FakeTabWidget(widgets.VBox, ResizableBase):
31 def __init__(self, resizable=None, *args, **kwargs):
32 if resizable == None:
33 resizable = False
34
35 widgets.VBox.__init__(self, *args, **kwargs)
36 ResizableBase.__init__(self, resizable, *args, **kwargs)
37
38 self.tabs = []
39
40 self.buttonbox = widgets.HBox()
41 self.widgetarea = widgets.VBox()
42 self.buttonbox.hexpand = 1
43 self.buttonbox.vexpand = 0
44 self.widgetarea.hexpand = 1
45 self.widgetarea.vexpand = 1
46
47 self.addChild(self.buttonbox)
48 self.addChild(self.widgetarea)
49
50 self.resizable_top = False
51 self.resizable_left = False
52 self.resizable_right = False
53 self.resizable_bottom = False
54
55 def __del__(self):
56 # Force deletion of C++ object
57 if self.real_widget:
58 self.real_widget.__del__()
59 self.real_widget = None
60
61 def addTab(self, widget, title):
62 for tab in self.tabs:
63 if tab[1] == widget:
64 return
65
66 widget.max_size = (5000, 5000)
67 widget.hexpand = 1
68 widget.vexpand = 1
69
70 button = widgets.ToggleButton(text=title, group="faketab_"+str(id(self)))
71 self.buttonbox.addChild(button)
72
73 tab = (title, widget, button)
74 self.tabs.append( tab )
75
76 button.capture(cbwa(self.showTab, tab))
77 self.showTab(tab)
78
79 return tab
80
81 def removeTab(self, widget):
82 for i, tab in enumerate(self.tabs):
83 if tab[1] == widget:
84 if widget.parent == self.widgetarea:
85 self.widgetarea.removeChild(widget)
86 self.buttonbox.removeChild(tab[2])
87 del self.tabs[i]
88 break
89 else: return
90
91 if len(self.tabs) > 0:
92 self.showTab(self.tabs[0])
93
94 def showTab(self, tab):
95 tab[2].toggled = True
96 self.widgetarea.removeAllChildren()
97 self.widgetarea.addChild(tab[1])
98 self.adaptLayout(False)
99
100