MCPcopy Create free account
hub / github.com/mhammond/pywin32 / GetActiveFileName

Function GetActiveFileName

Pythonwin/pywin/framework/scriptutils.py:151–183  ·  view source on GitHub ↗

Gets the file name for the active frame, saving it if necessary. Returns None if it cant be found, or raises KeyboardInterrupt.

(bAutoSave = 1)

Source from the content-addressed store, hash-verified

149 return (None, None)
150
151def GetActiveFileName(bAutoSave = 1):
152 """Gets the file name for the active frame, saving it if necessary.
153
154 Returns None if it cant be found, or raises KeyboardInterrupt.
155 """
156 pathName = None
157 active = GetActiveView()
158 if active is None:
159 return None
160 try:
161 doc = active.GetDocument()
162 pathName = doc.GetPathName()
163
164 if bAutoSave and \
165 (len(pathName)>0 or \
166 doc.GetTitle()[:8]=="Untitled" or \
167 doc.GetTitle()[:6]=="Script"): # if not a special purpose window
168 if doc.IsModified():
169 try:
170 doc.OnSaveDocument(pathName)
171 pathName = doc.GetPathName()
172
173 # clear the linecache buffer
174 linecache.clearcache()
175
176 except win32ui.error:
177 raise KeyboardInterrupt
178
179 except (win32ui.error, AttributeError):
180 pass
181 if not pathName:
182 return None
183 return pathName
184
185lastScript = ''
186lastArgs = ''

Callers 3

RunScriptFunction · 0.85
ImportFileFunction · 0.85
CheckFileFunction · 0.85

Calls 5

GetActiveViewFunction · 0.85
GetDocumentMethod · 0.45
GetPathNameMethod · 0.45
GetTitleMethod · 0.45
OnSaveDocumentMethod · 0.45

Tested by

no test coverage detected