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.


    ui.View Update

    Pythonista
    3
    13
    3342
    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.
    • DavinE
      DavinE last edited by

      Hey Guys,

      I have a new Problem...
      When i run "big" MYSQL Codes (one Function) i would do an Update an some Labels... when my first codes done in the Function...
      but the Text and Background of the "new" Label takes effect when the MYSQL Codes are Complete finished....

      Is it possible to solve this ??
      thanks and greets

      mikael 1 Reply Last reply Reply Quote 0
      • mikael
        mikael @DavinE last edited by

        @DavinE, to me, the easiest approach would be to use scripter, pip install pythonista-scripter, then you can write your function like this, and the UI will be updated always when you yield:

        from scripter import *
        
        @script
        def my_func(label):
            open_database()
            for loop:
                do_some_operations()
                label.text = "Some update"
                yield
            close_database()
        
        Enez Houad 1 Reply Last reply Reply Quote 0
        • DavinE
          DavinE last edited by DavinE

          @mikael, This looks great!
          but i don't know why this function in @script works and then it don't work....

          i used it in this way:

          from scripter import script
          
          @script
          def test(self, sender):
          	if......:
          		open_database()
          		close_database()
          		self.barcodeNumberCheckDisplayLabel.text = getText('datanormUpdateNONE', self.DEVICE)
          		self.barcodeNumberCheckDisplayLabel.bg_color = getColor('selectionNONE')
          		yield
          	else:
          		self.barcodeNumberCheckDisplayLabel.text = getText('datanormUpdateDONE', self.DEVICE)
          		self.barcodeNumberCheckDisplayLabel.bg_color = getColor('selectionYES')
          		yield
          		
          	if......:
          		open_database()
          		close_database()
          		
          		self.ebraNumberCheckDisplayLabel.text = getText('datanormUpdateNONE', self.DEVICE)
          		self.ebraNumberCheckDisplayLabel.bg_color = getColor('selectionNONE')
          		yield
          	else:
          		self.ebraNumberCheckDisplayLabel.text = getText('datanormUpdateDONE', self.DEVICE)
          		self.ebraNumberCheckDisplayLabel.bg_color = getColor('selectionYES')
          		yield
          		
          	if......:
          		open_database()
          		close_database()
          		
          		self.cuttingCheckDisplayLabel.text = getText('datanormUpdateNONE', self.DEVICE)
          		self.cuttingCheckDisplayLabel.bg_color = getColor('selectionNONE')
          		yield
          	else:
          		self.cuttingCheckDisplayLabel.text = getText('datanormUpdateDONE', self.DEVICE)
          		self.cuttingCheckDisplayLabel.bg_color = getColor('selectionYES')
          		yield
          

          is anything wrong on this ?

          EDIT: When i press the button sometimes it goes and sometimes it don't goes and nothing will happened...

          EDIT1: I know when the Problem is....
          I Open Pythonista... Run my App call the Function then i close my App and open it again... then it don't worked
          I need to reopen Pythonista then it works every Time.... but Why ?

          mikael 1 Reply Last reply Reply Quote 0
          • Enez Houad
            Enez Houad @mikael last edited by

            @mikael , Iโ€™ve got a simular problem ! My animations with calls to scripter only works one time ๐Ÿ˜ข. I need to restart Pythonista !
            I take this opportunity to thank you for your fantastic modules. iPadOS 14.3 beta on iPad mini 4

            1 Reply Last reply Reply Quote 0
            • mikael
              mikael @DavinE last edited by

              @DavinE, Enez, looks like the PyPI version had a bit of a globals issue, should be fixed now.

              Enez Houad 1 Reply Last reply Reply Quote 0
              • Enez Houad
                Enez Houad @mikael last edited by

                @mikael , unfortunately, the problem persists ! Do I need to reinstall something ?

                mikael 1 Reply Last reply Reply Quote 0
                • mikael
                  mikael @Enez Houad last edited by

                  @Enez-Houad, did you pip update pythonista-scripter? And maybe restart Pythonista to force re-import?

                  Enez Houad 1 Reply Last reply Reply Quote 0
                  • Enez Houad
                    Enez Houad @mikael last edited by

                    @mikael, Yes, Iโ€™ve updated Scripter (even uninstall and reinstall) and restarted Pythonista. And nowโ€ฆ it works the first time, doesnโ€™t the second and crash the third !

                    mikael 1 Reply Last reply Reply Quote 0
                    • mikael
                      mikael @Enez Houad last edited by

                      @Enez-Houad, anything you could share so I can reproduce/fix?

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

                        @mikael, here is a simple example:

                        import ui
                        from scripter import script
                        from anchors import dock, size_to_fit, attach
                        
                        
                        
                        mainview = ui.View(name='scripter_view', bg_color='black')
                        
                        
                        Label_1 = size_to_fit(ui.Label(name='Label_1', bg_color='red', text='nothing will happend'))
                        dock(Label_1).top_center(mainview)
                        
                        Label_2 = size_to_fit(ui.Label(name='Label_2', bg_color='red', text='nothing will happend'))
                        attach(Label_2).below(Label_1)
                        
                        Label_3 = size_to_fit(ui.Label(name='Label_3', bg_color='red', text='nothing will happend'))
                        attach(Label_3).below(Label_2)
                        
                        @script
                        def test():
                        	Label_1.text = 'okay'
                        	Label_1.bg_color = 'green'
                        	yield 2
                        	Label_2.text = 'okay'
                        	Label_2.bg_color = 'green'
                        	yield 2
                        	Label_3.text = 'okay'
                        	Label_3.bg_color = 'green'
                        	yield
                        
                        if __name__ == '__main__':
                        	mainview.present('fullscreen')
                        	test()
                        

                        the fist time it works perfect...
                        then close the view and reopen the view... nothing will happened..
                        you need to reopen Pythonista.

                        hope this will help you out

                        mikael 1 Reply Last reply Reply Quote 0
                        • mikael
                          mikael @DavinE last edited by

                          @DavinE, could not find a better way to make this reliable than requiring an explicit call to start_scripter, see example below (requires update).

                          import ui
                          from scripter import script, start_scripter
                          
                          mainview = ui.View(name='scripter_view', bg_color='black')
                          start_scripter(mainview)
                          
                          ...
                          
                          Enez Houad DavinE 2 Replies Last reply Reply Quote 1
                          • Enez Houad
                            Enez Houad @mikael last edited by

                            @mikael, Perfect ๐Ÿ‘๐Ÿ‘๐Ÿ™๐Ÿ‘
                            Thank you very much, I would find it hard to do without Scripter!

                            1 Reply Last reply Reply Quote 1
                            • DavinE
                              DavinE @mikael last edited by

                              @mikael said:

                              @DavinE, could not find a better way to make this reliable than requiring an explicit call to start_scripter, see example below (requires update).

                              import ui
                              from scripter import script, start_scripter
                              
                              mainview = ui.View(name='scripter_view', bg_color='black')
                              start_scripter(mainview)
                              
                              ...
                              

                              @mikael, It works Perfect!
                              Thanks for your help and work into it!

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