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.


    How to reference a switch made with ui Editor?

    Pythonista
    ui.switch ui.view
    2
    7
    3837
    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.
    • Frankson909
      Frankson909 last edited by Frankson909

      Im playing around with the ui editor. So I made a script and I want to give a switch, which I placed with the editor, a function when the switch is flicked (true/false). If I'm using the action field in the editor, the function is called every time, doesn't matter if I switched on or of. Somehow I cannot figure out how to reference exactly this switch im there where more than on. Can somebody explain it in a easy way?

      def switched(sender):
      if sender.value == True:
      iota_ticker(sw)

      #ui.load_view('tickerV2').present('sheet') < I would like to use this view with a switch

      sw = ui.Switch(action = switched)
      sw.present('sheet')

      cvp 1 Reply Last reply Reply Quote 0
      • cvp
        cvp @Frankson909 last edited by cvp

        @Frankson909 Did you define the switch and its action in the UI Editor?
        Like this

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

          yes I did. But can you give me a line of code to your example? Somehow I could not figure out to reference to my switch. I tried everything. And: if i put my function to the actions field, the function is fired every switch event but I just want thet if true. So I left the action field in the editor empty and put the action to my code.

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

            import ui

            v = ui.load_view()
            v.present('sheet')

            def switched_func(sw):
            if ui.Switch('switched').value == True:
            print('switch is switched')
            else:
            print('no')

            This is not working. Why?

            Warning: Could not bind action: name 'switched_func' is not defined

            cvp 2 Replies Last reply Reply Quote 0
            • cvp
              cvp @Frankson909 last edited by

              @Frankson909 because your def switched is after the v.present

              1 Reply Last reply Reply Quote 0
              • cvp
                cvp @Frankson909 last edited by cvp

                @Frankson909 with pyui of my picture

                import ui
                
                def switched(sender):
                	sender.superview.name = str(sender.value)
                
                v = ui.load_view('tickerV2')
                v.present('sheet')
                
                # to access attributes of switch in view
                v['switch1'].background_color = 'red'
                v['switch1'].corner_radius = v['switch1'].height/2
                
                1 Reply Last reply Reply Quote 0
                • Frankson909
                  Frankson909 last edited by

                  Thank u so much!!! I was going crazy already...

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