本文整理汇总了Python中quamash.QEventLoop方法的典型用法代码示例。如果您正苦于以下问题:Python quamash.QEventLoop方法的具体用法?Python quamash.QEventLoop怎么用?Python quamash.QEventLoop使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类quamash
的用法示例。
在下文中一共展示了quamash.QEventLoop方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start
# 需要导入模块: import quamash [as 别名]
# 或者: from quamash import QEventLoop [as 别名]
def start():
app = QApplication(sys.argv)
# 将Qt事件循环写到asyncio事件循环里。
# QEventLoop不是Qt原生事件循环,
# 是被asyncio重写的事件循环。
eventLoop = QEventLoop(app)
asyncio.set_event_loop(eventLoop)
try:
main = Window()
main.show()
# 当前音乐的显示信息。
# 因为需要布局之后重新绘制的宽高。
# 这个宽高会在show之后才会改变。
# 需要获取宽,高并嵌入到父窗口里。
main.playWidgets.currentMusic.resize(main.navigation.width(), 64)
with eventLoop:
eventLoop.run_forever()
sys.exit(0)
except:
logger.error("got some error", exc_info=True)
示例2: _wait_for_done
# 需要导入模块: import quamash [as 别名]
# 或者: from quamash import QEventLoop [as 别名]
def _wait_for_done(self, timeout):
"""
Will not return until either timeout expires or future becomes "done".
There is one potential deadlock situation here:
The deadlock occurs if we await_result while at the same
time, this future needs to await_result from another future
---> To be safe, don't use await_result() in a Qt slot...
"""
if self.cancelled():
raise CancelledError("Future was cancelled") # pragma: no-cover
if not self.done():
self.timer_timeout = None
if (timeout is not None) and timeout > 0:
self._timer_timeout = MainThreadTimer(timeout*1000)
self._timer_timeout.timeout.connect(self._exit_loop)
self._timer_timeout.start()
self.loop = QtCore.QEventLoop()
self.add_done_callback(self._exit_loop)
self.loop.exec_()
if self._timer_timeout is not None:
if not self._timer_timeout.isActive():
return TimeoutError("Timeout occured") # pragma: no-cover
else:
self._timer_timeout.stop()
示例3: main_gui
# 需要导入模块: import quamash [as 别名]
# 或者: from quamash import QEventLoop [as 别名]
def main_gui(args: argparse.Namespace):
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
app = QApplication(sys.argv)
loop = QEventLoop(app)
asyncio.set_event_loop(loop)
# Check environment first
from PyQt5.QtWidgets import QMessageBox, QSystemTrayIcon
def dialog(message: str) -> None:
QMessageBox.critical(None, "VirtScreen", message)
if not QSystemTrayIcon.isSystemTrayAvailable():
dialog("Cannot detect system tray on this system.")
sys.exit(1)
check_env(args, dialog)
app.setApplicationName("VirtScreen")
app.setWindowIcon(QIcon(ICON_PATH))
os.environ["QT_QUICK_CONTROLS_STYLE"] = "Material"
# Register the Python type. Its URI is 'People', it's v1.0 and the type
# will be called 'Person' in QML.
qmlRegisterType(DisplayProperty, 'VirtScreen.DisplayProperty', 1, 0, 'DisplayProperty')
qmlRegisterType(Backend, 'VirtScreen.Backend', 1, 0, 'Backend')
qmlRegisterType(Cursor, 'VirtScreen.Cursor', 1, 0, 'Cursor')
qmlRegisterType(Network, 'VirtScreen.Network', 1, 0, 'Network')
# Create a component factory and load the QML script.
engine = QQmlApplicationEngine()
engine.load(QUrl(MAIN_QML_PATH))
if not engine.rootObjects():
dialog("Failed to load QML")
sys.exit(1)
sys.exit(app.exec_())
with loop:
loop.run_forever()
示例4: sleep
# 需要导入模块: import quamash [as 别名]
# 或者: from quamash import QEventLoop [as 别名]
def sleep(delay):
"""
Sleeps for :code:`delay` seconds + runs the event loop in the background.
* This function will never return until the specified delay in seconds is elapsed.
* During the execution of this function, the qt event loop (== asyncio event-loop in pyrpl) continues to process events from the gui, or from other coroutines.
* Contrary to time.sleep() or async.sleep(), this function will try to achieve a precision much better than 1 millisecond (of course, occasionally, the real delay can be longer than requested), but on average, the precision is in the microsecond range.
* Finally, care has been taken to use low level system-functions to reduce CPU-load when no events need to be processed.
More details on the implementation can be found on the page: `<https://github.com/lneuhaus/pyrpl/wiki/Benchmark-asynchronous-sleep-functions>`_.
"""
tic = default_timer()
end_time = tic + delay
# 1. CPU-free sleep for delay - 1ms
if delay > 1e-3:
new_delay = delay - 1e-3
loop = QtCore.QEventLoop()
timer = MainThreadTimer(new_delay * 1000)
timer.timeout.connect(loop.quit)
timer.start()
try:
loop.exec_()
except KeyboardInterrupt as e: # pragma: no-cover
# try to recover from KeyboardInterrupt by finishing the current task
timer.setInterval(1)
timer.start()
loop.exec_()
raise e
# 2. For high-precision, manually process events 1-by-1 during the last ms
while default_timer() < end_time:
APP.processEvents()
示例5: main
# 需要导入模块: import quamash [as 别名]
# 或者: from quamash import QEventLoop [as 别名]
def main():
# Build default paths for files.
dirs = appdirs.AppDirs('QHangups', 'QHangups')
default_log_path = os.path.join(dirs.user_data_dir, 'hangups.log')
default_token_path = os.path.join(dirs.user_data_dir, 'refresh_token.txt')
# Setup command line argument parser
parser = argparse.ArgumentParser(prog='qhangups',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('-d', '--debug', action='store_true',
help='log detailed debugging messages')
parser.add_argument('--log', default=default_log_path,
help='log file path')
parser.add_argument('--token', default=default_token_path,
help='OAuth refresh token storage path')
args = parser.parse_args()
# Create all necessary directories.
for path in [args.log, args.token]:
directory = os.path.dirname(path)
if directory and not os.path.isdir(directory):
try:
os.makedirs(directory)
except OSError as e:
sys.exit('Failed to create directory: {}'.format(e))
# Setup logging
log_level = logging.DEBUG if args.debug else logging.WARNING
logging.basicConfig(filename=args.log, level=log_level, format=LOG_FORMAT)
# asyncio's debugging logs are VERY noisy, so adjust the log level
logging.getLogger('asyncio').setLevel(logging.WARNING)
# ...and if we don't need Hangups debug logs, then uncomment this:
# logging.getLogger('hangups').setLevel(logging.WARNING)
# Setup QApplication
app = QtWidgets.QApplication(sys.argv)
app.setOrganizationName("QHangups")
app.setOrganizationDomain("qhangups.eutopia.cz")
app.setApplicationName("QHangups")
app.setQuitOnLastWindowClosed(False)
app.installTranslator(translator)
app.installTranslator(qt_translator)
# Start Quamash event loop
loop = QEventLoop(app)
asyncio.set_event_loop(loop)
with loop:
widget = QHangupsMainWidget(args.token)
loop.run_forever()
示例6: main
# 需要导入模块: import quamash [as 别名]
# 或者: from quamash import QEventLoop [as 别名]
def main():
parser = argparse.ArgumentParser(
description='Run a single task processor',
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument(
'--host', '-H', dest='host', type=str, help='connect to host')
parser.add_argument(
'--port', '-p', dest='port', type=int, help='port number')
parser.add_argument(
'--unix_path', '-u', dest='unix_path', type=str,
help='connect to Unix domain socket')
parser.add_argument(
'--loop', '-l', dest='loop', default=0, type=int,
help='0=default 1=asyncio 2=uvloop 3=proactor 4=quamash')
parser.add_argument(
'--func_pickle', '-f', dest='func_pickle', default=1, type=int,
help='0=pickle 1=cloudpickle 2=dill')
parser.add_argument(
'--data_pickle', '-d', dest='data_pickle', default=0, type=int,
help='0=pickle 1=cloudpickle 2=dill')
args = parser.parse_args()
if not args.port and not args.unix_path:
print('distex installed OK')
return
if args.loop == LoopType.default:
loop = util.get_loop()
elif args.loop == LoopType.asyncio:
loop = asyncio.get_event_loop()
elif args.loop == LoopType.uvloop:
import uvloop
loop = uvloop.Loop()
elif args.loop == LoopType.proactor:
loop = asyncio.ProactorEventLoop()
elif args.loop == LoopType.quamash:
import quamash
import PyQt5.Qt as qt
qapp = qt.QApplication([]) # noqa
loop = quamash.QEventLoop()
asyncio.set_event_loop(loop)
processor = Processor( # noqa
args.host, args.port, args.unix_path,
args.func_pickle, args.data_pickle)
loop.run_forever()