]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/ide/activegrid/tool/Service.py
1 #----------------------------------------------------------------------------
3 # Purpose: Basic Reusable Service View for wx.lib.pydocview
9 # Copyright: (c) 2004-2005 ActiveGrid, Inc.
10 # License: wxWindows License
11 #----------------------------------------------------------------------------
15 import wx
. lib
. pydocview
19 FLOATING_MINIFRAME
= - 1
22 class ServiceView ( wx
. EvtHandler
):
23 """ Basic Service View.
27 #----------------------------------------------------------------------------
29 #----------------------------------------------------------------------------
31 def __init__ ( self
, service
):
32 wx
. EvtHandler
.__ init
__ ( self
)
33 self
._ viewFrame
= None
34 self
._ service
= service
36 self
._ embeddedWindow
= None
40 wx
. EvtHandler
. Destroy ( self
)
44 return self
._ viewFrame
47 def SetFrame ( self
, frame
):
48 self
._ viewFrame
= frame
51 def _CreateControl ( self
, parent
, id ):
59 def SetControl ( self
, control
):
60 self
._ control
= control
63 def OnCreate ( self
, doc
, flags
):
64 config
= wx
. ConfigBase_Get ()
65 windowLoc
= self
._ service
. GetEmbeddedWindowLocation ()
66 if windowLoc
== FLOATING_MINIFRAME
:
67 pos
= config
. ReadInt ( self
._ service
. GetServiceName () + "FrameXLoc" , - 1 ), config
. ReadInt ( self
._ service
. GetServiceName () + "FrameYLoc" , - 1 )
68 # make sure frame is visible
69 screenWidth
= wx
. SystemSettings
. GetMetric ( wx
. SYS_SCREEN_X
)
70 screenHeight
= wx
. SystemSettings
. GetMetric ( wx
. SYS_SCREEN_Y
)
71 if pos
[ 0 ] < 0 or pos
[ 0 ] >= screenWidth
or pos
[ 1 ] < 0 or pos
[ 1 ] >= screenHeight
:
72 pos
= wx
. DefaultPosition
74 size
= wx
. Size ( config
. ReadInt ( self
._ service
. GetServiceName () + "FrameXSize" , - 1 ), config
. ReadInt ( self
._ service
. GetServiceName () + "FrameYSize" , - 1 ))
75 title
= _ ( self
._ service
. GetServiceName ())
76 if wx
. GetApp (). GetDocumentManager (). GetFlags () & wx
. lib
. docview
. DOC_SDI
and wx
. GetApp (). GetAppName ():
77 title
= title
+ " - " + wx
. GetApp (). GetAppName ()
78 frame
= wx
. MiniFrame ( wx
. GetApp (). GetTopWindow (), - 1 , title
, pos
= pos
, size
= size
, style
= wx
. CLOSE_BOX|wx
. CAPTION|wx
. SYSTEM_MENU
)
79 wx
. EVT_CLOSE ( frame
, self
. OnCloseWindow
)
80 elif wx
. GetApp (). IsMDI ():
81 self
._ embeddedWindow
= wx
. GetApp (). GetTopWindow (). GetEmbeddedWindow ( windowLoc
)
82 frame
= self
._ embeddedWindow
84 pos
= config
. ReadInt ( self
._ service
. GetServiceName () + "FrameXLoc" , - 1 ), config
. ReadInt ( self
._ service
. GetServiceName () + "FrameYLoc" , - 1 )
85 # make sure frame is visible
86 screenWidth
= wx
. SystemSettings
. GetMetric ( wx
. SYS_SCREEN_X
)
87 screenHeight
= wx
. SystemSettings
. GetMetric ( wx
. SYS_SCREEN_Y
)
88 if pos
[ 0 ] < 0 or pos
[ 0 ] >= screenWidth
or pos
[ 1 ] < 0 or pos
[ 1 ] >= screenHeight
:
89 pos
= wx
. DefaultPosition
91 size
= wx
. Size ( config
. ReadInt ( self
._ service
. GetServiceName () + "FrameXSize" , - 1 ), config
. ReadInt ( self
._ service
. GetServiceName () + "FrameYSize" , - 1 ))
92 title
= _ ( self
._ service
. GetServiceName ())
93 if wx
. GetApp (). GetDocumentManager (). GetFlags () & wx
. lib
. docview
. DOC_SDI
and wx
. GetApp (). GetAppName ():
94 title
= title
+ " - " + wx
. GetApp (). GetAppName ()
95 frame
= wx
. GetApp (). CreateDocumentFrame ( self
, doc
, flags
, pos
= pos
, size
= size
)
97 if config
. ReadInt ( self
._ service
. GetServiceName () + "FrameMaximized" , False ):
99 wx
. EVT_CLOSE ( frame
, self
. OnCloseWindow
)
102 sizer
= wx
. BoxSizer ( wx
. VERTICAL
)
104 windowLoc
= self
._ service
. GetEmbeddedWindowLocation ()
105 if self
._ embeddedWindow
or windowLoc
== FLOATING_MINIFRAME
:
106 if ( self
._ service
. GetEmbeddedWindowLocation () == wx
. lib
. pydocview
. EMBEDDED_WINDOW_BOTTOM
):
107 if ServiceView
. bottomTab
== None :
108 ServiceView
. bottomTab
= wx
. Notebook ( frame
, wx
. NewId (), ( 0 , 0 ), ( 100 , 100 ), wx
. LB_DEFAULT
, "Bottom Tab" )
109 sizer
. Add ( ServiceView
. bottomTab
, 1 , wx
. TOP|wx
. EXPAND
, 4 )
110 def OnFrameResize ( event
):
111 ServiceView
. bottomTab
. SetSize ( ServiceView
. bottomTab
. GetParent (). GetSize ())
112 frame
. Bind ( wx
. EVT_SIZE
, OnFrameResize
)
114 self
._ control
= self
._ CreateControl
( ServiceView
. bottomTab
, wx
. NewId ())
115 if self
._ control
!= None :
116 ServiceView
. bottomTab
. AddPage ( self
._ control
, self
._ service
. GetServiceName ())
117 ServiceView
. bottomTab
. Layout ()
120 self
._ control
= self
._ CreateControl
( frame
, wx
. NewId ())
121 sizer
. Add ( self
._ control
)
124 self
._ control
= self
._ CreateControl
( frame
, wx
. NewId ())
125 sizer
. Add ( self
._ control
, 1 , wx
. EXPAND
, 0 )
126 frame
. SetSizer ( sizer
)
132 def OnCloseWindow ( self
, event
):
133 frame
= self
. GetFrame ()
134 config
= wx
. ConfigBase_Get ()
135 if frame
and not self
._ embeddedWindow
:
136 if not frame
. IsMaximized ():
137 config
. WriteInt ( self
._ service
. GetServiceName () + "FrameXLoc" , frame
. GetPositionTuple ()[ 0 ])
138 config
. WriteInt ( self
._ service
. GetServiceName () + "FrameYLoc" , frame
. GetPositionTuple ()[ 1 ])
139 config
. WriteInt ( self
._ service
. GetServiceName () + "FrameXSize" , frame
. GetSizeTuple ()[ 0 ])
140 config
. WriteInt ( self
._ service
. GetServiceName () + "FrameYSize" , frame
. GetSizeTuple ()[ 1 ])
141 config
. WriteInt ( self
._ service
. GetServiceName () + "FrameMaximized" , frame
. IsMaximized ())
143 if not self
._ embeddedWindow
:
144 windowLoc
= self
._ service
. GetEmbeddedWindowLocation ()
145 if windowLoc
== FLOATING_MINIFRAME
:
146 # don't destroy it, just hide it
149 # Call the original OnCloseWindow, could have subclassed SDIDocFrame and MDIDocFrame but this is easier since it will work for both SDI and MDI frames without subclassing both
150 frame
. OnCloseWindow ( event
)
153 def Activate ( self
, activate
= True ):
154 """ Dummy function for SDI mode """
158 def Close ( self
, deleteWindow
= True ):
160 Closes the view by calling OnClose. If deleteWindow is true, this
161 function should delete the window associated with the view.
169 #----------------------------------------------------------------------------
171 #----------------------------------------------------------------------------
173 def SetCallback ( self
, callback
):
174 """ Sets in the event table for a doubleclick to invoke the given callback.
175 Additional calls to this method overwrites the previous entry and only the last set callback will be invoked.
177 wx
. stc
. EVT_STC_DOUBLECLICK ( self
. GetControl (), self
. GetControl (). GetId (), callback
)
180 #----------------------------------------------------------------------------
182 #----------------------------------------------------------------------------
185 if not self
. GetFrame ():
187 return self
. GetFrame (). IsShown ()
194 def Show ( self
, show
= True ):
195 self
. GetFrame (). Show ( show
)
196 if self
._ embeddedWindow
:
197 mdiParentFrame
= wx
. GetApp (). GetTopWindow ()
198 mdiParentFrame
. ShowEmbeddedWindow ( self
. GetFrame (), show
)
201 class Service ( wx
. lib
. pydocview
. DocService
):
204 #----------------------------------------------------------------------------
206 #----------------------------------------------------------------------------
207 SHOW_WINDOW
= wx
. NewId () # keep this line for each subclass, need unique ID for each Service
210 def __init__ ( self
, serviceName
, embeddedWindowLocation
= wx
. lib
. pydocview
. EMBEDDED_WINDOW_LEFT
):
211 self
._ serviceName
= serviceName
212 self
._ embeddedWindowLocation
= embeddedWindowLocation
216 def GetEmbeddedWindowLocation ( self
):
217 return self
._ embeddedWindowLocation
220 def SetEmbeddedWindowLocation ( self
, embeddedWindowLocation
):
221 self
._ embeddedWindowLocation
= embeddedWindowLocation
224 def InstallControls ( self
, frame
, menuBar
= None , toolBar
= None , statusBar
= None , document
= None ):
225 viewMenu
= menuBar
. GetMenu ( menuBar
. FindMenu ( _ ( "&View" )))
226 menuItemPos
= self
. GetMenuItemPos ( viewMenu
, viewMenu
. FindItem ( _ ( "&Status Bar" ))) + 1
228 viewMenu
. InsertCheckItem ( menuItemPos
, self
. SHOW_WINDOW
, self
. GetMenuString (), self
. GetMenuDescr ())
229 wx
. EVT_MENU ( frame
, self
. SHOW_WINDOW
, frame
. ProcessEvent
)
230 wx
. EVT_UPDATE_UI ( frame
, self
. SHOW_WINDOW
, frame
. ProcessUpdateUIEvent
)
235 def GetServiceName ( self
):
236 """ String used to save out Service View configuration information """
237 return self
._ serviceName
240 def GetMenuString ( self
):
241 """ Need to override this method to provide menu item for showing Service View """
242 return _ ( self
. GetServiceName ())
245 def GetMenuDescr ( self
):
246 """ Need to override this method to provide menu item for showing Service View """
247 return _ ( "Show or hides the %s window" ) % self
. GetMenuString ()
250 #----------------------------------------------------------------------------
251 # Event Processing Methods
252 #----------------------------------------------------------------------------
254 def ProcessEvent ( self
, event
):
256 if id == self
. SHOW_WINDOW
:
257 self
. ToggleWindow ( event
)
263 def ProcessUpdateUIEvent ( self
, event
):
265 if id == self
. SHOW_WINDOW
:
266 event
. Check ( self
._ view
!= None and self
._ view
. IsShown ())
273 #----------------------------------------------------------------------------
275 #----------------------------------------------------------------------------
277 def _CreateView ( self
):
278 """ This method needs to be overridden with corresponding ServiceView """
279 return ServiceView ( self
)
283 # Window Menu Service Method
287 def SetView ( self
, view
):
291 def ShowWindow ( self
, show
= True ):
294 if not self
._ view
. IsShown ():
297 view
= self
._ CreateView
()
298 view
. OnCreate ( None , flags
= 0 )
302 if self
._ view
. IsShown ():
306 def HideWindow ( self
):
307 self
. ShowWindow ( False )
310 def ToggleWindow ( self
, event
):
311 show
= event
. IsChecked ()
312 wx
. ConfigBase_Get (). WriteInt ( self
. GetServiceName ()+ "Shown" , show
)
313 self
. ShowWindow ( show
)
316 def OnCloseFrame ( self
, event
):
320 if wx
. GetApp (). IsMDI ():
321 self
._ view
. OnCloseWindow ( event
)
322 # This is called when any SDI frame is closed, so need to check if message window is closing or some other window
323 elif self
._ view
== event
. GetEventObject (). GetView ():