Mercurial > fife-parpg
comparison tools/editor/scripts/gui/panel.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 import pychan | |
25 from fife.extensions.pychan import widgets | |
26 import scripts.editor | |
27 from fife import fife | |
28 from resizablebase import ResizableBase | |
29 | |
30 class Panel(widgets.Window, ResizableBase): | |
31 """ Panel is a window which can be resized and docked. | |
32 """ | |
33 def __init__(self, dockable=True, *args, **kwargs): | |
34 widgets.Window.__init__(self, *args, **kwargs) | |
35 ResizableBase.__init__(self, *args, **kwargs) | |
36 | |
37 self.dockable = dockable | |
38 self._movable = self.real_widget.isMovable() | |
39 self._resizable = self.resizable | |
40 | |
41 self._floating = True | |
42 self._titlebarheight = 16 | |
43 | |
44 self.dockarea = None | |
45 | |
46 self._editor = scripts.editor.getEditor() | |
47 | |
48 self._panel_startPos = (0, 0) | |
49 | |
50 def setDocked(self, docked): | |
51 """ | |
52 Dock or undock the panel | |
53 | |
54 setDocked(True) will disable resizing and moving | |
55 of this panel, but will not dock it in a dockarea. | |
56 | |
57 setDocked(False) will enable resizing and moving. | |
58 If this panel is docked in a dockarea or widget, | |
59 it will undock itself. The new position will be | |
60 offset by panelSize. | |
61 """ | |
62 if self.dockable is False: | |
63 return | |
64 | |
65 if docked is True and self._floating == True: | |
66 self._floating = False | |
67 self.real_widget.setTitleBarHeight(0) | |
68 self.real_widget.setMovable(False) | |
69 self._movable = False | |
70 self.resizable = False | |
71 | |
72 elif docked is False and self._floating is False: | |
73 self._floating = True | |
74 self._movable = True | |
75 self.real_widget.setMovable(True) | |
76 self.resizable = self._resizable | |
77 | |
78 # Since x and y coordinates are reset if the widget gets hidden, | |
79 # we need to store them | |
80 absX, absY = self.getAbsolutePos() | |
81 | |
82 # Remove from parent widget | |
83 if self.dockarea is not None: | |
84 # Use dockareas undock method | |
85 self.dockarea.undockChild(self, True) | |
86 self.dockarea = None | |
87 | |
88 elif self.parent is not None: | |
89 # Force removal | |
90 widgetParent = self.parent | |
91 widgetParent.removeChild(self) | |
92 widgetParent.adaptLayout() | |
93 self.hide() | |
94 | |
95 self.real_widget.setTitleBarHeight(self._titlebarheight) | |
96 self.show() | |
97 | |
98 # Slighly offset toolbar when undocking | |
99 mw = pychan.internal.screen_width() / 2 | |
100 mh = pychan.internal.screen_height() / 2 | |
101 if absX < mw: | |
102 self.x = absX + self._titlebarheight | |
103 else: | |
104 self.x = absX - self._titlebarheight | |
105 if absY < mh: | |
106 self.y = absY + self._titlebarheight | |
107 else: | |
108 self.y = absY - self._titlebarheight | |
109 | |
110 def isDocked(self): | |
111 """ Returns true if the panel is docked """ | |
112 return self._floating == False | |
113 | |
114 def mousePressed(self, event): | |
115 if self.resizable is False: | |
116 return | |
117 | |
118 self._panel_startPos = (self.x, self.y) | |
119 | |
120 ResizableBase.mousePressed(self, event) | |
121 if self._rLeft or self._rRight or self._rTop or self._rBottom: | |
122 self._movable = self.real_widget.isMovable() | |
123 self.real_widget.setMovable(False) # Don't let guichan move window while we resize | |
124 | |
125 def mouseDragged(self, event): | |
126 self._dragging = True | |
127 if self._resize is False and self.isDocked() is False: | |
128 if (self.x, self.y) == self._panel_startPos: | |
129 return | |
130 mouseX = self.x+event.getX() | |
131 mouseY = self.y+event.getY() | |
132 self._editor.getDockAreaAt(mouseX, mouseY, True) | |
133 else: | |
134 ResizableBase.mouseDragged(self, event) | |
135 | |
136 def mouseReleased(self, event): | |
137 didMove = False | |
138 if (self.x, self.y) != self._panel_startPos: | |
139 didMove = True | |
140 | |
141 # Resize/move done | |
142 self.real_widget.setMovable(self._movable) | |
143 | |
144 if self._resize: | |
145 ResizableBase.mouseReleased(self, event) | |
146 elif self._movable and didMove: | |
147 mouseX = self.x+event.getX() | |
148 mouseY = self.y+event.getY() | |
149 | |
150 dockArea = self._editor.getDockAreaAt(mouseX, mouseY) | |
151 if dockArea is not None: | |
152 self._editor.dockWidgetTo(self, dockArea, mouseX, mouseY) | |
153 | |
154 def hide(self): | |
155 """ Hides the panel. If the widget is docked, it is first undocked """ | |
156 if self.isDocked(): | |
157 self.setDocked(False) | |
158 widgets.Window.hide(self) | |
159 | |
160 def show(self): | |
161 """ Show the panel. """ | |
162 if self.isDocked(): | |
163 return | |
164 widgets.Window.show(self) | |
165 | |
166 | |
167 # Register widget to pychan | |
168 if 'Panel' not in widgets.WIDGETS: | |
169 widgets.WIDGETS['Panel'] = Panel | |
170 |