本文整理汇总了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)
示例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"])
示例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)
示例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}"')
示例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
示例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()
示例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
示例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()
示例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()
示例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
示例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)
示例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)
示例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)
示例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()
示例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)