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.
Outliner with drag/drop reordering - part 2
-
@cvp The script is local on both devices and the outlines are on iCloud. On the newer iPad Pro, watch time I run v 1.20 it says that v1.21 is available and then says it is downloaded and after I restart the script, it repeats. Restarting Pythonista does not help.
-
@ihf do you use on your boTh devices the outline.py script in a Pythonista tab or do you use a shortcut to run the script? I could understand that Pythonista has problems to replace an edited running script, although on my iPad I don't have any problem. Sorry, but I am completely in the fog.
My code to replace the running script by a new one is
url = 'https://raw.githubusercontent.com/cvpe/Pythonista-scripts/master/Gists/outline.py' data = requests.get(url).content with open('outline.py', mode='wb') as out_file: out_file.write(data) del data
But if I set an un existing url, the code runs without error and thus does not replace the script.
Perhaps does the problem come from this. -
@cvp the running outline script is in a tab. I had wondered about replacing a running script but it works just fine on the iPhone and the (older) iPad.
-
@ihf said
the running outline script is in a tab. I had wondered about replacing a running script but it works just fine on the iPhone and the (older) iPad.
I'm sincerely sorry, but I don't understand why this difference exists
-
@cvp have you considered using the editor module to make sure the current file isn't open, and close it if it is?
Also, stupid question, but is it possible that @ihf has two copies of the script, and is running the old version? Or a version in site-packages, etc?
Seems like you could also do a check of current file to check if that is the one to replace. -
https://github.com/omz/Pythonista-Issues/issues/510
Also, someone had a cool idea to do this'
https://forum.omz-software.com/topic/5756/close-editor-tab -
@JonB said
have you considered using the editor module to make sure the current file isn't open, and close it if it is?
Also, stupid question, but is it possible that @ihf has two copies of the script, and is running the old version? Or a version in site-packages, etc?
Seems like you could also do a check of current file to check if that is the one to replace.First: you never ask stupid questions, believe me.
A lot of good ideas. I'll think about it. Thursday.
I had also thought to check if new downloaded version was really downloaded, as I saw that a bad url did not give an error to requests line.But that should not explain that it works on all my devices, on two of @ihf and not on his iPad Pro.
Thus perhaps your idea of two versions in this iPad Pro. Normally, my script displays its version at top than he can check the version, even if he has two copies. -
@JonB said
Also, someone had a cool idea to do this'
Wow. I write too much code, I completely forgot that. thanks
-
The key, I think is that a tab is open with the code. When you write to the tile, and read back from it, it will all look good. But once the script ends, or focus switches to the tab, it will re-write itself to the disk. So I think you must close the tab before writing to the file.
An alternative would also be to use the editor module to replace the code in the tab, if you detect that a tab is open with the file. I remember having to do something like that in that editor sideview project a long while back, or maybe in
git
.As an aside, I wonder if there is a way to gracefully shut down the script (closing the views, then getting rid of anything with the new ObjC classes, like input view controllers or whatever -- then always use the objc classes from their variable names, instead of string. E.g. you'd create the classes (using the debug option, so class gets number assigned to it if it already exists) then never refer to the class by it's string name, only the variable . That way new ObjC classes doesn't require a restart of the app.
-
... yes, it was git:
def refresh_editor(): #reload current file in editor # TODO: only reload if the file was recently updated... try: sel = editor.get_selection() editor.open_file(editor.get_path()) import time time.sleep(0.5) #let the file load editor.replace_text(sel[0], sel[0], '') #force scroll editor.set_selection(sel[0], sel[1]) except: print('Could not refresh editor. continuing anyway')
I think I determined the issue only happens for the current tab -- any background tabs get checked and reloaded if needed already.
I'm not proud of that
sleep
, I'm sure there is another way to check state of the load, but I never dug into it. -
-
You can always force a crash if you want to restart pythonista.
-
@JonB os.abort?
-
Yes, abort.
Maybe paired with a notification set for a few seconds in the future to relaunch the app. At least takes that one variable out of the equation!
Or, your new code could have some indication that classes have been updated (like an objc class version separate from main script version), in which case, if classes have been updated, you would abort, otherwise could even relaunch the script.
-
@JonB thanks for your help, I have a lot to think about.
First, I think you did find the reason why it does not work if when you terminate a script in an edited tab, it rewrites it-self... -
@JonB said
Yes, abort. Maybe paired with a notification set for a few seconds in the future to relaunch the app. At least takes that one variable out of the equation!
I like it, thanks
-
@cvp Just to be clear, I only have one copy of the outline.py and, yes ,it is being run from the tab in both cases yet on one iPad it works and the other it fails.
-
@ihf Even with the advices of @JonB , I don't understand this difference...
What I will do, I think, but tomorrow because I have a big request of a neighbor for whom I have programmed also a big program (8248 lines, yours is only 5681), is:
- download from GitHub
- close tab if program runs in a edited tab (to avoid that script end saves the script in the file, replacing the downloaded one)
- abort the program, and thus Pythonista it-self
- try to create a notification for the user, one minute later, to allow him to restart Pythonista and the script (to be tested)
-
@ihf V01.22 and outline.versions with
Version V01.22 - when a new version is available, if user accepts to install it, this version will be installed, then Pythonista will abort to avoid the current edited version to be written and thus replace the new version
This new version only contains thus a supplementary
os.abort()
to force Pythonista to abort and to avoid that current running script, when it ends, saves it-self and thus erases the newly downloaded version. If it works correctly on all your devices, please thanks @JonB for his advice.To test (on all your devices) this, you can wait for the next version, or you can, after manually or automatically having downloaded this version, modify the line
Version = 'V01.22'
into
Version = 'V01.21
and run it, to force the script to believe it is of previous version.
After Pythonista abort, rerun the script and check its version, if it's V01.22, then all is ok.
Of course, I could also generate a notification appearing one minute later asking you to tap it to start Pythonista and the script. Please, tell me if this functionality could help you.
-
@cvp I tested as you suggested on the iPad which was having the problem with downloading the new releases and it worked. Not sure why this works since I had tried (on previous releases) to force quit Pythonista and restart it only to have it try to download the new release again, but happy to have it working now.