]>
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 ):
196 self
. GetFrame (). Show ( show
)
197 if self
._ embeddedWindow
:
198 mdiParentFrame
= wx
. GetApp (). GetTopWindow ()
199 mdiParentFrame
. ShowEmbeddedWindow ( self
. GetFrame (), show
)
202 class Service ( wx
. lib
. pydocview
. DocService
):
205 #----------------------------------------------------------------------------
207 #----------------------------------------------------------------------------
208 SHOW_WINDOW
= wx
. NewId () # keep this line for each subclass, need unique ID for each Service
211 def __init__ ( self
, serviceName
, embeddedWindowLocation
= wx
. lib
. pydocview
. EMBEDDED_WINDOW_LEFT
):
212 self
._ serviceName
= serviceName
213 self
._ embeddedWindowLocation
= embeddedWindowLocation
217 def GetEmbeddedWindowLocation ( self
):
218 return self
._ embeddedWindowLocation
221 def SetEmbeddedWindowLocation ( self
, embeddedWindowLocation
):
222 self
._ embeddedWindowLocation
= embeddedWindowLocation
225 def InstallControls ( self
, frame
, menuBar
= None , toolBar
= None , statusBar
= None , document
= None ):
226 viewMenu
= menuBar
. GetMenu ( menuBar
. FindMenu ( _ ( "&View" )))
227 menuItemPos
= self
. GetMenuItemPos ( viewMenu
, viewMenu
. FindItem ( _ ( "&Status Bar" ))) + 1
229 viewMenu
. InsertCheckItem ( menuItemPos
, self
. SHOW_WINDOW
, self
. GetMenuString (), self
. GetMenuDescr ())
230 wx
. EVT_MENU ( frame
, self
. SHOW_WINDOW
, frame
. ProcessEvent
)
231 wx
. EVT_UPDATE_UI ( frame
, self
. SHOW_WINDOW
, frame
. ProcessUpdateUIEvent
)
236 def GetServiceName ( self
):
237 """ String used to save out Service View configuration information """
238 return self
._ serviceName
241 def GetMenuString ( self
):
242 """ Need to override this method to provide menu item for showing Service View """
243 return _ ( self
. GetServiceName ())
246 def GetMenuDescr ( self
):
247 """ Need to override this method to provide menu item for showing Service View """
248 return _ ( "Show or hides the %s window" ) % self
. GetMenuString ()
251 #----------------------------------------------------------------------------
252 # Event Processing Methods
253 #----------------------------------------------------------------------------
255 def ProcessEvent ( self
, event
):
257 if id == self
. SHOW_WINDOW
:
258 self
. ToggleWindow ( event
)
264 def ProcessUpdateUIEvent ( self
, event
):
266 if id == self
. SHOW_WINDOW
:
267 event
. Check ( self
._ view
!= None and self
._ view
. IsShown ())
274 #----------------------------------------------------------------------------
276 #----------------------------------------------------------------------------
278 def _CreateView ( self
):
279 """ This method needs to be overridden with corresponding ServiceView """
280 return ServiceView ( self
)
284 # Window Menu Service Method
288 def SetView ( self
, view
):
292 def ShowWindow ( self
, show
= True ):
295 if not self
._ view
. IsShown ():
298 view
= self
._ CreateView
()
299 view
. OnCreate ( None , flags
= 0 )
303 if self
._ view
. IsShown ():
307 def HideWindow ( self
):
308 self
. ShowWindow ( False )
311 def ToggleWindow ( self
, event
):
312 show
= event
. IsChecked ()
313 wx
. ConfigBase_Get (). WriteInt ( self
. GetServiceName ()+ "Shown" , show
)
314 self
. ShowWindow ( show
)
317 def OnCloseFrame ( self
, event
):
321 if wx
. GetApp (). IsMDI ():
322 self
._ view
. OnCloseWindow ( event
)
323 # This is called when any SDI frame is closed, so need to check if message window is closing or some other window
324 elif self
._ view
== event
. GetEventObject (). GetView ():