Esempio n. 1
0
def getAppRefByPidofapp(processid):
    try:
        _pidreference = atomac.getAppRefByPid(processid)
        logging.info("Application RefferenceID : %s" % _pidreference)
    except Exception as er:
        logging.info('Not able to get Application ReferenceID')
        return False
    return _pidreference
Esempio n. 2
0
 def query_app(self, name=None, pid=0, bundle_id=None):
     if name:
         app = atomac.getAppRefByLocalizedName(name)
     elif pid:
         app = atomac.getAppRefByPid(pid)
     elif bundle_id:
         app = atomac.getAppRefByBundleId(bundle_id)
     else:
         app = atomac.getFrontmostApp()
     return self._push(MacUiElementOperand(app))
Esempio n. 3
0
    def get_window(self, obj_handle=None):
        filters = CG.kCGWindowListOptionOnScreenOnly | \
            CG.kCGWindowListExcludeDesktopElements * bool(obj_handle)

        obj_name = obj_handle if obj_handle else u'DesktopWindow Server'
        obj_name = \
            obj_name if type(obj_name) == unicode else obj_name.decode('utf-8')

        regex = MacUtils.convert_wildcard_to_regex(obj_name)

        win_list = CG.CGWindowListCopyWindowInfo(filters, CG.kCGNullWindowID)

        window = filter(lambda x:
                        re.match(MacUtils.replace_inappropriate_symbols(regex),
                                 MacUtils.replace_inappropriate_symbols(
                                     x.get('kCGWindowName', '')) +
                                 x.get('kCGWindowOwnerName', ''),
                                 re.IGNORECASE)
                        if x.get('kCGWindowName', '') else False,
                        win_list)

        window = window[0] if window else window
        if not window:
            obj_name = obj_name.encode(self._default_sys_encoding,
                                       errors='ignore')
            raise TooSaltyUISoupException('Can\'t find window "%s".' %
                                          obj_name)

        process_name = window['kCGWindowOwnerName']
        window_name = window['kCGWindowName']
        process_id = int(window['kCGWindowOwnerPID'])
        # Escape double quotes in window name.
        window_name = window_name.replace('"', '\\"')

        try:
            selector = \
                MacUtils.ApplescriptExecutor.get_apple_event_descriptor(
                    'window "%s"' % window_name,
                    process_name).applescript_specifier
        except TooSaltyUISoupException:
            selector = \
                MacUtils.ApplescriptExecutor.get_apple_event_descriptor(
                    'window 0',
                    process_name).applescript_specifier

        selector = \
            selector if type(selector) == unicode else selector.decode('utf-8')

        app = atomac.getAppRefByPid(process_id)
        window = app.windows()[0]

        return MacElement(window, process_name, process_id)
Esempio n. 4
0
    def __init__(self):
        """
		delegate = AppDelegate.alloc().init()
		NSApplication.sharedApplication().setDelegate_(delegate)
		AppHelper.runEventLoop()
		"""
        pids = self._getWoWPids()
        print(pids)
        if (len(pids) != 0):
            self.wow = am.getAppRefByPid(int(pids[0]))
        else:
            print "World of Warcraft is not running, or is not named 'World of Warcraft'"
            sys.exit(0)
Esempio n. 5
0
	def __init__(self):
		"""
		delegate = AppDelegate.alloc().init()
		NSApplication.sharedApplication().setDelegate_(delegate)
		AppHelper.runEventLoop()
		"""
		pids = self._getWoWPids()
		print(pids)
		if(len(pids) != 0):
			self.wow = am.getAppRefByPid(int(pids[0]))
		else:
			print "World of Warcraft is not running, or is not named 'World of Warcraft'"
			sys.exit(0)
Esempio n. 6
0
    def _find_windows_by_same_proc(self):
        """
        Find window by same process id.

        Arguments:
            - None

        Returns:
            - list of windows.
        """

        app = atomac.getAppRefByPid(self.proc_id)
        app.activate()
        return app.windowsR()
Esempio n. 7
0
File: OSXUI.py Progetto: adolli/Poco
    def EnumWindows(self, selector):
        names = []
        if 'bundleid' in selector:
            self.app = atomac.getAppRefByBundleId(selector['bundleid'])
            windows = self.app.windows()
            for i, w in enumerate(windows):
                names.append((w.AXTitle, i))
            return names

        if 'appname' in selector:
            self.app = atomac.getAppRefByLocalizedName(selector['appname'])
            windows = self.app.windows()
            for i, w in enumerate(windows):
                names.append((w.AXTitle, i))
            return names

        if 'appname_re' in selector:  # 此方法由于MacOS API,问题较多
            apps = atomac.NativeUIElement._getRunningApps()  # 获取当前运行的所有应用程序
            appset = set()  # 应用程序集合
            appnameset = set()  # 应用程序标题集合
            for t in apps:
                tempapp = atomac.getAppRefByPid(t.processIdentifier())
                if str(tempapp) == str(atomac.AXClasses.NativeUIElement()
                                       ):  # 通过trick判断应用程序是都否为空
                    continue
                attrs = tempapp.getAttributes()
                if 'AXTitle' in attrs:
                    tit = tempapp.AXTitle
                    if re.match(selector['appname_re'], tit):
                        appset.add(tempapp)
                        appnameset.add(
                            tit)  # 这里有Bug,可能会获取到进程的不同副本,所以要通过名字去判断是否唯一

            if len(appnameset) is 0:
                raise InvalidSurfaceException(
                    selector,
                    "Can't find any applications by the given parameter")
            if len(appnameset) != 1:
                raise NonuniqueSurfaceException(selector)
            while len(names) is 0:  # 有可能有多个副本,但只有一个真的应用程序有窗口,所以要枚举去找
                if len(appset) is 0:
                    return names
                self.app = appset.pop()
                windows = self.app.windows()  # 获取当前应用程序的所有窗口
                for i, w in enumerate(windows):
                    names.append((w.AXTitle, i))
            return names
        return names
Esempio n. 8
0
 def _get_windows(self, force_remap=False):
     if not force_remap and self._windows:
         # Get the windows list from cache
         return self._windows
     # Update current running applications
     # as force_remap flag has been set
     self._update_apps()
     windows = {}
     self._ldtpized_obj_index = {}
     for gui in set(self._running_apps):
         if self._app_under_test and \
                 self._app_under_test != gui.bundleIdentifier() and \
                 self._app_under_test != gui.localizedName():
             # Not the app under test, search next application
             continue
         # Get process id
         pid = gui.processIdentifier()
         # Get app id
         app = atomac.getAppRefByPid(pid)
         # Get all windows of current app
         app_windows = app.windows()
         try:
             # Tested with
             # selectmenuitem('appChickenoftheVNC', 'Connection;Open Connection...')
             if not app_windows and app.AXRole == "AXApplication":
                 # If app doesn't have any windows and its role is AXApplication
                 # add to window list
                 key = self._insert_obj(windows, app, "", -1)
                 windows[key]["app"] = app
                 continue
         except (atomac._a11y.ErrorAPIDisabled, \
                     atomac._a11y.ErrorCannotComplete, \
                     atomac._a11y.Error, \
                     atomac._a11y.ErrorInvalidUIElement):
             pass
         # Navigate all the windows
         for window in app_windows:
             if not window:
                 continue
             key = self._insert_obj(windows, window, "", -1)
             windows[key]["app"] = app
     # Replace existing windows list
     self._windows = windows
     return windows
Esempio n. 9
0
 def _get_windows(self, force_remap=False):
     if not force_remap and self._windows:
         # Get the windows list from cache
         return self._windows
     # Update current running applications
     # as force_remap flag has been set
     self._update_apps()
     windows={}
     self._ldtpized_obj_index={}
     for gui in set(self._running_apps):
         if self._app_under_test and \
                 self._app_under_test != gui.bundleIdentifier() and \
                 self._app_under_test != gui.localizedName():
             # Not the app under test, search next application
             continue
         # Get process id
         pid=gui.processIdentifier()
         # Get app id
         app=atomac.getAppRefByPid(pid)
         # Get all windows of current app
         app_windows=app.windows()
         try:
             # Tested with
             # selectmenuitem('appChickenoftheVNC', 'Connection;Open Connection...')
             if not app_windows and app.AXRole == "AXApplication":
                 # If app doesn't have any windows and its role is AXApplication
                 # add to window list
                 key=self._insert_obj(windows, app, "", -1)
                 windows[key]["app"]=app
                 continue
         except (atomac._a11y.ErrorAPIDisabled, \
                     atomac._a11y.ErrorCannotComplete, \
                     atomac._a11y.Error, \
                     atomac._a11y.ErrorInvalidUIElement):
             pass
         # Navigate all the windows
         for window in app_windows:
             if not window:
                 continue
             key=self._insert_obj(windows, window, "", -1)
             windows[key]["app"]=app
     # Replace existing windows list
     self._windows=windows
     return windows
Esempio n. 10
0
def getInstallerbuttons(pidofmasterinstaller):
    dmgwindow = atomac.getAppRefByPid(pidofmasterinstaller)
    Masterinstallerbuttons = getAppButtons(dmgwindow)
    return Masterinstallerbuttons