Mercurial > fife-parpg
comparison clients/editor/scripts/gui/dockarea.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 import pychan | |
2 from pychan import widgets | |
3 import scripts.editor | |
4 import fife | |
5 from panel import Panel | |
6 from faketabwidget import FakeTabWidget | |
7 from resizablebase import ResizableBase | |
8 | |
9 class DockArea(widgets.VBox, ResizableBase): | |
10 def __init__(self, side, resizable=True, *args, **kwargs): | |
11 widgets.VBox.__init__(self, margins=(0,0,0,0), *args, **kwargs) | |
12 ResizableBase.__init__(self, *args, **kwargs) | |
13 | |
14 self.cursor_id = 0 | |
15 self.cursor_type = 0 | |
16 | |
17 self.vexpand=0 | |
18 self.hexpand=0 | |
19 | |
20 self.side = side | |
21 self.resizable_top = (side == "bottom") | |
22 self.resizable_left = (side == "right") | |
23 self.resizable_right = (side == "left") | |
24 self.resizable_bottom = (side == "top") | |
25 | |
26 self.gui = None | |
27 | |
28 self.buildGui() | |
29 self.tabwidgets = [] | |
30 self.panels = [] | |
31 | |
32 def getDockLocation(self, x, y): | |
33 placeAfter = None | |
34 placeBefore = None | |
35 placeIn = None | |
36 | |
37 if x >= 0 and y >= 0: | |
38 # See if widget was dropped on a tabwidget | |
39 for tabwidget in self.tabwidgets: | |
40 absX, absY = tabwidget.getAbsolutePos() | |
41 | |
42 if absX <= x and absY <= y \ | |
43 and absX+tabwidget.width >= x and absY+tabwidget.height >= y: | |
44 # Check if the user tried to place it in front, or after this widget | |
45 if self.side == "left" or self.side == "right": | |
46 if y < absY+10: | |
47 placeBefore = tabwidget | |
48 elif y > absY+tabwidget.height-10: | |
49 placeAfter = tabwidget | |
50 else: | |
51 if x < absX+10: | |
52 placeBefore = tabwidget | |
53 elif x > absX+tabwidget.width-10: | |
54 placeAfter = tabwidget | |
55 if placeAfter is None and placeBefore is None: | |
56 placeIn = tabwidget | |
57 break | |
58 | |
59 return (placeIn, placeBefore, placeAfter) | |
60 | |
61 def dockChild(self, child, x, y): | |
62 for panel in self.panels: | |
63 if panel[0] == child: | |
64 return | |
65 | |
66 child.dockarea = self | |
67 child.setDocked(True) | |
68 | |
69 placeIn, placeBefore, placeAfter = self.getDockLocation(x, y) | |
70 | |
71 if placeIn is None: | |
72 tabwidget = FakeTabWidget(resizable=True) | |
73 tabwidget.hexpand=1 | |
74 tabwidget.vexpand=1 | |
75 | |
76 if self.side == "left" or self.side == "right": | |
77 tabwidget.resizable_bottom = True | |
78 else: | |
79 tabwidget.resizable_right = True | |
80 self.tabwidgets.append(tabwidget) | |
81 | |
82 if placeBefore: | |
83 self.gui.insertChildBefore(tabwidget, placeBefore) | |
84 elif placeAfter: | |
85 self.gui.insertChild(tabwidget, self.gui.children.index(placeAfter)+1) | |
86 else: | |
87 self.gui.addChild(tabwidget) | |
88 else: | |
89 tabwidget = placeIn | |
90 | |
91 tab = tabwidget.addTab(child, child.title) | |
92 self.panels.append( (child, tabwidget) ) | |
93 | |
94 def undock(event): | |
95 if event.getButton() != 2: # Right click | |
96 return | |
97 | |
98 self.undockChild(child) | |
99 | |
100 tab[2].capture(undock, "mouseClicked") | |
101 | |
102 def undockChild(self, child, childIsCaller=False): | |
103 tabwidget = None | |
104 for panel in self.panels: | |
105 if panel[0] == child: | |
106 tabwidget = panel[1] | |
107 self.panels.remove(panel) | |
108 break | |
109 else: | |
110 return | |
111 | |
112 tabwidget.removeTab(child) | |
113 if childIsCaller is False: | |
114 child.setDocked(False) | |
115 | |
116 if len(tabwidget.tabs) <= 0: | |
117 self.gui.removeChild(tabwidget) | |
118 self.tabwidgets.remove(tabwidget) | |
119 | |
120 # This stops a guichan exception when a widget with modul focus gets focused. | |
121 # It is not pretty, but crashes aren't pretty either | |
122 tabwidget.__del__() | |
123 del tabwidget | |
124 | |
125 self.adaptLayout() | |
126 | |
127 def buildGui(self): | |
128 if self.gui: | |
129 self.removeChild(self.gui) | |
130 | |
131 if self.side == "left" or self.side == "right": | |
132 self.gui = widgets.VBox() | |
133 else: | |
134 self.gui = widgets.HBox() | |
135 | |
136 self.gui.vexpand = 1 | |
137 self.gui.hexpand = 1 | |
138 | |
139 self.addChild(self.gui) | |
140 | |
141 def mouseReleased(self, event): | |
142 if self._resize: | |
143 if self._rLeft or self._rRight: | |
144 # Resize children | |
145 for child in self.gui.findChildren(parent=self.gui): | |
146 child.min_size = (self.width, child.min_size[1]) | |
147 child.max_size = (self.width, child.max_size[1]) | |
148 | |
149 if self._rTop or self._rBottom: | |
150 # Resize children | |
151 for child in self.gui.findChildren(parent=self.gui): | |
152 child.min_size = (child.min_size[0], self.height) | |
153 child.max_size = (child.max_size[0], self.height) | |
154 | |
155 self.gui.max_size = (self.width, self.height) | |
156 | |
157 ResizableBase.mouseReleased(self, event) | |
158 self.min_size = (0,0) # Override changes done in ResizableBase | |
159 |