Example #1
0
def get_areas(area_map):
    """Возвращает координаты квадрата для заданой сетки"""
    if len(area_map) == 0:
        return 0, 0, 0, 0

    xdo = Xdo()
    size = xdo.get_window_size(xdo.get_active_window())
    locations = xdo.get_window_location(xdo.get_active_window())
    wnd_w = int(size.width / len(area_map[0]))
    wnd_h = int(size.height / len(area_map))
    result = []

    for row_n in range(len(area_map)):
        for cell_n in range(len(area_map[row_n])):
            if area_map[row_n][cell_n] == 1:
                result.append(
                    (wnd_w * cell_n + locations.x,
                     wnd_h * row_n + locations.y,
                     wnd_w * cell_n + wnd_w + locations.x,
                     wnd_h * row_n + wnd_h + locations.y)
                )
    return result
Example #2
0
    def __init__(self, x1=None, y1=None, x2=None, y2=None):
        self.x1 = 0
        self.y1 = 0
        xdo = Xdo()
        size = xdo.get_window_size(xdo.get_active_window())
        self.x2 = size.width
        self.y2 = size.height

        if x1:
            self.x1 = x1
        if y1:
            self.y1 = y1
        if x2:
            self.x2 = x2
        if y2:
            self.y2 = y2
Example #3
0
async def term(editor, args):
    command = args.command
    if command:
        command += "\n"
    window_name = r"^Tilix:".encode("utf-8")
    xdo = Xdo()
    editor_window = xdo.get_active_window()
    windows = xdo.search_windows(window_name, only_visible=True)
    if not windows:
        return error("Tilix window not found")
    term = windows[0]
    xdo.focus_window(term)
    if command:
        xdo.enter_text_window(term, command.encode("utf-8"))
        xdo.focus_window(editor_window)
    else:
        xdo.raise_window(term)
    return result()
Example #4
0
    return ""

if args.version:
    print("{} v{}".format(progname, version))
    exit()

if not (filenames or filepat or xfilepat):
    argparser.print_help()
    exit()

print("(!) select window to send keypress events ...")
targetWin = xdo.select_window_with_click()
if targetWin:
    winname = getWindowName(targetWin)
    print("selected window: {}".format(winname))

for changes in watch("."):
    winname = getWindowName(targetWin)
    if winpat and not re.match(winpat, winname):
        continue

    reload = any([included(e[1]) for e in changes])
    time.sleep(args.delay)
    if reload:
        curWin = xdo.get_active_window()
        xdo.focus_window(targetWin)
        xdo.send_keysequence_window(targetWin, key.encode("utf-8"))
        xdo.focus_window(curWin)
        print("sending {} to {}".format(key, targetWin))

Example #5
0
#!/usr/bin/env python2

import subprocess
from xdo import Xdo

xdo = Xdo()
window = xdo.get_active_window()
window_pid = xdo.get_pid_window(window)
window_name = xdo.get_window_name(window)
active_process_pid = subprocess.check_output(
    ['pgrep', '-P', "%s" % window_pid]).split('\n')[0]


def get_pname(id):
    p = subprocess.Popen(
        ["ps -el |grep {} |grep -v zsh |grep ' [R|S] '".format(id)],
        stdout=subprocess.PIPE,
        shell=True)
    return str(p.communicate()[0])


active_process_name = get_pname(active_process_pid)
print(active_process_name)

subprocess.call(
    ['dunstify',
     "Active window %i %s" % (window, active_process_name)])

if 'vim' in active_process_name:
    subprocess.call(['dunstify', 'VIM'])
elif 'Emacs' in active_process_name:
Example #6
0
from pprint import pprint
from time import sleep

from datetime import datetime

wm = pyinotify.WatchManager()  # Watch Manager
mask = pyinotify.IN_DELETE | pyinotify.IN_CREATE | pyinotify.IN_CLOSE_WRITE  # watched events

PROJ_HOME = '/home/logic/_workspace/laravel_tryout/app/blog/'
incl_fileext_list = ['php', 'htm']
incl_dir_list = [PROJ_HOME + 'routes', PROJ_HOME + 'resources/views']

xdo = Xdo()
# win_id = xdo.search_windows('.+Chromium.+')

win_id_vscode = xdo.get_active_window()
print('click chrome window to get win_id_chrome')
win_id_chrome = xdo.select_window_with_click()

CWD = os.path.dirname(os.path.abspath(__file__))
# CWD = '/home/logic/_workspace/laravel_tryout/app/blog'


def get_target_log_line(string_input):
    return string_input.replace(PROJ_HOME, '$HOME/')


def get_utf8_string(string):
    # return string
    return string.encode('utf-8')
Example #7
0
def monAndReload():
    import pyinotify
    from xdo import Xdo
    from pprint import pprint
    from time import sleep

    wm = pyinotify.WatchManager()  # Watch Manager
    mask = pyinotify.IN_DELETE | pyinotify.IN_CREATE | pyinotify.IN_CLOSE_WRITE  # watched events

    xdo = Xdo()
    # win_id = xdo.search_windows('.+Chromium.+')

    win_id_vscode = xdo.get_active_window()
    print(red('click chrome window to get win_id_chrome'))
    win_id_chrome = xdo.select_window_with_click()

    CWD = os.path.dirname(os.path.abspath(__file__))

    # CWD = '/home/logic/_workspace/laravel_tryout/app/blog'

    def get_utf8_string(string):
        # return string.encode('utf-8')
        return string

    def reload_browser(win_id_chrome):
        xdo.activate_window(win_id_chrome)
        sleep(0.2)
        for i in range(0, 3):
            xdo.send_keysequence_window(win_id_chrome,
                                        get_utf8_string('Escape'))
        for i in range(0, 3):
            sleep(0.01)
            xdo.send_keysequence_window(win_id_chrome,
                                        get_utf8_string('Control_L+r'))
        # xdo.send_keysequence_window_up(win_id_chrome, get_utf8_string('Control_L+r'))

    def back_to_original(win_id_to_back):
        xdo.activate_window(win_id_to_back)

    def clear_holding_key(win_id_browser, win_id_editor):
        for i in range(0, 5):
            xdo.send_keysequence_window(win_id_browser,
                                        get_utf8_string('Escape'))
            xdo.send_keysequence_window_up(win_id_browser,
                                           get_utf8_string('Control_L'))
            xdo.send_keysequence_window_up(win_id_editor, get_utf8_string('r'))

    def perform_reload(win_id_browser, win_id_editor):
        from datetime import datetime

        print(green('reloading %s' % datetime.now().strftime('%s')))
        reload_browser(win_id_browser)
        back_to_original(win_id_editor)
        clear_holding_key(win_id_browser, win_id_editor)
        print(green('reload done'))
        # pass

    class Reload(Exception):
        pass

    class EventHandler(pyinotify.ProcessEvent):
        def process_IN_CREATE(self, event):
            # target = os.path.join(event.path, event.name)
            # if os.path.isdir(target):
            #     raise Reload()
            pass

        def process_IN_DELETE(self, event):
            # raise Reload()
            pass

        def process_IN_CLOSE_WRITE(self, event):
            target = os.path.join(event.path, event.name)
            for incl_fileext in incl_fileext_list:
                if target.find(incl_fileext) > 0:
                    perform_reload(win_id_chrome, win_id_vscode)
                    break
                else:
                    print(
                        yellow('ignore file change for {}'.format(event.path)))

    # excl_lst = ['']
    # excl = pyinotify.ExcludeFilter(excl_lst)

    incl_fileext_list = ['php', 'htm']

    print(green('start monitoring...'))
    handler = EventHandler()
    notifier = pyinotify.Notifier(wm, handler, read_freq=1)
    wdd = wm.add_watch(CWD, mask, rec=True, auto_add=True)

    notifier.loop()