Exemple #1
0
def replay(str_code, filename=''):
    if recorder:
        recorder.mode = "Play"
    else:
        main_overlay = oaam.Overlay(transparency=0.5)
        overlay_add_mode_icon(main_overlay, IconSet.hicon_play, 10, 10)
    try:
        script_dir = os.path.abspath(os.path.dirname(filename))
        os.chdir(os.path.abspath(script_dir))
        sys.path.append(script_dir)
        compiled_code = compile(str_code, filename, 'exec')
        exec(compiled_code)
    except Exception as e:
        windll.user32.ShowWindow(windll.kernel32.GetConsoleWindow(), 3)
        exc_type, exc_value, exc_traceback = sys.exc_info()
        output = traceback.format_exception(exc_type, exc_value, exc_traceback)
        i_line = d_line = 0
        full_traceback = False
        if not full_traceback:
            for line in output:
                i_line += 1
                if "pywinauto_recorder.py" in line:
                    d_line = i_line

        for line in output[d_line:]:
            print(line, file=sys.stderr, end='')
        input("Press Enter to continue...")
    if recorder:
        recorder.mode = "Stop"
    else:
        main_overlay.clear_all()
        main_overlay.refresh()
Exemple #2
0
 def __init__(self):
     Thread.__init__(self)
     self.main_overlay = oaam.Overlay(transparency=0.5)
     self.info_overlay = oaam.Overlay(transparency=0.0)
     self.desktop = pywinauto.Desktop(backend='uia',
                                      allow_magic_lookup=False)
     self.daemon = True
     self.event_list = []
     self.mode = 'Pause'
     self.last_element_event = None
     self.distance_inside = 0.0
     self.mouse_x_inside = 99
     self.mouse_y_inside = 99
     self.hicon = None
     self.hicon_light_on = None
     self.hicon_light_off = None
     self.started_recording_with_keyboard = False
     self.start()
 def __init__(self, path_separator='->', type_separator='||'):
     Thread.__init__(self)
     core.path_separator = path_separator
     core.type_separator = type_separator
     self.main_overlay = oaam.Overlay(transparency=0.5)
     self.desktop = pywinauto.Desktop(backend='uia',
                                      allow_magic_lookup=False)
     self._is_running = False
     self.daemon = True
     self.event_list = []
     self.last_element_event = None
     self.start()
Exemple #4
0
def display_splash_screen():
	splash_screen = oaam.Overlay(transparency=0.0)
	screen_width = GetSystemMetrics(0)
	screen_height = GetSystemMetrics(1)
	nb_band = 15
	line_height = (screen_height / 2) / nb_band
	text_lines = [''] * nb_band
	text_lines[1] = 'Pywinauto recorder'
	text_lines[2] = 'version ' + __version__
	text_lines[4] = 'CTRL+ALT+R : Recording/Pause'
	text_lines[6] = 'Search algorithm speed'
	text_lines[8] = 'CTRL+SHIFT+F : Copy element path in clipboard'
	text_lines[10] = 'CTRL+ALT+Q : Quit'
	text_lines[12] = 'Drag and drop a recorded file on '
	text_lines[13] = 'pywinauto_recorder.exe to replay it'
	for n in xrange(5):
		splash_screen.clear_all()
		color = [60, 70, 90]
		i = 0
		while i < nb_band:
			splash_screen.add(
				x=screen_width / 3 - i*8, y=screen_height / 4 + i * line_height, width=screen_width / 3 + i*8*2,
				height=line_height, text=text_lines[i], text_color=(0, 0, 0), color=tuple(color),
				geometry=oaam.Shape.rectangle, thickness=1, brush=oaam.Brush.solid, brush_color=tuple(color))
			color[0], color[1], color[2] = color[0] + 2, color[1] + 1, color[2] + 3
			i = i + 1
		if n % 2 == 0:
			overlay_add_record_icon(
				splash_screen, screen_width / 3 + screen_width / 18, screen_height / 4 + line_height * 4)
		else:
			overlay_add_pause_icon(
				splash_screen, screen_width / 3 + screen_width / 18, screen_height / 4 + line_height * 4)
		overlay_add_progress_icon(
			splash_screen, n % 5, screen_width / 3 + screen_width / 18, screen_height / 4 + line_height * 6)
		overlay_add_play_icon(
			splash_screen, screen_width / 3 + screen_width / 18, int(screen_height / 4 + line_height * 12.5))
		splash_screen.refresh()
		time.sleep(0.8)
	splash_screen.clear_all()
	splash_screen.refresh()
Exemple #5
0
def display_splash_screen():
    import urllib.request
    import urllib.error
    from pywinauto_recorder import __version__
    url_version = "https://raw.githubusercontent.com/beuaaa/pywinauto_recorder/master/bin/VersionInfo.rc"
    latest_version = __version__
    try:
        with urllib.request.urlopen(url_version) as f:
            line = f.read().decode('utf-8')
        latest_version = line.split('ProductVersion')[1].split('"')[2]
    except urllib.error.URLError:
        pass

    if __version__ == latest_version:
        print("Your Pywinauto recorder is up to date.")
    else:
        print("Pywinauto recorder v" + latest_version + " is available!")

    splash_foreground = oaam.Overlay(transparency=0.0)
    time.sleep(0.2)
    splash_background = oaam.Overlay(transparency=0.1)
    screen_width = GetSystemMetrics(0)
    screen_height = GetSystemMetrics(1)
    nb_band = 24
    line_height = 22.4
    text_lines = [''] * nb_band
    if __version__ == latest_version:
        text_lines[6] = 'Pywinauto recorder ' + __version__
    else:
        text_lines[
            6] = 'Your version of Pywinauto recorder (' + __version__ + ') is not up to date (' + latest_version + ' is available!)'
    text_lines[7] = 'by David Pratmarty'
    text_lines[
        9] = 'Record / Stop                            Smart mode On / Off'
    text_lines[
        10] = 'CTRL+ALT+R                                      CTRL+ALT+S'
    text_lines[12] = 'Search algorithm speed        Display / Hide information'
    text_lines[
        13] = '                                                       CTRL+SHIFT+D'
    text_lines[
        15] = 'Copy python code in clipboard          Click on "Quit" in'
    text_lines[
        16] = 'CTRL+SHIFT+F                                tray menu to quit'
    text_lines[
        18] = 'To replay your recorded file you can:                          '
    text_lines[19] = '- Drag and drop it on pywinauto_recorder.exe            '
    text_lines[
        20] = '- Click on "Start replaying clipboard" in tray menu       '
    text_lines[
        21] = '- Run "python.exe recorded_file.py"                           '

    splash_background.clear_all()
    w, h = 640, 540
    x, y = screen_width / 2 - w / 2, screen_height / 2 - h / 2
    splash_width = w
    splash_height = h
    splash_left = x
    splash_right = x + w
    splash_top = y
    splash_bottom = y + h
    splash_background.add(geometry=oaam.Shape.triangle,
                          thickness=0,
                          xyrgb_array=((x, y, 200, 0, 0),
                                       (x + w, y, 0, 128, 0), (x + w, y + h, 0,
                                                               0, 155)))
    splash_background.add(geometry=oaam.Shape.triangle,
                          thickness=0,
                          xyrgb_array=((x + w, y + h, 0, 0, 155),
                                       (x, y + h, 22, 128, 66), (x, y, 200, 0,
                                                                 0)))

    splash_background.refresh()

    mouse_was_splash_screen = False
    x, y = win32api.GetCursorPos()
    if (splash_left < x < splash_right) and (splash_top < y < splash_bottom):
        mouse_was_splash_screen = True
        message_to_continue = 'To continue: move the mouse cursor out of this window'
    else:
        message_to_continue = 'To continue: move the mouse cursor over this window'

    py_rec_icon_rect = (splash_left + splash_width / 2 - 200 / 2,
                        splash_top + 30, 200, 100)
    overlay_add_pywinauto_recorder_icon(splash_background, py_rec_icon_rect[0],
                                        py_rec_icon_rect[1])
    continue_after_splash_screen = True
    n = 0
    while continue_after_splash_screen:
        splash_foreground.clear_all()
        i = 0
        while i < nb_band:
            if i < 2:
                font_size = 44
            else:
                font_size = 20
            splash_foreground.add(x=splash_left,
                                  y=splash_top + i * line_height,
                                  width=splash_width,
                                  height=line_height,
                                  text=text_lines[i],
                                  font_size=font_size,
                                  text_color=(254, 255, 255),
                                  color=(255, 255, 255),
                                  geometry=oaam.Shape.rectangle,
                                  thickness=0)
            i = i + 1
        if n % 6 in [0, 1, 2]:
            overlay_add_mode_icon(splash_foreground, IconSet.hicon_record,
                                  splash_left + 50,
                                  splash_top + line_height * 8.7)
        else:
            overlay_add_mode_icon(splash_foreground, IconSet.hicon_stop,
                                  splash_left + 50,
                                  splash_top + line_height * 8.7)
        overlay_add_mode_icon(splash_foreground, IconSet.hicon_light_on,
                              int(splash_right - (52 + 50)),
                              int(splash_top + line_height * 8.7))
        overlay_add_progress_icon(splash_foreground, n % 6, splash_left + 50,
                                  splash_top + line_height * 11.7)
        overlay_add_mode_icon(splash_foreground, IconSet.hicon_search,
                              int(splash_right - (52 + 50)),
                              splash_top + line_height * 11.7)
        overlay_add_mode_icon(splash_foreground, IconSet.hicon_clipboard,
                              splash_left + 50,
                              splash_top + line_height * 14.7)
        overlay_add_mode_icon(splash_foreground, IconSet.hicon_power,
                              int(splash_right - (52 + 50)),
                              splash_top + line_height * 14.7)
        overlay_add_mode_icon(splash_foreground, IconSet.hicon_play,
                              splash_left + 50,
                              int(splash_top + line_height * 19.3))

        splash_foreground.refresh()
        time.sleep(0.4)
        if n % 2 == 0:
            text_lines[23] = message_to_continue
        else:
            text_lines[23] = ''
        continue_after_splash_screen = False
        x, y = win32api.GetCursorPos()
        if (splash_left < x < splash_right) and (splash_top < y <
                                                 splash_bottom):
            if mouse_was_splash_screen:
                continue_after_splash_screen = True
        else:
            if not mouse_was_splash_screen:
                continue_after_splash_screen = True
        n = n + 1
    splash_foreground.clear_all()
    splash_foreground.refresh()
    splash_background.clear_all()
    splash_background.refresh()
Exemple #6
0
def display_splash_screen():
    splash_foreground = oaam.Overlay(transparency=0.0)
    time.sleep(0.2)
    splash_background = oaam.Overlay(transparency=0.1)
    screen_width = GetSystemMetrics(0)
    screen_height = GetSystemMetrics(1)
    nb_band = 20
    line_height = (screen_height / 2) / nb_band
    text_lines = [''] * nb_band
    text_lines[6] = 'Pywinauto recorder ' + __version__
    text_lines[7] = 'by David Pratmarty'
    text_lines[9] = 'CTRL+ALT+R : Pause / Record / Stop'
    text_lines[11] = 'Search algorithm speed'
    text_lines[13] = 'CTRL+SHIFT+F : Copy element path in clipboard'
    text_lines[15] = 'CTRL+ALT+Q : Quit'
    text_lines[17] = 'Drag and drop a recorded file on '
    text_lines[18] = 'pywinauto_recorder.exe to replay it'

    splash_background.clear_all()
    x, y, w, h = screen_width / 3, screen_height / 4, screen_width / 3, line_height * nb_band
    splash_background.add(geometry=oaam.Shape.triangle,
                          thickness=0,
                          xyrgb_array=((x, y, 200, 0, 0),
                                       (x + w, y, 0, 128, 0), (x + w, y + h, 0,
                                                               0, 155)))
    splash_background.add(geometry=oaam.Shape.triangle,
                          thickness=0,
                          xyrgb_array=((x + w, y + h, 0, 0, 155),
                                       (x, y + h, 22, 128, 66), (x, y, 200, 0,
                                                                 0)))

    splash_background.refresh()

    py_rec_icon_rect = (screen_width / 3 + screen_width / 6 - 100,
                        screen_height / 4 + 30, 200, 100)
    overlay_add_pywinauto_recorder_icon(splash_background, py_rec_icon_rect[0],
                                        py_rec_icon_rect[1])
    from pywinauto_recorder.player import move as mouse_move
    mouse_move((py_rec_icon_rect[0] + py_rec_icon_rect[2] / 2,
                py_rec_icon_rect[1] + py_rec_icon_rect[3] / 2))
    mouse_cursor_on_py_rec_icon = True
    n = 0
    while mouse_cursor_on_py_rec_icon:
        #for n in range(10):
        splash_foreground.clear_all()
        i = 0
        while i < nb_band:
            if i < 2:
                font_size = 44
            else:
                font_size = 20
            splash_foreground.add(x=screen_width / 3,
                                  y=screen_height / 4 + i * line_height,
                                  width=screen_width / 3,
                                  height=line_height,
                                  text=text_lines[i],
                                  font_size=font_size,
                                  text_color=(254, 255, 255),
                                  color=(255, 255, 255),
                                  geometry=oaam.Shape.rectangle,
                                  thickness=0)
            i = i + 1
        if n % 3 == 0:
            overlay_add_record_icon(splash_foreground,
                                    screen_width / 3 + screen_width / 18,
                                    screen_height / 4 + line_height * 8.6)
        if n % 3 == 1:
            overlay_add_pause_icon(splash_foreground,
                                   screen_width / 3 + screen_width / 18,
                                   screen_height / 4 + line_height * 8.6)
        if n % 3 == 2:
            overlay_add_stop_icon(splash_foreground,
                                  screen_width / 3 + screen_width / 18,
                                  screen_height / 4 + line_height * 8.6)
        overlay_add_progress_icon(splash_foreground, n % 5,
                                  screen_width / 3 + screen_width / 18,
                                  screen_height / 4 + line_height * 10.8)
        overlay_add_play_icon(splash_foreground,
                              screen_width / 3 + screen_width / 18,
                              int(screen_height / 4 + line_height * 17.3))
        splash_foreground.refresh()
        time.sleep(0.4)
        x, y = win32api.GetCursorPos()
        mouse_cursor_on_py_rec_icon = False
        if py_rec_icon_rect[0] < x < py_rec_icon_rect[0] + py_rec_icon_rect[2]:
            if py_rec_icon_rect[
                    1] < y < py_rec_icon_rect[1] + py_rec_icon_rect[3]:
                mouse_cursor_on_py_rec_icon = True
        n = n + 1

    splash_foreground.clear_all()
    splash_foreground.refresh()
    splash_background.clear_all()
    splash_background.refresh()
Exemple #7
0
if __name__ == '__main__':
    windll.user32.ShowWindow(windll.kernel32.GetConsoleWindow(), 6)
    parser = argparse.ArgumentParser()
    parser.add_argument("filename",
                        metavar='path',
                        help="replay a python script",
                        type=str,
                        action='store',
                        nargs='?',
                        default='')
    parser.add_argument("--no_splash_screen",
                        help="Does not display the splash screen",
                        action='store_true')
    args = parser.parse_args()
    if args.filename:
        main_overlay = oaam.Overlay(transparency=0.5)
        from pywinauto_recorder.recorder import overlay_add_play_icon
        import traceback
        import codecs
        overlay_add_play_icon(main_overlay, 10, 10)
        if os_path_isfile(args.filename):
            with codecs.open(args.filename, "r",
                             encoding='utf-8') as python_file:
                data = python_file.read()
            print("Replaying: " + args.filename)
            try:
                compiled_code = compile(data, '<string>', 'exec')
                exit_code = eval(compiled_code)
            except Exception as e:
                windll.user32.ShowWindow(windll.kernel32.GetConsoleWindow(), 3)
                exc_type, exc_value, exc_traceback = sys.exc_info()