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.


    Custom Attributes - PYUI files. Identifying the sender

    Pythonista
    attr custom sender pyui attributes
    2
    3
    3374
    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.
    • Phuket2
      Phuket2 last edited by Phuket2

      I am not sure how many know you can put something like

      {
      	'cmd':self.sayhello(2, 1)
      }
      Ok, the feature was to dynamically add attrs to the object. You can see internally, eval is being called.
      
      

      This syntax is per the method for loading the pyui as described in this post. You can also do it for normally loading pyui files.

      Anyway, with the above you are calling a method in your own custom class in this case with 2 params. It all works, when the object is created the method is called along with the params.

      I wondered if there was some Python trickery I could do to pass the object or object name to the method. I meaning without hard coding in the name of the object to pass as a parameter.

      Maybe, there is something that can be done in the method that is being called to determine the object that's being evaluated.

      I have played around with it, I can't figure it out, not something I would try to do.

      I understand this is a bit of a stretch, but seems most things can be solved here 😱😁😁😁

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

        @Phuket2 I am a bit lost... Where does this code above go? Into ui.load_view.bindings dict? Or do you put that code into the .pyui file itself? Normal execution of that code uses the CALL_FUNCTION bytecode but does not do an eval().

        import dis
        
        def bubba():
            return {'cmd':self.sayhello(2, 1)}
        
        print(dis.dis(bubba))
        
        Phuket2 1 Reply Last reply Reply Quote 0
        • Phuket2
          Phuket2 @ccc last edited by Phuket2

          @ccc , sorry for not being clear. It goes into the pyui file. Screenshot, below. Sorry, I left it full screen so it's clear to others also.

          Edit: oops, that is creating a dynamic attr in pic. But it's the same place / same idea.

          The eval is called on the CustomAtrributes, in the ui.py function _view_from_dict

          Sorry a few edits: I rushed this. But the self.sayhello(1,2) evals() to calling a method of that name in our class. You can leave off the self and call a function, but I think from memory you have to return True, otherwise warnings are printed.
          This seems very close to what the action method does , when it's defined inside the pyui file.

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