omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Outliner with drag/drop reordering - part 2

    Pythonista
    9
    594
    181452
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • cvp
      cvp last edited by

      @ccc thanks for the advice

      1 Reply Last reply Reply Quote 1
      • cvp
        cvp last edited by 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?

        1 Reply Last reply Reply Quote 3
        • ihf
          ihf last edited by

          @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 2 Replies Last reply Reply Quote 2
          • cvp
            cvp @ihf last edited by 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 1 Reply Last reply Reply Quote 1
            • cvp
              cvp @ihf last edited by

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

              1 Reply Last reply Reply Quote 1
              • cvp
                cvp @cvp last edited by 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...

                1 Reply Last reply Reply Quote 0
                • ccc
                  ccc last edited by ccc

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

                  brew install python

                  cvp 1 Reply Last reply Reply Quote 1
                  • cvp
                    cvp @ccc last edited by

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

                    1 Reply Last reply Reply Quote 0
                    • ihf
                      ihf last edited by

                      @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 2 Replies Last reply Reply Quote 0
                      • cvp
                        cvp @ihf last edited by

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

                        1 Reply Last reply Reply Quote 0
                        • cvp
                          cvp @ihf last edited by

                          @ihf How do you call the script with argument?

                          1 Reply Last reply Reply Quote 0
                          • ihf
                            ihf last edited by

                            @cvp outline_viewer path_to_file

                            cvp 4 Replies Last reply Reply Quote 0
                            • cvp
                              cvp @ihf last edited by

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

                              1 Reply Last reply Reply Quote 0
                              • cvp
                                cvp @ihf last edited by 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.

                                1 Reply Last reply Reply Quote 0
                                • cvp
                                  cvp last edited by 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.

                                  1 Reply Last reply Reply Quote 0
                                  • cvp
                                    cvp @ihf last edited by 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

                                    1 Reply Last reply Reply Quote 0
                                    • cvp
                                      cvp @ihf last edited by

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

                                      1 Reply Last reply Reply Quote 0
                                      • ihf
                                        ihf last edited by

                                        @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 2 Replies Last reply Reply Quote 0
                                        • cvp
                                          cvp @ihf last edited by 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.

                                          1 Reply Last reply Reply Quote 0
                                          • cvp
                                            cvp @ihf last edited by

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

                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post
                                            Powered by NodeBB Forums | Contributors