Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Close editor tab
-
Not sure this has not yet be done (sorry if yes), but this little script allows to close an open tab.
import editor from objc_util import * @on_main_thread def closeTab(file_name): win = UIApplication.sharedApplication().keyWindow() root_vc = win.rootViewController() tabs_vc = root_vc.detailViewController() for tab in tabs_vc.tabViewControllers(): if tab.isKindOfClass_(ObjCClass('PA2UniversalTextEditorViewController')): #print(str(tab.filePath())) tab_file = str(tab.filePath()) if tab_file == editor.get_path(): # crash if try to close edited file continue if file_name in tab_file: tabs_vc.closeTab_(tab) return True return False print(closeTab('xxxxxx'))
-
@cvp, thanks.
What is your use case for this?
-
@mikael I wrote an application for a friend and, as usually, there are a lot of new functionalities and bugs and thus a lot of new versions.
My friend always uses his iMac and not often his iPad.
When a new version is ready, I send it by mail. So, my friend can save it on his iMac where the standard SFTP is configured (System Preferences/Sharing/Remote Login). His mail is not configured of the iPad and, if it was, he should, in the mail, share the new file, select Pythonista, import the file, move it to the right folder etc... He almost never use the iPad.
The best solution would be that I write the script on his iMac...When the script begins, actions are:
- check if the same file name exists on the Mac
- if yes, download the .py file as .server
- check if newer version (first line is "Version = 'xxx'".
- if yes,
- rename actual (running) .py into .xxx (its version)
- rename new .server into .py
- protect the .py file as readonly to be sure that my friend does not modify it by mistake
- run a little PY2 script which will start the new .py file.
The reason is that the script is PY3 thus I can't start a 2nd PY3 interpreter to re-launch it.
That works perfectly but my friend does not like that the editor tab with the .py becomes .xxx after renaming the script.
Thus, I've tried to close this tab, what editor module did not offer.Sorry for a so long explanation.
-
@cvp, thanks, always nice to understand what kind of things people are building and doing with Pythonista.
-
@mikael You're right. I'm just busy to modify my script so, if my little PY2 script does not yet exist on the iPad, the PY3 script will download it from the iMac before launching it.
Complex, isn't it? 🤔