List the windows. Sleep is useful to wait some time before obtaining the new content when something in the window has changed. This also sets L{self.windows} as the list of windows. @type sleep: int @param sleep: sleep in seconds before proceeding t
(self, sleep=1)
| 3680 | return self.views |
| 3681 | |
| 3682 | def list(self, sleep=1): |
| 3683 | """ |
| 3684 | List the windows. |
| 3685 | |
| 3686 | Sleep is useful to wait some time before obtaining the new content when something in the |
| 3687 | window has changed. |
| 3688 | This also sets L{self.windows} as the list of windows. |
| 3689 | |
| 3690 | @type sleep: int |
| 3691 | @param sleep: sleep in seconds before proceeding to dump the content |
| 3692 | |
| 3693 | @return: the list of windows |
| 3694 | """ |
| 3695 | |
| 3696 | if sleep > 0: |
| 3697 | time.sleep(sleep) |
| 3698 | |
| 3699 | if self.useUiAutomator: |
| 3700 | raise Exception("Not implemented yet: listing windows with UiAutomator") |
| 3701 | else: |
| 3702 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 3703 | try: |
| 3704 | s.connect((VIEW_SERVER_HOST, self.localPort)) |
| 3705 | except socket.error as ex: |
| 3706 | raise RuntimeError("ERROR: Connecting to %s:%d: %s" % (VIEW_SERVER_HOST, self.localPort, ex)) |
| 3707 | s.send('list\r\n') |
| 3708 | received = "" |
| 3709 | doneRE = re.compile("DONE") |
| 3710 | while True: |
| 3711 | received += s.recv(1024) |
| 3712 | if doneRE.search(received[-7:]): |
| 3713 | break |
| 3714 | s.close() |
| 3715 | if DEBUG: |
| 3716 | self.received = received |
| 3717 | if DEBUG_RECEIVED: |
| 3718 | print("received %d chars" % len(received), file=sys.stderr) |
| 3719 | print(file=sys.stderr) |
| 3720 | print(received, file=sys.stderr) |
| 3721 | print(file=sys.stderr) |
| 3722 | |
| 3723 | self.windows = {} |
| 3724 | for line in received.split('\n'): |
| 3725 | if not line: |
| 3726 | break |
| 3727 | if doneRE.search(line): |
| 3728 | break |
| 3729 | values = line.split() |
| 3730 | if len(values) > 1: |
| 3731 | package = values[1] |
| 3732 | else: |
| 3733 | package = "UNKNOWN" |
| 3734 | if len(values) > 0: |
| 3735 | wid = values[0] |
| 3736 | else: |
| 3737 | wid = '00000000' |
| 3738 | self.windows[int('0x' + wid, 16)] = package |
| 3739 | return self.windows |
no test coverage detected