Ejemplo n.º 1
0
def get_window(via_ipc, force_window=False, force_tab=False,
               force_target=None):
    """Helper function for app.py to get a window id.

    Args:
        via_ipc: Whether the request was made via IPC.
        force_window: Whether to force opening in a window.
        force_tab: Whether to force opening in a tab.
        force_target: Override the new-instance-open-target config
    """
    if force_window and force_tab:
        raise ValueError("force_window and force_tab are mutually exclusive!")
    if not via_ipc:
        # Initial main window
        return 0
    window_to_raise = None
    if force_target is not None:
        open_target = force_target
    else:
        open_target = config.get('general', 'new-instance-open-target')
    if (open_target == 'window' or force_window) and not force_tab:
        window = MainWindow()
        window.show()
        win_id = window.win_id
        window_to_raise = window
    else:
        try:
            win_mode = config.get('general', 'new-instance-open-target.window')
            if win_mode == 'last-focused':
                window = objreg.last_focused_window()
            elif win_mode == 'last-opened':
                window = objreg.last_window()
            elif win_mode == 'last-visible':
                window = objreg.last_visible_window()
        except objreg.NoWindow:
            # There is no window left, so we open a new one
            window = MainWindow()
            window.show()
            win_id = window.win_id
            window_to_raise = window
        win_id = window.win_id
        if open_target not in ['tab-silent', 'tab-bg-silent']:
            window_to_raise = window
    if window_to_raise is not None:
        window_to_raise.setWindowState(
            window.windowState() & ~Qt.WindowMinimized | Qt.WindowActive)
        window_to_raise.raise_()
        window_to_raise.activateWindow()
        QApplication.instance().alert(window_to_raise)
    return win_id
Ejemplo n.º 2
0
def get_target_window():
    """Get the target window for new tabs, or None if none exist."""
    try:
        win_mode = config.val.new_instance_open_target_window
        if win_mode == 'last-focused':
            return objreg.last_focused_window()
        elif win_mode == 'first-opened':
            return objreg.window_by_index(0)
        elif win_mode == 'last-opened':
            return objreg.window_by_index(-1)
        elif win_mode == 'last-visible':
            return objreg.last_visible_window()
        else:
            raise ValueError("Invalid win_mode {}".format(win_mode))
    except objreg.NoWindow:
        return None
Ejemplo n.º 3
0
def get_target_window():
    """Get the target window for new tabs, or None if none exist."""
    try:
        win_mode = config.get('general', 'new-instance-open-target.window')
        if win_mode == 'last-focused':
            return objreg.last_focused_window()
        elif win_mode == 'first-opened':
            return objreg.window_by_index(0)
        elif win_mode == 'last-opened':
            return objreg.window_by_index(-1)
        elif win_mode == 'last-visible':
            return objreg.last_visible_window()
        else:
            raise ValueError("Invalid win_mode {}".format(win_mode))
    except objreg.NoWindow:
        return None
Ejemplo n.º 4
0
 def handler(self, *args):
     self.last_focused_window = objreg.last_focused_window()
     print(self.last_focused_window)
     print(args)