本文整理汇总了Python中PyQt4.QtCore.QSocketNotifier.isEnabled方法的典型用法代码示例。如果您正苦于以下问题:Python QSocketNotifier.isEnabled方法的具体用法?Python QSocketNotifier.isEnabled怎么用?Python QSocketNotifier.isEnabled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtCore.QSocketNotifier
的用法示例。
在下文中一共展示了QSocketNotifier.isEnabled方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: QJsonRpcClient
# 需要导入模块: from PyQt4.QtCore import QSocketNotifier [as 别名]
# 或者: from PyQt4.QtCore.QSocketNotifier import isEnabled [as 别名]
#.........这里部分代码省略.........
self._outbuf = json.dumps(message).encode("utf8")
try:
nbytes = self._socket.send(self._outbuf)
except socket.error as e:
if e.errno in (errno.EAGAIN, errno.EWOULDBLOCK):
break
self.logger.error("send() error {0}".format(e.errno))
self.close()
break
self._outbuf = self._outbuf[nbytes:]
if not self._outbuf:
self._write_notifier.setEnabled(False)
def close(self):
"""Close the connection."""
if self._socket is None:
return
self._read_notifier.setEnabled(False)
self._write_notifier.setEnabled(False)
try:
self._socket.close()
except socket.error:
pass
self._log.debug("connection closed")
self._socket = None
def send_message(self, message):
"""Send a raw JSON-RPC message."""
if self._socket is None:
raise RuntimeError("not connected")
if not jsonrpc.check_message(message):
raise ValueError("invalid JSON-RPC message")
self._outgoing.append(message)
if not self._write_notifier.isEnabled():
self._write_notifier.setEnabled(True)
def send_notification(self, method, *args):
"""Send a JSON-RPC notification."""
message = jsonrpc.create_notification(method, args)
self.send_message(message)
def event(self, event):
# Process the DispatchMessages event
if isinstance(event, _Dispatch):
self._dispatch()
event.accept()
return True
else:
event.ignore()
return False
def _dispatch(self):
# Dispatch message from the connection.
while self._incoming:
message = self._incoming.popleft()
if "result" in message or "error" in message:
# response
key = message["id"]
callback = self._method_calls.get(key, None)
if callback:
callback(message, self)
elif self._message_handler:
self._message_handler(message, self)
else:
self._log.info("no handler, cannot handle incoming message")