• Phuket2

    In the example above, if you say want to set the action attr of a ui.Button in the ui Designer, you cant refer to self to access a method in your class. In the case of the example above, the class is named MyClass, so if you had a method in MyClass called hit, in the ui Designer in the action property of the btn you would enter MyClass.hit, not self.hit.
    If your action is a func in the same source file you would do as normal, just enter the name of the func.

    I cant remember if it was always like this. It's possible that @omz made some changes to prevent injection attacks. I thought before that self.method worked. But maybe I am dreaming.

    Regardless many things can be done with pyui files. It's worth searching the forum.

    posted in Pythonista read more
  • Phuket2

    @Sabarblatoe, not sure you are interested or not. Below is some code that reads a pyui/UIFile into a class and class behaves as if it is a Custom ui View. I think its handy for many reasons and it can make life a little easier (Maybe not in all cases). But in the demo below you can see you can code directly against the view rather than the pyui file being a subview of another view. This has been posted on the forum many times before.
    Anyway, maybe its interesting to you.

    @omz do you have any plans to add this functionality directly into API? I know I have asked before. But I still believe this would be a great addition to the API. It would also then be documented, I think a lot of ppl would use this approach to loading UIFiles if it was documented and built in.

    import ui
    
    
    class PYUILoader(ui.View):
        # this acts as a normal Custom ui.View class
        # the root view of the class is the pyui file read in
        # from @JonB
        def WrapInstance(obj):
            class Wrapper(obj.__class__):
                def __new__(cls):
                    return obj
            return Wrapper
    
        def __init__(self, pyui_fn, *args, **kwargs):
            bindings = globals().copy()
            bindings[self.__class__.__name__] = self.WrapInstance()
    
            ui.load_view(pyui_fn, bindings)
    
            # call after so our kwargs modify attrs
            super().__init__(*args, **kwargs)
    
    
    class MyClass(PYUILoader):
        '''
        This class acts the same as a ui Custom View would even though its
        been loaded in from a pyui file.
    
        *** NOTE ***
        You have to do 2 things for this to work correctly.
    
        1. pass the file name of your .pyui file when creating the class
        2. in the ui Designer, you need to set the 'Custom View Class' field in the
           Inspector to the name of this class's name. In this case 'MyClass'
    
           - Finding the 'Custom View Class' in the ui Designer
           Make sure you are at the root level, i.e not in a subview
           In the ui Designer, tap anywhere to make sure nothing is selected,
           Then you will see the 'Size Presets' in the Inspector. Directly
           below you will see the 'Custom View Class' field.
        '''
        def __init__(self, pyui_fn, *args, **kwargs):
            super().__init__(pyui_fn, *args, **kwargs)
            self.update_interval = 1
    
        def did_load(self):
            print('view loaded')
    
        def layout(self):
            print('in layout')
    
        def update(self):
            print('update fired')
    
    if __name__ == '__main__':
        f = (0, 0, 480, 600)
        v = MyClass('MyUIFile.pyui', frame=f)
        v.present(style='sheet')
    

    posted in Pythonista read more
  • Phuket2

    @mikael, thanks for your reply. As regards to the error I am having, I am pretty sure somehow I have corrupted something. But at the moment my home internet is on and off like a yoyo :( Its cable issues in the streets. So its not so easy to do app downloads etc to reset. I will have to wait until they sort it out, again!

    I like your example notice! But it really does illustrates something. How you intend your lib to be used. I know its going to seem stupid, but the name of the Lib does says it all. I didn't really get that somehow. I was looking at your lib more from a macro point of view rather than a micro POV.
    I am not sure I have explained that clearly or not. But as I say, I will keep trying to get my head around it. In terms of doing animated views vrs PowerPoint slides concept. One could say they are they same or very similar(but they are not). I think the great thing is that your lib/module can support either direction. At least I think that...

    posted in Pythonista read more
  • Phuket2

    A lot of articles appearing today talking about ios12 and the relevant MacOS in terms of being able to run iOS apps on Mac. Not sure if these are unfounded rumours or not. This is not the first time this has been in the news, but it appears the speculation is growing. For me, I will keep my fingers crossed that they do it. Its not just being able to run Pythonista the editor on the Mac, but also the programs you write. I know the last sentence sounds strange, but thats the real point in my view. Its not just to have a larger screen with a external keyboard, its the ability to run your Pythonista apps/scripts on a Mac.
    Just my personal view for my circumstance.

    posted in General Discussion read more
  • Phuket2

    @mikael , ok no problems. I just misunderstood your post. I started having problems yesterday (I think after I updated to 11.2.5) about script not being defined. Strange, the trace back is below. I didn't have much time to found out the cause. The only thing i can think of is how I copied the Scripter code into Pythonista (I did a drag and drop copy from a clone of the repo in Working Copy). I am not really sure. Anyway, I am not really reporting it here as I need to try more things first.
    Anyway, when I come across this issue, I was just going to make a view that used your wobble script to wobble a ui.Button at regular interval (to draw attention to it). I was just interested to see how this all would work out. I.e the containing view having and update method as well as calling the script on the container views update fire. I assume it would work.
    As far as I can see there is no way for a script to re-animate given a duration/pause(maybe I am wrong) but I think its an interesting point, as some elements in a ui, you would like them to continue to animate forever, but with a pause between the animations so its not over the top. Even better the pause could have a ease function. Anyway, I am just talking giving my ideas. I dont expect anything from you, its your project.
    I come from the dummies side of things, meaning the less I need to know about using a Lib the better. But I do understand that libs are also written with a certain expectation that the user of the Lib/module has a degree of understanding of some primitives core to the lib.

    Traceback (most recent call last):
    File "/private/var/mobile/Containers/Shared/AppGroup/3533032E-E336-4C25-BBC4-112A6BF2AF75/Pythonista3/Documents/site-packages-3/scripter/scripter-demo.py", line 90, in <module>
    @script
    NameError: name 'script' is not defined

    posted in Pythonista read more
  • Phuket2

    @mikael , thanks for the update. It appears that maybe you haven't pushed the last update to the repo. Last update appears to be the corrections for the rotation.

    Yes I understand your comments about self animating views (so to speak). Over the last few days I haven't had much time to experiment all though I do some stuff each day. But look for whatever reason, animations scare the hell out of me :) Just a mental block about the math. Eg. Easy for me to get confused. So its slow going for me. But, I am going to stick at it. The prospect of being able to construct views like this and other View animations on this site is exciting to me.

    Anyway, I will keep working on it. I have always been a little suprised that some of these more tantalising animations/transitions views have not shown up in Pythonista apps. Aka the feeling you are using a very polished native app. Its not a criticism, I just think its not a real focus for a lot of Python programmers (UI). Maybe I need to be burnt at the stake for that comment :)

    posted in Pythonista read more
  • Phuket2

    @mikael , thanks! Rotating examples working now. Maybe its not a big deal, but in the demo, maybe some of the btns like 'roll to' should have the button's enable property set to False until its finished animating. Look its a small issue, But more than likely in an implementation you would want this behaviour.

    posted in Pythonista read more
  • Phuket2

    Some how its not said directly here ( at least from what I can see). But normally in StaSh, pip remove 'module' works. Granted, i does not remove dependencies that were installed. Anyway, if I screw up something like this, then In StaSh, I will do pip remove <package>, then do pip list to see if it has been removed. Then do a hard restart on Pythonista. In the past I have forgotten to do a hard restart, after using the pip remove cmd. Even though it looks like the new version is installed, the old module is still in memory and being used. Well at least that has been my experience

    posted in Pythonista read more
  • Phuket2

    @cvp , ok thanks. There is something wrong though, if I use it multiple times I can get it to freeze. Hopefully someone will spot the problem

    posted in Pythonista read more
  • Phuket2

    Regarding the pythonista_info function I posted above. I have since had a few freezes with using it (Pythonista becomes unresponsive) and a hard restart is required.
    Ok, I found the original post, its over 2 years old. @ccc , @JonB and @dgelessus all helped out on this post. It would be nice if anyone could see why it would be intermittently freezing now. I can imagine quite a few things have changed in 2 years :). Anyway, it would nice to have it stable or an equivalent for easily getting your devices info, to be able to paste into posts if needed. I realise the dict keys could be better if they are to be used as part of the output.
    @cpv, have you had a freeze using it?

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!