本文整理汇总了Python中lutris.thread.LutrisThread.attach_thread方法的典型用法代码示例。如果您正苦于以下问题:Python LutrisThread.attach_thread方法的具体用法?Python LutrisThread.attach_thread怎么用?Python LutrisThread.attach_thread使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lutris.thread.LutrisThread
的用法示例。
在下文中一共展示了LutrisThread.attach_thread方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Game
# 需要导入模块: from lutris.thread import LutrisThread [as 别名]
# 或者: from lutris.thread.LutrisThread import attach_thread [as 别名]
#.........这里部分代码省略.........
def play(self):
""" Launch the game. """
if not self.prelaunch():
return False
gameplay_info = self.runner.play()
logger.debug("Launching %s: %s" % (self.name, gameplay_info))
if isinstance(gameplay_info, dict):
if 'error' in gameplay_info:
show_error_message(gameplay_info)
return False
launch_arguments = gameplay_info['command']
else:
logger.error("Old method used for returning gameplay infos")
launch_arguments = gameplay_info
resolution = self.game_config.get_system('resolution')
if resolution:
desktop_control.change_resolution(resolution)
if self.game_config.get_system('reset_pulse'):
desktop_control.reset_pulse()
if self.game_config.get_system('hide_panels'):
self.desktop.hide_panels()
oss_wrapper = self.game_config.get_system("oss_wrapper")
if oss_wrapper:
launch_arguments.insert(0, audio.get_oss_wrapper(oss_wrapper))
ld_preload = gameplay_info.get('ld_preload')
if ld_preload:
launch_arguments.insert(0, 'LD_PRELOAD="{}"'.format(ld_preload))
ld_library_path = gameplay_info.get('ld_library_path')
if ld_library_path:
launch_arguments.insert(
0, 'LD_LIBRARY_PATH="{}"'.format(ld_library_path)
)
killswitch = self.game_config.get_system('killswitch')
self.heartbeat = GLib.timeout_add(5000, self.poke_process)
self.game_thread = LutrisThread(" ".join(launch_arguments),
path=self.runner.get_game_path(),
killswitch=killswitch)
if hasattr(self.runner, 'stop'):
self.game_thread.set_stop_command(self.runner.stop)
self.game_thread.start()
if 'joy2key' in gameplay_info:
self.joy2key(gameplay_info['joy2key'])
xboxdrv_config = self.game_config.get_system('xboxdrv')
if xboxdrv_config:
self.xboxdrv(xboxdrv_config)
def joy2key(self, config):
""" Run a joy2key thread. """
win = "grep %s" % config['window']
if 'notwindow' in config:
win = win + ' | grep -v %s' % config['notwindow']
wid = "xwininfo -root -tree | %s | awk '{print $1}'" % win
buttons = config['buttons']
axis = "Left Right Up Down"
rcfile = "~/.joy2keyrc"
command = "sleep 5 "
command += "&& joy2key $(%s) -X -rcfile %s -buttons %s -axis %s" % (
wid, rcfile, buttons, axis
)
joy2key_thread = LutrisThread(command)
self.game_thread.attach_thread(joy2key_thread)
joy2key_thread.start()
def xboxdrv(self, config):
command = ("pkexec xboxdrv --daemon --detach-kernel-driver "
"--dbus session --silent %s"
% config)
logger.debug("xboxdrv command: %s", command)
thread = LutrisThread(command)
thread.start()
def poke_process(self):
""" Watch game's process. """
if not self.game_thread.pid:
self.quit_game()
return False
return True
def quit_game(self):
""" Quit the game and cleanup. """
self.heartbeat = None
quit_time = time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime())
logger.debug("game has quit at %s" % quit_time)
if self.game_config.get_system('resolution'):
desktop_control.reset_desktop()
if self.game_config.get_system('xboxdrv'):
logger.debug("Shutting down xboxdrv")
os.system("pkexec xboxdrvctl --shutdown")
if self.game_thread:
self.game_thread.stop()
示例2: Game
# 需要导入模块: from lutris.thread import LutrisThread [as 别名]
# 或者: from lutris.thread.LutrisThread import attach_thread [as 别名]
#.........这里部分代码省略.........
self.game_thread = LutrisThread(launch_arguments,
runner=self.runner, env=env,
rootpid=gameplay_info.get('rootpid'),
term=terminal)
if hasattr(self.runner, 'stop'):
self.game_thread.set_stop_command(self.runner.stop)
self.game_thread.start()
self.state = self.STATE_RUNNING
if 'joy2key' in gameplay_info:
self.joy2key(gameplay_info['joy2key'])
xboxdrv_config = system_config.get('xboxdrv')
if xboxdrv_config:
self.xboxdrv_start(xboxdrv_config)
self.heartbeat = GLib.timeout_add(HEARTBEAT_DELAY, self.beat)
def joy2key(self, config):
"""Run a joy2key thread."""
if not system.find_executable('joy2key'):
logger.error("joy2key is not installed")
return
win = "grep %s" % config['window']
if 'notwindow' in config:
win += ' | grep -v %s' % config['notwindow']
wid = "xwininfo -root -tree | %s | awk '{print $1}'" % win
buttons = config['buttons']
axis = "Left Right Up Down"
rcfile = os.path.expanduser("~/.joy2keyrc")
rc_option = '-rcfile %s' % rcfile if os.path.exists(rcfile) else ''
command = "sleep 5 "
command += "&& joy2key $(%s) -X %s -buttons %s -axis %s" % (
wid, rc_option, buttons, axis
)
joy2key_thread = LutrisThread(command)
self.game_thread.attach_thread(joy2key_thread)
joy2key_thread.start()
def xboxdrv_start(self, config):
command = [
"pkexec", "xboxdrv", "--daemon", "--detach-kernel-driver",
"--dbus", "session", "--silent"
] + config.split()
logger.debug("[xboxdrv] %s", ' '.join(command))
self.xboxdrv_thread = LutrisThread(command)
self.xboxdrv_thread.set_stop_command(self.xboxdrv_stop)
self.xboxdrv_thread.start()
def xboxdrv_stop(self):
os.system("pkexec xboxdrvctl --shutdown")
if os.path.exists("/usr/share/lutris/bin/resetxpad"):
os.system("pkexec /usr/share/lutris/bin/resetxpad")
def beat(self):
"""Watch the game's process(es)."""
if self.game_thread.error:
dialogs.ErrorDialog("<b>Error lauching the game:</b>\n"
+ self.game_thread.error)
self.on_game_quit()
return False
self.game_log = self.game_thread.stdout
killswitch_engage = self.killswitch and \
not os.path.exists(self.killswitch)
if not self.game_thread.is_running or killswitch_engage:
logger.debug("Game thread stopped")
self.on_game_quit()
return False
return True
示例3: Game
# 需要导入模块: from lutris.thread import LutrisThread [as 别名]
# 或者: from lutris.thread.LutrisThread import attach_thread [as 别名]
#.........这里部分代码省略.........
ld_preload = gameplay_info.get('ld_preload')
if ld_preload:
env["LD_PRELOAD"] = ld_preload
ld_library_path = []
if self.use_runtime(system_config):
env['STEAM_RUNTIME'] = os.path.join(settings.RUNTIME_DIR, 'steam')
ld_library_path += runtime.get_runtime_paths()
game_ld_libary_path = gameplay_info.get('ld_library_path')
if game_ld_libary_path:
ld_library_path.append(game_ld_libary_path)
if ld_library_path:
ld_full = ':'.join(ld_library_path)
env["LD_LIBRARY_PATH"] = "{}:$LD_LIBRARY_PATH".format(ld_full)
# /Env vars
self.game_thread = LutrisThread(launch_arguments,
runner=self.runner, env=env,
rootpid=gameplay_info.get('rootpid'),
term=terminal)
self.state = self.STATE_RUNNING
if hasattr(self.runner, 'stop'):
self.game_thread.set_stop_command(self.runner.stop)
self.game_thread.start()
if 'joy2key' in gameplay_info:
self.joy2key(gameplay_info['joy2key'])
xboxdrv_config = system_config.get('xboxdrv')
if xboxdrv_config:
self.xboxdrv_start(xboxdrv_config)
if self.runner.is_watchable:
# Create heartbeat every
self.heartbeat = GLib.timeout_add(HEARTBEAT_DELAY, self.beat)
def joy2key(self, config):
"""Run a joy2key thread."""
if not system.find_executable('joy2key'):
logger.error("joy2key is not installed")
return
win = "grep %s" % config['window']
if 'notwindow' in config:
win += ' | grep -v %s' % config['notwindow']
wid = "xwininfo -root -tree | %s | awk '{print $1}'" % win
buttons = config['buttons']
axis = "Left Right Up Down"
rcfile = os.path.expanduser("~/.joy2keyrc")
rc_option = '-rcfile %s' % rcfile if os.path.exists(rcfile) else ''
command = "sleep 5 "
command += "&& joy2key $(%s) -X %s -buttons %s -axis %s" % (
wid, rc_option, buttons, axis
)
joy2key_thread = LutrisThread(command)
self.game_thread.attach_thread(joy2key_thread)
joy2key_thread.start()
def xboxdrv_start(self, config):
command = [
"pkexec", "xboxdrv", "--daemon", "--detach-kernel-driver",
"--dbus", "session", "--silent"
] + config.split()
logger.debug("xboxdrv command: %s", command)
self.xboxdrv_thread = LutrisThread(command)
self.xboxdrv_thread.set_stop_command(self.xboxdrv_stop)
self.xboxdrv_thread.start()
def xboxdrv_stop(self):
os.system("pkexec xboxdrvctl --shutdown")
def beat(self):
"""Watch game's process."""
self.game_log = self.game_thread.stdout
killswitch_engage = self.killswitch and \
not os.path.exists(self.killswitch)
if not self.game_thread.is_running or killswitch_engage:
self.on_game_quit()
return False
return True
def stop(self):
self.game_thread.stop(killall=True)
def on_game_quit(self):
"""Restore some settings and cleanup after game quit."""
self.heartbeat = None
quit_time = time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime())
logger.debug("game has quit at %s" % quit_time)
self.state = self.STATE_STOPPED
if self.resolution_changed\
or self.runner.system_config.get('reset_desktop'):
display.change_resolution(self.original_outputs)
if self.runner.system_config.get('restore_gamma'):
display.restore_gamma()
if self.runner.system_config.get('xboxdrv'):
self.xboxdrv_thread.stop()
if self.game_thread:
self.game_thread.stop()
示例4: Game
# 需要导入模块: from lutris.thread import LutrisThread [as 别名]
# 或者: from lutris.thread.LutrisThread import attach_thread [as 别名]
#.........这里部分代码省略.........
launch_arguments.insert(0, prefix_command)
ld_preload = gameplay_info.get('ld_preload')
if ld_preload:
launch_arguments.insert(0, 'LD_PRELOAD="{}"'.format(ld_preload))
ld_library_path = []
runtime64_path = os.path.join(settings.RUNTIME_DIR, "lib64")
if os.path.exists(runtime64_path):
ld_library_path.append(runtime64_path)
runtime32_path = os.path.join(settings.RUNTIME_DIR, "lib32")
if os.path.exists(runtime32_path):
ld_library_path.append(runtime32_path)
game_ld_libary_path = gameplay_info.get('ld_library_path')
if game_ld_libary_path:
ld_library_path.append(game_ld_libary_path)
if ld_library_path:
ld_full = ':'.join(ld_library_path)
ld_arg = 'LD_LIBRARY_PATH="{}:$LD_LIBRARY_PATH"'.format(ld_full)
launch_arguments.insert(0, ld_arg)
env = gameplay_info.get('env') or []
for var in env:
launch_arguments.insert(0, var)
killswitch = system_config.get('killswitch')
self.game_thread = LutrisThread(" ".join(launch_arguments),
path=self.runner.working_dir,
killswitch=killswitch)
if hasattr(self.runner, 'stop'):
self.game_thread.set_stop_command(self.runner.stop)
self.game_thread.start()
if 'joy2key' in gameplay_info:
self.joy2key(gameplay_info['joy2key'])
xboxdrv_config = system_config.get('xboxdrv')
if xboxdrv_config:
self.xboxdrv_start(xboxdrv_config)
if self.runner.is_watchable:
# Create heartbeat every
self.heartbeat = GLib.timeout_add(5000, self.poke_process)
def joy2key(self, config):
"""Run a joy2key thread."""
if not system.find_executable('joy2key'):
logger.error("joy2key is not installed")
return
win = "grep %s" % config['window']
if 'notwindow' in config:
win += ' | grep -v %s' % config['notwindow']
wid = "xwininfo -root -tree | %s | awk '{print $1}'" % win
buttons = config['buttons']
axis = "Left Right Up Down"
rcfile = os.path.expanduser("~/.joy2keyrc")
rc_option = '-rcfile %s' % rcfile if os.path.exists(rcfile) else ''
command = "sleep 5 "
command += "&& joy2key $(%s) -X %s -buttons %s -axis %s" % (
wid, rc_option, buttons, axis
)
joy2key_thread = LutrisThread(command)
self.game_thread.attach_thread(joy2key_thread)
joy2key_thread.start()
def xboxdrv_start(self, config):
command = ("pkexec xboxdrv --daemon --detach-kernel-driver "
"--dbus session --silent %s"
% config)
logger.debug("xboxdrv command: %s", command)
self.xboxdrv_thread = LutrisThread(command)
self.xboxdrv_thread.set_stop_command(self.xboxdrv_stop)
self.xboxdrv_thread.start()
def xboxdrv_stop(self):
os.system("pkexec xboxdrvctl --shutdown")
def poke_process(self):
"""Watch game's process."""
if not self.game_thread.pid:
self.quit_game()
return False
return True
def quit_game(self):
"""Quit the game and cleanup."""
self.heartbeat = None
quit_time = time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime())
logger.debug("game has quit at %s" % quit_time)
if self.resolution_changed\
or self.runner.system_config.get('reset_desktop'):
display.change_resolution(self.original_outputs)
if self.runner.system_config.get('restore_gamma'):
display.restore_gamma()
if self.runner.system_config.get('xboxdrv'):
self.xboxdrv_thread.stop()
if self.game_thread:
self.game_thread.stop()