(self)
Return the name and executable of a running application.
Return the name and executable of a running application.
Return the name and executable of a running application .
def check(self):
        """Return the name and executable of a running application."""
        #Get most recently loaded application
        if self.focus is None:
            
            matching_applications = {self.processes[app]: app
                                     for app in self.applist
                                     if app in self.processes}
            
            for index in sorted(matching_applications.keys())[::-1]:
                loaded_exe = matching_applications[index]
                names = self.applist[loaded_exe]
                try:
                    return names[None], loaded_exe

                #Only fallback to window name if it is the only entry for that application
                #Otherwise we don't know which entry to use, so ignore
                except KeyError:
                    if len(names) == 1 or len(set(names.values())) == 1:
                        return names[names.keys()[0]], loaded_exe
            return None

        #Get currently focused application
        elif self.focused_exe in self.applist:
            names = self.applist[self.focused_exe]

            #Check if record exists for current window name
            try:
                return names[self.focused_name], self.focused_exe
            except KeyError:
                try:
                    #Check for wildcard at start and end of window name
                    for name in names:
                        if name is None:
                            continue
                        
                        #Use regex if wildcard in name
                        if TRACKING_WILDCARD in name:
                            try:
                                regex = self._regex_cache[name]
                            except KeyError:
                                pattern = name.replace(TRACKING_WILDCARD, '(.*)')
                                regex = re.compile(pattern)
                                self._regex_cache[name] = regex

                            match = regex.search(self.focused_name) is not None
                        
                        else:
                           match = name == self.focused_name
                            
                        if match:
                            return names[name], self.focused_exe

                    #Return default name
                    return names[None], self.focused_exe

                #Default name doesn't exist
                except KeyError:
                    return None
def check ( self ) : #Get most recently loaded application if self . focus is None : matching_applications = { self . processes [ app ] : app for app in self . applist if app in self . processes } for index in sorted ( matching_applications . keys ( ) ) [ : : - 1 ] : loaded_exe = matching_applications [ index ] names = self . applist [ loaded_exe ] try : return names [ None ] , loaded_exe #Only fallback to window name if it is the only entry for that application #Otherwise we don't know which entry to use, so ignore except KeyError : if len ( names ) == 1 or len ( set ( names . values ( ) ) ) == 1 : return names [ names . keys ( ) [ 0 ] ] , loaded_exe return None #Get currently focused application elif self . focused_exe in self . applist : names = self . applist [ self . focused_exe ] #Check if record exists for current window name try : return names [ self . focused_name ] , self . focused_exe except KeyError : try : #Check for wildcard at start and end of window name for name in names : if name is None : continue #Use regex if wildcard in name if TRACKING_WILDCARD in name : try : regex = self . _regex_cache [ name ] except KeyError : pattern = name . replace ( TRACKING_WILDCARD , '(.*)' ) regex = re . compile ( pattern ) self . _regex_cache [ name ] = regex match = regex . search ( self . focused_name ) is not None else : match = name == self . focused_name if match : return names [ name ] , self . focused_exe #Return default name return names [ None ] , self . focused_exe #Default name doesn't exist except KeyError : return None