當前位置: 首頁>>代碼示例>>Python>>正文


Python i3ipc.Connection方法代碼示例

本文整理匯總了Python中i3ipc.Connection方法的典型用法代碼示例。如果您正苦於以下問題:Python i3ipc.Connection方法的具體用法?Python i3ipc.Connection怎麽用?Python i3ipc.Connection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在i3ipc的用法示例。


在下文中一共展示了i3ipc.Connection方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: save_workspace

# 需要導入模塊: import i3ipc [as 別名]
# 或者: from i3ipc import Connection [as 別名]
def save_workspace(workspace, numeric, directory, profile, swallow, target):
    """
    Save an i3 workspace's layout and running programs to a file.
    """
    if workspace is None:
        i3 = i3ipc.Connection()
        workspace = i3.get_tree().find_focused().workspace().name

    if profile is not None:
        directory = Path(directory) / 'profiles'

    # Create directory if non-existent.
    Path(directory).mkdir(parents=True, exist_ok=True)

    if target != 'programs_only':
        # Save workspace layout to file.
        swallow_criteria = swallow.split(',')
        layout.save(workspace, numeric, directory, profile, swallow_criteria)

    if target != 'layout_only':
        # Save running programs to file.
        programs.save(workspace, numeric, directory, profile) 
開發者ID:JonnyHaystack,項目名稱:i3-resurrect,代碼行數:24,代碼來源:main.py

示例2: toggle_quickterm

# 需要導入模塊: import i3ipc [as 別名]
# 或者: from i3ipc import Connection [as 別名]
def toggle_quickterm(conf, shell):
    conn = i3ipc.Connection()
    shell_mark = MARK_QT.format(shell)
    qt = conn.get_tree().find_marked(shell_mark)

    # does it exist already?
    if len(qt) == 0:
        term = TERMS.get(conf["term"], conf["term"])
        qt_cmd = "{} -i {}".format(sys.argv[0], shell)

        term_cmd = expand_command(
            term,
            title=quoted(term_title(shell)),
            expanded=qt_cmd,
            string=quoted(qt_cmd),
        )
        os.execvp(term_cmd[0], term_cmd)
    else:
        qt = qt[0]
        ws = get_current_workspace(conn)

        move_back(conn, "[con_id={}]".format(qt.id))
        if qt.workspace().name != ws.name:
            pop_it(conn, shell_mark, conf["pos"], conf["ratio"]) 
開發者ID:lbonn,項目名稱:i3-quickterm,代碼行數:26,代碼來源:main.py

示例3: restore_workspace

# 需要導入模塊: import i3ipc [as 別名]
# 或者: from i3ipc import Connection [as 別名]
def restore_workspace(workspace, numeric, directory, profile, target):
    """
    Restore i3 workspace layout and programs.
    """
    i3 = i3ipc.Connection()

    if workspace is None:
        workspace = i3.get_tree().find_focused().workspace().name

    if profile is not None:
        directory = Path(directory) / 'profiles'

    if numeric and not workspace.isdigit():
        util.eprint('Invalid workspace number.')
        sys.exit(1)

    # Get layout name from file.
    workspace_layout = layout.read(workspace, directory, profile)
    if 'name' in workspace_layout and profile is None:
        workspace_name = workspace_layout['name']
    else:
        workspace_name = workspace

    # Switch to the workspace which we are loading.
    i3.command(f'workspace --no-auto-back-and-forth "{workspace_name}"')

    if target != 'programs_only':
        # Load workspace layout.
        layout.restore(workspace_name, workspace_layout)

    if target != 'layout_only':
        # Restore programs.
        saved_programs = programs.read(workspace, directory, profile)
        programs.restore(workspace_name, saved_programs) 
開發者ID:JonnyHaystack,項目名稱:i3-resurrect,代碼行數:36,代碼來源:main.py

示例4: restore

# 需要導入模塊: import i3ipc [as 別名]
# 或者: from i3ipc import Connection [as 別名]
def restore(workspace_name, saved_programs):
    """
    Restore the running programs from an i3 workspace.
    """
    # Remove already running programs from the list of program to restore.
    running_programs = get_programs(workspace_name, False)
    for program in running_programs:
        if program in saved_programs:
            saved_programs.remove(program)

    i3 = i3ipc.Connection()
    for entry in saved_programs:
        cmdline = entry['command']
        working_directory = entry['working_directory']

        # If the working directory does not exist, set working directory to
        # user's home directory.
        if not Path(working_directory).exists():
            working_directory = Path.home()

        # If cmdline is array, join it into one string for use with i3's exec
        # command.
        if isinstance(cmdline, list):
            # Quote each argument of the command in case some of
            # them contain spaces. Also protect quotes contained in the
            # arguments and those to be added from i3's command parser.
            cmdline = [
                '\\"' + arg.replace('"', '\\\\\\"') + '\\"'
                for arg in cmdline
                if arg != ""
            ]
            command = ' '.join(cmdline)
        else:
            command = cmdline

        # Execute command via i3 exec.
        i3.command(f'exec "cd \\"{working_directory}\\" && {command}"') 
開發者ID:JonnyHaystack,項目名稱:i3-resurrect,代碼行數:39,代碼來源:programs.py

示例5: i3_daemon

# 需要導入模塊: import i3ipc [as 別名]
# 或者: from i3ipc import Connection [as 別名]
def i3_daemon(disabled_during_pomodoro, nagbar):
    def generated_daemon():
        workspace_policy = create_workspace_policy(disabled_during_pomodoro)
        i3 = i3ipc.Connection()
        i3_state = {
            "focused_workspace_name": get_focused_workspace(i3).name
        }
        i3.on('workspace::focus', handle_workspace_focus(
            i3, i3_state, workspace_policy, nagbar))
        i3.main()

    return generated_daemon 
開發者ID:kantord,項目名稱:i3-gnome-pomodoro,代碼行數:14,代碼來源:pomodoro-client.py

示例6: main

# 需要導入模塊: import i3ipc [as 別名]
# 或者: from i3ipc import Connection [as 別名]
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--debug',
        action='store_true',
        help='Print debug messages to stderr'
    )
    args = parser.parse_args()
    handler = partial(switch_splitting, debug=args.debug)
    i3 = Connection()
    i3.on(Event.WINDOW_FOCUS, handler)
    i3.main() 
開發者ID:nwg-piotr,項目名稱:autotiling,代碼行數:14,代碼來源:autotiling.py

示例7: create_connection

# 需要導入模塊: import i3ipc [as 別名]
# 或者: from i3ipc import Connection [as 別名]
def create_connection(self):
        logging.debug('I3Conn create_connection')
        con = i3ipc.Connection()
        con.on('ipc_shutdown', self.restart)
        return con 
開發者ID:city41,項目名稱:mate-i3-applet,代碼行數:7,代碼來源:i3conn.py

示例8: go_to_workspace

# 需要導入模塊: import i3ipc [as 別名]
# 或者: from i3ipc import Connection [as 別名]
def go_to_workspace(self, workspace_name):
        logging.debug('go to workspace: {}'.format(workspace_name))
        throwawayCon = i3ipc.Connection()
        throwawayCon.command('workspace ' + workspace_name)
        throwawayCon.close() 
開發者ID:city41,項目名稱:mate-i3-applet,代碼行數:7,代碼來源:i3conn.py

示例9: run

# 需要導入模塊: import i3ipc [as 別名]
# 或者: from i3ipc import Connection [as 別名]
def run():
	i3 = i3ipc.Connection()
	i3thread = Thread(target=i3.main)
	lemonbar = LemonBar(i3)
	lemonbar.render()

	i3.on('workspace::focus', lemonbar.render)
	i3.on('window::title',    lemonbar.on_window_title_change)
	i3.on('window::focus',    lemonbar.on_window_title_change)
	i3.on('window::urgent',   lemonbar.render)
	i3.on('ipc-shutdown',     shutdown)

	i3thread.start() 
開發者ID:mirekys,項目名稱:i3-lemonbar,代碼行數:15,代碼來源:i3_lemonbar_feeder.py

示例10: __init__

# 需要導入模塊: import i3ipc [as 別名]
# 或者: from i3ipc import Connection [as 別名]
def __init__(self,
                 i3_connection: i3ipc.Connection,
                 dry_run: bool = True):
        self.i3_connection = i3_connection
        self.dry_run = dry_run
        # i3 tree is cached for performance. Timing the i3ipc get_tree function
        # using `%timeit` in ipython shows about 1-2ms in my high performance
        # desktop. For lower performance machines, multiple calls to get_tree
        # may be noticable, so this is cached.
        # Other operations like get_workspaces and get_outputs were about 50µs
        # using the same method, which is more negligible.
        self.tree = None 
開發者ID:infokiller,項目名稱:i3-workspace-groups,代碼行數:14,代碼來源:i3_proxy.py

示例11: _handle_focus_shift

# 需要導入模塊: import i3ipc [as 別名]
# 或者: from i3ipc import Connection [as 別名]
def _handle_focus_shift(self, _: i3ipc.Connection, event: i3ipc.Event) -> None:
        if _is_mapped_window(event.container):
            logging.debug("Focus shifted to %s", event.container.id)
            self.queue_window(Window(event.container), WMEventType.FOCUS_SHIFT) 
開發者ID:fennerm,項目名稱:flashfocus,代碼行數:6,代碼來源:sway.py

示例12: _handle_new_mapped_window

# 需要導入模塊: import i3ipc [as 別名]
# 或者: from i3ipc import Connection [as 別名]
def _handle_new_mapped_window(self, _: i3ipc.Connection, event: i3ipc.Event) -> None:
        if _is_mapped_window(event.container):
            logging.debug("Window %s mapped...", event.container.id)
            self.queue_window(Window(event.container), WMEventType.NEW_WINDOW) 
開發者ID:fennerm,項目名稱:flashfocus,代碼行數:6,代碼來源:sway.py

示例13: launch_inplace

# 需要導入模塊: import i3ipc [as 別名]
# 或者: from i3ipc import Connection [as 別名]
def launch_inplace(conf, shell):
    conn = i3ipc.Connection()
    shell_mark = MARK_QT.format(shell)
    conn.command("mark {}".format(shell_mark))
    move_back(conn, "[con_mark={}]".format(shell_mark))
    pop_it(conn, shell_mark, conf["pos"], conf["ratio"])
    prog_cmd = expand_command(conf["shells"][shell])
    os.execvp(prog_cmd[0], prog_cmd) 
開發者ID:lbonn,項目名稱:i3-quickterm,代碼行數:10,代碼來源:main.py

示例14: main

# 需要導入模塊: import i3ipc [as 別名]
# 或者: from i3ipc import Connection [as 別名]
def main():
    parser = argparse.ArgumentParser(__doc__)
    parser.add_argument("-config-path",
                        help="Path to file that maps applications to icons in json format. Defaults to ~/.i3/app-icons.json or ~/.config/i3/app-icons.json or hard-coded list if they are not available.",
                        required=False)
    parser.add_argument("-d", "--delimiter",
                        help="The delimiter used to separate multiple window names in the same workspace.",
                        required=False,
                        default="|")
    parser.add_argument("-l", "--max_title_length", help="Truncate title to specified length.",
                        required=False,
                        default=12,
                        type=int)
    parser.add_argument("-u", "--uniq", help="Remove duplicate icons in case the same application ",
                        action="store_true",
                        required=False,
                        default=False)
    parser.add_argument('-n', "--no-match-not-show-name",
                        help="when you set '_no_match' in your app icons, if you don't want the application name set this option",
                        action="store_true", required=False, default=False)
    parser.add_argument("-v", "--verbose", help="verbose startup that will help you to find the right name of the window",
                        action="store_true",
                        required=False,
                        default=False)
    args = parser.parse_args()

    app_icons = _get_app_icons(args.config_path)

    # check for missing icons
    for app, icon_name in app_icons.items():
        if not icon_name in icons:
            print("Specified icon '{}' for app '{}' does not exist!".format(icon_name, app))

    # build i3-connection
    i3 = i3ipc.Connection()
    if args.verbose:
        _verbose_startup(i3)

    rename = build_rename(i3, app_icons, args)
    for case in ['window::move', 'window::new', 'window::title', 'window::close']:
        i3.on(case, rename)
    i3.main() 
開發者ID:cboddy,項目名稱:i3-workspace-names-daemon,代碼行數:44,代碼來源:i3_workspace_names_daemon.py

示例15: toggle_quickterm_select

# 需要導入模塊: import i3ipc [as 別名]
# 或者: from i3ipc import Connection [as 別名]
def toggle_quickterm_select(conf, hist=None):
    """Hide a quickterm visible on current workspace or prompt
    the user for a shell type"""
    conn = i3ipc.Connection()
    ws = get_current_workspace(conn)

    # is there a quickterm opened in the current workspace?
    qt = ws.find_marked(MARK_QT_PATTERN)
    if qt:
        qt = qt[0]
        move_back(conn, "[con_id={}]".format(qt.id))
        return

    with get_history_file(conf) as hist:
        # compute the list from conf + (maybe) history
        hist_list = None
        if hist is not None:
            with suppress(Exception):
                hist_list = json.load(hist)

                # invalidate if different set from the configured shells
                if set(hist_list) != set(conf["shells"].keys()):
                    hist_list = None

        shells = hist_list or sorted(conf["shells"].keys())

        proc = subprocess.Popen(
            expand_command(conf["menu"]), stdin=subprocess.PIPE, stdout=subprocess.PIPE
        )

        for r in shells:
            proc.stdin.write((r + "\n").encode())
        stdout, _ = proc.communicate()

        shell = stdout.decode().strip()

        if shell not in conf["shells"]:
            return

        if hist is not None:
            # put the selected shell on top
            shells = [shell] + [s for s in shells if s != shell]
            hist.truncate(0)
            json.dump(shells, hist)

    toggle_quickterm(conf, shell) 
開發者ID:lbonn,項目名稱:i3-quickterm,代碼行數:48,代碼來源:main.py


注:本文中的i3ipc.Connection方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。