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 Using a UI would be very nice but I would settle for the console. Python comes on the Mac but since it is OSX (and not iOS) you can pretty much install any Python distribution you like. I use Anaconda.
-
@ihf Ok, I've installed Python on my (very old and unused Mac) via https://docs.python.org/3/using/mac.html.
Then I wrote a very quick and dirty (as usual) script to
- define a path where to start the files dialog (see and set your default_path)
- open a files dialog allowing only .outline files
- select an outline file
- printing your file in console (outline in red, text in blue) without any image
Please, try it and tell me how you would want to see it better
#!/usr/bin/env python3 # coding: utf-8 from __future__ import print_function, absolute_import from ast import literal_eval import os import sys from tkinter import * from tkinter.filedialog import askopenfilename root = Tk() root.withdraw() default_path = os.path.expanduser('~/Desktop/Users/Christian/Pythonista/Backup/Outline') valid_types = [("Outline files", "*.outline")] RED = '\033[91m' BLUE = '\033[94m' def clear(): os.system('clear') def main(): file_path = askopenfilename(initialdir=default_path, message="Choose one outline file", multiple=False, title="Outline Selector", filetypes=valid_types) if not file_path: sys.exit("User cancelled") clear() print(file_path, end='\n') with open(file_path, mode='rt', encoding='utf-8', errors="surrogateescape") as fil: c = fil.read() c_prms = c.split('\n') c = c_prms[0] cs = literal_eval(c) del c del c_prms for c in cs: vals,outline,opts,dict_text = c text = dict_text['text'] print(f"{RED}{outline} {BLUE}{text}") del text del cs if __name__ == '__main__': sys.exit(main())
-
@ihf sorry, error due to late change, del text instead of del t
-
@ihf Instead of printing the outline file in the console, I could create a local html file with the outline content and open a new tab in Safari showing this html, but it is a little bit more complex. And surely if we want to include the images in the html...
-
https://brew.sh is the essential tool for macOS.
brew install python
-
@ccc Far from me to critic any Mac software , but, sincerely, I stopped to use my Mac some years ago and I have programmed all what I needed on my iPad in Pythonista, Shortcuts, Scriptable, IFTTT.
It is only when @ihf asked this last feature that I powered my Mac on. I don't want to spend more time to learn something new, but thanks for the info, as usual. -
@cvp I tried the viewer script. It worked fine on the first outline I tried but the second gave:
Traceback (most recent call last): File "/Users/ihf/Desktop/outline_viewer.py", line 48, in <module> sys.exit(main()) File "/Users/ihf/Desktop/outline_viewer.py", line 42, in main print(f"{RED}{outline} {BLUE}{text}") UnicodeEncodeError: 'ascii' codec can't encode character '\u2019' in position 27: ordinal not in range(128)
It would be helpful if a path to the Outline could optionally be passed to the script rather than requiring the selection each time.
As far as rendering in html, that would be useful if there are images and more elegant than using the console but at least I can see the outlines on the Mac.
-
@ihf Since IOS 15, I have a lot of problems with a lot of apps, including Pythonista and Pyto, obliging me to restart my iPad. They stay hanging even if restart from Safari or in safe mode for Pythonista.
I program the script on my iPad, in Pythonista with the script open as external on the Mac via the Files app. And if Pythonista hangs, I can't do anything.
I guess this encode problem comes from a special character in the file, not accepted by the print. -
@ihf How do you call the script with argument?
-
@cvp outline_viewer path_to_file
-
@ihf thus in terminal? I used in double clicking it in Finder
-
@ihf see V00.01 of mac_outline_viewer
You can pass as argument the entire path of the outline file, relative versus folder of script it-self.
-
@ihf see V00.02 of mac_outline_viewer with
V0.02 - runs on Mac and in Pythonista on iPad/iPhone - generates a web page (without images, font attributes, links...) - opens a new tab in Safari to display the html
As I don't know a lot about html/css, I don't see how I could make this script better so the html would support images (at left/right/...), font attributes, links and so on...
I wonder if the ideal would not be that the outline program generates a .pdf each time an .outline file is "finished", either when the program is closed, or when the option "new" creates a new one,
the mac_outline_viewer program would then allow you to choose a .pdf to display.
-
@ihf Are you interested by viewing your outlines (text) on your Apple Watch (if you have one as I think )?
If yes, I've found a way (after hours of tests), not yet programmed but feasible.
The outline.py program could, at each save, create/update the notes field (if accessible as I hope, but not sure, see here) of a contact named as
first name = outline
last name = file name (without the yyyymmdd_hhmmss part)
You would need to run a shortcut on your Apple Watch, shortcut as:- show a list of contacts with first name = outline
- you select one in the list
- get notes
- quick look of notes
It seems that from IOS 13, notes field of contact is no more available to apps.
Thus, my solution would not work.
I'll try to use notes fields of calendar events, for instance in a specific calendar...
Tried (not in outline.py) and ok
Concept is to store it in an area readable by Apple Watch shortcut and shared on all Idevices -
@ihf please give me news about the Mac script and the Apple Watch proposal
-
@cvp Sorry for the delay in replying. I am away from home this week and had some network issues yesterday. I will try to test the Mac script later today. As to the watch, that would be a great addition. I think I would use DataJar for this purpose. I have to look at how Pythonista could add values though.
-
@ihf oups, sorry to have insisted, no urgence at all.
don't know datajar, if you find a way that Pythonista could use it to update such a file, tell me. -
@ihf the only way I actually see to update the Data Jar database is via a shortcut, not via a Python script. Thus, I don't see how it could help you to store the ouTline data.
-
@cvp Yes but you can do this:
import shortcuts shortcuts.open_shortcuts_app(name="dj",shortcut_input="Hello World"
The Shortcut looks like this: https://www.icloud.com/shortcuts/a944a4779c0c4c71861a402cb6b6a138
Then it is easy to get to Datajar values from a shortcut that is run on the watch.
-
@ihf Did you try it? That will say that at each save of an outline file, I should run a shortcut, passing the text part of the outline? Agree?
To be compared to update a calendar event (fixed date, title = outline name) with its notes field = outline text part. And shortcut on Apple watch can show a list of all such events, user select one and show the text.