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.


    Action.call() bugged for callables expecting parameters ?

    Pythonista
    2
    3
    2377
    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.
    • zipit
      zipit last edited by zipit

      Hi,

      I cannot figure out how to use Action.call() properly on a function/ method that does expect the node and progress parameter as described in the docs.

      When I do implement the following:

          def do(node, progress):
             pass
      
          SomeNode.run_action(Action.call(do), 1)
      

      The debugger complains that the second parameter (duration) is not a string (which is a bit weird) and also that do() is being called passing no parameters while it does expect two parameters. The following snippet shows that do() is being called but without node and duration being passed.

      def do(self, *args, **kwargs):
      	print(1)
      	print (args)
      	print (kwargs)
      
      SomeNode.run_action(Action.call(do), str(1))
      

      What am I doing wrong ? I have not found any examples of Action.call() for a callable that does expect parameters here on the forums and I do not understand the docs (or the docs are wrong/ the method is buggy). Thanks for your help.

      Cheers,
      zipit

      Edit: Actual code, I am using a custom node class, which might matter.

      from scene import *
      from ui import Path
      import Data as d
      import random
      
      
      class BaseTile(Node):
      	'''Draws a rounded rectangle.
      	'''
      	def __init__(self, size, color, position=(0,0)):
      		self.path = Path.rounded_rect(0.0,
      									  0.0,
      									  size[0], 
      									  size[1], 
      									  d.tile_corner_radius)
      		self.position = position
      		self.add_child(ShapeNode(self.path, color))
      		
      								
      class NumericTile(BaseTile):
      	'''Draws a number on top of the BaseTile based on
      	its value field. Also handdles its background color.
      	based on its value and its size.
      	'''
      	def __init__(self, position, indices):
      		self.vid = random.randrange(d.tile_maxpower_new)
      		super().__init__(d.tile_size, 
      						 d.colors[0]['tile_bg'][self.vid], 
      						 position)
      		self.indices = indices
      		self.value = d.tile_values[self.vid]
      		self.number = LabelNode('', (d.tile_font,40))
      		self.number.color = d.colors[0]['tile_fg']
      		self.add_child(self.number)
      		self.SetText()
      		self.run_action(
      			Action.call(self.AnimationAddNode), str(1))
      	
      	def SetText(self):
      		self.number.text = '{0}'.format(self.value)
      		
      
      	def AnimationAddNode(self, *args, **kwargs):
      		print(1)
      		print (args)
      		print (kwargs)
      
      1 Reply Last reply Reply Quote 0
      • omz
        omz last edited by

        @zipit The duration of the action needs to be passed to the Action.call method, not to run_action. The reason it's complaining about 1 not being a string is that the second parameter of run_action is an optional key parameter (in short, it can be used to remove an action later).

        So the code should be something like:

        some_node.run_action(Action.call(do, 1.0))
        
        1 Reply Last reply Reply Quote 0
        • zipit
          zipit last edited by

          Doh. Stupid me. Thanks for the quick help.

          Cheers.

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