delay function [in wxPython]

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • agsupriya86
    New Member
    • Mar 2007
    • 34

    delay function [in wxPython]

    Hi,
    I need to add some delay function to my code where on clicking the exit button some text needs to be displayed on the text area..
    Right now the text is not not appearing coz there s no dealy between 2 events of closing and displaying text.

    following is my code for exit and i need to add a pause or delay between two events:
    Code:
    def OnExit(self, event):
            # wxGlade: MyFrame.<event_handler>
            display2=language_processor.thanks()
            self.text_ctrl_2.SetValue(display2)
            self.Close()
            event.Skip()
    Last edited by bartonc; May 2 '07, 06:56 PM. Reason: Added [CODE] [/CODE] tags
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Originally posted by agsupriya86
    Hi,
    I need to add some delay function to my code where on clicking the exit button some text needs to be displayed on the text area..
    Right now the text is not not appearing coz there s no dealy between 2 events of closing and displaying text.

    following is my code for exit and i need to add a pause or delay between two events:
    Code:
    def OnExit(self, event):
            # wxGlade: MyFrame.<event_handler>
            display2=language_processor.thanks()
            self.text_ctrl_2.SetValue(display2)
            self.Close()
            event.Skip()
    Code:
    wx.FutureCall(5000, self.Close)
    instead of
    Code:
    self.Close()
    will wait 5 seconds and the call Close().

    Comment

    • agsupriya86
      New Member
      • Mar 2007
      • 34

      #3
      Originally posted by bartonc
      Code:
      wx.FutureCall(5000, self.Close)
      instead of
      Code:
      self.Close()
      will wait 5 seconds and the call Close().
      Hi,
      Thanx for the suggestion ,It worked !
      Now i want to add one more thing that is when i click the button some text is to be displayed on text control for a minute and after that i need to hide it or remove it..
      Do i have a function for that??
      Code:
      def OnPress(self, event):
              # wxGlade: MyFrame.<event_handler>
              display2=language_processor.message()
              self.text_ctrl_2.SetValue(display2)
              wx.FutureCall(5000, ??)
      ??--What shud be the function here to hide the text??

      Comment

      • bartonc
        Recognized Expert Expert
        • Sep 2006
        • 6478

        #4
        Originally posted by agsupriya86
        Hi,
        Thanx for the suggestion ,It worked !
        Now i want to add one more thing that is when i click the button some text is to be displayed on text control for a minute and after that i need to hide it or remove it..
        Do i have a function for that??
        Code:
        def OnPress(self, event):
                # wxGlade: MyFrame.<event_handler>
                display2=language_processor.message()
                self.text_ctrl_2.SetValue(display2)
                wx.FutureCall(5000, ??)
        ??--What shud be the function here to hide the text??
        Please not the addition of [ CODE ] tags! Instructions for their use are in "REPLY GUIDELINES" on the right hand side of the page (while replying).

        Any object that inherits from wx.Window (like wx.TextCtrl) has a Hide() method. Just def a function, put something like:
        Code:
        thisTextCtrl.Hide()
        in it and call it with wx.FutureCall() .

        Comment

        • agsupriya86
          New Member
          • Mar 2007
          • 34

          #5
          Hi,

          I found one function time.sleep(sec) for delaying only.But im not getting how to implement it in my code to solve my purpose of displaying the text for 15 sec and then hiding it!
          Code:
          def help(self,event):
                  display3="hello"
                  time.sleep(15)
                  self.text_ctrl_3.SetValue(display3)
                  
                  time.sleep(5)
                  display3=""
                  self.text_ctrl_3.SetValue(display3)
          Why the above not solving my purpose??

          Comment

          • bartonc
            Recognized Expert Expert
            • Sep 2006
            • 6478

            #6
            Originally posted by agsupriya86
            Hi,

            I found one function time.sleep(sec) for delaying only.But im not getting how to implement it in my code to solve my purpose of displaying the text for 15 sec and then hiding it!
            Code:
            def help(self,event):
                    display3="hello"
                    time.sleep(15)
                    self.text_ctrl_3.SetValue(display3)
                    
                    time.sleep(5)
                    display3=""
                    self.text_ctrl_3.SetValue(display3)
            Why the above not solving my purpose??
            I've re-arranged the order of setting the text and then sleeping; you'll have to try it.
            The problem may be that sleep() doesn't return control to the mainloop(), but you can try:
            Code:
            def help(self,event):
                    display3="hello"
                    self.text_ctrl_3.SetValue(display3)
                    self.text_ctrl_3.Update()  # might need to add this, might not
                    time.sleep(15)
                    
                    display3=""
                    self.text_ctrl_3.SetValue(display3)
                    self.text_ctrl_3.Update()  # might need to add this, might not
                    time.sleep(5)

            Comment

            • agsupriya86
              New Member
              • Mar 2007
              • 34

              #7
              Originally posted by bartonc
              I've re-arranged the order of setting the text and then sleeping; you'll have to try it.
              The problem may be that sleep() doesn't return control to the mainloop(), but you can try:
              Code:
              def help(self,event):
                      display3="hello"
                      self.text_ctrl_3.SetValue(display3)
                      self.text_ctrl_3.Update()  # might need to add this, might not
                      time.sleep(15)
                      
                      display3=""
                      self.text_ctrl_3.SetValue(display3)
                      self.text_ctrl_3.Update()  # might need to add this, might not
                      time.sleep(5)
              Thanx,it worked !

              Comment

              • bartonc
                Recognized Expert Expert
                • Sep 2006
                • 6478

                #8
                Originally posted by agsupriya86
                Thanx,it worked !
                You are welcome!

                Comment

                Working...