def register_qt_recv_signal(self, rxMsgSignal, recvMatch=None): """The client is a Qt app, and wants to receive the messages specified in recvMatch via the rxMsgSignal """ self.rxMsgSignal = rxMsgSignal self.recvMatch = recvMatch if self.mavfile: if isinstance(self.mavfile, mavutil.mavmmaplog): self.thread = QThread() self.recvWorker = UqtMavFileRecvWorker(self.mavfile, self.rxMsgSignal, self.recvMatch) self.recvWorker.moveToThread(self.thread) self.recvWorker.finished.connect(self.thread.quit) self.thread.started.connect(self.recvWorker.worker) self.thread.start() elif type(self.mavfile) in [ mavutil.mavserial ]: fd = self.get_file_descriptor() if fd >= 0: self.notifier = QSocketNotifier(fd, QSocketNotifier.Read) self.notifier.activated.connect(self.can_read) elif type(self.mavfile) in [ mavutil.mavudp, mavutil.mavtcp, mavutil.mavtcpin, mavutil.mavmcast, mavutil.mavlogfile, mavutil.mavlogfile ]: fd = self.get_file_descriptor() if fd: self.notifier = QSocketNotifier(fd.fileno(), QSocketNotifier.Read) self.notifier.activated.connect(self.can_read) elif isinstance(self.mavfile, mavutil.mavchildexec): pass
def wrap_socket(self, sock): """Sets the underlying socket to use.""" self._read_notifier = QSocketNotifier(sock.fileno(), QSocketNotifier.Read, self) self._read_notifier.activated.connect(self._notify_read) self._read_notifier.setEnabled(True) self._write_notifier = QSocketNotifier(sock.fileno(), QSocketNotifier.Write, self) self._write_notifier.activated.connect(self._notify_write) self._write_notifier.setEnabled(True) self._socket = sock
def initialize_socket(self, sock): self._recv_notifier = QSocketNotifier(sock.fileno(), QSocketNotifier.Read, self) self._recv_notifier.activated.connect(self._handle_recv_ready) self._recv_notifier.setEnabled(True) self._send_notifier = QSocketNotifier(sock.fileno(), QSocketNotifier.Write, self) self._send_notifier.activated.connect(self._handle_send_ready) self._send_notifier.setEnabled(True) self._socket = sock self._connected = True self._incoming = [] self._outgoing = []
def __init__(self): super().__init__() self.inotify = INotify() self.qnotifier = QSocketNotifier(self.inotify.fd, QSocketNotifier.Read) self.qnotifier.activated.connect(self._on_activated) self.wd = None
def __init__(self): super(QObject, self).__init__() conn_parent, conn_child = socketpair() # TODO: figure out which of the two sockets should be set to # inheritable and which should be passed to the child if hasattr(conn_child, 'set_inheritable'): conn_child.set_inheritable(True) # Use a local variable for child so that we can talk to the child in # on_finalize without needing a reference to self child = mp.Process(target=_converter_process_func, args=(conn_parent, conn_child)) child.daemon = True child.start() self.child = child conn_child.close() self.conn = conn_parent self.busy = False self.notificationPending = False self.conversionNotifier = QSocketNotifier(self.conn.fileno(), QSocketNotifier.Read) self.conversionNotifier.activated.connect(self._conversionNotifierActivated) def on_finalize(conn): sendObject(conn_parent, {'command':'quit'}) conn_parent.close() child.join() weakref.finalize(self, on_finalize, conn_parent)
def __init__(self, parent=None): super().__init__(parent) self._context = zmq.Context() self._sub_socket = self._context.socket(zmq.SUB) self._sub_socket.bind('tcp://*:3901') self._sub_socket.setsockopt(zmq.SUBSCRIBE, b'') self._pub_socket = self._context.socket(zmq.PUB) self._pub_socket.bind('tcp://*:3902') self._notifier = QSocketNotifier(self._sub_socket.getsockopt(zmq.FD), QSocketNotifier.Read, self) self._notifier.activated.connect(self._on_sub_socket_event) self._config_status = 0 self._score = 0 self._heartbeat = 0 self._match_timer = 0 self._side = 0 self._match_state = 0 self._odrive_state = '00' self._odrive_error = False self._tirette = False self._emergency_stop = False
def setup(self, db_widget, sock, width=960, ffmly='Fantasque Sans Mono', fscale=1.0): """Initialization routine for GUI dashboard widget: Call the base-class initialization routine, then establish a callback to receive messages over the socket. """ self.db_widget, self.sock = db_widget, sock self.setupUi(db_widget, width=width, ffmly=ffmly, fscale=fscale) """ tabulate distinct fonts in widget for subsequent use in rescaling, etc. """ self.font_set = set() def find_fonts(w): if hasattr(w, 'font'): self.font_set.add(w.font()) for child in w.children(): find_fonts(child) find_fonts(self.db_widget) log('Found {} fonts:'.format(len(self.font_set))) for font in self.font_set: log(' {}'.format(font.toString())) """ arrange for read_input to be called whenever data is available on the socket""" self.sock.setblocking(False) self.notifier = QSocketNotifier(sock.fileno(), QSocketNotifier.Read, db_widget) self.notifier.setEnabled(True) self.notifier.activated.connect(self.read_input)
def __init__(self, parent: Optional[QObject] = None) -> None: super().__init__(parent) self.inotify = INotify() self.qnotifier = QSocketNotifier(self.inotify.fd, QSocketNotifier.Read) self.qnotifier.activated.connect(self._on_activated) self.wd = None
def __init__(self): conn_parent, conn_child = mp.Pipe() # Use a local variable for child so that we can talk to the child in # on_finalize without needing a reference to self child = mp.Process(target=_converter_process_func, args=(conn_parent, conn_child)) child.daemon = True child.start() self.child = child conn_child.close() self.conn = conn_parent self.busy = False self.conversionNotifier = QSocketNotifier(self.conn.fileno(), QSocketNotifier.Read) # assign the activated signal of the notifier to a conversionDone # member to get a more meaningful signal name for others to connect to self.conversionDone = self.conversionNotifier.activated def on_finalize(conn): conn_parent.send({'command': 'quit'}) conn_parent.close() child.join() weakref.finalize(self, on_finalize, conn_parent)
def activate(self): """Set up signal handlers. On Windows this uses a QTimer to periodically hand control over to Python so it can handle signals. On Unix, it uses a QSocketNotifier with os.set_wakeup_fd to get notified. """ self._orig_handlers[signal.SIGINT] = signal.signal( signal.SIGINT, self.interrupt) self._orig_handlers[signal.SIGTERM] = signal.signal( signal.SIGTERM, self.interrupt) if utils.is_posix and hasattr(signal, 'set_wakeup_fd'): # pylint: disable=import-error,no-member,useless-suppression import fcntl read_fd, write_fd = os.pipe() for fd in [read_fd, write_fd]: flags = fcntl.fcntl(fd, fcntl.F_GETFL) fcntl.fcntl(fd, fcntl.F_SETFL, flags | os.O_NONBLOCK) self._notifier = QSocketNotifier(typing.cast(sip.voidptr, read_fd), QSocketNotifier.Read, self) self._notifier.activated.connect( # type: ignore[attr-defined] self.handle_signal_wakeup) self._orig_wakeup_fd = signal.set_wakeup_fd(write_fd) # pylint: enable=import-error,no-member,useless-suppression else: self._timer.start(1000) self._timer.timeout.connect(lambda: None) self._activated = True
def activate(self): """Set up signal handlers. On Windows this uses a QTimer to periodically hand control over to Python so it can handle signals. On Unix, it uses a QSocketNotifier with os.set_wakeup_fd to get notified. """ self._orig_handlers[signal.SIGINT] = signal.signal( signal.SIGINT, self.interrupt) self._orig_handlers[signal.SIGTERM] = signal.signal( signal.SIGTERM, self.interrupt) if os.name == 'posix' and hasattr(signal, 'set_wakeup_fd'): # pylint: disable=import-error,no-member import fcntl read_fd, write_fd = os.pipe() for fd in (read_fd, write_fd): flags = fcntl.fcntl(fd, fcntl.F_GETFL) fcntl.fcntl(fd, fcntl.F_SETFL, flags | os.O_NONBLOCK) self._notifier = QSocketNotifier(read_fd, QSocketNotifier.Read, self) self._notifier.activated.connect(self.handle_signal_wakeup) self._orig_wakeup_fd = signal.set_wakeup_fd(write_fd) else: self._timer.start(1000) self._timer.timeout.connect(lambda: None) self._activated = True
def connect(self, sock): """Sets the underlying socket to utilize.""" self._accept_notifier = QSocketNotifier(sock.fileno(), QSocketNotifier.Read, self) self._accept_notifier.activated.connect(self._notify_accept) self._accept_notifier.setEnabled(True) self._socket = sock self._connected = True
def init_connect_zmq(self, on_poll, uri, topicfilter): logger.debug('QWZMQListener.init_connect_zmq uri=%s' % uri) self.zmq_context = zmq.Context(1) self.zmq_socket = self.zmq_context.socket(zmq.SUB) self.zmq_socket.connect(uri) self.zmq_socket.setsockopt(zmq.SUBSCRIBE, topicfilter) self.zmq_notifier = QSocketNotifier(self.zmq_socket.getsockopt(zmq.FD), QSocketNotifier.Read, self) self.zmq_notifier.activated.connect(on_poll)
def connect(self, sock): """ Wraps the socket with the current object. :param sock: the socket """ self._read_notifier = QSocketNotifier(sock.fileno(), QSocketNotifier.Read, self) self._read_notifier.activated.connect(self._notify_read) self._read_notifier.setEnabled(True) self._write_notifier = QSocketNotifier(sock.fileno(), QSocketNotifier.Write, self) self._write_notifier.activated.connect(self._notify_write) self._write_notifier.setEnabled(False) self._socket = sock self._connected = True
def init_zocp(self): self.z = ZOCP("QT UI TEST") self.z.register_float("myFloat", 2.3, 'rw', 0, 5.0, 0.1) self.notifier = QSocketNotifier(self.z.inbox.getsockopt(zmq.FD), QSocketNotifier.Read) self.notifier.setEnabled(True) self.notifier.activated.connect(self.zocp_event) self.z.on_modified = self.on_modified self.z.start()
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 __init__(self, widget, model): self._widget = widget self._model = model self.buffer = "" # Setup pty m,s = pty.openpty() self._ptymaster = m self.slave_name = os.ttyname(s) self.notifier = QSocketNotifier(m, QSocketNotifier.Read) self.notifier.activated.connect(self.onSocketRead)
def __init__(self, filepath, parent=None): super().__init__(parent) self._filepath = filepath # We open as R/W so we never get EOF and have to reopen the pipe. # See http://www.outflux.net/blog/archives/2008/03/09/using-select-on-a-fifo/ # We also use os.open and os.fdopen rather than built-in open so we # can add O_NONBLOCK. fd = os.open(filepath, os.O_RDWR | os.O_NONBLOCK) # pylint: disable=no-member self.fifo = os.fdopen(fd, 'r') self._notifier = QSocketNotifier(fd, QSocketNotifier.Read, self) self._notifier.activated.connect(self.read_line)
def _connect_socket_to_notifier(self, socket, message_queue): def _handle_message_to_queue(): if not message_queue.handleMessages(): # TODO: Localization QMessageBox.warning( self, "Server error", "Error while receiving message from server. Please see logs.") self._timer.timeout.disconnect(_handle_message_to_queue) socket_notifier = QSocketNotifier(socket.fd, QSocketNotifier.Read, self) socket_notifier.activated.connect(_handle_message_to_queue) self._timer.timeout.connect(_handle_message_to_queue) self._socket_notifiers.append(socket_notifier)
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 self.notifier.activated.connect(self.fn)
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 _setup_wakeup_fd(self): """Set up wakeup filedescriptor for signal handling. This returns the control from the Qt main loop in C++ back to python and allows signal handling in python. Only available for unix-like systems. """ logging.debug("Setting up wakeup filedescriptor for unix-like systems") read_fd, write_fd = os.pipe() for fd in (read_fd, write_fd): flags = fcntl.fcntl(fd, fcntl.F_GETFL) fcntl.fcntl(fd, fcntl.F_SETFL, flags | os.O_NONBLOCK) notifier = QSocketNotifier(read_fd, QSocketNotifier.Read, self) notifier.activated.connect(lambda: None) signal.set_wakeup_fd(write_fd)
def start(self): self._logger.debug("Starting servers discovery....") self._socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self._socket.bind(("", 31013)) self._socket.settimeout(0) self._socket.setblocking(0) self._read_notifier = QSocketNotifier(self._socket.fileno(), QSocketNotifier.Read, self) self._read_notifier.activated.connect(self._notify_read) self._read_notifier.setEnabled(True) self._started = True self._timer.start()
def connect(self, sock): """ Wraps the socket with the current object. :param sock: the socket """ sock.settimeout(0) self._accept_notifier = QSocketNotifier(sock.fileno(), QSocketNotifier.Read, self) self._accept_notifier.activated.connect(self._notify_accept) self._accept_notifier.setEnabled(True) self._socket = sock self._connected = True
def start_server(self): self._server = Server() ret = self._server.start(self.address_text.text()) if ret is not True: self._log("[ZMQError]: " + repr(ret)) return socket = self._server.socket self._notifier = QSocketNotifier(socket.getsockopt(zmq.FD), QSocketNotifier.Read, self) self._notifier.activated.connect(self._socket_activity) self._notifier.setEnabled(True) self.connect_button.clicked.disconnect() self.connect_button.clicked.connect(self.stop_server) self.connect_button.setText('Stop server') self._log("[Socket] Start server")
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)
def start(self, host, port, ssl): self._logger.debug("Starting clients discovery...") self._info = "%s %d %s" % (host, port, ssl) self._socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) self._socket.settimeout(0) self._socket.setblocking(0) self._read_notifier = QSocketNotifier(self._socket.fileno(), QSocketNotifier.Read, self) self._read_notifier.activated.connect(self._notify_read) self._read_notifier.setEnabled(True) self._started = True self._timer.start() self._send_request()
def start(self, host, port, ssl): """Start the discovery process and broadcast the given information.""" self._logger.debug("Starting clients discovery") self._info = "%s %d %s" % (host, port, ssl) # Create a datagram socket capable of broadcasting self._socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) self._socket.settimeout(0) # No timeout self._socket.setblocking(0) # No blocking self._read_notifier = QSocketNotifier(self._socket.fileno(), QSocketNotifier.Read, self) self._read_notifier.activated.connect(self._notify_read) self._read_notifier.setEnabled(True) self._started = True self._timer.start() self._send_request()
def start(self): """Start the discovery process and listen for discovery requests.""" self._logger.debug("Starting servers discovery") # Create a datagram socket bound on port 31013 self._socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) if platform.system() == "Darwin": self._socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1) self._socket.bind(("", 31013)) self._socket.settimeout(0) self._socket.setblocking(0) self._read_notifier = QSocketNotifier(self._socket.fileno(), QSocketNotifier.Read, self) self._read_notifier.activated.connect(self._notify_read) self._read_notifier.setEnabled(True) self._started = True
def __init__(self): super().__init__() # uic.loadUi('button.ui',self) pg.setConfigOptions(antialias=True) self._client = Client() socket = self._client.socket self._notifier = QSocketNotifier(socket.getsockopt(zmq.FD), QSocketNotifier.Read, self) self._notifier.activated.connect(self._socket_activity) self._counter = 0 self.setupUi(self) self._log('[UI] started') s_thrd = Thread(target=self.sub_thrd) s_thrd.start() self._log('[Thread] started') self.buff_size = 200 #버튼에 기능을 연결하는 코드 self.pBut.clicked.connect(self.button1Function) self.p = self.gview self.p.setRange(xRange=[0, self.buff_size], yRange=[0, 500]) self.p2 = self.gview_2 self.p2.setRange(xRange=[0, self.buff_size], yRange=[-250, 250]) # self.p.enableAutoRange(axis='x') # self.p2.enableAutoRange(axis='x') self.data = np.empty(self.buff_size) self.data2 = np.empty(self.buff_size) self.time = np.empty(self.buff_size) self.sizeArray = (np.random.random(500) * 20.).astype(int) self.ptr = 0 self.lastTime = time() self.nowTime = time() dt = self.nowTime - self.lastTime self.fps = -1.0 #1.0/dt self.timer = QtCore.QTimer() self.timer.timeout.connect(self._update) self.timer.start(0)