Get a focus

Incognito
2006-02-15
2013-05-28
  • Incognito

    Incognito - 2006-02-15

    Hi Mark,

    I've a test application (GUI) with an Exit (labelled Quitter) button (only that).

    I've created a class to start and stop this application (see bellow).

    When I run it, it works very well, I can start and stop application as I want. But if I click on another window, between the call of the Start and the Stop function, the Stop function will not close the application (only activates the "Quitter" button), but if I duplicates the call to the "self.MyApp.TestGui.Quitter.Click()" function into the Stop function, it closes the application.

    I think that the first call to the "self.MyApp.TestGui.Quitter.Click()" function sets the window focus and the second sets the action. Is there any way to get the focus of the application ?

    I've another problem, if in start function I try to get the control identifiers, I've an attribute error "WindowSpecification has no 'print_control_identifiers' method", while in documentation there is a method...

    ----
    Class file
    ----
        .
        . 
        .

    class MyTest :
        def __init__ (self, ExecFullPath) :
            self.bIsConnected = False
            self.Path = ExecFullPath
           
        def start (self) :
            self.MyApp = application.Application()
           
            try:
                self.MyApp.start_(self.Path)
                self.bIsConnected = True
    #            print self.MyApp.print_control_identifiers()
            except application.ProcessNotFoundError:
                self.bIsConnected = False

        def stop (self) :
            self.MyApp.TestGui.Quitter.Click()
    #        self.MyApp.TestGui.Quitter.Click()
             self.bIsConnected = False

        def isConnected (self) :
            return self.bIsConnected

    ----
    Main file
    ----
        .
        .
        .

    def main :
        .
        .
        .
        testApp = MyTest ("C:\test\test.exe")

        testApp.start()
        time.sleep(3)
        testApp.stop()

    if __name__ == "__main__":
        main()

     
    • Mark Mc Mahon

      Mark Mc Mahon - 2006-02-15

      Hi,

      I obviously don't have your test app :-) but I tried it out with Notepad and I didn't have a problem:...

      from pywinauto.application import Application as App
      app = App().start_("Notepad")
      app.MenuSelect("File->Page Setup")
      # now make sure that the Page Setup dialog is not visible

      app.PageSetup.Cancel.Click() # <- Closes the dialog

      Is your dialog minimized? I am not sure if it would work when minimized.

      If you are still having problems then you can set a particular dialog or control as the control with the focus by using pywinauto.win32functions.SetForegroundWindow()

      so you could do the following
      from pywinauto.win32functions import SetForegroundWindow
      SetForegroundWindow(self.MyApp.TestGui.Quitter.handle)

      I should probably add a SetFocus() method to HwndWrapper (which will make it available for all controls)

      I do not know why you are getting the message that WindowSpecification has no print_control_identifiers method.

      You are using pywinauto 0.2.0? Can you open pywinauto.application and do a search for print_control_identifiers?

      Thanks
         Mark

       

Log in to post a comment.