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