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.


    SFSymbols?

    Pythonista
    7
    39
    14024
    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.
    • mikael
      mikael @JonB last edited by

      @JonB, looks to me like imageAsset is readonly.

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

        @JonB

        i.objc_instance.setImageAsset_(o.imageAsset()) 
        

        gives

        TypeError: expected 5 arguments, got 1 
        
        JonB 1 Reply Last reply Reply Quote 0
        • mikael
          mikael last edited by mikael

          Ok, a quick and dirty symbol browser here. Expects to have the list of symbol names linked above in the same directory.

          Tap on row to copy symbol name to clipboard. Tap on ”Thin” to cycle through different weights. Symbols restricted by Apple for a specific app are shown in orange.

          Demo

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

            @mikael said:

            quick and dirty

            are reserved (by me) words, you'll have to pay royalties 😂

            And, your code is never dirty... while mine, yes

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

              @cvp strange, works on my ios9 ipad. ill have to play around with my ios13.

              mikael 1 Reply Last reply Reply Quote 0
              • mikael
                mikael @JonB last edited by

                @JonB, must have changed since iOS 9? As said, imageAsset is now marked as readonly in the docs, and there is this statement in the first paragraph of UIImage:

                ”Image objects are immutable, so you always create them from existing image data, such as an image file on disk or programmatically created image data.”

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

                  As a half-accidental result, you can use the file linked above as a package:

                  import sfsymbol
                  
                  img = sfsymbol.SymbolImage('arrow.right.to.line')
                  

                  There are three optional parameters:

                  • point_size - Integer font size
                  • weight - Font weight, one of sfsymbol.ULTRALIGHT, THIN, LIGHT, REGULAR, MEDIUM, SEMIBOLD, BOLD, HEAVY, BLACK
                  • scale - Size relative to font size, one of SMALL, MEDIUM, LARGE
                  cvp 1 Reply Last reply Reply Quote 1
                  • cvp
                    cvp @mikael last edited by

                    @mikael if you call your code dirty again, I promise to stop writing programs 😂

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

                      @mikael thanks for this, excellent. (If only it had a fuzzy search function... Just if you feel bored...)

                      mikael 1 Reply Last reply Reply Quote 0
                      • mikael
                        mikael @pulbrich last edited by mikael

                        @pulbrich, others, any suggestions for a fuzzy search? fuzzywuzzy is good, but I would like to avoid requiring an extra install. difflib.get_close_matches results are highly unintuitive.

                        Is there something easy to use provided by iOS?

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

                          @mikael you could try FuzzyFinder in 10 lines of Python

                          Cheers,

                          1 Reply Last reply Reply Quote 1
                          • pulbrich
                            pulbrich last edited by

                            I would go with @TPO ‘s idea, perfectly enough for the purpose.

                            mikael 1 Reply Last reply Reply Quote 0
                            • mikael
                              mikael @pulbrich last edited by

                              @pulbrich, @TPO, thanks. Search now included, see the updated picture above.

                              Usability is not 100% - for some reason textfield.end_editing() does not hide the keyboard, at least on my phone.

                              cvp 1 Reply Last reply Reply Quote 1
                              • pulbrich
                                pulbrich last edited by

                                @mikael Many, many thanks! Perfect now!

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

                                  @mikael said:

                                  for some reason textfield.end_editing() does not hide the keyboard

                                  Same on my iPad mini 4 (iOS 13 + Pythonista beta)
                                  There is a kind of flicking, I think that the keyboard is dismissed and then comes back.

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

                                    FWIW:

                                    from ui import *
                                    from objc_util import *
                                    uiimage=ObjCClass('UIImage')
                                    v=Image.named('test:Lenna')
                                    u=uiimage.systemImageNamed_('lessthan.circle')
                                    v.objc_instance._setImageAsset_(u.imageAsset())
                                    

                                    Leading underscore did the trick, iPadOS 13.1.3.
                                    Maybe not the most future proof, but does the job...

                                    cvp mikael 2 Replies Last reply Reply Quote 0
                                    • cvp
                                      cvp @JonB last edited by

                                      @JonB As usual, you're the 🤴

                                      1 Reply Last reply Reply Quote 0
                                      • mikael
                                        mikael @JonB last edited by

                                        @JonB, thanks. Intuitively this seems like it should be faster and more efficient than going via the PNG conversion.

                                        But when I went to test the performance I ran into a couple of issues with the asset approach:

                                        • Resulting image size is dependent on the size of the original ui.Image created.
                                        • Both the original and ”asset-applied” images are retained in the ui.Image somehow, and for example ButtonItems do not really handle that well.

                                        See below couple of example images. First one uses a too-large initializing picture (Lenna), the second too small one (triangle arrow icon), which you can see presented in the title area.

                                        Break 1
                                        Break 2

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

                                          @mikael your module now crashes with

                                          Traceback (most recent call last):
                                            File "/private/var/mobile/Containers/Shared/AppGroup/668A7D98-7216-47ED-917D-AA0B6173167E/Pythonista3/Documents/MesTests/sfsymbol.py", line 233, in <module>
                                              data_source = symbol_table.data_source = SymbolSource(root, symbol_table)
                                            File "/private/var/mobile/Containers/Shared/AppGroup/668A7D98-7216-47ED-917D-AA0B6173167E/Pythonista3/Documents/MesTests/sfsymbol.py", line 76, in __init__
                                              image=SymbolImage('arrow.left', 8, weight=THIN),
                                            File "/private/var/mobile/Containers/Shared/AppGroup/668A7D98-7216-47ED-917D-AA0B6173167E/Pythonista3/Documents/MesTests/sfsymbol.py", line 27, in SymbolImage
                                              conf = UIImageSymbolConfiguration.configurationWithConfiguration_and_(
                                            File "/var/containers/Bundle/Application/34BAEE1A-BC33-4D6F-A0C1-B733E4991F31/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/objc_util.py", line 445, in __getattr__
                                              cached_method = ObjCClassMethod(self, attr)
                                            File "/var/containers/Bundle/Application/34BAEE1A-BC33-4D6F-A0C1-B733E4991F31/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/site-packages/objc_util.py", line 752, in __init__
                                              raise AttributeError('No class method found for selector "%s"' % (self.sel_name))
                                          AttributeError: No class method found for selector "configurationWithConfiguration:and:"
                                          
                                          mikael 1 Reply Last reply Reply Quote 0
                                          • mikael
                                            mikael @cvp last edited by

                                            @cvp, yes, just noticed. iOS 14 must’ve changed it. Will take a look.

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