Esempio n. 1
0
# close win2 if its still open
if win2 is not None:
    win2.close()

try:
    subprocess.Popen(leaguePath)
except FileNotFoundError:
    ag.alert(text="Error 404, File not found, change file path to correct one",
             title="Error",
             button="OK")
timePassed = 0

while True:
    tic = time.perf_counter()
    win = ahk.win_get(title="Riot Client")

    # Honestly this might be a waste of time considering Window Active != actually showing up on screen
    if win.exist:
        break
    elif timePassed > 60:
        break
        ag.alert(text="Timed out, League Client is not running properly",
                 title="Error",
                 button="OK")

    time.sleep(0.05)
    toc = time.perf_counter()
    timePassed += tic - toc

win.activate()
Esempio n. 2
0
class TestWindow(TestCase):
    def setUp(self):
        self.ahk = AHK()
        self.p = subprocess.Popen('notepad')
        time.sleep(1)
        self.win = self.ahk.win_get(title='Untitled - Notepad')
        self.assertIsNotNone(self.win)

    def test_transparent(self):
        self.assertEqual(self.win.transparent, 255)

        self.win.transparent = 220
        self.assertEqual(self.win.transparent, 220)

        self.win.transparent = 255
        self.assertEqual(self.win.transparent, 255)

    def test_pinned(self):
        self.assertFalse(self.win.always_on_top)

        self.win.always_on_top = True
        self.assertTrue(self.win.always_on_top)

        self.win.always_on_top = False
        self.assertFalse(self.win.always_on_top)

    def test_close(self):
        self.win.close()
        self.assertFalse(self.win.exist)

    def test_show_hide(self):
        self.win.hide()
        time.sleep(0.5)
        self.assertFalse(self.win.exist)

        self.win.show()
        time.sleep(0.5)
        self.assertTrue(self.win.exist)

    def test_kill(self):
        self.win.kill()
        time.sleep(0.5)
        self.assertFalse(self.win.exist)

    def test_max_min(self):
        self.assertTrue(self.win.non_max_non_min)

        self.win.maximize()
        time.sleep(0.5)
        self.assertTrue(self.win.maximized)

        self.win.minimize()
        time.sleep(0.5)
        self.assertTrue(self.win.minimized)

        self.win.restore()
        time.sleep(0.5)
        self.assertTrue(self.win.maximized)

    def test_names(self):
        self.assertEqual(self.win.class_name, b'Notepad')
        self.assertEqual(self.win.title, b'Untitled - Notepad')
        self.assertEqual(self.win.text, b'')

    def tearDown(self):
        self.p.terminate()
Esempio n. 3
0
class AHKHandeler:

    WINDOW_CLASSES = WindowClassEnum

    def __init__(self, stream_name: str, json_dict):
        """
            Stream name
        """
        self.decoder = json_dict
        self.stream_title = stream_name

        self.ahk = AHK()
        self.get_OBS()
        self.get_ProPresenter()
        #self.start_hotkeys()
        atexit.register(self.stop_hotkeys)

    def start_hotkeys(self):
        self.camera_scene_hotkey = Bindable_Hotkey(
            self.ahk, self.decoder[JSD.CAMERA_SCENE_HOTKEY])
        self.camera_scene_hotkey.bind(
            lambda: self.OBS_send(self.decoder[JSD.CAMERA_SCENE_OBS]))
        self.screen_scene_hotkey = Bindable_Hotkey(
            self.ahk, self.decoder[JSD.CENTER_SCREEN_HOTKEY])
        self.screen_scene_hotkey.bind(
            lambda: self.OBS_send(self.decoder[JSD.CENTER_SCREEN_OBS]))

        self.camera_scene_hotkey.start()
        self.screen_scene_hotkey.start()
        return

    def stop_hotkeys(self):
        self.camera_scene_hotkey.stop()
        self.screen_scene_hotkey.stop()

    def get_ProPresenter(self):
        self.ProPresenter = self.ahk.win_get(
            self.decoder[JSD.WINDOW_PROPRESENTER])
        return self.ProPresenter

    def propresenter_send(self, key, window=None):
        old_window = self.ahk.active_window
        if self.ahk.active_window == self.get_ProPresenter():
            self.ahk.send(key)
        if window == None:
            window = self.get_ProPresenter()
            window.activate()
            time.sleep(2)
            self.ahk.send(key)
            time.sleep(.5)
            old_window.activate()

    def bring_to_front(self, preset_classes, window_class=None):
        if window_class == None:
            if preset_classes == self.WINDOW_CLASSES.CHROME:
                window_class = "Chrome_WidgetWin_1"
        self.ahk.run_script(
            f"WinActivate, ahk_class {window_class} \n WinMaximize")
        return

    def get_OBS(self):
        self.OBS = self.ahk.win_get("OBS")
        if self.OBS.id == "":
            self.open_OBS()
            self.OBS = self.ahk.win_get("OBS")
        return self.OBS

    def open_OBS(self):
        self.ahk.run_script(
            "CoordMode, Mouse, Screen\n" +
            f"MouseMove, {self.decoder[JSD.TRAY_OBS_POS][0]}, " +
            f"{self.decoder[JSD.TRAY_OBS_POS][1]} \n Click\n" +
            "Sleep 500 \n MouseMove, 500, 500")
        time.sleep(1)
        return

    def OBS_send(self, key, window=None):
        old_window = self.ahk.active_window
        if window == None:
            window = self.get_OBS()
        logging.warning(f"sending {key} to obs")
        window.activate()
        time.sleep(.5)
        self.ahk.send(key)
        time.sleep(.5)
        window.to_bottom()
        old_window.activate()
        return

    def chrome_facebook_live_start(self):
        webbrowser.open("https://www.facebook.com/CenterEvents1/")

        # Upstairs deployment settings
        thread = Thread(target=self.setup_stream_facebook,
                        args=(8000, (430, 593), (719, 152), self.stream_title,
                              (1018, 518)))

        # Nick's Laptop
        # thread = Thread(target=self.setup_stream_facebook, args=(8000, (711, 741),
        # (1084, 190), "A really cool title", (1577, 649)))
        thread.start()

    def setup_stream_facebook(
            self,
            # Facebook related
            wait_time: int,
            live_position: tuple,
            connect_position: tuple,
            stream_title: str,
            stream_label_position: tuple,
            obs_window=None):

        if obs_window == None:
            obs_window = self.get_OBS()
        if self.stream_title == None:
            raise ValueError("No stream title was given")

        self.bring_to_front(self.WINDOW_CLASSES.CHROME)
        self.ahk.run_script(
            f"#NoEnv \n CoordMode, Mouse, Screen" +
            " \n Sleep {wait_time} \n " +
            # Click Live
            f"MouseMove, 500, 500 \n Sleep 500 \n" +
            f"MouseMove, {live_position[0]}, {live_position[1]} \n" +
            "Sleep 250 \n Click \n Sleep 5000 \n" +
            # Click connect
            f"MouseMove, {connect_position[0]}, {connect_position[1]} \n Sleep 250 \n"
            + "Click \n Sleep 1500 \n")

        # Start the OBS stream
        self.OBS_send(self.decoder[JSD.OBS_START_STREAM])
        time.sleep(2)

        # Click go live button on facebook
        self.ahk.run_script(
            f"#NoEnv \n" +
            # Click Title label
            f"MouseMove, {stream_label_position[0]}, {stream_label_position[1]},"
            + f"\n Sleep 250 \n Click \n Send {stream_title} \n")

        return

    def start_facebook_stream(self, stream_go_live_position=(1018, 518)):
        original_window = self.ahk.active_window
        self.bring_to_front(self.WINDOW_CLASSES.CHROME)
        time.sleep(1)
        self.ahk.run_script(f"MouseMove, {stream_go_live_position[0]}," +
                            f" {stream_go_live_position[1]}\n" +
                            "Sleep 250 \n Click",
                            blocking=False)
        original_window.activate()

    def stop_facebook_stream(self):

        self.OBS_send(self.decoder[JSD.OBS_STOP_STREAM])
        self.bring_to_front(self.WINDOW_CLASSES.CHROME)

        self.OBS_send("^!j")

        raise ReferenceError
Esempio n. 4
0
        self.assertTrue(self.win.non_max_non_min)

        self.win.maximize()
        time.sleep(0.5)
        self.assertTrue(self.win.maximized)

        self.win.minimize()
        time.sleep(0.5)
        self.assertTrue(self.win.minimized)

        self.win.restore()
        time.sleep(0.5)
        self.assertTrue(self.win.maximized)

    def test_names(self):
        self.assertEqual(self.win.class_name, b'Notepad')
        self.assertEqual(self.win.title, b'Untitled - Notepad')
        self.assertEqual(self.win.text, b'')

    def tearDown(self):
        self.p.terminate()


if __name__ == "__main__":
    ahk = AHK()
    p = subprocess.Popen('notepad')
    time.sleep(1)
    win = ahk.win_get(title='Untitled - Notepad')
    print(win.transparent)
    win.transparent = 255
Esempio n. 5
0
class TestWindow(TestCase):
    def setUp(self):
        self.ahk = AHK()
        self.p = subprocess.Popen('notepad')
        time.sleep(1)
        self.win = self.ahk.win_get(title='Untitled - Notepad')
        self.assertIsNotNone(self.win)

    def test_transparent(self):
        self.assertEqual(self.win.transparent, 255)

        self.win.transparent = 220
        self.assertEqual(self.win.transparent, 220)

        self.win.transparent = 255
        self.assertEqual(self.win.transparent, 255)

    def test_pinned(self):
        self.assertFalse(self.win.always_on_top)

        self.win.always_on_top = True
        self.assertTrue(self.win.always_on_top)

        self.win.always_on_top = False
        self.assertFalse(self.win.always_on_top)

    def test_close(self):
        self.win.close()
        self.assertFalse(self.win.exist)

    def test_show_hide(self):
        self.win.hide()
        time.sleep(0.5)
        self.assertFalse(self.win.exist)

        self.win.show()
        time.sleep(0.5)
        self.assertTrue(self.win.exist)

    def test_kill(self):
        self.win.kill()
        time.sleep(0.5)
        self.assertFalse(self.win.exist)

    def test_max_min(self):
        self.assertTrue(self.win.non_max_non_min)

        self.win.maximize()
        time.sleep(0.5)
        self.assertTrue(self.win.maximized)

        self.win.minimize()
        time.sleep(0.5)
        self.assertTrue(self.win.minimized)

        self.win.restore()
        time.sleep(0.5)
        self.assertTrue(self.win.maximized)

    def test_names(self):
        self.assertEqual(self.win.class_name, b'Notepad')
        self.assertEqual(self.win.title, b'Untitled - Notepad')
        self.assertEqual(self.win.text, b'')

    def test_height_change(self):
        current_height = self.win.height
        self.win.height = current_height + 100
        assert self.win.height == current_height + 100

    def test_width_change(self):
        current_width = self.win.width
        self.win.width = current_width + 100
        assert self.win.width == current_width + 100

    def test_rect_setter(self):
        """
        get rect ;-)
        """
        x, y, width, height = self.win.rect
        self.win.rect = (x + 10, y + 10, width + 10, height + 10)
        assert self.win.rect == (x + 10, y + 10, width + 10, height + 10)

    def test_title_change(self):
        self.win.title = 'foo'
        assert self.win.title == b'foo'

    def tearDown(self):
        self.p.terminate()

    def test_find_window(self):
        win = self.ahk.find_window(title=b'Untitled - Notepad')
        assert win.id == self.win.id

    def test_find_window_nonexistent_is_none(self):
        win = self.ahk.find_window(title=b'This should not exist')
        assert win is None

    def test_winget_nonexistent_window_is_none(self):
        win = self.ahk.win_get(title='This should not exist')
        assert win is None

    def test_winwait_nonexistent_raises_timeout_error(self):
        with pytest.raises(TimeoutError):
            win = self.ahk.win_wait(title='This should not exist')

    def test_winwait_existing_window(self):
        win = self.ahk.win_wait(title='Untitled - Notepad')
        assert win.id == self.win.id