• AlbertoAEC

    @cvp yes, load_framework is no needed.
    Thanks to both of you for your time

    posted in Pythonista read more
  • AlbertoAEC

    @cvp @JonB THANK YOU VERY MUCH!!

    It works perfectly.
    You can try the code using other content type like phone number.
    UITextContentTypeTelephoneNumber

    import ui
    from objc_util import *
    
    load_framework('UIKit')
    
    UITextContentTypeOneTimeCode=c_void_p.in_dll(c, 'UITextContentTypeTelephoneNumber')
    
    if UITextContentTypeOneTimeCode:
        UITextContentTypeOneTimeCode = ObjCInstance(UITextContentTypeOneTimeCode)
        
    tf = ui.TextField()
    tf.keyboard_type = ui.KEYBOARD_NUMBER_PAD
    tfo=tf.objc_instance.textField()
    print(tfo.setTextContentType_.encoding)
    
    my_method = ObjCInstanceMethod(tfo, 'setTextContentType_')
    my_method.sel_name='setTextContentType:'
    my_method.encoding=b'v@:@'
    my_method(UITextContentTypeOneTimeCode)
    
    tf.present('sheet')
    

    I couldn’t answer to you before because I was working.

    Best regards,
    Alberto

    posted in Pythonista read more
  • AlbertoAEC

    @mikael @cvp Thank you guys for the quick responses.

    As far as I understand, the value of the textContentType is a Structure of the type UITextContentType. I think is a internal constant but I don’t know how to get it from pythonista.

    Here is the official documentation:
    https://developer.apple.com/documentation/uikit/uitextcontenttype/2980930-onetimecode

    posted in Pythonista read more
  • AlbertoAEC

    Hello!
    I want to make a dialog that ask for a received sms code.
    The oficial form is by a parameter of the UITextField but in Pythonista there is not implemented yet. How can I make it by ObjC? I can not import UIKit by ObjCClass because Pythonista drops an error.

    https://stackoverflow.com/questions/39631168/automatic-otp-verification-in-ios

    Thanks you in advance.
    alberto

    posted in Pythonista read more
  • AlbertoAEC

    @JonB Thank you very much for your help. Your code works perfectly. I barely had used the numpy lib and you made me a lesson of use.
    I think too the error is caused by how the version interpret the ui.Path.

    @mikael change the “centro” variable that is the center point of the 3D figure

    self.centro = np.mat([500,400,0]).T
    

    posted in Pythonista read more
  • AlbertoAEC

    @JonB Both problems seems to be caused by the iOS version. Before update all works perfectly. You can try the code in your own device to try something.

    Automatic rotation is already coded in the script posted above. To try it you need to make a single tap at any point of the screen.
    I post you two screenshots. First at the initial position and the second one at random angle.
    http://i990.photobucket.com/albums/af26/AEC_railsim/9DE5F099-6B4A-40C5-A018-F8C93F338354_zpscu2jzikq.png~original

    http://i990.photobucket.com/albums/af26/AEC_railsim/C9367625-6273-4A69-8EA3-85DB20AC926A_zps82tytquh.png~original

    posted in Pythonista read more
  • AlbertoAEC

    @mikael Thank you, I have imagined that. I will wait for future version that fix it.

    @jgoalby said:

    Another point of reference for you. I have iOS 11 on my iPad still and it runs fine at 60fps. Sometimes goes down to 58fps when I rotate. I’ll update my iPad to iOS 12 soon and can confirm the slowness most likely.

    Yes, in previous version I had the same behaviour and it seems you will report the same slowness when you updates.

    @JonB said:

    Out of curiosity, have you tried writing this as numpy arrays? You can transform all of the points at the same time, should be a lot faster...

    Thank you for the info. The script was only for fun purpose and I didn’t though so much.

    posted in Pythonista read more
  • AlbertoAEC

    Hello!
    First of all is the first time i am writing in this forum. I want to say this app is incredible and thanks to everyone here because this site was so util for me.

    I am using this app for a year now and never I had any problems but yesterday I updated my iPad (2017 version) and script that uses Scene lib has execution problems.
    Is a script to represents some figures in 3D. Previously, with iOS 10 (iOS 11 doesn't convinced me) where I wrote the code, Pythonista ran it in 60 fps and visualice correctly a cube or a piramid (depending the uncomment lines).
    Now don't draw correctly the figures without change the code and runs in 14 fps.

    Do anyone have any idea? Thanks in advance

    from scene import *
    #import sound
    import random
    import math
    A = Action
    
    class Punto (SpriteNode):
        def __init__(self, r=10, *args, **kwargs):
            SpriteNode.__init__(self, 'shp:Circle', *args, **kwargs)
            self.size = (r, r)
            #self.color = random.choice(['white','yellow','blue','cyan','red','orange','purple','black','green'])
    
    class Linea (ShapeNode):
        def __init__(self, orig, dest, *args, **kwargs):
            ShapeNode.__init__(self, *args, **kwargs)
            self.line_path(orig, dest)
            self.stroke_color = '#ffffff'
            
        def line_path(self, orig, dest):
            x1,y1 = orig
            x2,y2 = dest
            self.position=((x2-x1)/2 + x1, (y2-y1)/2 + y1)
            path = ui.Path()
            path.line_width = 2
            path.move_to(x1,y2)
            path.line_to(x2,y1)
            self.path = path
    
        
    class Vector3D (object):
        def __init__(self, values):
            self.vector = values
            
        def to2D(self):
            elem = [[1, 0, 0],
                            [0, 1, 0]]
                            
            return (elem[0][0] * self.vector[0] + elem[0][1] * self.vector[1] + elem[0][2] * self.vector[2],
                            elem[1][0] * self.vector[0] + elem[1][1] * self.vector[1] + elem[1][2] * self.vector[2])
                            
        def rotateX(self, fi):
            rotMat = [[math.cos(fi), -math.sin(fi), 0],
                                [math.sin(fi), math.cos(fi), 0],
                                [0, 0, 1]]
            self.rotate(rotMat)
            
        def rotateY(self, fi):
            rotMat = [[math.cos(fi), 0, -math.sin(fi)],
                                [0, 1, 0],
                                [math.sin(fi), 0, math.cos(fi)]]
            self.rotate(rotMat)
            
        def rotateZ(self, fi):
            rotMat = [[1, 0, 0],
                                [0, math.cos(fi), -math.sin(fi)],
                                [0, math.sin(fi), math.cos(fi)]]
            self.rotate(rotMat)
        
        def rotate(self, rotMat):       
            self.vector = [rotMat[0][0] * self.vector[0] + rotMat[0][1] * self.vector[1] + rotMat[0][2] * self.vector[2],
                            rotMat[1][0] * self.vector[0] + rotMat[1][1] * self.vector[1] + rotMat[1][2] * self.vector[2],
                            rotMat[2][0] * self.vector[0] + rotMat[2][1] * self.vector[1] + rotMat[2][2] * self.vector[2]]
                            
        def center(self, centro):
            return Vector3D([self.vector[0] + centro[0], self.vector[1] + centro[1], self.vector[2] + centro[2]])
            
    class MyScene (Scene):
        def setup(self):
            self.angle = 0.005
            self.angleX = 0
            self.angleY = 0
            self.init_angle = self.angle
            self.centro = [500,400,0]
            #----CUBE-----
    #       self.p = [Vector3D([-100,-100,-100]),
    #                           Vector3D([100,-100,-100]),
    #                           Vector3D([100,100,-100]),
    #                           Vector3D([-100,100,-100]),
    #                           Vector3D([-100,-100,100]),
    #                           Vector3D([100,-100,100]),
    #                           Vector3D([100,100,100]),
    #                           Vector3D([-100,100,100])]
    
            #-----PIRAMID-----
            self.p = [Vector3D([-100,-100,-100]),
                                Vector3D([100,-100,-100]),
                                Vector3D([100,100,-100]),
                                Vector3D([-100,100,-100]),
                                Vector3D([0,0,100]),
                                Vector3D([0,0,100]),
                                Vector3D([0,0,100]),
                                Vector3D([0,0,100])]
                                
            self.puntos = []
            for i,punto in enumerate(self.p):
                self.puntos.append(Punto(position=punto.to2D()))
                self.add_child(self.puntos[i])
            
            self.uniones = []
            for j in range(0,4):
                self.uniones.append(Linea(self.p[j].center(self.centro).to2D(), self.p[j+4].center(self.centro).to2D()))
                
            for j in range(0,3):
                self.uniones.append(Linea(self.p[j].center(self.centro).to2D(), self.p[j+1].center(self.centro).to2D()))    
            self.uniones.append(Linea(self.p[0].center(self.centro).to2D(), self.p[3].center(self.centro).to2D()))
    
            for j in range(4,7):
                self.uniones.append(Linea(self.p[j].center(self.centro).to2D(), self.p[j+1].center(self.centro).to2D()))    
            self.uniones.append(Linea(self.p[4].center(self.centro).to2D(), self.p[7].center(self.centro).to2D()))
    
            for uni in self.uniones:
                self.add_child(uni)
            
        def did_change_size(self):
            pass
        
        def update(self):
            for p in self.p:
                #p.rotateX(self.angle)
                p.rotateY(self.angleX)
                p.rotateZ(self.angleY)
            
            for i,punto in enumerate(self.puntos):
                punto.position = self.p[i].center(self.centro).to2D()
            
            for j in range(0,4):
                self.uniones[j].line_path(self.puntos[j].position, self.puntos[j+4].position)
                
            for j in range(0,3):
                self.uniones[j+4].line_path(self.puntos[j].position, self.puntos[j+1].position)
            self.uniones[7].line_path(self.puntos[0].position, self.puntos[3].position)
            
            for j in range(4,7):
                self.uniones[j+4].line_path(self.puntos[j].position, self.puntos[j+1].position)
            self.uniones[11].line_path(self.puntos[4].position, self.puntos[7].position)
    
        
        def touch_began(self, touch):
            #self.angle = 0
            self.move = 0
            x, y = touch.location
            self.inicio = {'x':x, 'y':y}
        
        def touch_moved(self, touch):
            self.move = 1
            x, y = touch.location
            x = abs(self.inicio['x']) - abs(x)
            y = abs(self.inicio['y']) - abs(y)
            self.angleX = math.radians(x)/50
            self.angleY = math.radians(y)/50
        
        def touch_ended(self, touch):
            #self.angle = self.init_angle
            if self.move == 1:
                self.angleX = 0
                self.angleY = 0
            else:
                self.angleX = self.angle
                self.angleY = self.angle
            
    
    if __name__ == '__main__':
        run(MyScene(), show_fps=True)
    

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!