当前位置: 首页>>代码示例>>Python>>正文


Python QSocketNotifier.setEnabled方法代码示例

本文整理汇总了Python中PyQt4.QtCore.QSocketNotifier.setEnabled方法的典型用法代码示例。如果您正苦于以下问题:Python QSocketNotifier.setEnabled方法的具体用法?Python QSocketNotifier.setEnabled怎么用?Python QSocketNotifier.setEnabled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt4.QtCore.QSocketNotifier的用法示例。


在下文中一共展示了QSocketNotifier.setEnabled方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _addNotifier

# 需要导入模块: from PyQt4.QtCore import QSocketNotifier [as 别名]
# 或者: from PyQt4.QtCore.QSocketNotifier import setEnabled [as 别名]
 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,代码行数:12,代码来源:qt4reactor.py

示例2: Signal

# 需要导入模块: from PyQt4.QtCore import QSocketNotifier [as 别名]
# 或者: from PyQt4.QtCore.QSocketNotifier import setEnabled [as 别名]
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,代码行数:53,代码来源:posixsignal.py

示例3: __init__

# 需要导入模块: from PyQt4.QtCore import QSocketNotifier [as 别名]
# 或者: from PyQt4.QtCore.QSocketNotifier import setEnabled [as 别名]
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,代码行数:18,代码来源:eventlet.py

示例4: register_io

# 需要导入模块: from PyQt4.QtCore import QSocketNotifier [as 别名]
# 或者: from PyQt4.QtCore.QSocketNotifier import setEnabled [as 别名]
    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,代码行数:19,代码来源:qt4_reactor.py

示例5: FdEvent

# 需要导入模块: from PyQt4.QtCore import QSocketNotifier [as 别名]
# 或者: from PyQt4.QtCore.QSocketNotifier import setEnabled [as 别名]
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,代码行数:13,代码来源:qtwrap.py

示例6: VNCClient

# 需要导入模块: from PyQt4.QtCore import QSocketNotifier [as 别名]
# 或者: from PyQt4.QtCore.QSocketNotifier import setEnabled [as 别名]
class VNCClient(QObject):
    started = pyqtSignal()
    finished = pyqtSignal()
    imageSizeChanged = pyqtSignal(QSize)
    imageChanged = pyqtSignal(int, int, int, int)
    passwordRequested = pyqtSignal(bool)
    textCut = pyqtSignal(unicode)

    def __init__(self, host, port, settings, parent=None):
        super(VNCClient, self).__init__(parent)
        self.thread = QThread()
        self.moveToThread(self.thread)
        self.host = host
        self.port = port
        self.settings = settings
        self.username = None
        self.password = None
        self.rfb_client = None
        self.socket_notifier = None
        self.thread.started.connect(self._SH_ThreadStarted)
        self.thread.finished.connect(self._SH_ThreadFinished)

    def _get_settings(self):
        return self.__dict__['settings']

    def _set_settings(self, settings):
        old_settings = self.__dict__.get('settings', None)
        if settings == old_settings:
            return
        self.__dict__['settings'] = settings
        if self.thread.isRunning():
            QApplication.postEvent(self, RFBConfigureClientEvent())

    settings = property(_get_settings, _set_settings)
    del _get_settings, _set_settings

    @property
    def image(self):
        return self.rfb_client.image if self.rfb_client is not None else None

    def start(self):
        self.thread.start()

    def stop(self):
        self.thread.quit()

    def key_event(self, key, down):
        if self.thread.isRunning():
            QApplication.postEvent(self, RFBKeyEvent(key, down))

    def mouse_event(self, x, y, button_mask):
        if self.thread.isRunning():
            QApplication.postEvent(self, RFBMouseEvent(x, y, button_mask))

    def cut_text_event(self, text):
        if text and self.thread.isRunning():
            QApplication.postEvent(self, RFBCutTextEvent(text))

    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)

    def _SH_ThreadFinished(self):
        self.finished.emit()
        notification_center = NotificationCenter()
        notification_center.post_notification('VNCClientWillEnd', sender=self)
        if self.socket_notifier is not None:
            self.socket_notifier.activated.disconnect(self._SH_SocketNotifierActivated)
            self.socket_notifier = None
        self.rfb_client = None
        notification_center.post_notification('VNCClientDidEnd', sender=self)

    def _SH_SocketNotifierActivated(self, sock):
        self.socket_notifier.setEnabled(False)
        try:
            self.rfb_client.handle_server_message()
        except RFBClientError:
            self.thread.quit()
        else:
            self.socket_notifier.setEnabled(True)

    def _SH_ConfigureRFBClient(self):
        if self.rfb_client is not None:
            self.rfb_client.configure()

    def customEvent(self, event):
        handler = getattr(self, '_EH_%s' % event.name, Null)
        handler(event)

    def _EH_RFBConfigureClientEvent(self, event):
#.........这里部分代码省略.........
开发者ID:scudella,项目名称:blink-qt,代码行数:103,代码来源:vncclient.py

示例7: TwistedSocketNotifier

# 需要导入模块: from PyQt4.QtCore import QSocketNotifier [as 别名]
# 或者: from PyQt4.QtCore.QSocketNotifier import setEnabled [as 别名]
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,代码行数:73,代码来源:qt4reactor.py

示例8: RFIDReaderThread

# 需要导入模块: from PyQt4.QtCore import QSocketNotifier [as 别名]
# 或者: from PyQt4.QtCore.QSocketNotifier import setEnabled [as 别名]
class RFIDReaderThread(QThread):
    signalStatusChange = pyqtSignal(Status)
    signalAccess = pyqtSignal('QString', dict)
    
    def __init__(self, parent=None):
        QThread.__init__(self, parent)

        self.status = Status.INIT
        
        self.hw = DoorHW(red_pin=qsetup.RED_PIN, green_pin=qsetup.GREEN_PIN, door_pin=qsetup.DOOR_PIN, beep_pin=qsetup.BEEP_PIN)

        self.reader = rfid_reader.factory(qsetup.READER_TYPE)
        self.reader.initialize(baud_rate=qsetup.READER_BAUD_RATE)

        self.authenticate = Authenticate.factory(qsetup.AUTHENTICATE_TYPE, qsetup.AUTHENTICATE_FILE)

        botlog.info('authentication file date %s' % self.authenticate.get_file_time())
        botlog.info('RFIDReaderThread Initialized.')
        
    def __del__(self):
        botlog.info('RFIDReaderThread Thread Deletion.')
        self.wait()

    def updateLEDs(self):
        if self.status == Status.INIT:
            self.hw.green(on=True)
            self.hw.red(on=True)
        elif self.status == Status.READY:
            self.hw.green(on=self.blinkPhase)
            self.hw.red(on=False)
        elif self.status == Status.DENIED or self.status == Status.UNKNOWN:
            self.hw.green(on=False)
            self.hw.red(on=True)
        elif self.status == Status.ALLOWED or self.status == Status.LATCHED:
            self.hw.green(on=True)
            self.hw.red(on=False)
        elif self.status == Status.ERROR:
            self.hw.green(on=False)
            self.hw.red(on=self.blinkPhase)
        
    def blink(self):
        self.updateLEDs()
        self.blinkPhase = not self.blinkPhase

    def setStatus(self, s):
        botlog.debug('status change from %s to %s' % (self.status, s))
        self.status = s
        self.signalStatusChange.emit(s)
        self.updateLEDs()
        
    def unlatch(self):
        self.hw.latch(open=False)
        self.setStatus(Status.READY)
        self.reader.flush()
        self.notifier.setEnabled(True)

    def undelay(self):
        self.setStatus(Status.READY)
        self.reader.flush()
        self.notifier.setEnabled(True)

        
    def onData(self):
        rfid_str = self.reader.get_card()
        if not rfid_str:
            return
        
        botlog.debug( 'RFID string >>%s<<' % rfid_str)

        # Several things can happen:
        # 1. some error in reading.
        # 2. good card, not allowed
        # 3. good card, allowed:
        # 3a.  schedule permits access at this time, so open door
        # 3b.  schedule does not permit access at this time.
        # 4. bad card from some reason
        # 5. unknown card
        try :
            self.setStatus(Status.READING)
            rfid = int(rfid_str)
            
            access = self.authenticate.get_access(rfid)
                    
            if access:
                allowed = access['allowed']
                member = access['member']
                plan = access['plan']
                
                print(allowed)
                print(access)
                print(plan)
                
                if 'allowed' in allowed :
                    if qsetup.schedule.isAllowed(plan):
                        # 3a. open the door
                        #
                        botlog.info('%s allowed' % member)

                        self.setStatus(Status.ALLOWED)
                        self.setStatus(Status.LATCHED)
#.........这里部分代码省略.........
开发者ID:MomentumV,项目名称:doorbot,代码行数:103,代码来源:qdoor.py

示例9: QJsonRpcClient

# 需要导入模块: from PyQt4.QtCore import QSocketNotifier [as 别名]
# 或者: from PyQt4.QtCore.QSocketNotifier import setEnabled [as 别名]
class QJsonRpcClient(QObject):
    """A JSON-RPC client integrated with the Qt event loop."""

    default_timeout = 5

    def __init__(self, message_handler=None, timeout=-1, parent=None):
        """Create a new message bus connection.

        The *handler* specifies an optional message handler.
        """
        super(QJsonRpcClient, self).__init__(parent)
        self._message_handler = message_handler
        self._timeout = timeout if timeout != -1 else self.default_timeout
        self._socket = None
        self._method_calls = {}
        self._outbuf = b""
        self._incoming = collections.deque()
        self._outgoing = collections.deque()
        self._protocol = jsonrpc.JsonRpcProtocol(True)
        self._read_notifier = None
        self._write_notifier = None
        self._log = logging.get_logger(self)

    @property
    def timeout(self):
        return self._timeout

    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

    def _do_read(self):
        # Read messages from the socket and put them into the incoming queue
        # until nothing more can be read.
        while True:
            try:
                buf = self._socket.recv(4096)
            except socket.error as e:
                if e.errno in (errno.EAGAIN, errno.EWOULDBLOCK):
                    break
                self._log.error("recv() error {0}".format(e.errno))
                self.close()
                break
            if buf == b"":
                self._log.error("peer closed connection")
                self.close()
                break
            # XXX: should not be using protocol private attributes
            # Expose .error and .get_message() ?
            nbytes = self._protocol.data_received(buf)
            if self._protocol._error:
                self._log.error("parse error {0!s}", self._protocol._error)
                self.close()
                break
            while self._protocol._queue.qsize():
                message = self._protocol._queue.get(block=False)
                self._incoming.append(message)
        # Schedule a dispatch if there are incoming messages
        if self._incoming:
            QCoreApplication.instance().postEvent(self, _Dispatch())

    def _do_write(self):
        # Drain message from the outgoing queue until we would block or until
        # the queue is empty.
        while True:
            if not self._outbuf:
                if not self._outgoing:
                    break
                message = self._outgoing.popleft()
                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:
#.........这里部分代码省略.........
开发者ID:geertj,项目名称:bluepass,代码行数:103,代码来源:qjsonrpc.py

示例10: create_watch

# 需要导入模块: from PyQt4.QtCore import QSocketNotifier [as 别名]
# 或者: from PyQt4.QtCore.QSocketNotifier import setEnabled [as 别名]
 def create_watch(self, socket, type, callback):
     socket.setblocking(0)
     notifier = QSocketNotifier(socket.fileno(), type, self)
     notifier.activated.connect(callback)
     notifier.setEnabled(True)
     return notifier
开发者ID:LucaLanziani,项目名称:bluepass,代码行数:8,代码来源:messagebus.py

示例11: ComarIface

# 需要导入模块: from PyQt4.QtCore import QSocketNotifier [as 别名]
# 或者: from PyQt4.QtCore.QSocketNotifier import setEnabled [as 别名]
class ComarIface(QObject):
    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)

    def slotComar(self, sock):
        try:
            reply = self.comar.com.read_cmd()
        except:
            if not self.wait_comar():
                logger.error("Can not connect to comar daemon")
            return

        if reply.command == "notify":
            (notification, script, data) = (reply.notify, reply.script, reply.data)
            data = unicode(data)

            if notification == "System.Upgrader.error":
                pass

            elif notification == "System.Upgrader.notify":
                pass

            elif notification == "System.Upgrader.progress":
                pass

            elif notification == "System.Upgrader.started":
                self.emit(SIGNAL("stepStarted(QString)", data))

            elif notification == "System.Upgrader.finished":
                self.emit(SIGNAL("stepFinished(QString)", data))

            else:
                print "Got notification : %s , for script : %s , with data : %s" % (notification, script, data)

    def wait_comar(self):
        self.notifier.setEnabled(False)
        import socket, time
        sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
        timeout = 5
        while timeout > 0:
            try:
                if pisi.api.ctx.comar_sockname:
                    sock.connect(pisi.api.ctx.comar_sockname)
                    return True
                else:
                    self.comar.notifier.setEnabled(True)
                    sock.connect("/var/run/comar.socket")
                    return True
            except socket.error:
                timeout -= 0.2
            time.sleep(0.2)
        return False

    def prepare(self):
        self.com.call("System.Upgrader.prepare")

    def setRepositories(self):
        self.com.call("System.Upgrader.setRepositories")

    def download(self):
        self.com.call("System.Upgrader.download")

    def upgrade(self):
        self.com.call("System.Upgrader.upgrade")

    def cleanup(self):
        self.com.call("System.Upgrader.cleanup")

    def cancel(self):
        self.com.cancel()
开发者ID:Tayyib,项目名称:uludag,代码行数:85,代码来源:comariface.py

示例12: __init__

# 需要导入模块: from PyQt4.QtCore import QSocketNotifier [as 别名]
# 或者: from PyQt4.QtCore.QSocketNotifier import setEnabled [as 别名]
class _EventDispatcherQTFD:
    """Internal fdw wrapper used by EventDispatcherQT"""

    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)

    def process_readability(self, fd):
        self.fdw.process_readability()

    def process_writability(self, fd):
        self.fdw.process_writability()

    def read_r(self):
        self.qsn_read.setEnabled(True)

    def write_r(self):
        self.qsn_write.setEnabled(True)

    def read_u(self):
        self.qsn_read.setEnabled(False)

    def write_u(self):
        self.qsn_write.setEnabled(False)

    def _unregister_all(self):
        for qsn in (self.qsn_read, self.qsn_write, self.qsn_oob):
            if qsn.isEnabled():
                qsn.setEnabled(False)

    def close(self):
        self._unregister_all()
        disconnect(self.qsn_read, SIGNAL("activated(int)"), self.fd_read)
        disconnect(self.qsn_write, SIGNAL("activated(int)"), self.fd_write)
        disconnect(self.qsn_oob, SIGNAL("activated(int)"), self.fd_oob)
        self.qsn_read.deleteLater()
        self.qsn_write.deleteLater()
        self.qsn_oob.deleteLater()
        self.qsn_read = None
        self.qsn_write = None
        self.qsn_oob = None
开发者ID:sh01,项目名称:gonium,代码行数:50,代码来源:__qt4.py


注:本文中的PyQt4.QtCore.QSocketNotifier.setEnabled方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。