<commit_before>'''
@date 2015-02-22
@author <NAME> <<EMAIL>>
'''

import re
import subprocess
from . import common
from ..mouse import Mouse

class Window(common.Window):
    def __init__(self, handle):
        super(Window, self).__init__()
        
        self.__handle = int(handle)
        
    @property
    def title(self):
        output = subprocess.check_output(["xdotool", "getwindowname", str(self.__handle)])
        return output.strip('\r\n').strip()
    
    @property
    def geometry(self):
        output = subprocess.check_output(["xdotool", "getwindowgeometry", str(self.__handle)])
        matched = re.match(
            "(?:\n|.)*"
            "Absolute upper-left X:[^\d]*(\d+)[^\d]*(?:\n|.)*"
            "Absolute upper-left Y:[^\d]*(\d+)[^\d]*(?:\n|.)*"
            "idth:[^\d]*(\d+)[^\d]*(?:\n|.)*"
            "eight:[^\d]*(\d+)[^\d]*(?:\n|.)*", output, re.M)
        return (int(matched.group(1)),
            int(matched.group(2)),
            int(matched.group(3)),
            int(matched.group(4)))
    
    def raise_(self):
        subprocess.call(["xdotool", "windowraise", "--sync", str(self.__handle)]) 
        
    def activate(self):
        subprocess.call(["xdotool", "windowactivate", "--sync", str(self.__handle)])
        
    def close(self):
        subprocess.call(["xdotool", "windowkill", "--sync", str(self.__handle)])
        
class Manager(common.Manager):
    
    def __init__(self):
        super(Manager, self).__init__()
        self.__mouse = Mouse()
    
    def get_active(self):
        output = subprocess.check_output(["xdotool", "getactivewindow"])
        return Window(int(output.strip('\r\n').strip()))
    
    def get_from_position(self, position):
        old_position = None
        
        if position != self.__mouse.position():
            old_position = self.__mouse.position()
            self.__mouse.move(position)
        try:
            output = subprocess.check_output(["xdotool", "getmouselocation"])
            matched = re.match("(?:\n|.)*window:(\d+)*(?:\n|.)*", output)<commit_msg>Fixed invoke xdotool windowkill with invalid argument : "--sync"<commit_after>'''
@date 2015-02-22
@author <NAME> <<EMAIL>>
'''

import re
import subprocess
from . import common
from ..mouse import Mouse

class Window(common.Window):
    def __init__(self, handle):
        super(Window, self).__init__()
        
        self.__handle = int(handle)
        
    @property
    def title(self):
        output = subprocess.check_output(["xdotool", "getwindowname", str(self.__handle)])
        return output.strip('\r\n').strip()
    
    @property
    def geometry(self):
        output = subprocess.check_output(["xdotool", "getwindowgeometry", str(self.__handle)])
        matched = re.match(
            "(?:\n|.)*"
            "Absolute upper-left X:[^\d]*(\d+)[^\d]*(?:\n|.)*"
            "Absolute upper-left Y:[^\d]*(\d+)[^\d]*(?:\n|.)*"
            "idth:[^\d]*(\d+)[^\d]*(?:\n|.)*"
            "eight:[^\d]*(\d+)[^\d]*(?:\n|.)*", output, re.M)
        return (int(matched.group(1)),
            int(matched.group(2)),
            int(matched.group(3)),
            int(matched.group(4)))
    
    def raise_(self):
        subprocess.call(["xdotool", "windowraise", "--sync", str(self.__handle)]) 
        
    def activate(self):
        subprocess.call(["xdotool", "windowactivate", "--sync", str(self.__handle)])
        
    def close(self):
        subprocess.call(["xdotool", "windowkill", str(self.__handle)])
        
class Manager(common.Manager):
    
    def __init__(self):
        super(Manager, self).__init__()
        self.__mouse = Mouse()
    
    def get_active(self):
        output = subprocess.check_output(["xdotool", "getactivewindow"])
        return Window(int(output.strip('\r\n').strip()))
    
    def get_from_position(self, position):
        old_position = None
        
        if position != self.__mouse.position():
            old_position = self.__mouse.position()
            self.__mouse.move(position)
        try:
            output = subprocess.check_output(["xdotool", "getmouselocation"])
            matched = re.match("(?:\n|.)*window:(\d+)*(?:\n|.)*", output)
{'fraction_non_alphanumeric': 0.1933635712580568, 'fraction_numerical': 0.005729291000238721, 'mean_word_length': 2.423202614379085, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '344597', 'n_tokens_mistral': 1343, 'n_tokens_neox': 1323, 'n_words': 227}