本文整理汇总了Python中PyQt4.QtCore.QSocketNotifier类的典型用法代码示例。如果您正苦于以下问题:Python QSocketNotifier类的具体用法?Python QSocketNotifier怎么用?Python QSocketNotifier使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QSocketNotifier类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _addNotifier
def _addNotifier(self, descriptor, descmap, type):
if descriptor not in descmap:
fd = descriptor.fileno()
if fd == -1:
raise RuntimeError("Invalid file descriptor")
notifier = QSocketNotifier(fd, type)
descmap[descriptor] = notifier
notifier._descriptor = descriptor
self.connect(notifier, SIGNAL("activated(int)"), self._notifierSlot)
notifier.setEnabled(True)
示例2: __init__
def __init__(self, reactor, watcher, type):
QSocketNotifier.__init__(self, watcher.fileno(), type)
self.reactor = reactor
self.watcher = watcher
self.fn = None
if type == QSocketNotifier.Read:
self.fn = self.read
elif type == QSocketNotifier.Write:
self.fn = self.write
QObject.connect(self, SIGNAL("activated(int)"), self.fn)
示例3: __init__
def __init__(self, reactor, watcher, type):
QSocketNotifier.__init__(self, watcher.fileno(), type)
self.reactor = reactor
self.watcher = watcher
self.fn = None
if type == QSocketNotifier.Read:
self.fn = self.read
elif type == QSocketNotifier.Write:
self.fn = self.write
self.activated[int].connect(self.fn)
示例4: __init__
def __init__(self, fdw):
self.fdw = fdw
self.qsn_read = QSocketNotifier(int(self.fdw), QSocketNotifier.Read)
self.qsn_write = QSocketNotifier(int(self.fdw), QSocketNotifier.Read)
self.qsn_oob = QSocketNotifier(int(self.fdw), QSocketNotifier.Exception)
self.qsn_read.setEnabled(False)
self.qsn_write.setEnabled(False)
self.qsn_oob.setEnabled(False)
connect(self.qsn_read, SIGNAL("activated(int)"), self.fd_read)
connect(self.qsn_write, SIGNAL("activated(int)"), self.fd_write)
示例5: Signal
class Signal(QObject):
signal = pyqtSignal(int)
fds = {}
def __init__(self, signum, parent):
super(Signal,self).__init__(parent)
self.signum = signum
self.sn = None
self.fd = [None,None]
if self.setupHandler() < 0:
return
self.sn = QSocketNotifier(self.fd[1].fileno(), QSocketNotifier.Read, parent)
self.sn.activated.connect( self.handleSignal)
def __del__(self):
signal.signal( self.signum, signal.SIG_DFL)
if Signal.fds.has_key( self.signum):
Signal.fds.pop(self.signum)
if self.fd[0] is not None:
self.fd[0].close()
if self.fd[1] is not None:
self.fd[1].close()
super(Signal,self).__del__()
@staticmethod
def create(signum,parent):
if Signal.fds.has_key(signum):
if Signal.fds[signum].sn:
sip.delete(Signal.fds[signum].sn)
del(Signal.fds[signum])
return Signal(signum,parent)
def handleSignal(self):
self.sn.setEnabled(False)
self.fd[1].recv(1)
self.signal.emit(self.signum)
self.sn.setEnabled(True)
def setupHandler(self):
self.fd = socket.socketpair(socket.AF_UNIX,socket.SOCK_STREAM,0)
if not self.fd:
return -1
Signal.fds[self.signum] = self
signal.signal(self.signum,self.handler)
signal.siginterrupt(self.signum,False)
return 0
@staticmethod
def handler(signum,frame):
Signal.fds[signum].fd[0].send(chr(1))
示例6: connect
def connect(self, address):
"""Connect to a JSON-RPC server at *address*."""
if isinstance(address, socket.socket):
sock = address
else:
sock = util.create_connection(address, self._timeout)
sock.settimeout(0)
self._read_notifier = QSocketNotifier(sock.fileno(), QSocketNotifier.Read, self)
self._read_notifier.activated.connect(self._do_read)
self._read_notifier.setEnabled(True)
self._write_notifier = QSocketNotifier(sock.fileno(), QSocketNotifier.Write, self)
self._write_notifier.activated.connect(self._do_write)
self._write_notifier.setEnabled(False)
self._socket = sock
示例7: run
def run(self):
botlog.info('RFIDReaderThread Running.')
self.blinkPhase = False
self.blinkTimer = QTimer()
self.blinkTimer.timeout.connect(self.blink)
self.latchTimer = QTimer()
self.latchTimer.timeout.connect(self.unlatch)
self.latchTimer.setSingleShot(True)
self.delayTimer = QTimer()
self.delayTimer.timeout.connect(self.undelay)
self.delayTimer.setSingleShot(True)
self.notifier = QSocketNotifier(self.reader.fileno(), QSocketNotifier.Read)
self.notifier.activated.connect(self.onData)
self.blinkTimer.start(250)
self.notifier.setEnabled(True)
self.setStatus(Status.READY)
self.exec()
botlog.info('RFIDReaderThread Stopped.')
示例8: __init__
class QtListener:
def __init__(self, evtype, fileno, cb):
self.evtype, self.fileno, self.cb = evtype, fileno, cb
self.notifier = QSocketNotifier(fileno, self.eventType(evtype))
self.notifier.activated.connect(cb)
def __del__(self):
self.notifier.setEnabled(False)
self.notifier = None
def eventType(self, evtype):
assert evtype in (BaseHub.READ, BaseHub.WRITE)
if evtype == BaseHub.READ:
return QSocketNotifier.Read
elif evtype == BaseHub.WRITE:
return QSocketNotifier.Write
示例9: register_io
def register_io(self, fd, callback, mode, *args, **kwargs):
handler = six.next(self._handlers)
notifier = QSocketNotifier(self.fd_number(fd), self.constants[mode])
with self._mutex:
self._io_handlers[handler] = notifier
def _io_cb(*_):
if not self._safe_callback(callback, fd, *args, **kwargs):
self.unregister_io(handler)
with self._mutex:
# we need to store the closure callback to avoid the garbage collector
# from collecting the closure
self._io_handlers[handler] = (notifier, _io_cb)
notifier.setEnabled(True)
notifier.activated.connect(_io_cb)
示例10: __init__
def __init__(self, signum, parent):
super(Signal,self).__init__(parent)
self.signum = signum
self.sn = None
self.fd = [None,None]
if self.setupHandler() < 0:
return
self.sn = QSocketNotifier(self.fd[1].fileno(), QSocketNotifier.Read, parent)
self.sn.activated.connect( self.handleSignal)
示例11: __init__
def __init__(self, parent, reactor, watcher, socketType):
QObject.__init__(self, parent)
self.reactor = reactor
self.watcher = watcher
fd = watcher.fileno()
self.notifier = QSocketNotifier(fd, socketType, parent)
self.notifier.setEnabled(True)
if socketType == QSocketNotifier.Read:
self.fn = self.read
else:
self.fn = self.write
QObject.connect(self.notifier, SIGNAL("activated(int)"), self.fn)
示例12: _SH_ThreadStarted
def _SH_ThreadStarted(self):
self.started.emit()
notification_center = NotificationCenter()
notification_center.post_notification('VNCClientWillStart', sender=self)
self.rfb_client = RFBClient(parent=self)
try:
self.rfb_client.connect()
except RFBClientError:
self.thread.quit()
else:
self.socket_notifier = QSocketNotifier(self.rfb_client.socket, QSocketNotifier.Read, self)
self.socket_notifier.activated.connect(self._SH_SocketNotifierActivated)
notification_center.post_notification('VNCClientDidStart', sender=self)
示例13: __init__
def __init__(self):
self.com = comar.Link()
# Notification
self.com.ask_notify("System.Upgrader.progress")
self.com.ask_notify("System.Upgrader.error")
self.com.ask_notify("System.Upgrader.warning")
self.com.ask_notify("System.Upgrader.notify")
self.com.ask_notify("System.Upgrader.started")
self.com.ask_notify("System.Upgrader.finished")
self.com.ask_notify("System.Upgrader.cancelled")
self.notifier = QSocketNotifier(self.com.sock.fileno(), QSocketNotifier.Read)
self.connect(self.notifier, SIGNAL("activated(int)"), self.slotComar)
示例14: FdEvent
class FdEvent(Event):
def __init__(self, *args, **kw):
self.note = QSocketNotifier(*args, **kw)
self.note.setEnabled(False)
Event.__init__(self, self.note.activated)
def arm(self, *args):
Event.arm(self, *args)
self.note.setEnabled(True)
def close(self, *args):
self.note.setEnabled(False)
Event.close(self, *args)
示例15: TwistedSocketNotifier
class TwistedSocketNotifier(QObject):
"""
Connection between an fd event and reader/writer callbacks.
"""
def __init__(self, parent, reactor, watcher, socketType):
QObject.__init__(self, parent)
self.reactor = reactor
self.watcher = watcher
fd = watcher.fileno()
self.notifier = QSocketNotifier(fd, socketType, parent)
self.notifier.setEnabled(True)
if socketType == QSocketNotifier.Read:
self.fn = self.read
else:
self.fn = self.write
QObject.connect(self.notifier, SIGNAL("activated(int)"), self.fn)
def shutdown(self):
self.notifier.setEnabled(False)
self.disconnect(self.notifier, SIGNAL("activated(int)"), self.fn)
self.fn = self.watcher = None
self.notifier.deleteLater()
self.deleteLater()
def read(self, fd):
if not self.watcher:
return
w = self.watcher
# doRead can cause self.shutdown to be called so keep a
# reference to self.watcher
def _read():
# Don't call me again, until the data has been read
self.notifier.setEnabled(False)
why = None
try:
why = w.doRead()
inRead = True
except:
inRead = False
log.err()
why = sys.exc_info()[1]
if why:
self.reactor._disconnectSelectable(w, why, inRead)
elif self.watcher:
# Re enable notification following sucessfull read
self.notifier.setEnabled(True)
self.reactor._iterate(fromqt=True)
log.callWithLogger(w, _read)
def write(self, sock):
if not self.watcher:
return
w = self.watcher
def _write():
why = None
self.notifier.setEnabled(False)
try:
why = w.doWrite()
except:
log.err()
why = sys.exc_info()[1]
if why:
self.reactor._disconnectSelectable(w, why, False)
elif self.watcher:
self.notifier.setEnabled(True)
self.reactor._iterate(fromqt=True)
log.callWithLogger(w, _write)