Forum Archive

How to close out scripts in Pythonista?

tactfulgamer

I almost deleted the script by swiping to the left on it, from the left side panel. Is the a way to close out the open script?

I don’t see an x button or anything.

Thank you!

JonB

Are you on iPhone or iPad?

cvp

It is sure that if you have only one edited script, there is no x button, thus no way to close it.
You have to open another file. At least on iPad.

mikael

@cvp, same on iPhone.

eric_bixby

I just figured out an alternative. Click on the [+] icon (top right) which opens a new tab, then close the file tab.

stephen

possibly can setup an editor action to habdle creating z virtual temp file so you can clase all tabs then by removing thr temp file the app should default to the menu. ill look around and see if i can whip something up

cvp

@stephen you could define this little script as a Pythonista tool, it will close all tabs

from objc_util import *

@on_main_thread
def main():
    win = UIApplication.sharedApplication().keyWindow()
    root_vc = win.rootViewController()
    if root_vc.isKindOfClass_(ObjCClass('PASlidingContainerViewController')):
        tabs_vc = root_vc.detailViewController()
        for tab in tabs_vc.tabViewControllers():
            if tab.isKindOfClass_(ObjCClass('PA2UniversalTextEditorViewController')):
                tabs_vc.closeTab_(tab)  

if __name__ == '__main__':
    main() 
stephen

Outstanding @cvp!

i am just about to get into objc_utils so i dont think of there yet for solutions lol i was going to try and get a script to buffer copies of open tabbed files then close originals. then compare to make sure they closed without corruption or anything, and so on.. i really need to jump into objc_utils lol

Appologies for so many typos...

here you go @tactfulgamer from cvp

@cvp said:

@stephen you could define this little script as a Pythonista tool, it will close all tabs
```python
from objc_util import *

@on_main_thread
def main():
win = UIApplication.sharedApplication().keyWindow()
root_vc = win.rootViewController()
if root_vc.isKindOfClass_(ObjCClass('PASlidingContainerViewController')):
tabs_vc = root_vc.detailViewController()
for tab in tabs_vc.tabViewControllers():
if tab.isKindOfClass_(ObjCClass('PA2UniversalTextEditorViewController')):
tabs_vc.closeTab_(tab)

if name == 'main':
main()
```

cvp

@stephen I had already written that here but, at this moment, to close the edited tab did crash, and now, it doesn't