def helloworld():
    from xdo import Xdo
    xdo = Xdo()
    win_id = xdo.select_window_with_click()

    from pprint import pprint
    # pprint(win_id)
    pprint(xdo.get_window_name(win_id))

    win_id = xdo.search_windows('.+Chromium')
    pprint(win_id)
Esempio n. 2
0
def getWindowName(winId):
    name = xdo.get_window_name(winId)
    if name:
        return name.decode("utf-8")
    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"))
Esempio n. 3
0
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')


def reload_browser(win_id_chrome):
Esempio n. 4
0
# getting informations about monitor / window to capture
monitor = None
window = None
if args.source:
    try:
        source_int = int(args.source)
    except:
        source_int = None
    if args.source == 'list-mon':
        print(list_monitors(monitors_list))
        sys.exit(0)
    elif args.source == 'list-win':
        print(list_windows(windows_list))
        sys.exit(0)
    elif args.source == 'select':
        window = xdo.select_window_with_click()
    elif args.source == 'focus':
        window = xdo.get_focused_window_sane()
    elif args.source in monitors_list:
        monitor = monitors_list[args.source]
    elif source_int is None:
        print("error: monitor '%s' not found !" % args.source)
        print(list_monitors(monitors_list))
        sys.exit(1)
    elif source_int in windows_list:
        window = source_int
    else:
        print("error: window '%s' not found !" % args.source)
        print(list_windows(windows_list))
        sys.exit(2)
else:
Esempio n. 5
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()