當前位置: 首頁>>代碼示例>>Python>>正文


Python QtCore.QSocketNotifier類代碼示例

本文整理匯總了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)
開發者ID:nnemkin,項目名稱:deluge_qt,代碼行數:10,代碼來源:qt4reactor.py

示例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)
開發者ID:AlickHill,項目名稱:Lantern,代碼行數:10,代碼來源:qt4reactor.py

示例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)
開發者ID:Pesa,項目名稱:forse,代碼行數:10,代碼來源:qt4reactor.py

示例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)
開發者ID:sh01,項目名稱:gonium,代碼行數:10,代碼來源:__qt4.py

示例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))
開發者ID:jmechnich,項目名稱:appletlib,代碼行數:51,代碼來源:posixsignal.py

示例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
開發者ID:geertj,項目名稱:bluepass,代碼行數:14,代碼來源:qjsonrpc.py

示例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.')
開發者ID:MomentumV,項目名稱:doorbot,代碼行數:25,代碼來源:qdoor.py

示例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
開發者ID:OSUser,項目名稱:eventlet-pyqt,代碼行數:16,代碼來源:eventlet.py

示例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)
開發者ID:caetanus,項目名稱:pygel,代碼行數:17,代碼來源:qt4_reactor.py

示例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)
開發者ID:jmechnich,項目名稱:appletlib,代碼行數:10,代碼來源:posixsignal.py

示例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)
開發者ID:cgc1983,項目名稱:qtreactor,代碼行數:12,代碼來源:qt4reactor.py

示例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)
開發者ID:scudella,項目名稱:blink-qt,代碼行數:13,代碼來源:vncclient.py

示例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)
開發者ID:Tayyib,項目名稱:uludag,代碼行數:15,代碼來源:comariface.py

示例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)
開發者ID:vadmium,項目名稱:webvi-qt,代碼行數:11,代碼來源:qtwrap.py

示例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)
開發者ID:cgc1983,項目名稱:qtreactor,代碼行數:71,代碼來源:qt4reactor.py


注:本文中的PyQt4.QtCore.QSocketNotifier類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。