예제 #1
0
        def _reset(m):
            self.save_state()
            self.count = 0
            x, y = ctrl.mouse_pos()

            if pos >= 0:
                self.screen = ui.screens()[pos]
            else:
                self.screen = ui.screen_containing(x, y)

            # print(screens)
            # self.screen = screens[self.screen_index]
            self.offset_x = self.screen.x
            self.offset_y = self.screen.y
            self.width = self.screen.width
            self.height = self.screen.height
            if self.mcanvas is not None:
                self.mcanvas.unregister("draw", self.draw)
            self.mcanvas = canvas.Canvas.from_screen(self.screen)
            # self.mcanvas.register("draw", self.draw)
            if eye_mouse.control_mouse.enabled:
                self.was_eye_tracking = True
                eye_mouse.control_mouse.toggle()
            if self.was_eye_tracking and self.screen == ui.screens()[0]:
                # if self.screen == ui.screens()[0]:
                self.narrow_to_pos(x, y)
                self.narrow_to_pos(x, y)
                # self.narrow_to_pos(x, y)
            # print(self.offset_x, self.offset_y, self.width, self.height)
            # print(*self.pos())
            self.mcanvas.freeze()
    def setup(self, *, rect: Rect = None, screen_num: int = None):
        screens = ui.screens()
        # each if block here might set the rect to None to indicate failure
        if rect is not None:
            try:
                screen = ui.screen_containing(*rect.center)
            except Exception:
                rect = None
        if rect is None and screen_num is not None:
            screen = screens[screen_num % len(screens)]
            rect = screen.rect
        if rect is None:
            screen = screens[0]
            rect = screen.rect
        self.rect = rect.copy()
        self.screen = screen
        self.img = None
        if self.mcanvas is not None:
            self.mcanvas.close()
        self.mcanvas = canvas.Canvas.from_screen(screen)
        if self.active:
            self.mcanvas.register("draw", self.draw)
            self.mcanvas.freeze()

        self.columns = int(self.rect.width // self.field_size)
        self.rows = int(self.rect.height // self.field_size)