本文整理匯總了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")