示例#1
0
    def enable(self, persisted=False):
        if not self.enabled:
            # Copied over from layout widget enabled to make sure blocks_mouse setting isn"t changed
            if self.mouse_enabled:
                self.mouse_capture_canvas = canvas.Canvas(
                    min(self.x, self.limit_x), min(self.y, self.limit_y),
                    max(self.width, self.limit_width),
                    max(self.height, self.limit_height))
                self.mouse_capture_canvas.blocks_mouse = True
                self.mouse_capture_canvas.register("mouse", self.on_mouse)
                self.mouse_capture_canvas.freeze()

            self.enabled = True
            self.canvas = canvas.Canvas(min(self.x, self.limit_x),
                                        min(self.y, self.limit_y),
                                        max(self.width, self.limit_width),
                                        max(self.height, self.limit_height))
            self.canvas.register("draw", self.draw_cycle)
            self.animation_tick = self.animation_max_duration if self.show_animations else 0
            self.canvas.resume()
            if persisted:
                self.preferences.enabled = True
                self.preferences.mark_changed = True
                self.event_dispatch.request_persist_preferences()
            self.cleared = False
示例#2
0
 def enable(self, animated=True):
     if not self.enabled:
         self.enabled = True
         self.canvas = canvas.Canvas(self.x, self.y, self.width, self.height)
         self.canvas.register('draw', self.draw_cycle)
         self.animation_tick = self.animation_max_duration if animated else 0
         self.canvas.resume()
         self.preferences.persist_preferences({self.id + '_enabled': True})
         self.cleared = False
    def on_pop(self, noise):
        if len(mouse.eye_hist) < 2:
            return
        if noise != 'hiss_start':
            return
        now = time.time()
        if self.state == STATE_IDLE:
            if now - self.last_click < config.double_click:
                ctrl.mouse_click(hold=32000)
                return

            l, r = mouse.eye_hist[-1]
            p = (l.gaze + r.gaze) / 2
            main_gaze = -0.02 < p.x < 1.02 and -0.02 < p.y < 1.02 and bool(
                l or r)
            if not main_gaze:
                pass  # return

            ctrl.cursor_visible(False)

            self.gaze = eye_config.size_px * p
            capture = self.gaze - (config.screen_area / 2)
            capture.x = min(max(capture.x, 0),
                            main_screen.width - config.screen_area.x)
            capture.y = min(max(capture.y, 0),
                            main_screen.height - config.screen_area.y)
            self.rect = (capture.x, capture.y, config.screen_area.x,
                         config.screen_area.y)
            self.pos = self.gaze - (config.screen_area * config.img_scale) / 2
            self.pos.x = min(
                max(self.pos.x, 0),
                main_screen.width - config.screen_area.x * config.img_scale)
            self.pos.y = min(
                max(self.pos.y, 0),
                main_screen.height - config.screen_area.y * config.img_scale)
            self.size = Point2d(config.screen_area.x * config.img_scale,
                                config.screen_area.y * config.img_scale)
            self.off = Point2d(0, 0)

            self.frame = 0
            self.canvas = canvas.Canvas(self.pos.x, self.pos.y, self.size.x,
                                        self.size.y)
            if not config.live:
                self.capture()
            self.canvas.register('draw', self.draw)
            self.state = STATE_OVERLAY
        elif self.state == STATE_OVERLAY:
            self.state = STATE_IDLE
            ctrl.cursor_visible(True)
            self.canvas.unregister('draw', self.draw)
            self.canvas.close()
            self.canvas = None
            dot, origin = self.get_pos()
            if origin:
                ctrl.mouse(origin.x, origin.y)
                ctrl.mouse_click(hold=32000)
                self.last_click = time.time()
示例#4
0
    def generate_canvases(self):
        if self.mouse_enabled:
            self.mouse_capture_canvas = canvas.Canvas(
                min(self.x, self.limit_x), min(self.y, self.limit_y),
                max(self.width, self.limit_width),
                max(self.height, self.limit_height))
            self.mouse_capture_canvas.blocks_mouse = True
            self.mouse_capture_canvas.register("mouse", self.on_mouse)
            self.mouse_capture_canvas.freeze()

        # Copied over from base widget enabled to make sure blocks_mouse setting isn"t changed
        self.canvas = canvas.Canvas(min(self.x, self.limit_x),
                                    min(self.y, self.limit_y),
                                    max(self.width, self.limit_width),
                                    max(self.height, self.limit_height))
        self.canvas.register("draw", self.draw_cycle)
        self.animation_tick = self.animation_max_duration if self.show_animations else 0
        self.canvas.resume()
示例#5
0
 def enable(self):
     if self.enabled:
         return
     self.enabled = True
     self.last_pos = None
     self.canvas = canvas.Canvas(0, 0, self.width + 2, self.height + 2)
     self.check_mouse()
     self.canvas.register('mousemove', self.on_mouse)
     self.canvas.register('draw', self.draw_canvas)
     self.canvas.freeze()
     # uncomment this if the mouse movement event isn't working
     self.job = cron.interval('16ms', self.check_mouse)
示例#6
0
    def create_canvases(self, region_indices_used=None):
        if not region_indices_used:
            region_indices_used = []

        for index, region in enumerate(self.regions):
            if index not in region_indices_used:
                canvas_rect = self.align_region_canvas_rect(region)
                canvas_reference = {
                    "canvas":
                    canvas.Canvas(canvas_rect.x, canvas_rect.y,
                                  canvas_rect.width, canvas_rect.height)
                }
                canvas_reference[
                    "callback"] = lambda canvas, self=self, region=region: self.draw_region(
                        canvas, region)
                canvas_reference["region"] = region
                canvas_reference["canvas"].register(
                    "draw", canvas_reference["callback"])
                canvas_reference["canvas"].freeze()
                self.canvases.append(canvas_reference)
示例#7
0
    def enable(self, persisted=False):
        if not self.enabled:
            self.enabled = True
            self.canvas = canvas.Canvas(min(self.x, self.limit_x),
                                        min(self.y, self.limit_y),
                                        max(self.width, self.limit_width),
                                        max(self.height, self.limit_height))
            self.canvas.register('draw', self.draw_cycle)
            self.animation_tick = self.animation_max_duration if self.show_animations else 0
            self.canvas.resume()

            if self.mouse_enabled:
                self.canvas.blocks_mouse = True
                self.canvas.register('mouse', self.on_mouse)

            if persisted:
                self.preferences.enabled = True
                self.preferences.mark_changed = True
                actions.user.persist_hud_preferences()
            self.cleared = False
示例#8
0
    line_height = paint.get_fontmetrics(1.5)[0]

    h = active_word_list
    h_string = ["%d . %s" % (i + 1, h[i]) for i in range(len(h))]
    paint.color = "ffffff"
    for i in range(len(h_string)):
        h = h_string[i]
        canvas.draw_text(
            h, canvas.x + padding_left, canvas.y + line_height + (i * line_height)
        )


# initialize the overlay
screen = ui.main_screen()
w, h = screen.width / 3, screen.height / 3
panel = canvas.Canvas(w, h, w, h, panel=True)
panel.register("draw", draw_homophones)
panel.hide()


def close_homophones():
    panel.hide()
    pick_context.unload()


def make_selection(m, is_selection, transform=lambda x: x):
    cron.after("0s", close_homophones)
    words = m._words
    d = None
    if len(words) == 1:
        d = int(parse_word(words[0]))
示例#9
0
    def start_setup(self, setup_type, mouse_position=None):
        """Starts a setup mode that is used for moving, resizing and other various changes that the user might setup"""
        if (mouse_position is not None):
            self.drag_position = [
                mouse_position[0] - self.limit_x,
                mouse_position[1] - self.limit_y
            ]

        if (setup_type not in self.allowed_setup_options
                and setup_type not in ["", "cancel", "reload"]):
            return

        pos = ctrl.mouse_pos()

        # Persist the user preferences when we end our setup
        if (self.setup_type != "" and not setup_type):
            self.drag_position = []
            rect = self.canvas.rect

            if (self.setup_type == "dimension"):
                self.x = 0
                self.y = 0
                self.width = int(rect.width)
                self.height = int(rect.height)
                self.limit_width = int(rect.width)
                self.limit_height = int(rect.height)
                self.preferences.width = self.limit_width
                self.preferences.height = self.limit_height
                self.preferences.limit_width = self.limit_width
                self.preferences.limit_height = self.limit_height
            elif (self.setup_type == "font_size"):
                self.preferences.font_size = self.font_size

            self.setup_type = setup_type
            self.preferences.mark_changed = True
            self.canvas.pause()
            self.canvas.unregister("draw", self.setup_draw_cycle)
            self.canvas = None

            self.event_dispatch.request_persist_preferences()
        # Cancel every change
        elif setup_type == "cancel":
            self.drag_position = []
            if (self.setup_type != ""):
                self.load({}, False)

                self.setup_type = ""
                if self.canvas:
                    self.canvas.unregister("draw", self.setup_draw_cycle)
                    self.canvas = None

                for canvas_reference in self.canvases:
                    canvas_rect = self.align_region_canvas_rect(
                        canvas_reference["region"])
                    canvas_reference["canvas"].rect = canvas_rect
                    canvas_reference["canvas"].freeze()

        elif setup_type == "reload":
            self.drag_position = []
            self.setup_type = ""
            for canvas_reference in self.canvases:
                canvas_reference["canvas"].freeze()

        # Start the setup by mocking a full screen screen region to place the canvas in
        else:
            main_screen = ui.main_screen()
            region = HudScreenRegion("setup", "Setup mode text", "command_icon", "DD4500", main_screen.rect, \
                Point2d(main_screen.rect.x, main_screen.rect.y))
            region.vertical_centered = True
            canvas_rect = self.align_region_canvas_rect(region)
            self.x = canvas_rect.x
            self.y = canvas_rect.y

            if not self.canvas:
                self.canvas = canvas.Canvas(self.x, self.y, self.limit_width,
                                            self.limit_height)
                self.canvas.register("draw", self.setup_draw_cycle)
            self.canvas.move(self.x, self.y)
            self.canvas.resume()
            super().start_setup(setup_type, mouse_position)
示例#10
0
    for k, v in zip(alnum, string.ascii_lowercase):
        canvas.draw_text('%s - %s' % (k, v), canvas.x + padding_left,
                         canvas.y + (num * line_height))
        num += 1


# initialize the overlay
screen = ui.main_screen()
w, h = screen.width, screen.height

x_position = w / 3
y_position = h / 4
x_dimension = w / 6
y_dimension = h / 1.5

panel = canvas.Canvas(x_position, y_position, x_dimension, y_dimension)
panel.register('draw', draw_alphabet)
panel.hide()


def show_alphabet(_):
    global alphabet_context

    panel.show()
    panel.freeze()

    keymap = {
        '(0 | exit | escape)': lambda x: close_alphabet(),
    }

    alphabet_context.keymap(keymap)