Mercurial > fife-parpg
comparison clients/editor/scripts/gui/faketabwidget.py @ 255:51cc05d862f2
Merged editor_rewrite branch to trunk.
This contains changes that may break compatibility against existing clients.
For a list of changes that may affect your client, see: http://wiki.fifengine.de/Changes_to_pychan_and_FIFE_in_editor_rewrite_branch
author | cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Mon, 08 Jun 2009 16:00:02 +0000 |
parents | |
children | 6add14ebe9f5 |
comparison
equal
deleted
inserted
replaced
254:10b5f7f36dd4 | 255:51cc05d862f2 |
---|---|
1 from pychan import widgets | |
2 from pychan.tools import callbackWithArguments as cbwa | |
3 from resizablebase import ResizableBase | |
4 | |
5 import scripts | |
6 | |
7 class FakeTabWidget(widgets.VBox, ResizableBase): | |
8 def __init__(self, resizable=None, *args, **kwargs): | |
9 if resizable == None: | |
10 resizable = False | |
11 | |
12 widgets.VBox.__init__(self, *args, **kwargs) | |
13 ResizableBase.__init__(self, resizable, *args, **kwargs) | |
14 | |
15 self.tabs = [] | |
16 | |
17 self.buttonbox = widgets.HBox() | |
18 self.widgetarea = widgets.VBox() | |
19 self.buttonbox.hexpand = 1 | |
20 self.buttonbox.vexpand = 0 | |
21 self.widgetarea.hexpand = 1 | |
22 self.widgetarea.vexpand = 1 | |
23 | |
24 self.addChild(self.buttonbox) | |
25 self.addChild(self.widgetarea) | |
26 | |
27 self.resizable_top = False | |
28 self.resizable_left = False | |
29 self.resizable_right = False | |
30 self.resizable_bottom = False | |
31 | |
32 def __del__(self): | |
33 # Force deletion of C++ object | |
34 if self.real_widget: | |
35 self.real_widget.__del__() | |
36 self.real_widget = None | |
37 | |
38 def addTab(self, widget, title): | |
39 for tab in self.tabs: | |
40 if tab[1] == widget: | |
41 return | |
42 | |
43 widget.max_size = (5000, 5000) | |
44 widget.hexpand = 1 | |
45 widget.vexpand = 1 | |
46 | |
47 button = widgets.ToggleButton(text=title, group="faketab_"+str(id(self))) | |
48 self.buttonbox.addChild(button) | |
49 | |
50 tab = (title, widget, button) | |
51 self.tabs.append( tab ) | |
52 | |
53 button.capture(cbwa(self.showTab, tab)) | |
54 self.showTab(tab) | |
55 | |
56 return tab | |
57 | |
58 def removeTab(self, widget): | |
59 for i, tab in enumerate(self.tabs): | |
60 if tab[1] == widget: | |
61 if widget.parent == self.widgetarea: | |
62 self.widgetarea.removeChild(widget) | |
63 self.buttonbox.removeChild(tab[2]) | |
64 del self.tabs[i] | |
65 break | |
66 else: return | |
67 | |
68 if len(self.tabs) > 0: | |
69 self.showTab(self.tabs[0]) | |
70 | |
71 def showTab(self, tab): | |
72 tab[2].toggled = True | |
73 self.widgetarea.removeAllChildren() | |
74 self.widgetarea.addChild(tab[1]) | |
75 self.widgetarea.adaptLayout() | |
76 | |
77 |