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 change a size from a subview

    Pythonista
    ui.button ui.view ui.imageview
    3
    4
    5766
    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.
    • RMurtsoo
      RMurtsoo last edited by

      Hi Pythonista crew

      I try to change a Imageview height by his name.
      But "ui.Imageview('Image').height = 120" is not working
      So how would you try to change something in a ui.Button or ui.Imageview if you use the
      Ui.Button.name. = 'button'

      This my script:

      view = ui.View()
      view.present('portrait')

      def button():
      ui.Imageview('Image').height = 120

      img = ui.ImageView()
      img.name = 'Veer'
      img.heigt = 150
      view.add_subview(img)

      button = ui.Button()
      button.action = button
      view.add_subview(button)

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

        @RMurtsoo I am going to try an explain why this hasn't worked for you with out actually giving you a direct answer, not because I am trying to be rude/annoying but it is in my honest belief that we don't learn very well when just given an answer. So if this does come across as rude or demeaning I appologise.
        So to pull your code apart

        view = ui.View()  # this is correct however you might want to consider setting a frame size. `view = ui.View(frame=(0,0,width,height))` as the default is less than 200/200 from memory
        view.present('portrait')  # from documentation `ui.View.present(style='default', animated=True, popover_location=None, hide_title_bar=False, title_bar_color=None, title_color=None, orientations=None)` therefore if you want to force a orientation you need to provide values for `orientations` not `style` http://omz-software.com/pythonista/docs/ios/ui.html#ui.View.present
        
        def button():  # `ui.Button` actions require a sender argument, ie `def button(sender):...` where `sender` can be named anything
            ui.Imageview('Image').height = 120  # this creates a new `ui.ImageView` and doesn't actually reference any view from you `view` variable in the global stack. This is why you `ui.ImageView` height is not changing. Consider reading the documentation and examples to see how this is done
        
        img = ui.ImageView()  # this is correct however you might want to set a new frame size here as the default is 0/0. Which cause also be an attributing reason to why you aren't seeing anything. `ui.ImageView(frame=(0,0,200,200)` or you can set it later with `img.width`, `img.height`, `img.x` and `img.y`
        img.name = 'Veer'
        img.heigt = 150  # I'm going to assume that this is just a typo
        view.add_subview(img)
        
        button = ui.Button()  # by naming the variable of this object to `button` you have overrided the method by the same name, thus you will get a `Exception` when tapping the button. Consider renaming either the method name to something else or renaming this variable to something else.
        button.action = button
        view.add_subview(button)
        

        I would highly recommend reading the documentation for Pythonista, and for Python. Out of curiosity which version of Pythonista are you using?

        1 Reply Last reply Reply Quote 3
        • RMurtsoo
          RMurtsoo last edited by RMurtsoo

          Pythonista 3

          Thanks for Your input. And cange my script to:

          import ui
          tel = 0
          view=ui.View(frame=(0, 0, 300, 300), background_color=None, name='view')
          def omdat(sender):
          global tel
          if tel==0:
          view['Veer'].height = 120
          tel = 1
          elif tel == 1:
          view['Veer'].height = 50
          tel = 0

          img = ui.ImageView(frame=(0, 100, 50, 50), background_color=(.54, .7, 1.0),name = 'Veer')
          view.add_subview(img)

          btn = ui.Button(frame=(200, 100, 50, 50), background_color=(.54, .3, 1.0),name = 'btn')
          btn.action = omdat
          view.add_subview(btn)

          view.present(style='full_screen', animated=False, hide_title_bar=False, orientations='portrait')

          Is my understanding good if u use style='full_screen' and orientations='portrait' your iPad screen stars in portrait?

          r

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

            def omdat(sender):
                global tel
                view['Veer'].height = 50 if tel else 120
                tel = not tel
            
            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            Powered by NodeBB Forums | Contributors