/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/UI/dock.py
ViewVC logotype

Annotation of /branches/WIP-pyshapelib-bramz/Thuban/UI/dock.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 566 - (hide annotations)
Wed Mar 26 11:10:41 2003 UTC (21 years, 11 months ago) by jonathan
Original Path: trunk/thuban/Thuban/UI/dock.py
File MIME type: text/x-python
File size: 6001 byte(s)
Added missing import line.

1 jonathan 561 # Copyright (c) 2003 by Intevation GmbH
2     # Authors:
3     # Jonathan Coles <[email protected]>
4     #
5     # This program is free software under the GPL (>=v2)
6     # Read the file COPYING coming with Thuban for details.
7    
8     """Classes for creating dockable windows"""
9    
10     __version__ = "$Revision$"
11    
12     from Thuban import _
13    
14     from wxPython.wx import *
15    
16     from Thuban.Lib.connector import Publisher
17    
18 jonathan 566 from dialogs import NonModalDialog
19    
20 jonathan 561 from messages import DOCKABLE_DOCKED, DOCKABLE_UNDOCKED, DOCKABLE_CLOSED
21    
22     ID_BUTTON_DOCK = 4001
23     ID_BUTTON_UNDOCK = 4002
24    
25     class DockPanel(wxPanel):
26    
27     def __init__(self, parent, id):
28    
29     wxPanel.__init__(self, parent, id)
30    
31     self.SetDockParent(None)
32    
33     def SetDockParent(self, parent):
34     self.dockParent = parent
35    
36     def GetDockParent(self):
37     return self.dockParent
38    
39     def Dock(self):
40     self.GetDockParent().Dock()
41    
42     def UnDock(self):
43     self.GetDockParent().UnDock()
44    
45     def IsDocked(self):
46     return self.GetDockParent().IsDocked()
47    
48     class DockableWindow(NonModalDialog, Publisher):
49    
50     def __init__(self, parent, id, name,
51     title, dockWindow, panel, docked = False, show = True):
52    
53     NonModalDialog.__init__(self, parent, name, title)
54    
55     self.id = id
56     self.dockWindow = dockWindow
57     self.docked = docked
58    
59     self.dockBorder = None
60     self.dockBorderParent = self
61    
62     self.size = None
63     self.position = None
64    
65     self.SetPanel(panel)
66     self.SetDock(self.docked)
67    
68     self.Show(show)
69    
70     def SetPanel(self, panel, orient = wxVERTICAL):
71    
72     if not isinstance(panel, DockPanel):
73     raise TypeError("")
74    
75     self.panel = panel
76     self.panel.SetDockParent(self)
77     self.orientation = orient
78     self.__CreateBorder()
79    
80     def SetDock(self, dock):
81     if dock:
82     self.Dock()
83     else:
84     self.UnDock()
85    
86     def Dock(self):
87     #if self.IsDocked(): return
88    
89     self.docked = True
90    
91     self.size = self.GetSize()
92     self.position = self.GetPosition()
93     #print self.position
94    
95    
96     NonModalDialog.Hide(self)
97    
98     self.dockBorderParent = self.dockWindow
99     self.dockBorder.Reparent(self.dockBorderParent)
100    
101     self.dockButton.SetLabel(_("Undock"))
102    
103     self.issue(DOCKABLE_DOCKED, self.id, self)
104    
105     def UnDock(self):
106    
107     #if not self.IsDocked(): return
108    
109     self.docked = False
110    
111     self.dockBorderParent = self
112     self.dockBorder.Reparent(self.dockBorderParent)
113    
114     self.dockButton.SetLabel(_("Dock"))
115    
116     if self.position is not None:
117     #print self.position
118     self.SetPosition(self.position)
119    
120     NonModalDialog.Show(self) # this needs to come before SetSize()
121    
122     if self.size is not None:
123     self.SetSize(self.size)
124    
125     self.issue(DOCKABLE_UNDOCKED, self.id, self)
126    
127     def IsDocked(self):
128     return self.docked
129    
130     def OnClose(self, event):
131     self.issue(DOCKABLE_CLOSED, self.id, self)
132     NonModalDialog.OnClose(self, event)
133    
134     # def Show(self, show = True):
135    
136     # if show:
137    
138     # if self.IsDocked():
139     # self.docked = False
140     # self.Dock()
141     # else:
142     # self.docked = True
143     # self.UnDock()
144     # #NonModalDialog.Show(self)
145     # else:
146     # self.docked = True
147     # self.UnDock()
148     # NonModalDialog.Hide(self)
149    
150     def GetSize(self):
151     return self.dockBorder.GetSize()
152    
153     def GetBestSize(self):
154     return self.dockBorder.GetBestSize()
155    
156     def GetClientSize(self):
157     return self.dockBorder.GetClientSize()
158    
159     def GetAdjustedBestSize(self):
160     return self.dockBorder.GetAdjustedBestSize()
161    
162     def GetSizeTuple(self):
163     return self.dockBorder.GetSizeTuple()
164    
165     def _OnDock(self, event):
166    
167     self.SetDock(not self.docked)
168    
169     # if self.IsDocked():
170     # win.SetLabel(_("Undock"))
171     # self.UnDock()
172     # else:
173     # win.SetLabel(_("Dock"))
174     # self.Dock()
175    
176     #def _OnUnDock(self, event):
177     #self.UnDock()
178    
179     def __CreateBorder(self):
180    
181     self.panel.Reparent(self) # Make sure we hang on to the panel
182    
183    
184     sizer = wxBoxSizer(self.orientation)
185    
186     self.dockBorder = wxPanel(self.dockBorderParent, -1)
187     #self.dockBorder.SetBackgroundColour(wxColour(255, 0, 0))
188    
189     if self.orientation == wxVERTICAL:
190     buttonBoxOrient = wxHORIZONTAL
191     else:
192     buttonBoxOrient = wxVERTICAL
193    
194     buttonBox = wxStaticBoxSizer(
195     wxStaticBox(self.dockBorder, -1, ""),
196     buttonBoxOrient)
197    
198     button = wxStaticText(self.dockBorder, -1,
199     self.GetTitle(),
200     style = wxSIMPLE_BORDER | wxALIGN_CENTRE)
201     buttonBox.Add(button, 0,
202     wxSHAPED | wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL, 0)
203    
204     buttonBox.Add(60, 20, 1, wxGROW)
205    
206     #
207     # Perhaps using wxToggleButton would be better, but it's only
208     # supported under wxMSW and wxGTK as of v2.4.0.3
209     #
210     self.dockButton = wxButton(self.dockBorder, ID_BUTTON_DOCK,
211     "WWWWWW", style = wxGROW | wxBU_EXACTFIT | wxADJUST_MINSIZE)
212     buttonBox.Add(self.dockButton, 0, wxALIGN_RIGHT, 0)
213    
214     #button = wxButton(self.dockBorder, ID_BUTTON_UNDOCK,
215     # _("Undock"),
216     # style = wxSIMPLE_BORDER | wxBU_EXACTFIT)
217     #buttonBox.Add(button, 0, wxALIGN_RIGHT, 0)
218    
219     sizer.Add(buttonBox, 0, wxGROW, 0)
220    
221     self.panel.Reparent(self.dockBorder)
222    
223     sizer.Add(self.panel, 1, wxGROW | wxALL, 0)
224     self.dockBorder.SetSizer(sizer)
225     self.dockBorder.SetAutoLayout(True)
226    
227     #self.dockBorderParent.SetAutoLayout(True)
228    
229     EVT_BUTTON(self.dockBorder, ID_BUTTON_DOCK, self._OnDock)
230     #EVT_BUTTON(self.dockBorder, ID_BUTTON_UNDOCK, self._OnUnDock)
231    

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26