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.


    search for phrase within script

    Pythonista
    3
    8
    1443
    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.
    • frankL
      frankL last edited by

      Is there a search function in the pythonista editor? How can I find a specific word or phrase in a script on iphone without reading through the entire script looking for it?

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

        @frankL on iPhone, down arrow at right of script name, then magnify glass...

        then

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

          Thank you.

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

            I have yet another question...over the past few months I have written a number of scripts in which I use a number of TextFields and Buttons in multiple views within the script. I have been creating duplicate versions of the TextFields and Buttons to use in each of the various views. I have been having some small success lately creating classes so I thought I could create a class to contain a set of fields and buttons that I could instantiate for each view. I tried writing a simple class and I can instantiate a button and field in a view but I have so far been unable to populate the field as a result of the button push. If I change the value of the TextField text in the button press function, it prints correctly to the console but does not update the contents of the field in the view. What am I doing wrong? Thanks.

            import ui
            #
            class Common_View (object):
            	def __init__(self):
            		pass
            		
            		def select_author(sender):
            			print(self.author_result.text)
            			self.author_result.text = 'selected author'
            			print(self.author_result.text)
            			return
            		
            		self.author_button = ui.Button(title='Author', frame=(10,5,350,100), border_color='black', border_width=2, background_color='#EAECEE', action=select_author, font=('Arial Rounded MT Bold',18))
            		self.author_button.width=70
            		self.author_button.height=40
            
            		self.author_result = ui.TextField(name='author',frame=(100,5,250,40), border_color='black', border_width=3, text= 'empty')
            #
            w, h = ui.get_screen_size()
            view = ui.View(name= 'Test View', bg_color='lightblue', frame=(0, 0, w, h))
            
            main_author = Common_View().author_result
            view.add_subview(main_author)
            main_author_button = Common_View().author_button
            view.add_subview(main_author_button)
            
            nav_view = ui.NavigationView(view)
            nav_view.present('sheet')
            1 Reply Last reply Reply Quote 0
            • JonB
              JonB last edited by ccc

              The issue is that you create two different CommonViews, but the button refers to one, and the Test field is from the other. So self.author_response doesn't do what you want.

              Create one instance:

              C=CommonView()
              #then refer to
              view.add_subview(C.author_response)
              view.add_subview(C.author_button)
              

              Instead of creating new objects each time.

              Also, you can subclass ui.View, so that the add_subviews would be inside init, and would be self.add_subview, etc.

              class Common_View(ui.View):
                  def select_author(self, sender):
                      print(self.author_result.text)
                      self.author_result.text = "selected author"
                      print(self.author_result.text)
                      return
              
                  def __init__(self, *args, **kwargs):
                      self.author_button = ui.Button(
                          title="Author",
                          frame=(10, 5, 350, 100),
                          border_color="black",
                          border_width=2,
                          background_color="#EAECEE",
                          action=self.select_author,
                          font=("Arial Rounded MT Bold", 18),
                      )
                      self.author_button.width = 70
                      self.author_button.height = 40
              
                      self.author_result = ui.TextField(
                          name="author",
                          frame=(100, 5, 250, 40),
                          border_color="black",
                          border_width=3,
                          text="empty",
                      )
              
                      w, h = ui.get_screen_size()
                      ui.View.__init__(
                          self, name="Test View", bg_color="lightblue", frame=(0, 0, w, h), **kwargs
                      )
              
                      self.add_subview(main_author)
                      self.add_subview(main_author_button)
              
              
              view = CommonView()
              
              nav_view = ui.NavigationView(view)
              nav_view.present("sheet")
              
              1 Reply Last reply Reply Quote 0
              • JonB
                JonB last edited by JonB

                Sorry white space maybe got messed up -- both defs should be at same level, inside the class. And the spacing in second method got screwed up too. But hopefully this helps

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

                  Thank you. The first suggestion works and I like the idea of subclassing ui.View, but after I moved the white space around, I'm still getting an error message:
                  Traceback (most recent call last):
                  File "/private/var/mobile/Containers/Shared/AppGroup/99B62839-B39E-4ADF-9308-D5D986E28E91/Pythonista3/Documents/Frank/CommonView2.py", line 19, in <module>
                  view = Common_View()
                  File "/private/var/mobile/Containers/Shared/AppGroup/99B62839-B39E-4ADF-9308-D5D986E28E91/Pythonista3/Documents/Frank/CommonView2.py", line 15, in init
                  self.add_subview(main_author)
                  NameError: name 'main_author' is not defined

                  import ui
                  class Common_View(ui.View):
                      def select_author(self, sender):
                          print(self.author_result.text)
                          self.author_result.text = "selected author"
                          print(self.author_result.text)
                          return
                      def __init__(self, *args, **kwargs):
                          self.author_button = ui.Button(title="Author", frame=(10, 5, 350, 100), border_color="black", border_width=2, background_color="#EAECEE", action=self.select_author, font=("Arial Rounded MT Bold", 18))
                          self.author_button.width = 70
                          self.author_button.height = 40
                          self.author_result = ui.TextField(name="author", frame=(100, 5, 250, 40), border_color="black", border_width=3, text="empty")
                          w, h = ui.get_screen_size()
                          ui.View.__init__(self, name="Test View", bg_color="lightblue", frame=(0, 0, w, h), **kwargs)
                          self.add_subview(main_author)
                          self.add_subview(main_author_button)
                  
                  
                  view = Common_View()
                  
                  nav_view = ui.NavigationView(view)
                  nav_view.present("sheet")```
                  1 Reply Last reply Reply Quote 0
                  • frankL
                    frankL last edited by

                    No need to respond, I figured out the problem.

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