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 __init__(self): if len(ui.screens()) == 1: return tap.register(tap.MMOVE, self.on_move) tracker.register("gaze", self.on_gaze) self.top = None if len(ui.screens()) >= 2: print("Have top screen") self.top = ui.screens()[1] self.saved_mouse_top = Point2d(self.top.x + self.top.width // 2, self.top.y + self.top.height // 2) self.main_mouse = False self.main_gaze = False self.restore_counter = 0
def initial_load_preferences(self): user_preferences_screen_file_path = self.preferences.get_screen_preferences_filepath( ui.screens()) if not os.path.exists(user_preferences_file_location): self.preferences.persist_preferences( self.preferences.default_prefs, True) self.preferences.load_preferences(user_preferences_screen_file_path)
def draft_named_move(name: str, screen_number: Optional[int] = None): """ Lets you move the window to the top, bottom, left, right, or middle of the screen. """ screen = ui.screens()[screen_number or 0] window_rect = draft_manager.get_rect() xpos = (screen.width - window_rect.width) / 2 ypos = (screen.height - window_rect.height) / 2 if name == "top": ypos = 50 elif name == "bottom": ypos = screen.height - window_rect.height - 50 elif name == "left": xpos = 50 elif name == "right": xpos = screen.width - window_rect.width - 50 elif name == "middle": # That's the default values pass # Adjust for the fact that the screen may not be at 0,0. xpos += screen.x ypos += screen.y draft_manager.reposition(xpos=xpos, ypos=ypos)
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)
def move_screen(off): win = ui.active_window() src_screen = win.screen screens = ui.screens() dst_screen = screens[(screens.index(src_screen) + off) % len(screens)] if src_screen == dst_screen: return src = src_screen.visible_rect dst = dst_screen.visible_rect old = win.rect change_screen_mode = config.get("window_management.change_screen_mode", "same") if change_screen_mode == "same": new_rectangle = ui.Rect( dst.left + (old.left - src.left) / src.width * dst.width, dst.top + (old.top - src.top) / src.height * dst.height, old.width / src.width * dst.width, old.height / src.height * dst.height, ) elif change_screen_mode == "full": new_rectangle = dst else: raise ValueError("{} screen mode not understood."(change_screen_mode)) win.rect = new_rectangle time.sleep(0.25) win.rect = new_rectangle
def get_sorted_screens(): """Return screens sorted by their topmost, then leftmost, edge. Screens will be sorted leftto-right, then top-to-bottom as a tiebreak. """ return sorted( sorted(ui.screens(), key=lambda screen: screen.visible_rect.top), key=lambda screen: screen.visible_rect.left, )
def get_watch_directories(self): screens = ui.screens() watch_list = [self.get_main_preferences_filename(), self.get_screen_preferences_filepath(screens)] if self.hud_environment: temp_environment = self.hud_environment self.hud_environment = "" watch_list.extend([self.get_main_preferences_filename(), self.get_screen_preferences_filepath(screens)]) self.hud_environment = temp_environment return watch_list
def load_default_preferences(self): preferences = {} for key, value in self.default_prefs.items(): preferences[key] = value if self.hud_environment != "": lines = [] real_hud_environment = self.hud_environment self.hud_environment = "" monitor_file_path = self.get_screen_preferences_filepath(ui.screens()) file_path = self.get_main_preferences_filename() if os.path.exists(file_path): fh = open(file_path, "r") lines.extend(fh.readlines()) fh.close() if monitor_file_path is not None: if os.path.exists(monitor_file_path): fh = open(monitor_file_path, "r") lines.extend(fh.readlines()) fh.close() preferences = {} for key, value in self.default_prefs.items(): preferences[key] = value # Clear context_menu and walk_through stuff so the new sizes can be applied migrate_v05 = False # Override defaults with file values for index,line in enumerate(lines): split_line = line.strip("\n").split(",", 1) key = split_line[0] if not migrate_v05 and key.startswith("walk_through"): migrate_v05 = True value = split_line[1] if (key in self.boolean_keys): preferences[key] = True if int(value) > 0 else False elif value is not None: preferences[key] = value self.hud_environment = real_hud_environment if migrate_v05: keys = list(preferences.keys()) for key in keys: if key.startswith("context_menu") or key.startswith("walk_through"): del preferences[key] self.base_prefs = preferences return copy.copy(preferences)
def load_widgets(self): """Load the user defined widgets""" # TODO - Make the widgets properly user-definable # By making them addable and removable # With subscribed content, topics etc for specific widgets # For now, we will just use the default widgets taken from the display widgets array self.widgets = self.get_default_widgets() self.previous_screen_rects = [] for screen in ui.screens(): self.previous_screen_rects.append( ui.Rect(screen.x, screen.y, screen.width, screen.height))
def __init__(self): self.states = [] # self.screen_index = 0 self.screen = ui.screens()[0] self.offset_x = self.screen.x self.offset_y = self.screen.y self.width = self.screen.width self.height = self.screen.height self.states.append((self.offset_x, self.offset_y, self.width, self.height)) self.mcanvas = canvas.Canvas.from_screen(self.screen) self.active = False self.moving = False self.count = 0 self.was_eye_tracking = False
def __init__(self): if len(ui.screens()) == 1: return tap.register(tap.MMOVE, self.on_move) tap.register(tap.MCLICK, self.on_click) tracker.register("gaze", self.on_gaze) self.left = None self.right = None if len(ui.screens()) >= 2: print("Have left screen") self.left = ui.screens()[1] self.saved_mouse_left = Point2d( self.left.x + self.left.width // 2, self.left.y + self.left.height // 2) if len(ui.screens()) == 3: print("Have right screen") self.right = ui.screens()[2] self.saved_mouse_right = Point2d( self.right.x + self.right.width // 2, self.right.y + self.right.height // 2) self.main_mouse = False self.main_gaze = False self.restore_counter = 0
def __init__(self): self.states = [] # self.screen_index = 0 self.screen = ui.screens()[0] self.offset_x = self.screen.x self.offset_y = self.screen.y self.width = self.screen.width self.height = self.screen.height self.states.append((self.offset_x, self.offset_y, self.width, self.height)) self.mcanvas = canvas.Canvas.from_screen(self.screen) self.img = None self.wants_capture = 0 self.active = False self.moving = False self.count = 0 self.was_control_mouse_active = False self.was_zoom_mouse_active = False
def move_screen(off): win = ui.active_window() src_screen = win.screen screens = ui.screens() dst_screen = screens[(screens.index(src_screen) + off) % len(screens)] if src_screen == dst_screen: return src = src_screen.visible_rect dst = dst_screen.visible_rect old = win.rect win.rect = ui.Rect( dst.left + (old.left - src.left) / src.width * dst.width, dst.top + (old.top - src.top) / src.height * dst.height, old.width / src.width * dst.width, old.height / src.height * dst.height, )
def _reset(_): self.save_state() self.count = 0 if pos >= 0: self.screen_index = pos screens = ui.screens() # 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) print(self.offset_x, self.offset_y, self.width, self.height)
def move_screen(direction: int): """Moves a window between screens""" win = ui.active_window() src_screen = win.screen screens = ui.screens() dst_screen = screens[(screens.index(src_screen) + direction) % len(screens)] if src_screen == dst_screen: return src = src_screen.rect dst = dst_screen.rect old = win.rect win.rect = ui.Rect( dst.left + (old.left - src.left) / src.width * dst.width, dst.top + (old.top - src.top) / src.height * dst.height, old.width / src.width * dst.width, old.height / src.height * dst.height, )
def draft_named_move(name: str, screen_number: Optional[int] = None): """Move the draft window to a named position on screen. Options are top, bottom, left, right, or middle. """ screen = ui.screens()[screen_number or 0] window_rect = draft_manager.get_rect() xpos = (screen.width - window_rect.width) / 2 ypos = (screen.height - window_rect.height) / 2 if name == "top": ypos = 50 elif name == "bottom": ypos = screen.height - window_rect.height - 50 elif name == "left": xpos = 50 elif name == "right": xpos = screen.width - window_rect.width - 50 elif name == "middle": # That's the default values pass draft_manager.reposition(xpos=xpos, ypos=ypos)
def __init__(self, preferences: HeadUpDisplayUserPreferences, theme: HeadUpDisplayTheme, event_dispatch: HeadUpEventDispatch): self.default_screen_rect = ui.Rect(0, 0, 1920, 1080) self.default_screen_mm_size = [527.0, 296.0] self.previous_talon_hud_environment = "" self.previous_screen_rects = [] self.preferences = preferences self.theme = theme self.event_dispatch = event_dispatch self.initial_load_preferences() self.load_widgets() # Reload the preferences according to the monitor sizes if the given file does not exist if not os.path.exists( self.preferences.get_screen_preferences_filepath( ui.screens())): self.previous_screen_rects = [ ui.Rect(self.default_screen_rect.x, self.default_screen_rect.y, self.default_screen_rect.width, self.default_screen_rect.height) ] self.reload_preferences(True, self.previous_talon_hud_environment)
def screen_key(): return str( sorted(ui.screens(), key=lambda screen: screen.visible_rect.left))
def __init__(self, hud_environment = "", hud_version = 5): self.hud_environment = hud_environment self.load_preferences(self.get_screen_preferences_filepath(ui.screens())) self.hud_version = hud_version
def sorted_screens(): """ return screens sorted by their left most edge, from left to right """ return sorted(ui.screens(), key=lambda screen: screen.visible_rect.left)
def reload_preferences(self, force_reload=False, current_hud_environment="") -> str: # Check if the screen dimensions have changed current_screen_rects = [] dimensions_changed = force_reload for index, screen in enumerate(ui.screens()): current_screen_rects.append( ui.Rect(screen.x, screen.y, screen.width, screen.height)) if index < len(self.previous_screen_rects ) and dimensions_changed == False: previous_screen_rect = self.previous_screen_rects[index] if previous_screen_rect.x != screen.x or \ previous_screen_rect.y != screen.y or \ previous_screen_rect.width != screen.width or \ previous_screen_rect.height != screen.height: dimensions_changed = True dimensions_changed = dimensions_changed or len( current_screen_rects) != len(self.previous_screen_rects) # Reload the main preferences in case the Talon HUD mode changed new_theme = self.preferences.prefs["theme_name"] environment_changed = current_hud_environment != self.previous_talon_hud_environment if environment_changed: self.preferences.set_hud_environment(current_hud_environment) # Prevent two reloads after another if the monitor has also changed if not dimensions_changed: self.preferences.load_preferences( self.preferences.get_main_preferences_filename()) self.previous_talon_hud_environment = current_hud_environment if dimensions_changed: screen_preferences_file = self.preferences.get_screen_preferences_filepath( current_screen_rects) # If the dimensions have changed, but no preferences file is available, # Determine the positioning of the widgets dynamically compared to the last screen settings if not os.path.exists(screen_preferences_file): self.preferences.load_preferences(screen_preferences_file) new_preferences = {} for key in self.preferences.default_prefs.keys(): new_preferences[key] = self.preferences.default_prefs[key] for widget in self.widgets: widget_prefs = self.get_widget_preference( widget, current_screen_rects) for key in widget_prefs.keys(): new_preferences[key] = widget_prefs[key] self.preferences.persist_preferences(new_preferences) else: self.preferences.load_preferences(screen_preferences_file) if environment_changed: new_theme = self.preferences.prefs["theme_name"] # Apply the new preferences to the widgets directly for widget in self.widgets: # First cancel any set up to make sure there won"t be some weird collision going on with persistence if widget.setup_type != "": widget.start_setup("cancel") widget.load(self.preferences.prefs, False, environment_changed) if widget.enabled: widget.start_setup("reload") # Set the screen info to be used for comparison in case the screen changes later self.previous_screen_rects = current_screen_rects return new_theme