Forum Archive

Outliner with drag/drop reordering - part 2

cvp

@ccc thanks for the advice

cvp

@ihf said

This a (low priority) idea for the wish list: I sometimes want to read my outlines on the Mac. What I do now is save them in pdf or some other format that the Mac understands. This works fine but I have to remember to do it after any change so that the outline will be up-to-date. A reader script in python would permit me to view an outline on the Mac or on anything that runs python and has access to the iCloud files.

Written in my todo list, but when you say "view an outline", that will say use an UI...or print it in the console of this Python interpreter.

I have never used Python on a Mac, which free app do I need?

ihf

@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.

cvp

@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())
cvp

@ihf sorry, error due to late change, del text instead of del t

cvp

@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...

ccc

https://brew.sh is the essential tool for macOS.

brew install python

cvp

@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.

ihf

@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.

cvp

@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.

cvp

@ihf How do you call the script with argument?

ihf

@cvp outline_viewer path_to_file

cvp

@ihf thus in terminal? I used in double clicking it in Finder

cvp

@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.

cvp

@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.

cvp

@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

cvp

@ihf please give me news about the Mac script and the Apple Watch proposal

ihf

@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.

cvp

@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.

cvp

@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.

ihf

@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.

cvp

@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.

ihf

@cvp Yes I tested saving text from Pythonista to Data Jar. However, your idea of using the calendar may turn out to perform better as it does not depend on a 3rd party app. Also, depending on the formatting, the calendar route might offer a way to see an outline on the Mac. (There is a DataJar for the Mac in beta but I have not tried it).

cvp

@ihf I guess that is possible on Mac to read calendars, but I don't know how in Python (quid about Two-factor authentication?).

But is my script on Mac not sufficient? Read the outline file is not better?

ihf

@cvp Reading the outline with Python is better although having it in the calendar as you suggested would also make it readable on the watch as well as on the Mac without any additional programs. I’m just not sure how usable it will be on the Watch given the display limitations and the inability to check off outline items. I’m happy to try it, if you implement it (either with Datajar or the calendar).

cvp

@ihf said:

the inability to check off outline items

What do you mean? Mac and Apple Watch would only be used to read the outlines, not to update them by checking them, isn't it?

ihf

@cvp yes, I was just thinking that without any even minimal interaction capability and given the size of the display and the amount of text it can show, reading outlines on the watch may be of limited utility. But without trying it, I can’t really know for sure.

cvp

@ihf if you want to try on an Apple Watch, create a calendar event
- in calendar named "Outline"
- on 2022/01/01 01:00
- notes = text of your outline like seen by Files/send to app/.txt

See it with this shortcut

ihf

@cvp I had to change the date in the Shortcut to 1/1/2022 01:00 but it worked well…very fast on the watch.

cvp

@ihf yes, sorry, 01:01. Do you think you could use it on your watch? If yes, do you want I modify outline.py to generate such an event? And if yes, agree for calendar name, date, time?

ihf

@cvp yes, it is usable on the watch and is a good enhancement

ihf

@cvp I was trying to get someone to try out Outline and they did not have the support files. They got the message in the console that had links to the 5 or so support scripts. Could you possibly change that so that if it does not find the files, it asks if the user wants to do the download (using requests)? It could greatly simplify getting someone started with Outline.

cvp

@ihf I know and it is on my todo list but not yet done (I'm in a foreign country for the week).

cvp

@ihf V01.05 and outline.versions with

Version V01.05
  - automatic download of needed modules 

It seems that for blackmamba module, this automatic process does not work.
If it is the case, you get in the console an explanation message to download the blackmamba folder.

It is only needed to execute in the console the installation action foreseen by the author:

import requests as r; exec(r.get('http://bit.ly/get-blackmamba').text)

ihf

@cvp I ran v1.05 on my iPad and it gave 4 messages about needing modules that were already there (not sure which but I think it include swizzle and gestures). After accepting, the script ran fine. Perhaps it is not looking in all the valid places?

cvp

@ihf said:

Perhaps it is not looking in all the valid places?

Perhaps you did not install them at the right place 😂
I guess they are all in sites-packages, except blackmamba in sites-packages-3 (done by author installation process)

Nb I don't have these messages, thus....please move them at the right place

cvp

@ihf V01.06 and outline.versions with

Version V01.06
  - add/update calendar event at each outline file save, with
    - calendar = Outline
    - start/end date = 20220101 01:01
    - title = outline file name
    - notes = outline text
    nb: to be used on Apple Watch via shortcuts
cvp

@ihf Please, give me some feedback about Apple Watch and Mac (Safari web page) solutions.

ihf

@cvp The new save to calendar worked fine on my iPhone. However, I then ran it on my iPad with the same Outline and it wrote a second (modified) calendar item with same name. The Shortcut seems to pickup the older one (I presume should only be one).
I’ll check out the Mac reader shortly.

cvp

@ihf said

The Shortcut seems to pickup the older one

I got the same problem during some time, exactly like if the Apple Watch kept a cache of the previous calendar event notes, because there was only one event in the calendar.
iCloud updating of the calendar event takes some time... Not the first time I note that.

ihf

@cvp It’s hours later and there are still 2 calendar items with same name.

cvp

@ihf Weird becuse when I create an event, I store its unique id (event title is not a key) in the outline file and when I update an outline file, I reuse this id to update the event, I don't create a 2nd one.
Did you use the outline.py on two devices on the same outline?

Édit: when you have tested the shortcut, days before The last version of outline.py, you had created manually an event to test the shortcut. Before testing the V01.06, did you remove these manual events? Perhaps, one of your two events is manual and the other automatic?

cvp

@ihf V01.07 and outline.versions with

Version V01.07
  - correction of bug "when automatic event was already existing, 
    updating the outline did not update the event. Only add was ok"

but anyway, this bug does not explain how you could have two same events, please read and check my edit part in my previous post, and give feedback, thanks

ihf

@cvp I thought I had deleted the manual event but I suppose it’s possible that I did not. And yes I edited the same outline on two devices.

ihf

@cvp I think I’m getting a little confused. I deleted the duplicate events and downloaded the latest version of outline.py. I then opened the outline and did a save. Should that now create a calendar event or do I have to create one with no content before it will save it there? In any case, I don’t see any event created on that date.

cvp

@ihf I did exactly what you did:
- delete existing event
- open the outline
- modify it (did you modify it?)
- save
- a new event is appeared

ihf

@cvp sorry, ignore that report. It works as expected and is quite useful on the Watch.

ihf

@cvp Correction to my correction. I ran version 1.07 on my iPhone and it correctly created an event. I just downloaded version 1.07 on my iPad and opened that outline and made a change and saved it now I have two events with the same outline name in the calendar.

cvp

@ihf I don't see any explication to your problem. Perhaps you did run on a second device before the calendar has been synced via iCloud on this device. I've remarked that iCloud calendar synchronization is not very quick.
Just to be sure, settings calendar/sync has to be set to "all events".

The only modification that I could do is: if the outline contains an eventid, that implies that an event has been already created, but if this eventid is not reachable (not yet synced), actually I create another event, I could give a message and bypass this new creation but in this case, the notes field would not be updated.

ihf

@cvp I’ll delete both events and try again on both devices. I’ll confirm that the first device has written the event before trying the second. Stay tuned.

cvp

@ihf The eventid is stored in the outline file, thus if you delete the event it-self, when the script tries to update the event, this one is not reachable thus the script should create a new one.

ihf

@cvp Sorry to report that it wrote 2 events for the same outline. It never erased the one from the iPad when it wrote the one from the iPhone.

cvp

@ihf said

Sorry to report that it wrote 2 events for the same outline. It never erased the one from the iPad when it wrote the one from the iPhone.

Annoying. That will say that the eventid of the "created on iPad" event is not reachable on iPhone.
I did not test on two devices because my outlines folder is local on my iPad. I need to change that for next tests. Sorry for you, but that will not be immediate.

cvp

@ihf The problem comes from the fact that eventIdentifier is not the same on different devices, and I thought it was shared on devices. My mistake, thus I have to search for a different solution. Sorry for you. but, I'll do it.

I think that I'll (try to) identify the event by its title and if I need to update it, even on another device, I'll search the event with the same title (at 20220101 01:01 in Outline calendar ) If not found, I create it, else I update it.

V01.08 and outline.versions with

Version V01.08
  - correction of bug "eventIdentifier not shared cross devices for outline event"

Nb: - if you rename the outline file, renaming the event title is not yet supported
- this problem of eventIdentifier not shared on different devices has the same consequences for events for due dates (remember problems we got) but I'm not ready to correct this part because it has a lot of implications. Sorry.

you have to manually remove events and install the same version on all devices before testing

ihf

@cvp I may not be understanding this correctly but could you just put a unique identifier in the outline file and in the event and use that?

cvp

@ihf I could, but I would have to scan all events of the day to find the right one. That is what I hoped with the eventIdentifier field of the event, without knowing that this id was not the same on all devices, thus not unique. I use now the outline file name which is unique by definiTion.
I had used the identifier because it is the key of the calendar, you have a method to get the event from this id. But anyway, that should work now, at least for this outline event for the Apple Watch.

cvp

@ihf said:

could you just put a unique identifier in the outline file and in the event and use that?

Do you want that I manage an own unique field, like this:
- when I create a new outline event, I store in location (unique free field in a calendar event) a string equal to date time now, so we would be sure it's unique because you would not run the script exactly at the same time on two different devices.
- I store this value also in the outline file it-self
- when I update an outline, I will scan calendar events in calendar "Outline" with start date = 20220101 01:01 to find the same unique field as this one stored in the file, so I could update the notes field

ihf

@cvp I don't have any preference as to how to prevent duplicate events. I would go with whatever you think is most efficient in the script.
By the way, would it be possible for the script to check for updates automatically (or as a menu item?). I have 3 devices I am using with Outline and on each one I am updating Outline.py as well as outline.versions to be sure that any problems that might arise are using the latest versions. Of course, this assume that you will continue to be interested in enhancing this incredibly useful program. (Also, having the outlines on the Apple Watch has proved very useful!)

cvp

@ihf V01.09 and outline.versions with

Version V01.09
  - check and ask to automatically install new version if available

From this version, at start, the program will:
- check if a new version is available on GitHub (needs internet )
- if yes, warn the user and ask him if he wants its automatic installation
- if yes, install automatically the new .versions and .py files in folder of running script
- warn the user to restart the program (this is not automatic, let's not make the user lazy 😂)

Not only checking as requested but also installing...

Not yet testable as is, but as soon you tell me that you have installed it on your devices, I'll create a dummy new version, without any modification, only for testing this one.
Or a version which writes event notes with emoji for checkbox. If you like it, tell me, and you can even decide which emojis you want for checked and unchecked.

ihf

@cvp That looks great. Unrelated: I might have imagined it but did you once ask if it would be useful to permit an outline to have text, for example as a header, that was not part of the numbered outline? If so, (and assuming it is not already there and I don’t realize it), it would be a nice addition.

cvp

@ihf please warn me if you have installed this version, so I prepare a next one for testing the automatic install

cvp

@ihf did:

text, for example as a header, that was not part of the numbered outline

Please try
https://i.imgur.com/jMJGpDX.jpg

Then

ihf

@cvp if I turn that option off it turns itself right back on if I go back to it

cvp

@ihf you have to turn it off AND select a type, even if it is the same (ex: alphanumeric)

ihf

@cvp OK, I gather that once you turn it off you can’t turn it back on for an outline

cvp

@ihf this switch forces that all outlines of first level are without the outline number.
If you want to use it as a title, use only once. Do you want something else?

ihf

@cvp perhaps I am not using this as you intended. There were 2 use cases I was envisioning. One was to have a title (or whatever introductory text) followed by the outline. As far as I can see, the way to do this now is to turn off the 1st level has outline and then the 2nd level and beyond is the outline and 1st level is title. I’m not sure what you mean when you said “use only once”. If I turn off that option and trun it back on the title will be part of the outline. (Sorry if I am being dense about this). The second use case was to have explanatory text in other places in the outline (not just the title at the top). Again, the way I would do this now is to turn off the option and use the 1st level for the non-numbered text and use the lower levels for the outline. Is this how you imagined it, or am I missing something?

I know that undo/redo is not working and it is on your list, but once it is working again, would it be able to reverse the use of the 1st level is outline option?

cvp

@ihf said

The second use case was to have explanatory text in other places in the outline (not just the title at the top)

Yes

used only once

If only at first row, it becomes a title.

would it be able to reverse the use of the 1st level is outline option?

You can always reset the flag on and select the same format

once it is working again

Perhaps never

Anyway, if you want something else as title, feel free to describe your request

And please, tell me when you have installed the V01.09 so I can post a V01.10 to test the automatic install.

ihf

@cvp v1.09 is installed.

cvp

@ihf V01.10 and outline.versions with

Version V01.10
  - outline text in event notes for Apple Watch will contain emoji for (un)checkbox

New version should be automatically checked, confirmed, installed by V01.09

ihf

@cvp with regard to the checkboxes on the watch. What I am seeing is an unchecked box to the left of every line in the outline. I may have misunderstood but I imagined that checked or unchecked boxes would appear next to lines with a checkbox in the outline.

cvp

@ihf you should see checked or unchecked box on the Apple Watch exactly like you see with outline.py, don't you?

Édit: only after an update of the outline with the new V01.10 of course

ihf

@cvp I think I see the problem. I was using an outline that has checkboxes on some lines , but not all. It also had the 1st line has outline turned off. It appears that the event notes have a checkbox whether or not it is in the outline.

cvp

@ihf you may have check box on some lines and not on other ones. But I agree I don't use the switch off/on about 1st level

ihf

@cvp I tried another outline which does not have that option turned off (all lines are part of the outline) but where some lines do not have a checkbox. The event notes show a checkbox on all lines.

cvp

@ihf said:

It appears that the event notes have a checkbox whether or not it is in the outline

Sure event notes already up to date? There is some delay of sync between devices

cvp

@ihf said

The event notes show a checkbox on all lines.

Thus, you don't see an empty gray checkbox if there is no checked box in a line?
Could you post a screen capture of outline.py and of the Watch

ihf

@cvp Yes, the event notes are up-to-date and I see other changes but every line has a checkbox regardless of whether it is in the outline.

cvp

@ihf not a gray checkbox, you mean a checked box?

ihf

@cvp every line has an unchecked box (except those that are checked). In other words, if I turn off a checkbox on one or more lines, they still appear as unchecked boxes in the calendar event notes.

cvp

@ihf said:

if I turn off a checkbox on one or more lines, they still appear as unchecked boxes in the calendar event notes.

Ok, I think that I understand now. Sorry, I had completely forgotten that we can turn off a checkbox. My app has so much functionalities 🙄
I'll correct this later.
Thus I have to support:
- no checkbox
- unchecked check box ◻️
- checked checkbox ✅
- due date set for unchecked 🕦

ihf

@cvp Yes, your creation has so much functionality that sometimes I forget all that it does (until I think of something I want to do and I realize you have already implemented it!)

cvp

@ihf How do you want I align a line without checkbox?
At left?
After some spaces?
Other emoji to show that there is no checkbox?
Ex: unchecked could be 🔲 and no checkbox could be ⬜️

ihf

@cvp Outline has become an important part of my “workflow”. I don’t want to think about what I’ll do if Pythonista were to stop working at some point.

ihf

@cvp I think that either no checkbox and aligned on the left would be ok as would a solid bullet.

cvp

@ihf please choose
No check box
Or
• no check box
⬜️ Not checked
✅ checked
🕦 due date unchecked

ihf

@cvp I would use the bullet for the lines with no-check-box.

cvp

@ihf you did not tell me if automatic install has been ok

cvp

@ihf V01.11 and outline.versions with

Version V01.11
  - outline text in event notes for Apple Watch will contain
    - clock emoji for unchecked outline with due date already set
    - bullet for outline without check box

Edit: if bullet is not at level 1, as it is narrower than an emoji, the outline seems to be not aligned

⬜️1.0  unchecked
🕦  1.1  due date unchecked
✅    1.1.1  checked
•    1.1.2  no checkbox

We should use also an emoji instead of a bullet, but which one?

Could be

⬜️1.0  unchecked
🕦  1.1  due date unchecked
✅    1.1.1  checked
▪️    1.1.2  no checkbox
ihf

@cvp this works great! I guess having the symbol next to the text is better than lined up on the left (which is where I see them now)

cvp

@ihf you want this?

⬜️1.0  unchecked
🕦  1.1  due date unchecked
✅    1.1.1  checked
     •1.1.2 no checkbox

Or this

⬜️1.0  unchecked
🕦  1.1  due date unchecked
✅    1.1.1  checked
    ▪️1.1.2  no checkbox
ihf

@cvp If that is the size of the bullet then I would go with the square

cvp

@ihf V01.12 and outline.versions with

Version V01.12
  - square emoji used for outline without checkbox and aligning texts

Édit: it is ok when you edit the notes field but square emoji does not appear correctly on the Apple Watch, weird. (Zoom the image and you'll see squares, perhaps due to black squares on black background)

ihf

@cvp yes, that is hard to see on the watch.

cvp

@ihf V01.13 and outline.versions with

Version V01.13
  - gray square emoji used for outline without checkbox due to black background

ihf

@cvp and the auto-install is a BIG time saver. Thank you!

cvp

@ihf you're welcome. If you use this program so frequently, I can't imagine you don't meet a lot of circumstances where a new functionally could be hoped.

cvp

@ihf V01.14 and outline.versions with

Version V01.14
  - correction of bug "title of popup menu was 'outline for xxx' where xxx
    was not the tapped outline but the text of an eventual copied row, same
    as 'paste xxx...'"

😂 Just to prove that I

continue to be interested in enhancing this incredibly useful program

ihf

@cvp haha. OK, here goes. It would be nice if the due date event could optionally set the Repeat interval and the Alert/Second alert timing.

ihf

@cvp you implemented a select with copy, delete, etc. from within outline but is there already a way to select and copy to the pasteboard so that the items can be pasted into another app?

cvp

@ihf did:

but is there already a way to select and copy to the pasteboard so that the items can be pasted into another app?

No. But, of course, I could foresee such an option but whaT do you want To paste? Only the texts or also the outlines? And for several lines?

@ihf said

It would be nice if the due date event could optionally set the Repeat interval and the Alert/Second alert timing.

No code is incorporated in outline.py, but could you test this little script only to see if you like the standard calendar event dialog

import ui
from objc_util import *
load_framework('EventKitUI')

def EventEditViewController(title=None):
  v = ui.View()
  if title:
    v.name = title
  v.rgb = None
  vc = ObjCInstance(v)
  store = ObjCClass('EKEventStore').alloc().init()
  calendar = None
  for cal in store.calendars():
    #print(cal.title())
    if str(cal.title()) == 'Outline':
      calendar = cal
      break
  EKEventEditViewController = ObjCClass('EKEventEditViewController').new().autorelease()
  EKEventEditViewController.eventStore = store
  event = ObjCClass('EKEvent').eventWithEventStore_(store)
  event.title = 'Todo: text line'
  event.setCalendar_(calendar)
  EKEventEditViewController.event = event
  clview = EKEventEditViewController.view()
  w,h = ui.get_screen_size()
  v.frame = (0,0,w,h)
  vc.addSubview_(clview)
  v.present('sheet')
  v.wait_modal()
  return   

EventEditViewController()
ihf

@cvp Script gets an error:

Traceback (most recent call last):
  File "/private/var/mobile/Containers/Shared/AppGroup/05D14C00-CCAC-4E98-A3CC-96C6944B8534/Pythonista3/Documents/test_outline_dateUI.py", line 32, in <module>
    EventEditViewController()
  File "/private/var/mobile/Containers/Shared/AppGroup/05D14C00-CCAC-4E98-A3CC-96C6944B8534/Pythonista3/Documents/test_outline_dateUI.py", line 18, in EventEditViewController
    EKEventEditViewController = ObjCClass('EKEventEditViewController').new().autorelease()
  File "/var/containers/Bundle/Application/8778D1CF-1C08-48BA-9714-9D2CFE524EA1/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/objc_util.py", line 429, in __init__
    raise ValueError('no Objective-C class named \'%s\' found' % (name,))
ValueError: no Objective-C class named 'b'EKEventEditViewController'' found
ihf

@cvp As to what text to copy: yes, multiple lines with the outline numbers and text. Obviously I can do this now in multiple steps (save as text, copy from there and paste to other app), but it would be useful to copy/paste or even share via share sheet a portion of the outline.

ihf

@cvp I seem to have just stumbled on a bug. When I touch the outline number of one of the items in order to get the pop-up menu ,instead of showing it for the line I touch, it shows it for one of the items in the middle of the outline. It shows this item no matter which one I touch. There may also be a related bug which is this particular outline item has a long line of text and the pop-up menu tries to show this entire line which pushes the right hand part of the menu off the screen

cvp

@ihf said:

Script gets an error:

Weird. I don't have any problem with this little script.
Could you check if code is identical no retry after a restart of Pythonista? Before testing any other script

cvp

@ihf said

I seem to have just stumbled on a bug. When I touch the outline number of one of the items in order to get the pop-up menu ,instead of showing it for the line I touch, it shows it for one of the items in the middle of the outline. It shows this item no matter which one I touch. There may also be a related bug which is this particular outline item has a long line of text and the pop-up menu tries to show this entire line which pushes the right hand part of the menu off the screen

Do you have this problem with new V 01.14version?

Where do you see in the popup window for which line it is?

cvp

@ihf popup window:
- at top, tapped outline
- at bottom, last copied text, stored in file outline.clipboard, able to be pasted

ihf

@cvp I tried the above script again after restarting Pythonista and I get the same error about a missing objective-C class. I presume you are running iOS 15?

ihf

@cvp I’m in landscape mode and the line I’m talking about is to the left of hide children in the pop-up menu. The interesting thing is that this line which is one line of an outline isn’t going away regardless of which item I touch even if I change outlines. It even persists if I start a new outline and touch 1.0 in the new outline.

cvp

@ihf said:

I presume you are running iOS 15

Yes. aren't you?

But this ObjectiveC class exists from ios4...
Did you try on a device where Pythonista is authorized to access calendar?

Could you try on iPad please?

Edit: same problem as you on my iPhone.

cvp

@ihf said:

I’m in landscape mode and the line I’m talking about is to the left of hide children in the pop-up menu. The interesting thing is that this line which is one line of an outline isn’t going away regardless of which item I touch even if I change outlines. It even persists if I start a new outline and touch 1.0 in the new outline

Ok, understood, you didn't say you work with horizontal popup (which has a bug). Will correct it.

cvp

@ihf V01.15 and outline.versions with

Version V01.15
  - when copy selected rows, outlines and texts are also copied in standard
    IOS PasteBoard for eventual paste in another app
  - correction of bug "left title of horizontal popup does not show the tapped 
    outline but the text of another line, even from a previous file"
ihf

@cvp I just tested the copy/paste function and got a strange result. I selected two lines that were at level one in an outline and then I created a new outline and did a paste. I got the two lines, the first at level one and the second at level 2.15.

cvp

@ihf V01.16 and outline.versions with

Version V01.16
  - correction of bug "paste lines of same level gave bad numbering results"
  - correction of bug "popup option paste crashes if no dates defined 
    in copied lines"
cvp

@JonB Perhaps could you know why

  EKEventEditViewController = ObjCClass('EKEventEditViewController').new().autorelease()

Gives this error, on some devices only (IOS 15.0.2 Pythonista v3.3 330025)

Solved: needs load_framework('EventKitUI') but why on some devices only? Perhaps different startup.

File "/var/containers/Bundle/Application/8778D1CF-1C08-48BA-9714-9D2CFE524EA1/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/objc_util.py", line 429, in __init__
    raise ValueError('no Objective-C class named \'%s\' found' % (name,))
ValueError: no Objective-C class named 'b'EKEventEditViewController'' found
cvp

@ihf did you test the paste in another app? Is that like you hoped?

ihf

@cvp yes, I also pasted discontiguous parts of an outline to another app and it looks perfect. Thanks!

cvp

@ihf at least one good news

cvp

@ihf did you test my little script of the standard iOS calendar event edit on iPad?
And, if yes, do you like this standard screen?
If it does not work on iPhone, I would need to program a part of the fields and we would need to decide which ones.

ihf

@cvp The traceback I posted above is from my iPad.

cvp

@ihf Thus the problem may occur on iPad or iPhone. I don't understand why objc_until could be different.

Solved: needs (sometimes?)

load_framework('EventKitUI')

Script edited

Thus, please, try it and tell me if you would be happy with this event editer .

cvp

I need help...
Next script works correctly, event is canceled or added but my delegate method is not called.
What is wrong? Thanks for helping me.

import ui
from objc_util import *

load_framework('EventKitUI')
EKEventEditViewController = ObjCClass('EKEventEditViewController')

def eventEditViewController_didCompleteWith_(_self, _cmd, _controller, _action):
    controller = ObjCInstance(_controller)
    action = ObjCInstance(_action)
    print(action)
    controller.dismissViewControllerAnimated_completion_(True, None)

try:
  MyEventEditViewDelegate = ObjCClass('MyEventEditViewDelegate')
except:
  MyEventEditViewDelegate = create_objc_class(
    'MyEventEditViewDelegate',
    methods=[eventEditViewController_didCompleteWith_,],
    protocols=['EKEventEditViewDelegate']
)

@on_main_thread 
def EventEdit(title=None):
  v = ui.View()
  if title:
    v.name = title
  v.rgb = None
  vc = ObjCInstance(v)
  store = ObjCClass('EKEventStore').alloc().init()
  calendar = None
  for cal in store.calendars():
    #print(cal.title())
    if str(cal.title()) == 'Outline':
      calendar = cal
      break
  EventEditViewController = EKEventEditViewController.new().autorelease()
  #print(dir(EventEditViewController))
  EventEditViewController.editViewDelegate = MyEventEditViewDelegate.alloc().init()
  EventEditViewController.eventStore = store
  event = ObjCClass('EKEvent').eventWithEventStore_(store)
  event.title = 'Todo: text line'
  event.setCalendar_(calendar)

  EventEditViewController.event = event
  clview = EventEditViewController.view()
  w,h = ui.get_screen_size()
  v.frame = (0,0,w,h)
  vc.addSubview_(clview)
  v.present('fullscreen')
  #v.wait_modal()
  return   

EventEdit()
ihf

@cvp Perhaps i have not thought this through, but would the event editor be used to set the default for events or would it be used to edit any event that has been added? If the latter, then I’m not sure what the advantage is to performing the edit within Pythonista as opposed to going to the calendar and editing it.

cvp

@ihf As you asked to be able to add some fields (2nd alarm, repeat) to a newly added due date event, I searched the easiest way which is this standard screen. But I did not wanted to allow editing, only adding.
But if you want....In French, we say "le client est roi" (I leave you translate 😀)
If you think you only need a few fields, please tell me which ones and I will program them instead of using this standard screen.

ihf

@cvp I think the English expression is “the customer is always right“, but it sounds better in French :-) The only fields that I was thinking of were repeat and alarm but I suppose that if I view the due date feature as a way to manage ToDo events generally, you might as well use the standard edit panel.

cvp

@ihf Said:

you might as well use the standard edit panel.

As you have seen in my other post, I need help to get feedback of the standard screen.

JonB

@cvp I'm not sure, but I think the method name needs to be

eventEditViewController_didCompleteWithAction_
Not
eventEditViewController_didCompleteWith_

Although objc_util let's you call using the shortcut eventEditViewController_didCompleteWith(action=obj), it dies that by trying kwarg names as the "nouns" when trying to find matching selectors that start the same. But the actual selector has the "noun" ("Action") in the selector name, and the underlying delegate mechanism is looking for the exact selector. Actually, I think you will find, since you confirmed to the protocol, that there actually is a method so named in your object, and that's the method getting called.

The apple reference docs usually default to swift, which has its own name mangling approach -- make sure you always change the drop-down to objc.

cvp

@JonB thanks to help
I changed the name as adviced and when I tap
- add, I get a segmentation fault in fault_log
- cancel, I get

cvp

@JonB EKEventEditViewController has a method editor_didCompleteWithAction_ but this did not work.

JonB

What if you create an empty method which simply returns. Do you get seg fault?

JonB

@cvp action will be an nsinteger! Hence segfault when cast as ObjCInstance

See typedef for EKEventEditViewAction.

cvp

@JonB you're right, I was just busy to directly prinT(_action) instead of getting its objcinstance

Thanks a lot as usual

cvp

@JonB I've still a problem to close/dismiss the ViewController

JonB

Possibly try calling the dismiss with on_main_thread?

Are you getting a segfault with the dismiss, it something else?

JonB

Oh I see. Can you print the full traceback?

cvp

@JonB no error but nothing happens, perhaps I have to close the ui.View

cvp

@JonB if I close thé ui.View without dismissing, it is ok

cvp

@JonB said:

make sure you always change the drop-down to objc.

I hadn't imagined it would be any different, I'll try not to forget to check every time. again a huge thank you for your skills and your availability to help

cvp

@ihf I just begin to (try to) integrate the standard event editor. I have some questions:
- when we paste copied lines, if a line had already a due date, actually the program also sets the due date of the new line with the same date, I don't think that's normal. Do you want I don't set automatically this due date, so you could always set the due date manually
- you know that we have sometimes duplicate. As now, we know that the standard eventIdentifier is not unique but depends of the device, I will change that in the future but actually, I advice that you set/unset/update a due date (thus the event) always on the same device to avoid this possible generation of duplicates. Do you agree?

ihf

@cvp I agree that copied lines should not create a new due date for the same item. Yes, I agree that setting snd unsetting due dates from the same device is ok as a temporary measure but, of course, it’s not intuitive.

cvp

@ihf Sid:

setting and unsetting due dates from the same device is ok as a temporary measure

The problem that will follow is that, if I change the way to identify an event, by an unique value cross devices, What do do with old events? Support old way and new way or only new way?

And, it is probable that I'll begin with outlines events for Apple Watch, less important if bugs.

And you will need to be patient. I'm less motivated than at the begin of the development.

ihf

@cvp I dont think you should worry about “legacy” implementations (LOL).
I hope you are still enjoying development of what has become a very useful program.

cvp

@ihf do you agree if for set/unset/update a due date event, I don't use anymore a separate datepicker nor an unset button but directly the standard event editor screen where you can
- delete the event (equivalent to unset)
- add a new or update and save an existing event

Or do you prefer I keep the datepicker, it's unset butTon and a new details buTton to get The standard event editor screen?

you are still enjoying development

New features, yes

ihf

@cvp my personal preference would be the latter, keep the current ability to set and unset but allow the addition of details through the event editor panel.

cvp

@ihf said:

my personal preference

must be the first rule...😂

cvp

@ihf sad:

I dont think you should worry about “legacy” implementations

When I'll modify the way I check an unique cross devices identifier, in a not immediate future, that will say you would no more be able to update events of old way. Or I don't understand your sentence.

cvp

@ihf V01.17 and outline.versions with

Version V01.17
  - a new 'details' button in the datepicker (set due date) view, will allow
    to add/update/delete an event via the standard event editor, so all fields
    like second alarm and repetition would be available
  - unset a due date will delete the associated event with all its future occurnces
  - when a row is pasted, if it had a due date (and event), the new row
    will not have its due date set, thus no new event will be added

Please, do some tests with
- set datepicker then tap outside
- tap unset
- tap details
- with new event: add, cancel
- with existing event: save, cancel, delete

And give me some feedback. If no problem, I'll begin to study protection via a cross devices id.

ihf

@cvp I know you’re not thrilled to hear about bugs but just now I opened an outline and double clicked on a word in the last item and the keyboard appeared (portrait mode on iPhone) and covered the line that I was editing. This may be an old problem but then I realized that the outline had three different lines at level 1.0 and two of those had child nodes at 1.1. I don’t know how the outline got this way but other than deleting and starting over I’m not sure how I would fix it either.

cvp

@ihf said:

I know you’re not thrilled to hear about bugs but just now I opened an outline and double clicked on a word in the last item and the keyboard appeared (portrait mode on iPhone) and covered the line that I was editing. This may be an old problem but then I realized that the outline had three different lines at level 1.0 and two of those had child nodes at 1.1. I don’t know how the outline got this way but other than deleting and starting over I’m not sure how I would fix it either.

Oups. Not easy for me to understand the problem, thus to solve it. Sorry

ihf

@cvp I can't send the actual outline but There a re multiple lines that say 1.0 (4 of them at different places in the outline. It may be related to using the 1st level is not part of the outline?

cvp

@ihf said:

I can't send the actual outline but There a re multiple lines that say 1.0 (4 of them at different places in the outline. It may be related to using the 1st level is not part of the outline?

I think it is normal.
The 1st level does not have outline, Thus 2nd level begins with numbers of 1st level.
Aaa
1.0
2.0
Bbb
1.0
2.0

ihf

@cvp If I turn on "1st level has outline" it turns itself back off after I leave the menu.

cvp

@ihf see my previous edited post

ihf

@cvp Yes, that makes sense, but I can't turn it back on...what am I forgetting?

cvp

@ihf said:

if I turn on "1st level has outline" it turns itself back off after I leave the menu.

Remember that when you change the switch on <-> off, you have to reselect thé format

ihf

@cvp Yes, I did that but it still goes back to off.

cvp

@ihf I don't have this problem, sure that you do that in one display

cvp

@ihf said:

if I turn on "1st level has outline" it turns itself back off after I leave the menu.

You are righT, this is a bug but only on iPhone, try on your iPad to confirm

Only I can do today is to add it on my todo list...

ihf

@cvp OK, I webt to the iPad and it does indeed work there and "fixes" the outline. However, I came up with a different problem there. I was running v.13 and the script asks to update to v1.17. It then say V1.17 has been installed and I then close nd restrat the program but it does the same thing again. I can manually download v1.17 but I wonder why it is suddenly having this problem (or did I forget something?)

cvp

@ihf said:

However, I came up with a different problem there. I was running v.13 and the script asks to update to v1.17. It then say V1.17 has been installed and I then close nd restrat the program but it does the same thing again. I can manually download v1.17 but I wonder why it is suddenly having this problem (or did I forget something?)

No idea comes to me, but now in my list. Late for me, thus .... later (not sure at all it could be tomorrow)

ihf

@cvp I downloaded manually and I'm back on v.1.17. I will test the date picker functionality now.

cvp

@ihf said:

However, I came up with a different problem there. I was running v.13 and the script asks to update to v1.17. It then say V1.17 has been installed and I then close nd restrat the program but it does the same thing again. I can manually download v1.17 but I wonder why it is suddenly having this problem (or did I forget something?)

I got the same problem on my iPhone and I retry and it was ok without manual install.
Not an explanation but if it happens again, retry to answer yes.

cvp

@ihf said:

However, I came up with a different problem there. I was running v.13 and the script asks to update to v1.17. It then say V1.17 has been installed and I then close nd restrat the program but it does the same thing again

Is it possible that outline.py was edited in Pythonista when you ran it?

cvp

@ihf V01.18 and outline.versions with

Version V01.18
    - correction of bug "on iPhone, modification of switch '1st level has outline'
      in menu of outLine formats does not work"

When I see that you find 3 bugs in a few minutes
- this corrected one (at least hoped)
- automatic updates download not working (not yet identified)
- keyboard hiding last line on vertical iPhone (not yet identified)
I understand why apps have so frequent updates 😂 but I hate debugging

cvp

@ihf V01.19 and outline.versions with

Version V01.19
  - correction of bug "only on iPhone in portrait mode, editing the last line
    of a file bigger than a screen, the keyboard appears but hides this line"
smh

@cvp + @ihf What a great project! Trying to get V01.19 working on M1 MacBook Air, and below is the traceback, any ideas? Also, does using emoji break bullets/cause weird line break issues for other users? Keep up the great work!

"
Traceback (most recent call last):

File "/Users//Library/Group Containers/group.pythonista/Pythonista3/Documents/outline.py", line 97, in load_ framework('EventKitUI')

File "/var/folders/tx/f122pq090xx2zc5ww_gtz0380000gn/X/3DCFE7F7-3144-5458-A0BE-545898853219/d/Wrapper/Pythonista3.app/Frameworks/Py3kit.framework/pylib/site-
packages/objc_util.py", line 934, in load_framework

return NSBundle.bundleWithPath_('/System/Library/Frameworks/%s.framework' % (name,)).load()
AttributeError: 'NoneType' object has no attribute 'load'

"

cvp

@smh said:

load_framework('EventKitUI')

I don't know why this line could give a problem on a Mac, sorry

You could try without this line, sometImes the framework is loaded by default

cvp

@smh said:

does using emoji break bullets/cause weird line break issues for other users?

I don'T understand, sorry

ihf

@cvp if I open one of my outlines that has about 14 lines in it and I position the cursor to the end of the first line the keyboard comes up but the outline is pushed up such that the insertion point is no longer visible. This is on an iPhone in portrait mode.

cvp

@ihf just tested and I see. What is weird is that if you scroll and retry to put your cursor at first line, the problem does not occur anymore. Annoying, I hate this kind of bugs

ihf

@cvp there is a problem when I type a long line (at least on the iPhone in portrait mode). When I get to the right side of the screen, the line is continued on the next line but the insertion point goes away (although the keyboard is still visible). In other words, I can’t type a line that has the automatic returns in it unless I position the insertion point after the word that has been moved to the next line.

cvp

@ihf said:

if I open one of my outlines that has about 14 lines in it and I position the cursor to the end of the first line the keyboard comes up but the outline is pushed up such that the insertion point is no longer visible. This is on an iPhone in portrait mode.

That happens only the first time when the keyboard is not yet appeared and my program does not know its height and the foreseen process to automatically scroll up to show a line under the keyboard is executed when it should not. Annoying, I'll check if I can correct it quickly.

cvp

@ihf V01.20 and outline.versions with

Version V01.20
  - correction of bug "before the keyboard has appeared a first time,
    the first edited outline is automatically scrolled up erroneously"

For your information, I get the keyboard height in keyboard_frame_did_change but this function is only called when the keyboard appears. I need to know this height because if you edit a row that would be hidden by the appearing keyboard, the row needs to be automatically scrolled up above the keyboard. But if you edit a row before the keyboard has appeared the first time, this height is not yet known. Thus I force the keyboard to appear and immediately be dismissed without we see it by creating, edit, end, delete a TextField during the general ui.View initialization. Magic, isn't it ?

ihf

@cvp Thanks for the quick fix to the scrolling problem. The lost insertion point on long lines that i mentioned above also occurs on the iPad in landscape mode.

cvp

@ihf said

there is a problem when I type a long line (at least on the iPhone in portrait mode). When I get to the right side of the screen, the line is continued on the next line but the insertion point goes away

I've seen that, and also on iPad as you said.

And you added

although the keyboard is still visible

Sure of that? For me, keyboard disappears

ihf

@cvp I just tested it again on the iPhone and confirmed that the keyboard remains visible although the insertion point disappears.

ihf

@cvp Probably an old Pythonista problem, but I just started a new outline entered three lines and then hit enter and Pythonista crashed.

cvp

@ihf said

Probably an old Pythonista problem, but I just started a new outline entered three lines and then hit enter and Pythonista crashed.

Unfortunately, this does not seem to be in my hands

But, anyway, try to check the reason in objc_exception.txt or faultlog folder

cvp

@ihf V01.21 and outline.versions with

Version V01.21
  - correction of bug "when typing a long line automatically splits the line,
    the keyboard sometimes disappears and cursor is no more visible"

As I can't reproduce your problem (in my case, keyboard disappears), perhaps this correction does not solve your bug (but only mine). Please, give me some feedback

ihf

@cvp I tested v1.21 on the iPad and the keyboard remained visible (although it seemed to go away and come right back). So that seems to be fixed (I will test on the iPhone). However, I had a different (new?) problem. I added an item and then tried to move it by holding and dragging it. It looked like it was working, but when I released it, I got an error. Here is the traceback:

Traceback (most recent call last):
  File "/private/var/mobile/Containers/Shared/AppGroup/05D14C00-CCAC-4E98-A3CC-96C6944B8534/Pythonista3/Documents/outline.py", line 3199, in tableview_cell_for_row
    v = MyInputAccessoryView(row)
  File "/private/var/mobile/Containers/Shared/AppGroup/05D14C00-CCAC-4E98-A3CC-96C6944B8534/Pythonista3/Documents/outline.py", line 476, in __init__
    self.width = mv.get_screen_size()[0]            # width of keyboard = screen
  File "/private/var/mobile/Containers/Shared/AppGroup/05D14C00-CCAC-4E98-A3CC-96C6944B8534/Pythonista3/Documents/outline.py", line 1132, in get_screen_size
    app = UIApplication.sharedApplication().keyWindow()
  File "/var/containers/Bundle/Application/8778D1CF-1C08-48BA-9714-9D2CFE524EA1/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/objc_util.py", line 801, in __call__
    ordered_args = list(args) + [kwargs[key] for key in kwarg_order]
TypeError: 'builtin_function_or_method' object is not iterable
cvp

@ihf said

Traceback (most recent call last):
File "/private/var/mobile/Containers/Shared/AppGroup/05D14C00-CCAC-4E98-A3CC-96C6944B8534/Pythonista3/Documents/outline.py", line 3199, in tableview_cell_for_row
v = MyInputAccessoryView(row)
File "/private/var/mobile/Containers/Shared/AppGroup/05D14C00-CCAC-4E98-A3CC-96C6944B8534/Pythonista3/Documents/outline.py", line 476, in init
self.width = mv.get_screen_size()[0] # width of keyboard = screen
File "/private/var/mobile/Containers/Shared/AppGroup/05D14C00-CCAC-4E98-A3CC-96C6944B8534/Pythonista3/Documents/outline.py", line 1132, in get_screen_size
app = UIApplication.sharedApplication().keyWindow()
File "/var/containers/Bundle/Application/8778D1CF-1C08-48BA-9714-9D2CFE524EA1/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/objc_util.py", line 801, in call
ordered_args = list(args) + [kwargs[key] for key in kwarg_order]
TypeError: 'builtin_function_or_method' object is not iterable

I already got that, not reproductible. Not in my code. I personally think that Pythonista has a lot of problems with iOS/ObjectiveC next versions. Sorry for you, but one more time, I think it is not in my hands.

ihf

@cvp I am not sure what to make of this but I am testing on an iPad and the auto update does not seem to work properly. When I start the script it tells me there is a new version and asks whether I want to update. I say yes and it comes back and says the update was done and to restart the program and I restart it as I do on my other devices. However the update does not seem to take and it goes through the same cycle again. This happened with the previous release and I thought that I would just do a manual update to 1.20 but it is now happening again with 1.21. It’s obviously not a big deal as I can always do the manual update but I thought I would mention it.

cvp

@ihf said

I am not sure what to make of this but I am testing on an iPad and the auto update does not seem to work properly. When I start the script it tells me there is a new version and asks whether I want to update. I say yes and it comes back and says the update was done and to restart the program and I restart it as I do on my other devices. However the update does not seem to take and it goes through the same cycle again. This happened with the previous release and I thought that I would just do a manual update to 1.20 but it is now happening again with 1.21. It’s obviously not a big deal as I can always do the manual update but I thought I would mention it.

Is your outline.py local or on iCloud, I got tHe same problem, only once, but my script is on iCloud and download from GitHub to iCloud was done but perhaps not yet to your local device.

If your script is in your local Pythonista, was it edited in a Pythonista tab or run from a shortcut?
When you restart, do you remove Pythonista from memory first? If no, not sure Pythonista does not have a cache.

It is always better to remove it from memory because if the script changes in some created ObjectiveC classes, they are not replaced without restarting Pythonista it-self.

Are you waiting some time before to restart?

ihf

@cvp I have 2 iPads and on the old iPad Pro, the auto update always works. (I run Outline.py that is in a tab, it asks if I want to download, I say yes, and I get a message saying the download completed and I restart the program. After I restart I am running the new version (I don't even have to quit Pythonista, just the script). On the newer iPad, I do the same exact thing except that when I restart the program it has not been updated. Weird.

cvp

@ihf The only difference I could see between your two devices is their speed, if you are running really on the two devices an edited script. I thought you used a shortcut to start the Pythonista script via its url scheme, and in this case you may run a not edited script.
You did not answer if the script is stored in iCloud or in a local folder. If it is in iCloud, the first device which will download the new version from GitHub to an iCloud folder would have done the job for the second device.
Anyway, I would prefer that you don't restart the script without restarting Pythonista it-self becuse, as explained in my previous post, if the new version changes code of a created ObjectiveC class, you need to restart Pythonista to use the updated code.

ihf

@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.

cvp

@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.

ihf

@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.

cvp

@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

JonB

@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.

JonB

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

cvp

@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.

cvp

@JonB said

Also, someone had a cool idea to do this'

Wow. I write too much code, I completely forgot that. thanks

JonB

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.

JonB

... 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.

cvp

@JonB I like the first idea (that is also the reason why I asked @ihf if he was running the script via url scheme "action=run" becuse this does not edit The script.)

I am not sure I could close all views, objc classes etc...
The dream is to entirely restart Pythonista.

JonB

You can always force a crash if you want to restart pythonista.

cvp

@JonB os.abort?

JonB

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.

cvp

@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...

cvp

@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

ihf

@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.

cvp

@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)

cvp

@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.

ihf

@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.

cvp

@ihf said

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

Perhaps did you force quit Pythonista after end of the script, which saves the script on file, even if not changed, it seems.

ihf

@cvp what is puzzling, but probably not worth pursuing, is why I get different behavior on the two iPads even though I’m doing exactly the same thing. In any case, it works now.

cvp

@ihf Life (and my programs 😂) always have a bit of a mystery

cvp

@ihf do you want a version that, just before the Pythonista abort, creates a local notification which should appear some seconds later. Tapping on this notification will automatically restart outline.py

Bambla

Do some of you use outliner on iPhone?

On my iPhone 12 mini the application crashes when I create new entries continuously. Sooner or later an error appears (see Screenshot).

On my ipad 2020 the Problem does not occur. I use version 1.22.

cvp

@Bambla Unfortunately, not reproducible. Please, restart Pythonista itself and retry, sorry for you.

ihf

@Bambla I use outline on my iPhone and iPad all the time. I haven’t seen that problem .

JonB

@cvp I haven't tested it, but it looks like
https://github.com/andy-landy/traceback_with_variables
Should work with pythonista.

This might provide some more useful tracebacks -- that traceback implies that kwargs got stomped on somehow. It could be useful to know what it was stomped with.

Bambla

Thanks for the feedback. As soon as I find out more I will post it here.

cvp

@Bambla when such a problem occurs, you could check outLine.trace file, perhaps that could help to identify the problem, but not sure at all

cvp

@JonB said

traceback-with-variables

Be sure that I'm not a Python specialist and thaT I don't understand anything about this traceback, but, promised, I'll try it. Thanks to continue to try to help.

ihf

@cvp I was deleting a line from an outline (it may have had one child note) and got this:

Traceback (most recent call last):
  File "/private/var/mobile/Containers/Shared/AppGroup/6CCAAFF1-947E-4DC8-B33B-58EE87A0823C/Pythonista3/Documents/outline.py", line 575, in tableView_heightForRowAtIndexPath_
    return tv_py.delegate.tableview_height_for_section_row(tv_py,section,row)
  File "/private/var/mobile/Containers/Shared/AppGroup/6CCAAFF1-947E-4DC8-B33B-58EE87A0823C/Pythonista3/Documents/outline.py", line 1250, in tableview_height_for_section_row
    vals,n,opts = tv.data_source.items[row]['content']
IndexError: list index out of range
Traceback (most recent call last):
  File "/private/var/mobile/Containers/Shared/AppGroup/6CCAAFF1-947E-4DC8-B33B-58EE87A0823C/Pythonista3/Documents/outline.py", line 575, in tableView_heightForRowAtIndexPath_
    return tv_py.delegate.tableview_height_for_section_row(tv_py,section,row)
  File "/private/var/mobile/Containers/Shared/AppGroup/6CCAAFF1-947E-4DC8-B33B-58EE87A0823C/Pythonista3/Documents/outline.py", line 1250, in tableview_height_for_section_row
    vals,n,opts = tv.data_source.items[row]['content']
IndexError: list index out of range
Traceback (most recent call last):
  File "/private/var/mobile/Containers/Shared/AppGroup/6CCAAFF1-947E-4DC8-B33B-58EE87A0823C/Pythonista3/Documents/outline.py", line 2928, in tableview_cell_for_row
    hrow = self.tableview_height_for_section_row(tableview,section,row)
  File "/private/var/mobile/Containers/Shared/AppGroup/6CCAAFF1-947E-4DC8-B33B-58EE87A0823C/Pythonista3/Documents/outline.py", line 1250, in tableview_height_for_section_row
    vals,n,opts = tv.data_source.items[row]['content']
IndexError: list index out of range
cvp

@ihf I am completely demotivated by this kind of not reproducible error. i understand that @omz does not want to continue his support 😀

Delete how? Via "delete with children" in popup menu or via "delete" in menu after having selected lines.

ccc

Software development is just plain hard!!!

  File "/private/var/mobile/Containers/Shared/AppGroup/6CCAAFF1-947E-4DC8-B33B-58EE87A0823C/Pythonista3/Documents/outline.py", line 1250, in tableview_height_for_section_row
    vals,n,opts = tv.data_source.items[row]['content']
IndexError: list index out of range

Here is what I would do... Go to line 1250 and see if you can make this change.

vals,n,opts = tv.data_source.items[row]['content']

# -->

try:
    vals,n,opts = tv.data_source.items[row]['content']
except IndexError:
    print(f"{row = } but {len(tv.data_source.items) = }")
    raise

This should show you that row is off the end of the data source.

Then look for all the places where tableView_heightForRowAtIndexPath_() is called and wrap them also:

try:
    tableView_heightForRowAtIndexPath_(x, y, z, path)
except IndexError:
    print(f"{path = }")
    raise

Keep the code between the try and except as few lines as possible.

Avoid like the plague that it is try: something except: pass.
* https://realpython.com/the-most-diabolical-python-antipattern

cvp

@ccc said

Software development is just plain hard!!!

Believe me, I know it, I personally have developed in a lot of programming languages during 40 years before I meet Python(ista).
I'll try your code, but I'm no more motivated because sometimes error come from ObjectiveC usage and I don't have access to what it does.

Édit: That's what I said, this tableView_heightForRowAtIndexPath_() is never called by my code but by ObjectiveC code (I use @JonB 's swizzle for That).

Thus the error is not so obvious. Personally, I think that the error comes from the ObjectiveC calls.

ihf

@cvp It was delete with children via the pop-up menu. I am also seeing some problems with cursor being hidden but I will try to find a minimal failing case.

cvp

@ihf said

It was delete with children via the pop-up menu

And of course not reproducible ?

ihf

@cvp not sure, but certainly not something I've seen before.

cvp

@ihf sincerely, I only want to 😭

ihf

@cvp Just know that these bugs do not prevent me from making productive use of the program.

cvp

@ccc said

tv.data_source.items[row]['content']

This TextView is the base of all my code and is used a lot of times in the code. I don't see how it could be corrupted, except by automatic calls in objectiveC hidden part of ui.TextView.

cvp

@ihf said

Just know that these bugs do not prevent me from making productive use of the program.

you are too nice but these bugs annoy me because they probably make you lose data and force you to start processes again

For my curiosity, do you use the mac_outline_viewer.py displaying the outline in a safari tab?

ihf

@cvp I run it in iTerm but I suppose if I put it on my webserver I could run it in a browser tab but it would need to be modified to put out html. Not so?

ihf

@cvp also the viewer does not show whether items are checked (completed) or dates which limits its utility.

ihf

@cvp I just realized that I am running v.01 not v.02 which has html. But if I go to Github, I don't see v.02?

cvp

@ihf did

if I go to Github, I don't see v.02

Weird, Github version is V00.02

ihf

@cvp I'm using the link in your post above: https://github.com/cvpe/Pythonista-scripts/blob/7a0ea85d3f0b7c0def0eb4472aac2ac099730bc3/Gists/mac_outline_viewer.py and this takes me to v.01

cvp

@ihf you are righT and I don't understand why it links to an old version, but I have to say I don't know a lot about GitHub, sorry

Please, use https://github.com/cvpe/Pythonista-scripts/blob/master/Gists/mac_outline_viewer.py

ihf

@cvp Yes, I can run that in iTerm (or using the Python Launcher) and I get the outline in a browser tab.

cvp

@ihf Version V00.03 with

Versions
  V0.03
    - show if item is unchecked, checked, completed or without checkbox

JonB

This is where that better traceback library might shine -- we'd be able to see what row was trying to be accessed, how many rows were in the list in question, etc.

When you delete a row, are you calling the tableview functions that tell the view that a row was deleted? Perhaps your datasource is getting updated before letting iOS know about it, such that it may have a query queued up for a scroll that is happening before you have let it know.

Another thing that could be helpful would be a decorator that you can decorate all functions with, that try/catch and reraise, after printing out what the current thread is. Things that operate on datasource have to be on the main thread.

cvp

@JonB said

This is where that better traceback library might shine -- we'd be able to see what row was trying to be accessed, how many rows were in the list in question, etc.

I did not forget this traceback but not yet tested.

When you delete a row, are you calling the tableview functions that tell the view that a row was deleted? Perhaps your datasource is getting updated before letting iOS know about it, such that it may have a query queued up for a scroll that is happening before you have let it know.

Good question, I have to check

Édit: I build the new data_source.items without the deleted one(s) and I call reload_data, that's all.
I sincerely have always thought it was the right way.

Edit2: in another case of deletion, I del self.tv.data_source.items[row] and reload_data.

Another thing that could be helpful would be a decorator that you can decorate all functions with, that try/catch and reraise, after printing out what the current thread is. Things that operate on datasource have to be on the main thread.

All that becomes too heavy for my poor knowledge.

And as usual, thanks to spend time for us.

ihf

@cvp If I execute the mac_outline_viewer in iTerm with python mac_outline_viewer.py, it works as expected and the file selector opens to my idrive outlines folder. But if I make the .py file executable and simply give its name in iTerm, it runs but the outline selector opens in the local Documents directory.

cvp

@ihf sorry, I can't help you, I don't know anything in terminal/command mode of Mac OS.
But remember that you can pass a path as program argument
I'm sure that you will get help in this forum.

ccc

If python3 mac_outline_viewer.py works on the macOS command-line then chmod +x mac_outline_viewer.py ; ./mac_outline_viewer.py should work exactly the same way. NOTE: The leading dot-slash (./) are REQUIRED.

cvp

@ccc having also worked on UNIX, I should have remembered that ... thank you for us

novika

Nice : www.scifringe.com

cvp

Test to check if topic becomes normal instead of grayed

ihf

@cvp I don't see this topic in the list of topics but I seem to be able to get to it using a stored url. However I am also getting popups that say "You do not have enough privileges for this action".

cvp

@ihf said

the viewer does not show whether items are checked (completed) or dates which limits its utility.

  • checked: done
  • dates: how do you want the program shows them in the web page?
cvp

@JonB said:

When you delete a row, are you calling the tableview functions that tell the view that a row was deleted? Perhaps your datasource is getting updated before letting iOS know about it, such that it may have a query queued up for a scroll that is happening before you have let it know.

In one case, I build the new data_source.items without the deleted one(s) and I call reload_data
in another case of deletion, I del self.tv.data_source.items[row] and reload_data.

Please, could you advice how to do it in a better way? Thanks

ihf

@cvp There are 4 dates that are stored (created, updated, due, ended) and all are useful. Perhaps some way of specifying which one(s) are desired? Your question got me playing with the date and sorting items. It could be that this is working as it should but I don’t understand this result: https://i.imgur.com/FUTsj7F

cvp

@ihf what don't you understand? Sorry but development is already far away ...

cvp

@ihf thé date is blank if not yet set, and the button at right of the title allows you to sort the items in ascending/descending/no order

ihf

@cvp I expected that the dates would be sorted. For example why is item 3.2 after 3.1?

cvp

@ihf did you tap the sort button 🔽?

ihf

@cvp I was certain I had but I went back to do it again just to be sure before I answered your question. Instead of confirming, I got the following error:
Traceback (most recent call last): File "/private/var/mobile/Containers/Shared/AppGroup/05D14C00-CCAC-4E98-A3CC-96C6944B8534/Pythonista3/Documents/outline.py", line 1146, in layout ws,hs = self.get_screen_size() File "/private/var/mobile/Containers/Shared/AppGroup/05D14C00-CCAC-4E98-A3CC-96C6944B8534/Pythonista3/Documents/outline.py", line 1137, in get_screen_size app = UIApplication.sharedApplication().keyWindow() File "/var/containers/Bundle/Application/8778D1CF-1C08-48BA-9714-9D2CFE524EA1/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/objc_util.py", line 801, in __call__ ordered_args = list(args) + [kwargs[key] for key in kwarg_order] TypeError: 'builtin_function_or_method' object is not iterable

I don’t think this has anything to do with the sorting question, since it appears even after I force quit Pythonista and start again.

ihf

@cvp I got it to run again and , yes the display I posted is after hitting the sort button

cvp

@ihf One of the usual Pythonista crashes for which, I think, my script is not responsible. I'm sorry for you and I would understand that you stop to use this program. It uses almost all internal functionalites of Pythonista, is big, uses a lot of memory, and crashes too much in not reproducible ways.

ihf

@cvp I can live with occasional crashes. (Just wish that @omz would reappear or let someone have the source to Pythonista). In any case, does the sort order look right to you?

cvp

@ihf did

yes the display I posted is after hitting the sort button

I don't think so, the sort button changes from 🔽 to 🔼 after you to it.

ihf

@cvp yes, it cycles thru up, down, and numeric.

cvp

@ihf yes, but the image you posted shows the button as 🔽, that will say the next tap will give a descending sort, actual is no sort

ihf

@cvp OK, so the button that shows is not the way it is sorted, but how it would be sorted if you hit the button? Not what I would have expected. However this has just surfaced a different bug. I went back and hit Expand All and the top line of icons is (mostly) gone.

ihf

@cvp but the sort does work (once I realize that the button is showing what will be not what is).

ihf

@cvp it happened a few times, but now I can't reproduce it reliably so I guess it is not worth spending time on.

cvp

@ihf said

the sort does work (once I realize that the button is showing what will be not what is).

Do you prefer that it should show what the sort is?

ihf

@cvp Yes, I would prefer that but now that I know what it is, I could live with it.

cvp

@ihf V01.23 and outline.versions with

Version V01.23
  - icon of dates sort button now shows the actual sort order, not the order if
    button would be tapped
ihf

@cvp If my outline is collapsed and I select view by completion date, and then select sort button to change to sort down, the display gets messed up in that lines are overlapping.

cvp

@ihf

cvp

@ihf said

If my outline is collapsed and I select view by completion date, and then select sort button to change to sort down, the display gets messed up in that lines are overlapping.

It seems that lines after sort keep height of initial order, I don't understand why because I recompute their height in tableview_cell_for_row delegate

Édit: but I guess that ObjectiveC code of TableView also calls it again. Very annoying.

ihf

@cvp I am glad to see that you are maintaining a sense of humor. (or at least I hope you are).

cvp

@ihf said

or at least I hope you are

I also hope it is humor, not instinct

Obviously, I should have to advice: don't collapse, don't sort, don't.....

cvp

@ihf Version mac_outline_viewer.py V00.04 with

  V0.04
    - use a dropdown selector to choose which dates to show

Thanks to you, I have had to use my poor JavaScript and HTML5
Feed-back hoped

JonB

@cvp I wonder if updates are not being made on the main thread...
https://stackoverflow.com/questions/2318445/uitableview-crashes-if-data-source-is-updated-during-scrolling

You can try beginUpdates() before updating your data (adding or deleting rows) then end updates() after reloading on the tableview ObjCInstance)

cvp

@JonB thanks for your continuous help. I remember that I already did something like that, without success.
I would try to incorporate this advice but it not so easy, and obviously no way to correctly test it because the problem is not reproducible on demand.

Don't forget that the way I update the TableView is only by modifying directly the items, wiThouT calling delete or add functions. There are a lot of script lines where I update items because there are a lot of ways to do it. And often, the call reload_data is not in the same function. Very annoying to update in your adviced way.

I have tried this beginUpdates before deleting item(s) and enUpdates() after reload_dara, and I get this ObjectiveC error (I remember now I already got it and stopped to use this code)

Invalid update: invalid number of rows in section 0. 
The number of rows contained in an existing section after the update (56)
 must be equal to the number of rows contained in that section before the update (60), 
plus or minus the number of rows inserted or deleted from that section (0 inserted, 
0 deleted)
 and plus or minus the number of rows moved into or out of that section (0 moved in, 
0 moved out). Table view: <SUITableView_PY3: 0x14233d000; baseClass = UITableView; 
frame =(0 74; 818 1106); 
clipsToBounds = YES; gestureRecognizers = <NSArray: 0x286c94480>; layer = <CALayer: 0x283c27a00>; contentOffset: {0, 373.5}; contentSize: {818, 2492};
 adjustedContentInset: {0, 0, 20, 0}; dataSource: <SUITableView_PY3: 0x14233d000; 
baseClass = UITableView; frame = (0 74; 818 1106); clipsToBounds = YES;
 gestureRecognizers = <NSArray: 0x286c94480>; layer = <CALayer: 0x283c27a00>; 
contentOffset: {0, 373.5}; contentSize: {818, 2492}; adjustedContentInset: {0, 0, 20, 0};
 dataSource: <SUITableView_PY3: 0x14233d000>>>

Perhaps due that to delete a row and its children, I rebuild the data_source.items before reload the TableView, without using any call to an eventUal delete function. And, that works always for me, I never have this crash posted by @ihf.

I think next time I write such a program (if ever) I will use a basic scroll view and draw all the necessary objects myself ...

cvp

@ihf V01.24 and outline.versions with

Version V01.24
    - correction of bug "sometimes after view dates, back and hit Expand All
    and the top line of icons is (mostly) gone"
cvp

@ihf not sure you had seen the post where there was a new version of Mac script, before new version of outline.py

ihf

@cvp I was just now testing it. I changed the line that had your path in it to: default_path = os.path.expanduser('~/Desktop/Pythonista/Backup/Outline')
I couldn't get it to work at first. Not sure what the problem was but I ended up with Firefox being frozen and I restarted it and now the script seems to work fine.In my case, it opens Safari but then the outline html file is opened (by default) in Firefox. It never actually uses Safari. Now are you ready for potential enhancements? The ultimate "enhancement" would be a complete rewrite so that the full outline runs as a webapp (no Pythonista)...LOL. A bit simpler, add sort on date to the html page.

cvp

@ihf said

The ultimate "enhancement" would be a complete rewrite so that the full outline runs as a webapp (no Pythonista)

Did you become crazy? 😂

cvp

@ihf on Mac OS, I do

os.system("open /Applications/Safari.app file:///"+os.getcwd()+"/"+fname)   

Then, I don't see how you could open Firefox.

On iOS, I do

        webbrowser.open('safari-http://localhost:' + port)
cvp

@ihf said

A bit simpler, add sort on date to the html page.

Simpler, you say that...

ihf

@cvp The script opens Safari but then when it actually opens the .html file my config must be defaulting to opening a tab in Firefox. Yes, rewriting to run in the web was not meant to be a serious proposal although it would have many virtues and to my knowledge does not exist. I will continue to enjoy your creation with the hope that Pythonista keeps running without support from @omz.

cvp

@ihf said

Now are you ready for potential enhancements?

I never forget the bugs or @JonB 's advices, all is written at top of my source code, but I'm no more motivated a lot to spend time for that. But, for new (realistic) functionalities, always.

ihf

@cvp je comprends que

cvp

@ihf For instance, I've spent some hours today to try to solve the problem of "the display gets messed up in that lines are overlapping." when sorting dates. But without success.

cvp

@ihf Version mac_outline_viewer.py V00.05 with

  V0.05
    - support sort on dates

Even if I 'm sincerely not proud of my quick and dirty script/html/JavaScript and maybe it could be very slow with long outlines, I don't know.

Feed-back hoped

ihf

@cvp It works great!

cvp

@ihf As you know, a TableView does not remember all TableViewCells but rebuilds them when they are visible. If scrolling makes them disappear, their memory is freed and if they reappear, they are built and displayed. It is therefore a saving of memory but a waste of time if the scrolling causes cells to appear and disappear often. But it seems that most of our problems would come from the possible desynchronization between the management of the table of items and their display.
I more and more want to try to replace the TableView with a simple ScrollView where I would manage the position of the rows myself. The cells would be subviews of the scrollview and would only be rebuilt if their content changes.
this solution, for which I cannot yet estimate the development time, would only be valid if your outlines did not contain too many lines (but how many = too many?). Could you tell me approximately how many lines are in your outlines?
And, would you agree to test a different version?

ihf

@cvp To answer your last question first, of course, I would be happy to test any future version. As far as how large my outlines are, Were you referring to how many lines in the outline or in a particular item?

cvp

@ihf said

how many lines in the outline

Yes

JonB

@cvp Another option is that you can store TableViewCells rather than returning new ones. That way the objc references never change .

Rather than starting cell_for_row with
cell=ui.TableViewCell()
like normal, you could manage your cells on your own, and build them all in advance, and then in cell_for_row, you simply return the pre-built value:

cell=self.cells[section][row]

Since you probably won't have outlines with thousands of rows, that's probably safe memory-wise.

I also wonder if it wouldn't be possible to use one of the omz text view classes (say extending the markdown formatter. ). That would require a lot of swizzling, or at least making implementing subclasses of objc classes that we don't have good documentation on (and just have to rely on swizzlelog to figure out the interfaces) ... so probably is not heading in the right direction...

cvp

@JonB that would not solve the problem we had for which you adviced to use begin /end update.
The internal code will still decide to call cell_for_row and perhaps still be désynchronised.

and yet, I followed the omz doc, namely modify my items and call reload for any modification or deletion

Édit: for info, I already stored cell in my own array self.cells, for usage when I'm sure that the row is still on screen, when the TextView in the row is edited

ihf

@cvp My Outline lengths are (up to now) <100 items. I can imagine them being somewhat longer but certainly <<1000.

cvp

@ihf ok. Thus I'll try to replace the base TableView of rows by a ScrollView. I know that it is not an easy job and that it should take a long time but so, if it works, it should avoid some bugs where invisible code is performed without I can manage it. So, Vital bugs excepted, you would not get new versions during some time...

ihf

@cvp I was thinking about whether there was a way to make your mac_outline_viewer work as a cgi-bin so that I could use the web to access outlines (for viewing). The problem I see (so far) is that the selection of the outline file requires access to the iCloud drive and I don't see an easy way to do that from a linux system that runs the webserver. Do you think the storage location of the outline files could (optionally) be another location that linux could access? Or perhaps you can think of another way to achieve access from the web?

cvp

@ihf I don't know anything about cgi-bin. Where would be your web server? On a Linux machine, no more on your Mac? Where do you want to store your outline files? No more on iCloud Drive? On a NAS?

Edit: perhaps could a web app read an iCloud calendar, like my Apple Watch shortcut does, get the file and display it...(shared public iCloud Calendar gets an url like webcal://...)

Edit2: perhaps could the outline.py script save a copy of the outline file on your web server, like it also does in the 2022 event.

PS For info, I'm still busy to convert my script for a ScrollView, I must admit that I am slow, for lack of desire/motivation, but I'll do it.

cvp

@ihf Said

Do you think the storage location of the outline files could (optionally) be another location that linux could access?

Could you store this little html file on your Linux web server and tell me on which machine you test it.
Is your iCloud configured on this machine (iDevice, Mac, PC)? It should have to be...

    <html>
        <head>
            <script>
            var openFile = function(event) {
                var input = event.target;
                var reader = new FileReader();
                reader.onload = function(){
                    var text = reader.result;
                    var node = document.getElementById('output');
                    node.innerText = text;
                    console.log(reader.result.substring(0, 200));
                };
            reader.readAsText(input.files[0]);
        };
        </script>
    </head>
        <body>
            <input type='file' accept='.outline' onchange='openFile(event)'><br>
            <div id='output'>
                ...
            </div>
        </body>
    </html> 

For instance, on my iPad, I get this file selector, and the third line gives access to iCloud Drive

I copy this html on a Web server that I use sometimes, and I open this html in Safari on my iPad.

ihf

@cvp Sorry, didn't see your post until now. I just tried it on my server (which has no access to iCloud). When I run it on my iMac wwhich has access, I get a browse button in the browser and I can access iCloud files, including the Outlines. The outline is displayed unformatted.

cvp

@ihf said

Sorry, didn't see your post until now. I just tried it on my server (which has no access to iCloud). When I run it on my iMac wwhich has access, I get a browse button in the browser and I can access iCloud files, including the Outlines. The outline is displayed unformatted.

Display unformatted is normal with this very little html, this is only a test to check if it works.
I could write (at least, I think I could) a more complex html containing a JavaScript code which would display the outline like my mac_outline_viewer.py does, but It will never access iCloud Drive files if ICloud is not accessible on the machine where you use it. Thus, what do you hope?

ihf

@cvp I think in this case the “machine” is any iDevice that has access to my iCloud files. The web server need not have access since it is the browser that is fetching the file. I just tested from my iPhone and iPad and it worked fine.

cvp

@ihf yes, you gave a good summary.
If the html and its included JavaScript code allow you to select the file, select the date and its sort type, and display the outline like the mac_outline_viewer.py script, is that what you want/hope?

But, that should not be part of the Pythonista forum, nor even a Python forum 😀
And given my level in JavaScript, it will take some time.

ihf

@cvp yes, I suppose it is, strictly speaking, off topic, but it is related. And yes, I was looking to have the outlines more accessible (having them on the Watch is great). Of course, this still requires that the browser be running where iCloud is accessible but that’s ok.

cvp

@ihf New outline_viewer.html

Please, copy it into your web server and give me some feedback.
Don't worry too much, this is just a first draft. And probably, given the level of my knowledge in html, css and JavaScript, a real "quick and dirty", as usual. Please, have also a look into the code it-self, not so long as I thought before, thus no so complex.

ihf

@cvp I tested outline_viewer.html and the first outline I tried gave this interesting result: https://imgur.com/a/TOPpJur (I am only showing the left hand side).

cvp

@ihf is it possible that you asked a sort before? I think that the bug comes from the fact that sort = none does not change the sequence, but not sure. I'll check,
But, if no bug, are you happy with the html?

Edit: not yet solved but identified: bug comes from my poor knowledge of JavaScript, I used array.sort() to sort an array, hoping it was generating another array but, in reality, it replaces the original array... sorry for that.

Édit: new V00.01 of outline_viewer.html should correct this problem

ihf

@cvp This seems to be working better but I just opened an outline and one line looked like this:
⬜️ 9.0 ', {'dates': ('2021-09-04 16:49:34', '2021-09-05 17:59:10', None, None), 'hidden': False, 'checkmark': 'no
It seems to be showing the dates and format but not the text. The rest of the outline looked fine

cvp

@ihf As I can't check the content of your outline file, it is difficult to identify the problem.
But I'll modify the html to "protect against old or corrupted line where text field is absent in a line".
This last case could generate such an error.

new V00.02 of outline_viewer.html

ihf

@cvp This is very strange. I ran the new version and line 9 is blank (no errors). I then went back to run the outline.py script and I immediately get an error:

Traceback (most recent call last):
File "/private/var/mobile/Containers/Shared/AppGroup/05D14C00-CCAC-4E98-A3CC-96C6944B8534/Pythonista3/Documents/outline.py", line 1167, in layout
ws,hs = self.get_screen_size()
File "/private/var/mobile/Containers/Shared/AppGroup/05D14C00-CCAC-4E98-A3CC-96C6944B8534/Pythonista3/Documents/outline.py", line 1158, in get_screen_size
app = UIApplication.sharedApplication().keyWindow()
File "/var/containers/Bundle/Application/8778D1CF-1C08-48BA-9714-9D2CFE524EA1/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/objc_util.py", line 801, in call
ordered_args = list(args) + [kwargs[key] for key in kwarg_order]
TypeError: 'builtin_function_or_method' object is not iterable

I tried again and got same error. I closed pythonista and ran it again and managed to open the same outline and it worked though line 9 has text. Short of sending the full outline, is there something I can post that would help?

ihf

@cvp That error is now popping up whenever I start the script.

cvp

@ihf I don't understand correctly all your posts.
The error has already happened in The past, not really from my py code.
Is the error coming only for the outline with blank line 9?
Of course, I would be happy to get your outline or at least line 9 (you can always edit the .outline as text in Pythonista, find "9.0" and extract via select/copy/post the line to post).

ihf

@cvp Here is line 9.0 which shows as blank in the html view but shows the text otherwise:

([8], '9.0 ', {'dates': ('2021-09-04 16:49:34', '2021-09-05 17:59:10', None, None), 'hidden': False, 'checkmark': 'no'}, {'text': "Return Peter's fluke"}),

cvp

@ihf thanks. I don't know (Ho yes, text includes a quotE) why but it is the first time that I meet

{'text': "xxxxxxx"}

in place of

{'text': 'xxxxxxx'}

In a py script, no problem, a dictionary is understood in both cases, but in my JavaScript code, I have to do it my self.

Next version will follow today

PS that does not explain the (old, already met) Pythonista crash

cvp

@ihf new V00.03 of outline_viewer.html

ihf

@cvp That fixed it!. Thank you!

cvp

@ihf Finally, is this html what you wanted to replace the Mac py?

ihf

@cvp I know JS is not what you want to work on, but if you are open to any enhancements to the .html file, one thing that would be nice is if it could default to the last file that was selected, rather than to have to select it each time. Or, perhaps it could open the file selection directly rather than have you click Select File which is always going to be required.

cvp

@ihf I don't think that html5 allows to set a default path, for security reasons. At least, I don't see how.

Édit: I'm busy to try (actually without success) to simulate a tap on the input file selector at page load.

I think I I'll give up. Finally, it is only to win one tap, isn' it?

ihf

@cvp Is it also difficult to have a version which just opens a specific file (i.e., no memory of file last used and no selection). If so, I could create a few .html files wach of which would open a different outline. Not elegant but it would avoid any selection.

cvp

@ihf said

Is it also difficult to have a version which just opens a specific file

So far as I have already read, I think it is not authorized in html5 to access a predefined path/file.
But, if you find a way, I agree to incorporate it in the html.

ihf

@cvp I don’t know about html5 limitations/restrictions. Perhaps it could all be done in a Python executable on the web server.

cvp

@ihf said:

Perhaps it could all be done in a Python executable on the web server.

Wow. what an imagination! That, if possible, seems very far of my skills. But, who knows?
In the mean time, what will you use: mac_outline_viewer.py or outline_viewer.html?

But, would you be able to configure iCloud access on the web server?

ihf

@cvp I will probably use outline_viewer.html as it is accessible from any web browser that is on a machine that is logged into my iCloud account. Unless I am mistaken, the web server does not need iCloud access as you are accessing the file from the client.

cvp

@ihf said:

the web server does not need iCloud access as you are accessing the file from the client.

I think it needs it if the Python program runs on the web server. If you run a code on the server, it is the server which access the file, not the client, at least, I think so.

A solution is perhaps to modify outline.py to save at each file end (not update: end of script or new other) the outline file on the web server, via ftp, sftp, smb at your choice.
The .html could access these local (on the web server) files, I don't know yet how but it should be possible, either via a selection, either via a fixed path

cvp

@ihf sorry, I updated previous post during your connection, please read it.

ihf

@cvp Sorry, I thought you were referring to the .html approach. Yes, if the viewer ran as a python script, then access to the file from the server would be needed. One problem with putting the outlines on the server that I hadn’t considered is not having any authentication for access.

cvp

@ihf you're right, it is not the right solution. Sincerely, is selecting an outline file so heavy? I had also thought to cookies but not sure it could help. I'am open to any feasible solution.

Perhaps I could store the last outline file as a local cookie but if you modify the file.....
But you may have max 20 x 4K bytes of cookies per site

ihf

@cvp I set a due date on a line in my outline and then viewed the outline with the .html. The due date showed up but was associated with a different line (the 1st line). The dates are sorted in descending order. Also, I modified another line and the modification shows in the viewer but the update date is from a couple of days ago (probably when it was created).

cvp

@ihf bugs will end when I'll stop to write code 😭

Could you check dates if no sort?

ihf

@cvp WIth Sort=none, the dates are correctly associated with their items.

cvp

@ihf new V00.04 of outline_viewer.html should correct this problem of erroneously associated items after a sort

ihf

@cvp Thanks! That works well.

cvp

@ihf sorry for all these bugs...

Anyway, That does not solve your request and I don't see a way to access an iCloud file without any user interaction. The only way I see is to copy the outline on your web server, perhaps encrypted, or password protected.

ihf

@cvp It's fine. I naively thought that the .html could bypass file selection and just "pre-select" an iCloud file (outline). That way I could just have multiple .html files, each with the name of the outline that it opened. The current.html file requires a couple more clicks but otherwise does exactly what I wanted.

cvp

@ihf if you want something new, don't hesitate.

Next week, I will continue converting outline.py from TableView to scrollView

ihf

@cvp FWIW, I really miss the undo/redo (probably because I make too many errors:-). Unrelated question, how do I add an item at the top of an outline when editing? What I do now is add elsewhere and drag it to the top. Is there a better way?

ihf

@cvp I thought this problem was resolved but I just opened an outline (it has about 20 lines) on my iPad in Landscape mode and when I position the cursor at the end of the last line, the keyboard appears and covers half the screen (including the cursor location).

cvp

@ihf
1) undo/redo: sorry but nothing promised before months
2) add item at top of outline: no other way actually, see at bottom of this post
3) keyboard hides last line problem: I also thought it was solved, no idea why no more ok, ios15?

PS don't hope anything in December, this modif excepted

V01.25 and outline.versions with

Version V01.25
    - add new option 'add before' in the popup menu to add a new row before 
      the selected one, even at top of outline file
cvp

@ihf If you imagine another way to add a line at begin of file, tell me

ihf

@cvp My first instinct was to place the cursor in front of the first character on the first line and hit return. however, that adds a blank line to the item (which is good), so I think the menu item is fine.

ihf

@cvp I know it is possible to hide or (only show) checked items but is there a way to sort on the completed check box? (i.e., to place the completed items at the end (or beginning)? I almost get this when I view the ended date and do a descending sort but that reorders the rest of the outline in descending order for some reason.

cvp

@ihf said:

when I view the ended date and do a descending sort but that reorders the rest of the outline in descending order for some reason

V01.26 and outline.versions with

Version V01.26
    - correction of bug "sorting on a date should not sort items without this
      date (fi: due date, end date)"

With this correction, do you still want a sort on the completed check box?

ihf

@cvp That works although it is multiple steps and the dates must be shown to do it. I’d say its not terribly important but a pure sort on the checkbox is what i envisioned . More important: I just noticed that there is a bug when you view the dates and you have items with multiple lines. The second line of an item becomes part of the next line. I can send an image if it would help.

cvp

@ihf said:

More important: I just noticed that there is a bug when you view the dates and you have items with multiple lines. The second line of an item becomes part of the next line. I can send an image if it would help.

You already got this error and you posted "If my outline is collapsed and I select view by completion date, and then select sort button to change to sort down, the display gets messed up in that lines are overlapping.".
I know that problem comes from computing TableView row's height which does not take in account that rows are sorted and I wanted to let this problem for the future version without TableView, and check if the problem still occurs.

Edit : I just tested with my new ScrollView version (still in development) and problem should disappear

ihf

@cvp oops, sorry about that. I guess I am dropping bits…so to speak 😕

cvp

@ihf No problem.

Suppose I can develop the sort on the completed check box witHout date, how do you imagine to ask that? I would like to not be obliged to add a sort button like 🔢.
I could add some options in the eye menu or in the popup menu.

ihf

@cvp I would say the eye menu is the most intuitive.

cvp

@ihf ok but do you agree to have 3 options: sort ascending/descending/no sort? To avoid a supplementary button

ihf

@cvp sure, that would be fine.

cvp

@ihf new V01.27 and outline.versions with

Version V01.27
  - add new options in eye menu to sort items on their completed checkbox,
    at beginning, at end, or reset without sort (same as 'Expand all')

Feed-back hoped

Now, if I modify outline.py, I also have to incorporate modifications in ScrollView version, still in development for some time. 😢

ihf

@cvp I just restarted outline (v1.25) and it did not tell me about a new version.

cvp

@ihf weird. Internet accessible ? Retry

ihf

@cvp I agree, very weird. I tried on iPhone and iPad (both have connectivity) and both are staying on v1.25 with no notice of an update.

ihf

@cvp I tried on another iPad where I had updated to v1.26 and it also does not tell me about v1.27. Something else change in v1.25?

cvp

@ihf did you not try the V01.26 just before the V01.27?

Édit: sorry, I crossed your previous post

cvp

@ihf I found the reason, I erroneously added a blank line at begin of .versions file.
Wait 1 minute please

cvp

@ihf ok, retry please

ihf

@cvp That did it. The new version looks good and does exactly what I was looking for. There appears to be one small glitch. When I sort by check boxes at beginning it works perfectly but when I do it at end, there is a blank line after the first of the checked (completed) lines. I tried on another outline and had a similar problem except it was when I did the sort to beginning and then the blank line (2 of them) were between the uncompleted items at the end. I tried on 3 more outlines and did not see the problem.

cvp

@ihf said:

small glitch.

Would it be possible that the problem comes from the same problem of rows with multiple lines like the previous described in sort of dates? This problem is not solved at all.
Rows height is not correctly computed if sorted rows

Or is it possible that you have rows without box?

ihf

@cvp It is quite possible that it is related to the other Tableview row height issues.

cvp

@ihf you could check that your outlines which do not give the same error do not have multi lines rows

ihf

@cvp yes, I think it is only a problem with outlines that have multi-lines.
Unrelated: I believe you already addressed this but I cant seem to find it in the forum thread. I would like to be able to select text and thru the share sheet, copy the text to an outline. I can’t seem to find the script that does this.. did I just imagine this?

cvp

@ihf If I correctly understand your request:

Select rows you want to copy, choose copy option, These rows will be stored in outline.clipboard file. Then, in the destination outline file, tap the outline after which you want to paste. In the appearing popup menu, choose paste xxxx option. xxxx is the text of the first copied row. The copied rows will be pasted after the row of the popup menu. Easy, isn'it?

Edit: I think there is a bug if you copy/paste several rows and that they don't have the same level as the destination row. Not yet identified...The paste works but you could have to promote/demote some pasted rows.

Would you agree if the paste operation would add pasted lines at same level of destination line, without taking in account the initial level of copied lines?

Please, tell me
1) if I had correctly understood your request
2) if the copy/paste described is what you want
3) if the proposition of the level of pasted lines is ok for you

...


...

...

ihf

@cvp Actually, I was asking an easier question. When i go to the ios share sheet and select “run pythonista script”, there is a script called“Copy to Todo”. If I select text in a document and invoke this script, it adds the text as the last item to the outline named Todo. I wanted to add another script to this share sheet that copied something to a different outline. However, when I searched for “Copy to Todo” in Pythonista, I didn’t see it. I finally realized that Copy to Todo merely invokes outline.py with the name of the outline (Todo) as an argument. The script then copies whatever is in the clipboard to the named outline. It all works, I just forgot how.
I answer to your question, the copy/paste is fine with the level of paste as it is not a problem to demote/promote after the operation ,when needed.

cvp

@ihf From V00.91 (I also forgot this functionality)... Sorry that I had not correctly understood your question. Anyway, so we now remember this (asked by you, written by me, both guilty) functionality.

cvp

@ihf My new program outline.py using a ScrollView in place of a TableView is done, but I cannot provide it yet because it is full of bugs and I am not motivated to debug it in the short term.
In the ScrollView version, the bug of bad rows heights when sorting rows on date or completed checkbox does not exist (there is no row), so I have corrected (at least, I hope I did it) this bug in the TableView version, so this is for you:

new V01.28 and outline.versions with

Version V01.28
  - correction of bug "when outline is sorted (on a date or completed checkbox),
    the height of multiple lines rows is incorrectly computed"

Feed back is hoped

ihf

@cvp There still seems to be the problem where the end of the second line of an item becomes part of the beginning of the next item when I view any of the dates. I can send screenshots if that helps.

cvp

@ihf new V01.29 and outline.versions with

Version V01.29
  - correction of bug "when an outline date is displayed, the height of multiple
    lines rows is still incorrectly computed"

Feed back hoped

ihf

Thanks! That fixed the problem. I was wondering if there was a way that I could write a shortcut which added an item to an outline much the way the share sheet can. The shortcut could put something in the clipboard but in order from the current script to add that, it looks to see if the script is running from the share sheet (appex). Is there a way to signal that the script is running from a shortcut (perhaps an additional parm)?

cvp

@ihf Please, confirm that I correctly understand: you want to run the outline.py from a shortcut, with as arguments:
- the name of The outline file
- something identifying that the program is started by a shortcut having stored the text in the clipboard.

Remember that the 2nd (optional) argument is the folder where to find the outline if not in the default one...

We could use an optional special character in front of 1st argument, like @ToDo specifying that comes from a shortcut, or put a special character alone as 2nd argument

cvp

@ihf new V01.30 and outline.versions with

Version V01.30
  - correction of bug "when we add a new row by passing its text via the share
    sheet, this new row did not have a creation date"

Please read also previous post and decide how you prefer to warn the script that it has to add a row with the text in the clipboard.
It could be with
1st argument = outline name
2nd argument = CLIPBOARD word in place of a folder

Or
1st argument = ©outline name

Don't forget that when you go via the share sheet, the program can close it-self and disappear.
But when you open Pythonista via an url, I could close the outline file, but do you want I also abort Pythonista to fall in the iDevice home screen?

ihf

@cvp I can’t think of a strong reason to pick between options one and two but I would lean slightly toward one because it seems a bit more intuitive.
You mentioned a good point, the shortcut would need to be able to add to the outline “quietly“. As with the Share sheet and Run Pythonista Script, the script runs without showing anything on the screen. Given that the Share sheet method can take 20 sec to run, I wonder if the Shortcut will timeout.

cvp

@ihf said

the shortcut would need to be able to add to the outline “quietly“. As with the Share sheet and Run Pythonista Script, the script runs without showing anything on the screen. Given that the Share sheet method can take 20 sec to run, I wonder if the Shortcut will timeout.

If a script runs Pythonista through its url scheme, Pythonista will appear, run and, I could call Shortcuts afterwards but with which shortcut?

ihf

@cvp I may be mistaken but if you return to Shortcuts (no particular shortcut specified) the shortcut that was running or just continue from there.

cvp

@ihf new V01.31 and outline.versions with

Version V01.31
  - support run mode to add a row with text pasted from Clipboard by Pythonista
    url scheme with arguments outline_name CLIPBOARD. Short run without
    opening full View and ending with opening Shortcuts app

Please try different modes
- normal run
- share sheet mode with shared text
- shortcut mode passing text via clipboard and calling Pythonista url scheme with
1st argument = outline name
2nd argument = CLIPBOARD word

Share sheet and clipboard mode should be short quick modes, without displaying an ui.View

And surely feed back hoped because last mode is not so easy (for me)

ihf

I tried this Shortcut but it did not work:
https://www.icloud.com/shortcuts/b04b6c9fc72a442ea4cbd9305f0dcdf7

ihf

@cvp I tested all 3 modes and they work fine. However, the Shortcut will not work from the watch. It says “could not open app for them URL scheme “Pythonista” because the app is not installed on this device “.

cvp

@ihf said

Shortcut will not work from the watch. It says “could not open app for them URL scheme “Pythonista” because the app is not installed on this device

Normal, Shortcuts app is very limited on the watch. Anyway, you don't have any clipboard on the watch, so...what could you hope to do on the watch even if shortcut was authorized?

Édit: Perhaps you know Pyto shortcuts action "run Pyto code"? Doc says Run Code will execute the given code with the given arguments. Can be executed in app or without leaving Shortcuts.
I've tried a little shortcut with only this action and a very short script:

path = '/var/mobile/Library/Mobile Documents/iCloud~is~workflow~my~workflows/Documents/a.txt'
with open(path, mode='at') as fil:
  fil.write('test')

And I have executed this shortcut on my Apple Watch and it works...
Thus, you could execute a short Python code on your Apple Watch without opening Pyto on your iPhone. I did not try all but I think that you can only access a file in the ICloud Drive/Shortcuts folder, not in the Pythonista ICloud folder. I also tried to write on a private folder in iCloud Drive: ok on my iPad, not authorized on my watch.
Thus, assume that your outlines are stored in the Shortcuts folder (why not?), with a more complex script (converted from Pythonista to Pyto), you could (perhaps, to be tested ) append a line to an outline file.
Of course, the text could not be added to the clipboard by the watch. But you can imagine you type/say the text into your watch. Your watch could even ask you which outline you want to append.
The script will check in the dir if the file exists, open it in append and write the wanted text.
Not sure it could be useful.

ihf

@cvp i dont think it matters since the pythonista url will fail on the watch but I’m not sure what you mean when you say there is no clipboard on the watch. The Shortcut I execute from the Watch asks for input and sets the clipboard and then opens the Pythonista URL with that clipboard as an arg. If I could tell it to run the URL on the phone, then maybe it would work.
Anyway, your pyto idea is good

cvp

@ihf said

if I could tell it to run the URL on the phone,

No way!

...

@ihf said

your pyto idea is good

But you would have to store your outlines in the iCloudDrive/Shortcuts/your folder/ folder.
If you don't like it, I will not develop the shortcut and its Pyto script

ihf

@cvp That is where I store them (in order to have access from all my iDevices).

cvp

@ihf I thought that you stored them in Pythonista iCloud

Can I have the exact folder of your outlines?

ihf

@cvp My error. Yes, they are in the Pythonista 3/Outlines (iCloud) folder

cvp

@ihf In this case, unfortunately, a shortcut running on an Apple Watch will not access the outlines.

But if you decide to use iCloudDrive/Shortcuts/Oulines as base folder for your outlines, an Apple Watch shortcut could be done for appending a text in an outline, without disturbing the other tasks (I think, not tested)

cvp

@ihf I have written a shortcut and its included Pyto code to:
- display a list of outlines in iCloudDrive/Shortcuts/Outlines folder
- ask the user to select one
- ask the user the text to add at end of outline
- add a row to the outline
- save the outline with same name
I keep the same name because the script would not be authorized to modify the outline.prm file with an eventual modified file name because this .prm file is local to Pythonista folder.
Thé script does not update the 2022 event's notes with the new content (used by Apple Watch shortcut to display an outline).

As is, the shortcut works on my iPad, but not on my Apple Watch, without any explanation as usual, during execution of Pyto code. I guess that something of the Pyto code is not authorized in the Watch.

Édit: on my watch, I get an error "impossible to listen to the last recorded vocal message", very helpful 😂

cvp

@ihf I don't understand how but the last action of my shortcut was "listen to last recorded vocal message". I guess I added it but not voluntarily.

OF COURSE, I removed this action but the shortcut does not work yet...on my watch

On my watch, the action "get folder content" returns nothing in place of the list of files as it does on iPad.

cvp

@ihf I try, in a shortcut on my Apple Watch, to get the list of files of a iCloud shortcuts sub-folder, and, as said previously, action "get folder content" does not work. I just tried an action "run Pyto code" with os.listdir() but it also returns None... on the Watch but is ok on my iPad.
If I want to write a shortcut/Pyto_code, I need to get the full file name, it is annoying.

cvp

@ihf I have a little shortcut with an included Pyto code, with these actions:
1. Set fixed file name of outline file to be appended
2. Ask text to append
3. Run Pyto code which will append text to specified outline, without
- changing file name
- updating .prm with last updated file
- changing 2022 event's notes with full file
Not sure this could help you as I can't find myself the full file name because Apple Watch is not authorized to get a list of files of a sub-folder even in shortcuts folder.
If you want to try, this is the shortcut but you have to set manually the full file name.

https://www.icloud.com/shortcuts/1ae173b064b54b23b83460080d85bc0f

cvp

@ihf I don't know if you want to try this shortcut.
If yes, create subfolder Outlines in ICloudDrive/Shortcuts folder and copy there an outline file.
Type its name (without .outline) in shortcut first text action.
And run shortcut on your watch.
After, you can always check the modified outline in outline.py by setting current path to this path and open the outline.
And please give some feedback
Thanks

ihf

@cvp I haven’t tested the shortcut yet. I just got a new iPhone 13 Pro and have been busy trying to get everything working from my old iPhone. I’ve noticed a problem when running Pythonista and the outline script. Touching the Close X in the left corner or the menu item is hit or miss. I’m not sure you could do anything about it as it may just be a problem with Pythonista on this new phone but I thought I’d let you know.

cvp

@ihf said

Touching the Close X in the left corner or the menu item is hit or miss

Not understood, sorry. I'll wait for more info.

ihf

@cvp On the iPhone 13, I have found that when I try to touch one of the menu items (e.g., the X to terminate the script), it does not recognize the touch. After several tries, I can get it to work but it is as if the menu bar is too high or the coordinates for the touch are not right for this phone.

cvp

@ihf Sorry but I sincerely don'T know what I could do. If the button is visible, how is it possible that the touch area could not be correct.

ihf

@cvp I agree but there it is.

ihf

@cvp the outline name is actually in the area at the top that ios places its icons for networks and the time and the battery. It could be an ios bug on the iphone 13. This was never an issue on the old iphone.

cvp

@ihf I guess that I'm responsible for the problem. The script displays outline name and undo button at 10 pixels from the screen top. And that is obviously not compatible with a device having a notch. I don't have this kind of device (only iPad Air 4 and iPhone SE2) thus I've never remarked a problem.
As you got an iPhone 13Pro as Xmas present, I'll have to quickly develop a new version supporting it 😂.
I'll foresee to not display anything in the safe area of the iDevice. You'll see that even the TableView will be limited just above the horizontal line at bottom.
But Pythonista fullscreen overrides the whole screen.
Wait until my evening.

ihf

@cvp I guess all the complaints about the notch were related to more than just aesthetics.

cvp

@ihf are all your devices where you actually use outline.py without notch?

cvp

@ihf new V01.32 and outline.versions with

Version V01.32
  - support all versions of iDevices, taking in account their "Safe Area"
    to display buttons and items

Hoping feed-back after tests with all your devices. If it works (even when turning your device), it could be my Xmas present.
My last problem has been turning the device when dates are displayed because the TableView has also been moved down to display date title.

ihf

@cvp That works perfectly on my iPhone 13. Best wishes for a Happy and Healthy (covid-free) 2022! And thank you so much for all of your work on outline!

cvp

@ihf thank you for your good wishes. In my turn, I wish you that 2022 will be wonderful for you and your loved ones. No thanks for outline, you are a very appreciated customer 😂

cvp

@ihf said

I haven’t tested the shortcut yet

Could you try?

ihf

@cvp After moving an outline file into the correct place and putting the name in the shortcut, I run the shortcut and it runs without error but I don’t see anything being added to the file. I’m not sure it’s actually running the Pyto script. I will play around some more

cvp

@ihf The best way to test it is first to test the shortcut on your iDevice before testing on Watch.
Then, in the action "run Pyto code", set "open console" switch ON.
Of course, Pyto has to be installed on your Watch

ihf

@cvp I had .outline on the filename in the shortcut. I removed it and now pyto says:
```
Traceback (most recent call last):
File "Library/Caches/Shortcuts.py", line 89
, in
with open(path+file,mode='rt', encoding='
utf-8', errors="surrogateescape") as filc:
PermissionError: [Errno 1] Operation not perm
itted: '/private/var/mobile/Library/Mobile Do
cuments/iCloud~is~workflow~my~workflows/Docum
ents/Outlines/ToDo_20211221_171407.outline'
Exception in thread Thread-5:
Traceback (most recent call last):

File "Library/python38/threading.py", l
ine 932, in _bootstrap_inner
self.run()
File "Pyto.app/scripts_runner.py", line 51,
in run
super().run()
File "Library/python38/threading.py", line
870, in run
self._target(self._args, *self._kwargs)
File "", line 18, in complete
File "Pyto.app/Lib/rubicon/objc/api.py", li
ne 651, in getattr
raise AttributeError(
AttributeError: rubicon.objc.api.ObjCClass Py
to.EditorViewController has no attribute code
ToComplete ```

cvp

@ihf you are sure that Outlines/ToDo_20211221_171407.outline Exists in iCloudDrive/Shortcuts

And you have to define Shortcuts in the accessible folders of Pyto

ihf

@cvp I added the Outlines directory in Shortcuts to the pyto accessible directories. I then ran the Shortcut on my iPad and the pyto script seemed to run without error. However, when I then run outline, change the path to the outlines in Shortcuts dir, and open the outline, I get “File does not (yet) exist, try again”.

cvp

@ihf You have also to authorize Pythonista to access iCloudDrive/Shortcuts folder in "external files/open/folder"

ihf

@cvp got it working from the phone but watch says

Could Not “Run Code”
This action encountered an error while running on your iPhone

cvp

@ihf Weird, I just retested now and successfully worked.
With last Watch OS, last Pyto update from today.
Did you reset switch "Open console" off in "run Pyto code" action?

Édit: ok even if switch on.

On the watch, after having asked the text to be appended, the shortcut asks if you authorize the shortcut to access to Pyto, I just tried to answer "refuse" in place of "authorize " and from this moment, I have The same problem as you.
I'LL search how to reauthorize...

Solved: IPhone/Settings/Shortcuts/Advanced/Allow Running Scripts ON

ihf

@cvp no luck. Works fine from phone but same error as before. Pyto was no longer on my watch (seems to have disappeared after I upgraded the phone)

cvp

@ihf For that, you only have to reinstall Pyto on your Watch, as usual

More: if your normal outlines are in IcloudDrive/Pythonista 3/Outlines/ folder and if you authorize, on the iPhone connected to the Apple Watch, Pyto access to this folder, you can change in the shortcut the line path = '.....' into
path = '/private/var/mobile/Library/Mobile Documents/iCloud~com~omz-software~Pythonista3/Documents/Outlines/' and your Apple Watch shortcut will access normal outlines, no more ones copied into the Shortcuts/Outlines folder. That's a one step forward.
One thing I can't do actually is to know in the shortcut the entire full name of the outline file, with its date-time part, reason for which you have to define it in the shortcut it-self. But I have some hope.😅

ihf

@cvp I deleted Pyto from my watch and reinstalled it. Now if I try to start it on the watch it immediately ends.

cvp

@ihf why do you want to start Pyto on the watch? Do you have a Pyto script running on the watch? Or do you mean you start a shortcut running a Pyto code?

ihf

@cvp I don't want to run anything (right now) in Pyto on the watch but I thought it was odd that it does that. In any case the error that I get when I run the add to outline shortcut from the watch persists.

cvp

@ihf did you set IPhone/Settings/Shortcuts/Advanced/Allow Running Scripts ON On the iPhone connected to the watch

ihf

@cvp Yes, I did.

cvp

@ihf Is the error still

Could Not “Run Code”
This action encountered an error while running on your iPhone
ihf

@cvp Yes, that is the message.

cvp

@ihf weird, this message should occur if IPhone/Settings/Shortcuts/Advanced/Allow Running Scripts Switch is not ON...

I guess that your new iPhone has access to iCloud Drive and that the shortcut is downloaded on your iPhone,not with the cloud symbol.

I also guess that you allowed shortcuts folder to be accessible by Pyto

ihf

@cvp Wouldn't not work on the iPhone (which it does) if permissions were incorrect?

cvp

@ihf I suppose you are right. So I don't understand why it does not work on your watch. I guess there is still a configuration setting missing, but which one... Could you compare Pyto settings on your boTh iPhones?

Does the shortcut ask you the text to append?

I just restested on my watch, still ok.

ihf

@cvp Yes, the Shortcut asks me for text and then for permission ("Allow "AddRowToFixedOutline"to access "Pyto". After I touch "Allow" I get the message "Could Not Run Code -This action encountered an error while running on your iPhone". I only have the iPhone 13 Pro.

cvp

@ihf I think that I remember that after I had set the IPhone/Settings/Shortcuts/Advanced/Allow Running Scripts Switch ON, I have had to power off/on the iPhone. Perhaps you could try.

ihf

@cvp Power cycling the phone did have an effect...no more error message. After getting input and asking for permission, the Shortcut hangs with the progress circle. Progress?

cvp

@ihf Is the outline file that you want to append already downloaded on your iPhone?

Is the outline folder accessible to Pyto on the iPhone?

@ihf said:

Power cycling the phone did have an effect...no more error message

Don't believe I'm a Pyto specialist but when I meet a problem, Power off/on is always my last try to solve it.

ihf

@cvp the file name had changed and Pyto was getting a file not found error. I changed he file name in the shortcut and now it works on the iPhone but fails again with the same message as beore when run from the watch.

cvp

@ihf Weird and, sincerely, it seems too complex for me.

Anyway, problem of file name would arrive, that's sure. I know this problem and I have already thought about a way to avoid it. The outline.py script could store in the 2022 event of file its full name and the shortcut could ask to choose an outline file like in the viewer shortcut, by listing all files found as 2022 events.
But, a thing that the shortcut nor the Pyto code couldn't do (I think) is, when you modify a file, save it as a new date-time name and modify the .prm with the new file name. That seems too much for a shortcut.

cvp

@ihf Is it really important for you to be able to append a text to any outline on your watch?

I don't understand how Apple still allows applications to be sold that haven't received updates for a very long time. Good for developers, but buyers take the risk of not profiting from their purchase for long. For me, Pythonista is the best app I have used, which is worth a lot more than its price and for which I would gladly agree to pay an annual subscription of 10 €, even without any updates, just so as not to see it one day disappear or no longer be functional. To be prepared if this disaster ever happens, I imagined converting outline.py to Pyto, but it would be long and not that easy. Indeed, any development in Pythonista also uses modules, like dialogs, which are not available in Pyto and which should therefore be rewritten. To give it a try, I converted SetTextFieldPad.py which is only 134 lines long and already there I encountered differences between the methods of the two UIs and the way to use ObjectiveC, differences that require spending time in searches and tests. If you are interested, try this little script in Pyto

You can even test this very little outline.py that only shows the buttons of the main screen, with these small functionalities:
- files menu, only to test a TableView and a shield
- open to test the Pyto file picker
- font size to test the SetTextFieldPad converted module
- Pyto color picker
- Pyto font picker

Thé script has only 300 lines, thus you can be sure it does nothing. It was only to have an idea of how complex a conversion would be. And I could only be motivated to do this heavy conversion if Pythonista was planned to disappear, and, of course, if you still use this script.

Anyway, I wish you a pretty year 2022 with full Pyt(h)o(nista) projects.

ihf

@cvp The ability to add to an outline from the watch is definitely not terribly important. Like you (and I am sure many others), I am concerned that Pythonista will stop working after some new iOS release. I wish that @omz would reappear or somehow agree to put Pythonista into open source. I doubt that either will happen. That means that, at least at the moment, Pyto is the best alternative for Python development. However, it would clearly take a great deal of effort for the Pyto developers to bring it to Pythonista’s level of maturity. Pyto does however have many advantages that are not relevant to outline of (e.g., scipy, pandas, etc.).
As far as my use of outline goes, I use it all the time and I can’t thank you enough for all the work you have put into it.
I wish you and your family a VERY HAPPY AND HEALTHY (including covid-free) 2022!

cvp

@ihf I want more and more to convert outline.py to Pyto (funny challenge) but I am torn between converting the current version (ui.TableView) or the ui.ScrollView version which is still in test (with a huge lack of motivation, I do it regret)

A little question: you always say that you use the program each day, but do you still have a lot of unexplained crashes with the ui.TableView (yours) version?

ihf

@cvp I still get crashes, I just stopped reporting them.

cvp

@ihf I had naively hoped that they could disappear with an iOS upgrade or a Pythonista upgrade, so hoped by a lot of people. So next week, I'll be brave and restart the tests of the ScrollView version.

ihf

@cvp I'm not sure what Apple did to iOS Shortcuts, but the Shortcut I have been using to view my outlines on the Watch no longer works from the Watch (though it works fine on the iPhone). Instead of showing the outlines found in the calendar and letting you select one, it shows a blank screen.

cvp

@ihf you're right. It still works on iPad but no more on Watch...

Pyto also does not work anymore on the watch, don't ask me why.

cvp

@ihf If you really need it, I could modify outline.py to store each saved outline in a contact in addition (or in place) of an event. I have tested that a shortcut running on the Apple Watch can access to the contacts even if it can't (temporarily ?) access to calendars

ihf

@cvp Using contacts would be a good workaround for the glitch with the calendar. The only problem I see is that some apps like to get access to contacts (I try never to permit it) and so outline info would be exposed. I hope Apple will fix what they broke.

cvp

@ihf After some hours to try and test some Shortcuts actions, I've found that even if the "search events" action does not work anymore (with last version of IOS and Apple Watch OS), it seems that "get a number of events from a particular calendar" works correctly....
Then, I advice you to save the current Outlines shortcut under another name (I called it "Outlines old") before installation of a new shortcut. I also advice you to check their content to understand how they are different. Also, the "get events" action needs to know the maximum number of events (here 100, up to you to change the value) to get n events at a specified date (here 01/01/2022) in a specified calendar (here "outline").
And, please, test it and give some feedback, thanks.

New Outline shortcuts is here https://www.icloud.com/shortcuts/302a6602e9474cb7b34860a8acfd6dcc

ihf

@cvp It works well. 👏

cvp

@ihf Perhaps you also follow Pyto Discord and you have seen that I've been able (by scrupulously reading the documentation 😇) to do an Apple Watch complication working.
Thus, if you imagine a complication on your watch warning you of some info about your outlines, let me know but don't forget that Pyto code of complications would be very limited in ram and in functionalities.

ihf

@cvp The first outline watch complication that come to mind would be related to any due dates that may be set in an outline. However I’m not certain as to how useful that really is. I will give it some more thought.
Unrelated to Pyto complications, I noticed this morning some thing that either I missed before or is new to iOS 15.3. The pop-up menu bar is cut off in outlines in landscape mode and possibly in portrait mode as well. Here are a couple of screenshots that might help illustrate this.
https://i.imgur.com/ieatwxT.png
https://i.imgur.com/UE6OMtg.png
https://i.imgur.com/iGEtjLx.png

cvp

@ihf said

The pop-up menu bar is cut off

It is scrollable 😉
- vertically for a vertical menu
- horizontally for an horizontal menu

cvp

@ihf said:

The pop-up menu bar is cut off

Question 1: Is the scrolling not ok?

Question 2: Do you know you can also put a shortcut as a complication

ihf

Answer 1: Oops, my apologies. The scrolling is perfect.
Answer 2: yes, I have a watch-face that has a complication that calls a shortcut. Although, I probably use Siri more often to start Shortcuts since I use quite a few.

cvp

@ihf said

Answer 1: Oops, my apologies. The scrolling is perfect.

it's me who apologizes, I'm always in a hurry to have an answer to a question 🙄

cvp

@ihf Not sure it could be useful, but it could be possible to show on your Apple Watch an outline file from your web server, this is a snapshot from my watch (it's the "display web page" action, thus you can zoom by tapping two times)

ihf

@cvp As you know, I can do that now with the outlines that get stored in the calendar. I’m not sure if viewing as the webpage has advantages.

cvp

@ihf sorting on dates

ihf

@cvp just checking in. Are you still in rewrite mode or have you “ moved on”?

cvp

@ihf I am sincerely sorry to let you down like this. I finished the modification of "ScrollView instead of TableView" mode but the first tests are catastrophic and I haven't (yet?) found the courage to debug. Why your question? Do you have new requests or are you having too many problems with the current version? Or have you decided not to use it anymore?

ihf

@cvp To answer your last question first, I definitely still use it regularly. It does crash Pythonista occasionally so that is mostly what reminded me to ask you about a revised version. I have not thought about any further enhancements as I did not want to complicate your rewrite.

cvp

@ihf I hate myself for having become so lazy and for not finding the energy or the motivation to debug my modified version

ihf

Dare I ask, any progress on the rewrite? I only as because I was just entering something into a new outline and it crashed, probably for the same reasons as before and it reminded me how much I seem to depend on it. Perhaps Pythonista was the best choice for prototyping on ios but not the best production environment for a script this complex?

cvp

@ihf said

any progress on the rewrite

Not at all, shame on me. I've to say that I don't spend anymore a lot of time in Pythonista. Only sometimes, some short answers in the forum, but no more a big script, even for myself.
But, anyway, it would be a rewrite always in Pythonista. Or do you mean a conversion in Pyto, which has also a lot of crashes, and no real support from the developer, no answer to questions.

Pythonista was the best choice for prototyping on ios

Not only prototyping, also for such a script, but without any correction for years. That's why Pyto could be better because the developer is 18 years old and we can hope she would update her app during years, excepted if she is very busy in her studies or later job.

ihf

@cvp I am happy to use Pyto if you think it would be better but in the meantime I will continue to use Outline as it is. I don't know if I am the only one using it but I certainly appreciate all of your hard work on it.

cvp

@ihf let's make a deal. In April, I'm very busy, including vacations in Italy, but I promise to spend my free time in May trying to fix bugs in the ScrollView version of Outline. If after that, it doesn't get better, I will abandon this direction. And I'll be sincerely sorry to let you down, but at some point I have to decide on an ending. Converting to Pyto seems doable to me but a work of several months.

ihf

@cvp In my limited experience using Pyto, it is buggier than Pythonista. However, given that the Pyto creator is maintaining it and it is OSS, there is some hope that it will become more reliable. I agree with your plan and that this was not meant to be a lifelong project :-)

I wish you a very enjoyable vacation!

ihf

@cvp There may already be a way to do this that I have forgotten but I wanted to take some text and paste it into Outline such that each line (delimited by EOL) would be a new outline element. In other words, if I paste in 5 lines of text to a new outline, I would get elements 1.0 thru 5.0. Related question, is there a way to take one element and break it into multiple elements?

cvp

@ihf no, sorry, that does not exist. I'll think about it

Related question, is there a way to take one element and break it into multiple elements?

No but that could be a good new functionality

ihf

@cvp I sometimes take notes in another app and I want them to be an Outline so an easy way to import them would be very useful.

cvp

@ihf I understand the request, I already think about it, but so long time I did not touch this script 😢

cvp

@ihf You know that there is a way to copy selected lines of an outline and paste them via the popup menu.

I'll try to reuse this code but I need to differentiate both cases. Not a little work

ihf

@cvp The thing I really miss is undo/redo but I know you said that was a major issue.

cvp

@ihf yes, I can understand but I think that you can forget it, unfortunately because it had never correctly worked with TableView where I have to delete/insert rows, but in the future, if ScrollView work with my own array of rows, who can say...

cvp

@ihf new V01.33 and outline.versions with

Version V01.33
  - add new "paste_text" option in popup menu to add multiple rows after the
    selected one by copying several lines from another note/text

ihf

@cvp I tried copying some text from another notes app and went to Outline. It pasted the text perfectly. However, if I click on the outline level to get the menu (on iPhone) it no longer displays properly.

cvp

@ihf said

it no longer displays properly

What does that mean ? Example? Perhaps I need to shorten the line if too long

ihf

@cvp I created a new outline and when I touch 1.0 to get the menu I got this:

https://i.imgur.com/JXu9PbE

cvp

@ihf Could you try to copy a text of some short lines, I think the problem comes from very long lines

ihf

@cvp It worked and displayed the Paste option with a few words and ...although it added 4 extra blank outline elements after the text.

cvp

@ihf said

although it added 4 extra blank outline elements after the text.

Don't understand. Do you mean that you did not copy some lines that are pasted?

I'll shorten to max 20 characters the first copied line in the menu but I'll paste all full copied lines

ihf

@cvp It worked fine when I copied several shorter lines (the extra lines were actually in the copied text so that is not a bug). I guess the problem is that when the lines are long it ruins the menu display.

cvp

@ihf see remark in edited previous post

ihf

@cvp that would be great. I'll test it after you make the change.

cvp

@ihf new V01.34 and outline.versions with

Version V01.34
  - shorten to maximum 20 characters of the first copied line but paste
    all full copied lines
ihf

@cvp C'est parfait! Merci!!

ihf

@cvp I just noticed that if I go to Settings or Show only if Level, and touch Done, I get an AttributeError (no attribute close).
Unrelated, I may have forgotten, but is there a way to delete an outline from within the script or Do I use Files app to delete it?

ihf

@cvp also got an IndexError when I went to menu and did Delete with Children.

cvp

@ihf said

just noticed that if I go to Settings or Show only if Level, and touch Done, I get an AttributeError (no attribute close).

😭never ending story

Édit: not for me, depends perhaps on what we did before, line number?

cvp

@ihf said

got an IndexError when I went to menu and did Delete with Children.

😭 never ending story bis

Édit: not for me, depends perhaps on what we did before, line number?

cvp

@ihf said

is there a way to delete an outline from within the script or Do I use Files app to delete it?

Not foreseen in program, sorry

cvp

@ihf said

C'est parfait

Parfait is an adjective that I never could use for this full bugs script 😂

cvp

@ihf I suppose that you don't use anymore on Apple Watch the shortcut to display outlines from the calendar events of 2022/01/01 because it does not work anymore. On Apple Watch the shortcut action to get a calendar event of the past does not work... Running the same shortcut on iPad/iPhone works. I could change the Pythonista script to store the outlines in calendar events in 2100 (far in the future) but you should need to manually move the existing events of 2022/01/01 to this future date.

cvp

@ihf when I say "not for me" in my answers to your new bugs, I mean that I don't meet these problems and the difference could come from some process done just before.

ihf

@cvp "not for me" equals the dreaded "works for me" (LOL).
I would like to use the Watch to view my Outlines. When it stopped working on the watch, I resorted to the phone.

cvp

@ihf said

When it stopped working on the watch

Did I forget or did you never tell me it stopped to work?

ihf

@cvp I searched but couldn't find where (or if) I told you about it so it was probably my memory, not yours.

cvp

@ihf Anyway, do you agree if:
1) I create a new version of script which will store future outlines on 01 January 2100 01:01:00
but please no immédiate run before the run of the shortcut of point 2
2) I create a shortcut to run only once before anything else
The shortcut will move all existing outlines from 01 January 2022 to 01 January 2100
3) I modify existing outlines shortcut, which runs on your Apple Watch, to display outlines of 01 January 2100

If you agree, could you tell me how much outlines events you have at 01 January 2022

If you agree, I'll do that tomorrow

I have to test if Apple Watch shortcut agrees to get a so far event

ihf

@cvp That sounds great. I have 10 outlines in the calendar.

cvp

@ihf ok, I don't do anything more today, you'll get news tomorrow. Bye

cvp

@ihf Thus this procedure will allow to store outlines as calendar events on 01 January 2042.
I guess an hope that you will no more use my script in 20 years. I've tested the script and shortcuts and all has been ok, even on Apple Watch. But you have to follow this procedure in the right sequence.

1) run this shortcut which will move all your outlines from calendar events 2022/01/01 into 2042/01/01
Personally, I ran it on my iPad and the events have been moved on my iPhone only 10 minutes later, thus be patient.

2) replace your outlines shortcut by this modified one which display outlines calendar event of 2042/01/01. And is ok also on Apple Watch.
Here also, I've been obliged to wait some time before shortcut has been updated on my IPhone and thus on my watch

3) install new V01.35 and outline.versions with

Version V01.35
  - outlines will be saved in calendar event on 01 January 2042
    in place of 01 January 2022 because Outlines Shortcut on Apple Watch
    does not allow to get calendar events in the past, only future events.
ihf

@cvp The new Outline shortcut works fine on the phone but on the watch I get a blank screen. I thought perhaps it hadn’t updated the shortcut yet so I duplicated the new shortcut which shows up immediately on the watch but still shows a blank screen.

cvp

@ihf that's what I said: I think you have to wait a long time before your calendar is synchronized on your iPhone

Check your calendar on iPhone and the shortcut which could also be not yet synchronized

I guess you first ran the one shot shortcut to move events to 2042

ihf

@cvp yes, after moving the outlines, the new Outlines shortcut runs fine on the iPad and iPhone. On the Watch, blank screen with the new Shortcut.

cvp

@ihf weird. If you have checked that the outlines shortcut on your iPhone reads 2042 events and that outline are now stored in 2042 events, the only solution is to remove shortcut app from the Apple Watch memory and retry, or to restart the Apple Watch. Please confirm you know how to perform both actions

ihf

@cvp force quit watch and restarted it. No change.

cvp

@ihf but did you check that the iPhone shortcut reads 2042 events and that events are stored at 2042/01/01?

And you said that you have duplicated a shortcut, sure you run the right one. There must be an easy explanation as usual and we look in the bad direction

ihf

@cvp this is very strange. If I go to the calendar,the events are no longer at January 1, 2022 but have been moved to 2042. The shortcut works fine. However, if for example on the iPad I do a search for one of the outlines it shows up in the search results as being on January 1, 2022 although it is not in the calendar on that date. It’s as if the search and the actual contacts are not in sync with one another. Perhaps, as you suggested, waiting will fix the problem. I’ll try again a little later and see if it changes.

cvp

@ihf said

search for one of the outlines

Not sure that search function in Apple calendar app searches so far in the future.

cvp

@ihf Sure you don't have two IPhones 😢?

cvp

@ihf You said you duplicate the shortcut. Sure that you use the modified one on your watch? Easy to add a log only to be sure

What you describe is that all is ok on calendar and iPhone but not on Apple Watch like if you still used on Watch a shortcut reading unexisting 2022 events (ex: read 2022 while they are 2042)

cvp

@ihf noThing new?

ihf

@cvp Review of status:

  1. All Outlines have been moved to 2042
  2. New Outline Shortcut works fine (shows list of outlines and displays them) in iPhone and iPad
  3. New Outline Shortcut shows a blank screen on Watch.
  4. Search in calendar app on Mac for one of the outlines, shows a result in 2042
  5. Search in calendar app on iPhone for one of the outlines, shows a result in 2022 (with the outlines in the Notes).

Weird, huh?

cvp

@ihf point 3 ok For me
point 5 same for me, weird

ihf

@cvp I know. #4 and #5 suggest where the problem lies but I don't know how to fix it.

cvp

@ihf if on your iPhone, you go in Shortcuts app end edit (not run) the Outline shortcut, do you see in the first action the date of 2042?

ihf

@cvp Yessir.

cvp

@ihf said

force quit watch and restarted it. No change.

What is quit Watch?

ihf

@cvp I tried killing the Shortcuts app and also rebooting the Watch. Neither helped.

cvp

@ihf last version os on iPhone and watch?

ihf

@cvp iPhone is 15.4.1 and WatchOS is 8.5.1

cvp

@ihf same for me. Strange and weird

cvp

@ihf did you also install the new outline.py and update an outline to check if updated is stored in 2042 event? And then ask outlines on Watch

ihf

@cvp definitely running the right Shortcut and script and yes everything is now in 2042.

cvp

@ihf said

running the right Shortcut

No comprendo signor

ihf

@cvp Sorry , was something not clear?

cvp

@ihf I don't understand that you would have rerun the shortcut? Which shortcut' not this one to be run only once.

Ok, I stop for today. If you have some news, don't hesitate to post it.

ihf

@cvp No, I meant the Shortcut that reads the calendar notes in 2042 (not the one that moved them there (I deleted that).

cvp

@ihf thus only stays the problem on Apple Watch

ihf

@cvp correct, problem is only on the watch

cvp

@ihf the only difference I see between your and my configuration is that you said you have duplicated the shortcut. Are sure you use the good one on the watch? And did you configure it as "on Apple Watch"?
And I only have 3 outlines?
And don't you have 2 iPhones ?
Perhaps reboot the iPhone ?
Sorry, but I try anything, even not smart at all.

For info, standard Apple calendar app on iOS can only search events maximum 1 year in the past and 1 year in the future. That's why I use Readdle Calendar5 app which allows a search of 10 years in the past.

ihf

@cvp I’ve tried both the original and the duplicate shortcut and yes thenare bot on watch and both work fine on the phone ipad. Ther’s something about finding the calendar entries on the watch that is not working but why it works for you is a mystery.

cvp

@ihf just for the fun, could you modify the first action of the shortcut to only "get 3 events". I agree this is not very a smart idea but perhaps iOS bugs do not follow smart rules 😀

iOS is worse than you think. Indeed, to easily test the move of events from 2022 to 2042, I first tested by moving to June 2022 to be able to easily check. Of course, later I reset everything to January 2022 to test the "one run" to 2042 shortcut. Since then when I search for the outlines events in the outlines calendar, the iOS calendar shows me the events in June 2022 despite that they are no longer there but they are in 2042. It is impossible to understand such a bug

ihf

@cvp tried with 3 events, no change.

ihf

@cvp boiled it down to the first few actions: https://www.icloud.com/shortcuts/ea369edfee254b138caf8dfc06394abc
That works on iPad and gives no output on Watch.

cvp

@ihf Ok, thus we have a problem...

I think I'll modify all to store the outlines in contacts in place of calendar events.
I could create a group "Outline" for contacts and add/update contacts of this group, with first name = outline title, group = outline and notes = outline content.

Of course, I have to
- create a "only once run" shortcut to copy outline from calendar 2042 events to contacts
- create a shortcut to select an outline and display its content (modify actual outlines shortcut)
- modify outline.py to add/update a contact with this info

You should manually perhaps delete the 2042 event when all is ok

Your opinion please or any other idea to improve that.

I'm going away in vacation next weekend, thus I would try to do this job still this week.

I'm afraid I could have already tried this solution in the past and met problems and forgotten...

ihf

@cvp Before you do that, I am going to try unpairing and re-pairing the Watch. It will take a little while.

ihf

@cvp unpaired and re-paired watch. No change. I can't think of anything else to try, so moving to contacts seems a good idea. It has the subsidiary benefit of not ceasing to work after 20 years :-)

cvp

@ihf said

It has the subsidiary benefit of not ceasing to work after 20 years

Cool, thus I can die without any stress

Then, I'LL begin. Agree that contacts will be
First name = outline title
Last name = Outline (needed to associate them to group Outline)
Group = Outline

ihf

@cvp D'accord.

cvp

@ihf Thanks, I'LL think first about sequence of operations...
What is sure is that I'LL not program something automatic to delete unused 2042 events.
If you only have 10 such outlines events, you can delete them manually and easily

First problem: I've
- created 3 contacts belonging to same group "Outline" with first name = outline title and last name = outline content
- created a shortcut to display first names of all contacts of "Outline" group and allow to select one and display its content

Shortcut ok on iPad but takes a very long time on Apple Watch... I'll debug
Reason: on Watch, no filter, it extracts all contacts, on iPad only contacts of right group 😭

It seems that shortcuts on Apple Watch do not work exactly like on iDevice

Ok, group does not seem to be accessible on Apple Watch. If my shortcut filters on last name = "Outline", it works even on Apple Watch, thus we forget this group, agree?

ihf

@cvp Sure, I don't know anyone by that name.

ihf

@cvp A better way would be to use DataJar but have to figure out how to get the outline from the script to there. I just realized you solved this (DataJar) 6 months ago. :-)

cvp

@ihf I don't remember what I did, but it is normal for my old age. Tell me

ihf

@cvp I found the thread when I searched the web for Pythonista and DataJar. It was about six months ago and I think you knew how to get the data into DataJar using the Shortcuts module, however we decided that the calendar was a better approach.

cvp

@ihf ok, and now, do we agree that contacts is the best way?

ihf

@cvp The only problem I see is if I (or anyone using the script) shares their contacts as part of their connection to some other service. It may not be desirable to share the content of these outlines. I tend to avoid sharing contacts but it occurred to me that having the outline information in there could conceivably be problematic. DataJar would not have that privacy consideration.

cvp

@ihf Wow. Not thought about this privacy. Found the posts but problem was to run a shortcut at each outline update. Reason why we did prefer calendar event. Remember that we do this process only for Apple Watch...

ihf

@cvp Data Jar lets you store any files and quickly retrieve them in Shortcuts. It is a very useful app.

cvp

@ihf ok, I understand but that will say update this iCloud file at each outline update
And did you try to read a DataJar on Watch?

ihf

@cvp yes, I use Data Jar to retrieve images, sound and text files all to the Watch.

ihf

@cvp I don’t know if this is possible, but if Pythonista can write the data to the Data Jar directory in iCloud then it will be accessible to a shortcut using Data Jar.

cvp

@ihf Ok, do you want we try to go in this direction? If yes, perhaps not before my vacations and you will have to describe your request. Only one file? Multiple records, one per outline? Key=outline title, data=outline file?

cvp

@ihf said

but if Pythonista can write the data to the Data Jar directory in iCloud

We will fall one more time with iCloud problems when updating an iCloud file, remember multiple versions with a number in the file. I guess it is better to always use only one file which should be a big dictionary of your outlines .

ihf

@cvp The way I imagine it (which may not necessarily be the best way) is for each Outline to be a key value pair in Data Jar. A key being the outline name And the value being its content.

cvp

@ihf then, it is necessary to pass via a shortcut to use DataJar app with its risks and without checking if process has been done

ihf

@cvp yes, the Calendar is better except that it doesn’t work.

cvp

@ihf please read entire post, covers several subjects

I have thought to the fact that it works on my Apple Watch. I told you that I had done some tests with 2022 June 01 before I develop 2042 January 1.
The events of June 2022 do not exist any more but a search on my iPhone shows them. And perhaps the shortcut on Apple Watch shows them also and not the real ones of 2122...

But anyway, do you really share all your contacts? Just to be sure we forget this solution.

Or do you prefer something like this (automatically done by a little shortcut which scans my 2042 events).

ihf

@cvp I think that using Data Jar is preferable . You asked ifI share all of my contacts. I try not to but many platforms ask you to and it would be easy to slip. I presume that there is no way for Pythonista to write a file into the iCloud/DataJar folder thereby obviating the need for a shortcut to be run each time an Outline is changed?

cvp

@ihf I think that if we write ourselves an iCloud file we will meet new problems thus the best solution will be to run a quick shortcut which will add/update a key/value pair at store level (if you agree).

I have not yet updated outline.py, perhaps tomorrow if you agree this way.

Anyway, here is a shortcut to run only once to create a DataJar key/value for each 2042 event.

And here is a shortcut to get all keys, select one and display the value, also working on Apple Wach

Try them without danger

ihf

@cvp The Shortcuts worked as expected.

cvp

@ihf Ok, I stop for today but tomorrow, I'll modify outline.py to update the DataJar via a started shortcut but I'll not yet remove the 2042 event update to be sure at least one thing works.
Thus, hear you tomorrow

but first of all, is this solution ok for you: key/value at DataJar store level?

cvp

@ihf it is obvious that Outline.py could also manage a keyed file in iCloud Drive like DataJar but you know problems we have had when an iCloud file was not downloaded locally and that we had to assure it was first downloaded before its update... Thus if this app takes care of this problem itself, it is good for me.

cvp

@ihf Please install shortcut Clipboard_to_DataJar before installing new version of outline.py

Then, install V01.36 and outline.versions with

Version V01.36
  - in addition to save outline in calendar event on 01 January 2042,
    copy outline¥content in clipboard and
    run Clipboard_to_DataJar shortcut to also save outline in DataJar store
    as pair key=outline name value=outline content

And test, of course. You will see that saving an outline will run a shortcut then comes back to script.
Saving also as 2042 event is still active, I'll remove this code when you decide that DataJar is the right solution.
I advice to not set an automatic save which is too frequent

ihf

@cvp I ran Outline and saved a modified outline. The script ran the Shortcut and hung Shortcuts and after a minute or 2 crashed Shortcuts. I found that the Data Jar beta had expired so I reinstalled it and verified it works and that my outlines are there.
However, when I run the Outlines as DataJar, the newly modified Outline is not present (even after several minutes). I guess it takes awhile for it to show up? Also, the Shortcut lists all my Data Jar contents, not just the outlines.

Traceback (most recent call last):
File "/private/var/mobile/Containers/Shared/AppGroup/228D1F3E-E592-4896-BBF5-D6EA74943D0D/Pythonista3/Documents/outline.py", line 3321, in tableview_cell_for_row
v = MyInputAccessoryView(row)
File "/private/var/mobile/Containers/Shared/AppGroup/228D1F3E-E592-4896-BBF5-D6EA74943D0D/Pythonista3/Documents/outline.py", line 503, in init
self.width = mv.get_screen_size()[0] # width of keyboard = screen
File "/private/var/mobile/Containers/Shared/AppGroup/228D1F3E-E592-4896-BBF5-D6EA74943D0D/Pythonista3/Documents/outline.py", line 1168, in get_screen_size
for window in UIApplication.sharedApplication().windows():
File "/var/containers/Bundle/Application/F461CDE3-9B4B-426C-8867-7562C21CF685/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/objc_util.py", line 801, in call
ordered_args = list(args) + [kwargs[key] for key in kwarg_order]
TypeError: 'builtin_function_or_method' object is not iterable

cvp

@ihf sorry but I don't really understand what you said and why do you post a traceback while you don't describe any script crash, only shortcuts crash

You said

Also, the Shortcut lists all my Data Jar contents, not just the outlines.

Which shortcut do you run? This one ?

Édit: you're right, my DataJar only contains outlines, thus....
how could we distinguish them? Or we could not add them at store level but a lower level?
Up to you to tell me, I didn't even know DataJar until yesterday

Ok, I've a solution: create an entry "Oulines" at store level and store there pairs outlin_name/content

Agree? If yes, I'have to change all, tell me quickly, almost gone away

ihf

@cvp Sorry about the traceback, I first got a Pythonista error but restarting it cleared it. In regard to Data Jar, I believe that the Outlines could be one key and that key can have values such as lists or dictionaries. The dictionary (or list) could presumably hold each separate outline. However, a bigger problem is that the modified outline has yet to show up on the Watch (it shows up on 2 iPads so it must be on iCloud).

cvp

@ihf check my previous post please, update while you typed

cvp

@ihf said

However, a bigger problem is that the modified outline has yet to show up on the Watch (it shows up on 2 iPads so it must be on iCloud).

I ask me if I didn't start DataJar on iPhone before?

Perhaps, you have to run DataJar on your iPhone to force the download of the iCloud file

cvp

@ihf Even if I can have a shortcut action "set Outlines.name outline_content", thus at level lower than top level of DataJar, I don't find an action to get list of keys of this Outlines level

ihf

@cvp What happens if you have a key in Data Jar that in turn has a value of a dictionary and the key values in the dictionary are the Outline names with their content. Then the shortcut to get a value based on key from Data Jar would get you the dictionary and the shortcut to get values from a dictionary would get you the outline text. Would that work?

cvp

@ihf Not sure I understand your question but I have solved I think to have a dictionary named Outlines at store level and dictionary contains pairs key=name value=data.

Outline.py will stay the same but the 3 shortcuts need to be updated.

First, Clean manually your outlines in your DataJar

1) the shortcut to run only once Outlines 2042 Events to DataJar

Run it and check your DataJar

2) the shortcut to select an outline and display its content, even on Apple Watch

Outlines as DataJar

3) the shortcut executed by outline.py

Clipboard_to_DataJar

ihf

@cvp It works! Thank you!

cvp

@ihf so i deserved my vacation 😀

ihf

@cvp many times over :-)

cvp

@ihf please note that I've been obliged to run DataJar on my iPhone to see the outlines on my watch. Not sure it will always be so

Tell me when you want I comment/remove the code to store also the outlines as 2042 event

ihf

@cvp I am using the latest version which is running the shortcut properly. I have an outline with a blank item at the end and if I try to delete it through the menu “delete with children” it hangs the program.

cvp

@ihf I just try the same without problem.

But, from last iOS update, I meet sometimes some hangs, even when starting the script.
Removing Pythonista from memory does not solve the problem but rebooting the iPad does the job.
Don't ask me why. I guess that without any Pythonista update, we will meet this kind of problem more frequently.

cvp

@ihf We have got a lot of crashes but never, as I remember, hangs. Is it reproducible after the reboot of the iDevice ?

cvp

@ihf said

I have an outline with a blank item at the end and if I try to delete it through the menu “delete with children” it hangs the program.

Did you retry after a reboot of the iPad?

ihf

@cvp It appears to be working now.

cvp

@ihf very quick post from my room in Italy: it works without any action or after a reboot?

ihf

@cvp I hope that you enjoyed (or are still enjoying) your vacation. Unfortunately, the script is freezing rather frequently now. I’m not even sure what a minimal failing case is. I thought it was when I tried to delete an empty last item but I have seen it freeze at other times as well. I know this is not what you wanted to hear.

cvp

@ihf two last days in vacation. As I said, I meet frequent freezings with Pythonista, even with other scripts or even at script start since last iOS update. Sincerely, I don't have any Idea how I could solve this kind of problems.

cvp

@ihf I'm back from vacation but I brought the Covid with me 😢, thus I'll need some time before I'm really back on the ScrollView version.

DavinE

@cvp said:

@ihf I'm back from vacation but I brought the Covid with me 😢, thus I'll need some time before I'm really back on the ScrollView version.

Get well soon @cvp

ihf

@cvp i’m so sorry to hear that. I hope you have a very mild case. Best wishes for a speedy recovery.

cvp

@ihf @DavinE thanks

cvp

@ihf I'm still very tired due to the Covid and I can't concentrate enough to dive back into the ScrollView version of outline.py yet. And then, I see the new version 18.0 of Pyto arriving and I say to myself sadly that we will probably not see any new version of Pythonista while the young age of the developer of Pyto gives hope for a long future for her app. I wonder if it is worth spending more time modifying outline.py in Pythonista or should I decide to (try to) convert to Pyto, despite the fact that I know it will require a very major effort. Just thinking about it is already tiring me out. Could you give me your sincere opinion, thanks.

ihf

@cvp Most importantly, get some rest! As to continuing with Pythonista or switching to Pyto, that is a tough call. As least to date my experience with Pyto has not been good. It fails more frequently than Pythonista. Of course, given some degree of continuing support there is hope that it will eventually be more reliable than Pythonista, which gets no support. I suppose if you are interested in making the transition to Pyto for your projects more generally, then Outline is a good way to do it since you already have the feature-set, logic, and most of the code. If you are asking whether I would like to continue using Outline for the foreseeable future, the answer is yes.

ihf

@cvp After doing a delete with children the app freezes.

cvp

@ihf I think that you already met this problem. And freezing seems to occur more frequently. I personally think this comes not from Pythonista nor the script itself but from an iOS update.
What do you think I can do when a new problem occurs even if I did not change anything, just cry.

cvp

@ihf Rememeber, I was able to play normally without freezing afTer rebooting my iPad, no other way, even restarting Pythonista did not work. Reason for which I think the problem comes from the iOS.

ihf

@cvp I am wondering if the frequent freeze up is somehow related to the code that was added for Shortcuts syncing? Perhaps it would be worth trying to turn that off and see if the problem goes away.

cvp

@ihf do you mean the code added for

Version V01.36
  - in addition to save outline in calendar event on 01 January 2042,
    copy outline¥content in clipboard and
    run Clipboard_to_DataJar shortcut to also save outline in DataJar store
    as pair key=outline name value=outline content

If yes, the code is only

        clipboard.set(self.file + '¥' + notes)
        url_scheme = 'shortcuts://x-callback-url/run-shortcut?name=Clipboard_to_DataJar&input=clipboard&x-success=pythonista://'
        webbrowser.open(url_scheme)

You could comment or remove it or do you want a particular new version for it?

ihf

@cvp I commented those lines out. I'll let you know if it helps.

cvp

@ihf thanks, good luck

sardigarmi44

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.
mobdro apk

cvp

@ihf sais

I commented those lines out. I'll let you know if it helps.

And? Still freezing?

on my side, I didn't have much time and energy to test the version with ScrollView a lot. Lots of problems: slower, crashes etc... What if now Pythonista doesn't run well under iPadOS 16? What else can we hope for? Are you still using outline.py?

ihf

@cvp In answer to your last question first, YES, I am still using outline. As far as freezing, it seems pretty stable since I commented out the lines related to the Shortcut and DataJar. Of course, I haven't tried to put them back to see if the freezing returns but it is a decent assumption that that was (at least one) cause of the problems I was seeing.

cvp

@ihf said

it is a decent assumption that that was (at least one) cause of the problems I was seeing

Unhappily, I don't see any other way to start the Data Jar app.

ihf

@cvp I guess it is worth testing to see what happens when the DataJar app is running already and when it is not.

cvp

@ihf Good idea, give me some news