• cvp

    @Karina I suppose that you wanted to answer to @ccc 😀

    posted in Pythonista read more
  • cvp

    @OkieWolf .text_color = 'red'

    posted in Pythonista read more
  • cvp

    @OkieWolf already done here

    posted in Pythonista read more
  • cvp

    @cvp said:

    Nicer (not Pythonically speaking) than @mikael 's one

    I was only humorous and you're to kind to upvote my post.

    posted in Pythonista read more
  • cvp

    @Bumbo-Cactoni Nicer (not Pythonically speaking) than @mikael 's one 🙄 and ok for all your TextFields, with buttons in keyboard, not in view

    from   objc_util import *
    import ui
    
    def key_pressed(sender):
            import ui
            from objc_util import ObjCClass
            tv = sender.objc_instance.firstResponder()  # associated TextView
            # get actual cursor position                    
            cursor = tv.offsetFromPosition_toPosition_(tv.beginningOfDocument(), tv.selectedTextRange().start())
            tv.insertText_(sender.title)    
    
    class MyView(ui.View):
        def __init__(self, pad, *args, **kwargs):
            #super().__init__(self, *args, **kwargs)    
            self.width = ui.get_screen_size()[0]            # width of keyboard = screen
            self.background_color = 'lightgray'#(0,1,0,0.2)
            self.h_button = 32  
            self.pad = pad
            
            # build buttons
            for pad_elem in self.pad:
                button = ui.Button()                                    # Button for user functionnality
                button.name = pad_elem['key']
                button.background_color = 'white'           # or any other color
                button.corner_radius = 5        
                button.font = ('<system>',self.h_button - 8)
                button.title = pad_elem['key']
                button.tint_color = button.title
                button.action = key_pressed
                retain_global(button) # see https://forum.omz-software.com/topic/4653/button-action-not-called-when-view-is-added-to-native-view
                self.add_subview(button)    
            self.layout()       
    
        def layout(self):
            import ui
            # supports changing orientation
            dx = 8
            dy = 2
            x0 = 15
            y0 = 10
            dx_middle = 25 
            y = y0
            x = x0
            w_button = (ui.get_screen_size()[0] - 2*x0 - 17*dx - dx_middle)/18
            for pad_elem in self.pad:
                nw = pad_elem.get('width', 1)
                wb = w_button*nw + dx*(nw-1)
                if (x + wb + dx) > self.width:
                    y = y + self.h_button + dy
                    x = x0
                button = self[pad_elem['key']]
                xb = x + dx_middle if (x+wb) > self.width/2 else x
                button.frame = (xb,y,wb,self.h_button)
                if button.title != '':
                    font_size = self.h_button - 8
                    while True:
                        d = ui.measure_string(button.title,font=(button.font[0],font_size))[0]+4
                        if d <= wb:
                            break
                        font_size = font_size - 1           
                button.font = (button.font[0],font_size)
                x = x + wb + dx
            self.height = y + self.h_button + dy    
        
    @on_main_thread 
    def AddButtonsToPythonistaKeyboard(pad=None):
        if not pad:
            pad = [
            {'key':'red','width':2},
            {'key':'green','width':2},
            {'key':'blue','width':2}]   
        # create ui.View for InputAccessoryView above keyboard
        v = MyView(pad)                                             # view above keyboard
        vo = ObjCInstance(v)                                    # get ObjectiveC object of v
        retain_global(v) # see https://forum.omz-software.com/topic/4653/button-action-not-called-when-view-is-added-to-native-view
        return vo
    
    if __name__ == '__main__':  
        vo = AddButtonsToPythonistaKeyboard()
        
        v = ui.View()
        v.frame = (0,0,400,400)
        v.background_color = 'white'        
        tf1 = ui.TextField(frame=(10,50,200,32))
        ObjCInstance(tf1).textField().setInputAccessoryView_(vo)    
        v.add_subview(tf1)
        tf2 = ui.TextField(frame=(10,150,200,32))
        ObjCInstance(tf2).textField().setInputAccessoryView_(vo)    
        v.add_subview(tf2)
        v.present('sheet') 
    

    posted in Pythonista read more
  • cvp

    To get this file path, share a song to this small Pythonista script

    import appex
    fil = appex.get_file_path()
    print(fil)
    

    posted in Pythonista read more
  • cvp

    if you configure your NAS as SMB server in the standard Files app,
    like here

    and, in the left files browser of Pythonista, you open the Music folder of the NAS as external folder, like here

    you would be able to access your songs via a script like

    import os
    downloads_path = '/private/var/mobile/Library/LiveFiles/com.apple.filesystems.smbclientd/LTRovAMusique/Soirée/'
    os.chdir(downloads_path)
    filelist = os.listdir(downloads_path)
    for file in filelist:
        print(file) 
    

    N.b. The name LTRovAMusique is generated by Apple

    posted in Pythonista read more
  • cvp

    @ihf I think (and hope) he will.
    See "What's New in Pythonista" page in the documentation, where @omz says «If you’ve been using the beta, you may notice that the “Siri Shortcuts” feature is missing from this release. It’s still planned, but the beta implementation was based on already-outdated iOS 12 APIs, and I want to take a little more time for a version that makes use of new iOS 13 features like custom parameters. Thanks for your patience! There’s still a lot of new stuff to discover in this update.»

    posted in Pythonista read more
  • cvp

    @ihf known problem, I think, see here

    posted in Pythonista read more
  • cvp

    You are not alone, see here

    posted in Pythonista read more
  • cvp

    @vignesh it seems that if you want different colors per face, you have to play with triangles.
    Then you could generate two triangles per square face, both with same color, like

        for i in range(0,6):
          j = 6 + i*4
          # first triangle of square face
          indexes2 = [indexes[j],indexes[j+1],indexes[j+2]]
          indexes_array2 = (c_int*len(indexes2))(*indexes2)
          datIndexes2 = ObjCClass('NSData').dataWithBytes_length_(indexes_array2,sizeof(indexes_array2))
          e = ObjCClass('SCNGeometryElement').geometryElementWithData_primitiveType_primitiveCount_bytesPerIndex_(datIndexes2,0,1,sizeof(c_int))
          e2.append(e)
          rgb = getrgb(colors[i])
          r,g,b = tuple(c/255.0 for c in rgb)
          Material = SCNMaterial.material()
          Material.contents =           ObjCClass('UIColor').colorWithRed_green_blue_alpha_(r,g,b,1.0)
          Materials.append(Material)
          
          # 2nd triangle to create a square face
          indexes2 = [indexes[j+2],indexes[j+3],indexes[j]]
          indexes_array2 = (c_int*len(indexes2))(*indexes2)
          datIndexes2 = ObjCClass('NSData').dataWithBytes_length_(indexes_array2,sizeof(indexes_array2))
          e = ObjCClass('SCNGeometryElement').geometryElementWithData_primitiveType_primitiveCount_bytesPerIndex_(datIndexes2,0,1,sizeof(c_int))
          e2.append(e)
          # with same color
          Materials.append(Material)
          
        geometry2 = ObjCClass('SCNGeometry').geometryWithSources_elements_([s],e2)  
        geometry2.setMaterials_(Materials)
        geometry2_node = SCNNode.nodeWithGeometry_(geometry2)
    

    posted in Pythonista read more
  • cvp

    @vignesh but geometry2 is still composed of triangles due to

        e = ObjCClass('SCNGeometryElement').geometryElementWithData_primitiveType_primitiveCount_bytesPerIndex_(datIndexes,4,8,sizeof(c_int)) 
    

    posted in Pythonista read more
  • cvp

    @vignesh and

        #e = ObjCClass('SCNGeometryElement').geometryElementWithData_primitiveType_primitiveCount_bytesPerIndex_(datIndexes,4,8,sizeof(c_int))
        e = ObjCClass('SCNGeometryElement').geometryElementWithData_primitiveType_primitiveCount_bytesPerIndex_(datIndexes,4,6,sizeof(c_int)) 
    

    posted in Pythonista read more
  • cvp

    @vignesh and

        #for i in range(0,8):
        #  j = 8 + i*3
        for i in range(0,6):
          j = 6 + i*4
          #indexes2 = [indexes[j],indexes[j+1],indexes[j+2]]
          indexes2 = [indexes[j],indexes[j+1],indexes[j+2],indexes[j+3]]
    

    posted in Pythonista read more
  • cvp

    @vignesh said:

    0,3,2,1# bottom face

    It seems that some lines have a comma missing

    0,3,2,1, # bottom face
    
    

    posted in Pythonista read more
  • cvp

    @PinhoBD strange. In + / images / files, I see my thousands images, after some time, I agree

    posted in Pythonista read more
  • cvp

    @Bumbo-Cactoni Please try this, for the fun

    from   objc_util import *
    import ui
    
    UIColor = ObjCClass('UIColor')
    NSMutableAttributedString = ObjCClass('NSMutableAttributedString')
    UIFont = ObjCClass('UIFont')
    ansi_colors = {'[91m':'red', '[92m':'green', '[93m':'yellow', '[94m':'mediumpurple', '[95m':'purple', '[96m':'cyan', '[97m':'lightgray', '[98m':'black'}
    
    @on_main_thread
    def myprint(txt):
        from objc_util import ObjCClass
        win = ObjCClass('UIApplication').sharedApplication().keyWindow()
        main_view = win.rootViewController().view() 
        ret = ''
        font = UIFont.fontWithName_size_('Menlo', 15)
        def analyze(v):
            for tv in v.subviews():
                if 'OMTextView' in str(tv._get_objc_classname()):
                    su = tv.superview()
                    if 'OMTextEditorView' in str(su._get_objc_classname()): 
                        continue
                    # tv = console is a OMTextView baseClass = UIScrollView
                    #print(dir(tv))
                    txt_list = txt.split('\033')
                    for ele in txt_list:
                        if ele == '':
                            continue
                        #print('ele',ele)
                        c = ansi_colors[ele[:4]]
                        t = ele[4:]
                        color = UIColor.colorWithRed_green_blue_alpha_(*ui.parse_color(c))
                        attr_str = NSMutableAttributedString.alloc().initWithString_(t)             
                        attributes = {ns('NSColor'):color, ns('NSFont'):font}
                        attr_str.setAttributes_range_(attributes, NSRange(0, len(t)))
                        tv.appendAttributedText_(attr_str)
                ret = analyze(tv)
                if ret:
                    return ret
        ret = analyze(main_view)
    
    if __name__ == '__main__':
        print()
        myprint("\033[91m {} \033[94m {}".format('this is red','this is mediumpurple')) 
    

    posted in Pythonista read more
  • cvp

    @donnybahama said:

    Can I send keystrokes to an app?

    I don't understand the question, sorry

    posted in General Discussion read more
  • cvp

    @donnybahama said:

    Can I use Pythonista (and its GUI to write WatchOS apps?

    No

    posted in General Discussion read more
Internal error.

Oops! Looks like something went wrong!