Esempio n. 1
0
 def __init__(self):
     self._rsock, self._wsock = socket.socketpair()
     self._queue = Queue.Queue()
     self._qt_object = QtCore.QObject()
     self._notifier = QtCore.QSocketNotifier(self._rsock.fileno(),
                                             QtCore.QSocketNotifier.Read)
     self._notifier.activated.connect(self._recv)
Esempio n. 2
0
    def __init__(self, sock, client_address, server, packet_len=False):
        QtCore.QObject.__init__(self)
        GlibTCPHandler.__init__(self, sock, client_address, server, packet_len)

        self.socket_notifier = QtCore.QSocketNotifier(\
            self.socket.fileno(), QtCore.QSocketNotifier.Read)
        self.socket_notifier.setEnabled(True)
        self.socket_notifier.activated.connect(self._socketwatcher_recv)
Esempio n. 3
0
 def __init__(self, context, socketType):
     QtCore.QObject.__init__(self, context)
     self.zmq_socket = context.zmq_context.socket(socketType)
     self.fd = self.zmq_socket.getsockopt(zmq.FD)
     self.readNotifier = QtCore.QSocketNotifier(self.fd,
                                                QtCore.QSocketNotifier.Read,
                                                self)
     self.readNotifier.activated.connect(self.notifierActivity)
Esempio n. 4
0
 def _set_events(self, value):
     self._events = self._ev2qt(value)
     already_started = self._handle.isEnabled()
     self._handle = QtCore.QSocketNotifier(self._fd, self._events,
                                           self.loop._loop)
     self._handle.setEnabled(False)
     if already_started:
         self._handle.activated.connect(self._poll_cb)
         self._handle.setEnabled(True)
Esempio n. 5
0
 def __init__(self):
     # Create a socket pair for signalling between the two threads
     self._rsock, self._wsock = createSocketPair()
     # A queue to store messages
     self._queue = Queue.Queue()
     # A QtObject to trigger Qt signals
     self._qt_object = QtCore.QObject()
     # A notifier which will call self._recv() when there is data on the socket
     self._notifier = QtCore.QSocketNotifier(self._rsock.fileno(),
                                             QtCore.QSocketNotifier.Read)
     self._notifier.activated.connect(self._recv)
Esempio n. 6
0
    def newInputMonitor(self, fd, callback):
        """Convenience function to create a notification callback when input is available on a file descriptor.

        :param fd: integer file descriptor
        :param callback: one-argument function callback(fd) to be called with the file descriptor
        :return: the underlying QSocketNotifier object
        """
        notifier = QtCore.QSocketNotifier(fd, QtCore.QSocketNotifier.Read)
        QtCore.QObject.connect(
            notifier, QtCore.SIGNAL(QtCore.QString.fromUtf8("activated(int)")),
            callback)
        return notifier
Esempio n. 7
0
 def __init__(self, parent, reactor, watcher, socketType):
     QtCore.QObject.__init__(self, parent)
     self.reactor = reactor
     self.watcher = watcher
     fd = watcher.fileno()
     self.notifier = QtCore.QSocketNotifier(fd, socketType, parent)
     self.notifier.setEnabled(True)
     if socketType == QtCore.QSocketNotifier.Read:
         self.fn = self.read
     else:
         self.fn = self.write
     QtCore.QObject.connect(self.notifier, QtCore.SIGNAL("activated(int)"),
                            self.fn)
Esempio n. 8
0
 def __init__(self, flags=None, default=True):
     assert (not QtCore.QCoreApplication.startingUp())
     self._loop = QtCore.QEventLoop()
     self._loop.default = default
     self.__callback_timers = {}
     self._signal_watchers = {}
     self._raised_signal = None
     self._child_watchers = {}
     self._loop.excepthook = functools.partial(self.handle_error, None)
     self._signal_notifier = QtCore.QSocketNotifier(
         _signal_rfd.fileno(), QtCore.QSocketNotifier.Read, self._loop)
     self._signal_notifier.activated.connect(self._handle_signal_in_loop)
     self._signal_notifier.setEnabled(True)
     self._watchers = set()
     self._sigchld_handle = None
Esempio n. 9
0
    def start_solver(self, task_name, param, mesh_dir, **kwargs):
        cwd = os.getcwd()
        self.task_dir = os.makedirs(os.path.join(cwd, 'cycas_' + task_name))
        if kwargs.get('not_copy_mesh') is None:
            shutil.move(mesh_dir, self.task_dir)
        shutil.copy(self.cycas_dir, self.task_dir)

        input_pard = open(os.path.join(self.task_dir, 'inp.inp'), 'w')
        input_pard.write(param)

        self.logfile = open(os.path.join(self.task_dir, 'out'), 'w')
        self.task = sp.Popen(['./cycas'], stdout=self.logfile)

        fd = os.open(self.logfile.name, os.O_RDONLY)
        self.notifier = QtCore.QSocketNotifier(fd, QtCore.QSocketNotifier.Read)
        self.notifier.activated.connect(self.log_update_slot)
        self.notifier.setEnabled(True)
Esempio n. 10
0
    def __init__(self, parent, qt_reactor, watcher, socket_type):
        QtCore.QObject.__init__(self, parent)
        self.qt_reactor = qt_reactor
        self.watcher = watcher
        fd = watcher.fileno()
        self.notifier = QtCore.QSocketNotifier(fd, socket_type, parent)
        self.notifier.setEnabled(True)
        if socket_type == QtCore.QSocketNotifier.Read:
            self.fn = self.read
        else:
            self.fn = self.write

        if qtreactor_config.get_qt_name() == "PyQt4":
            # Fallback for PyQt<4.5
            QtCore.QObject.connect(self.notifier,
                                   QtCore.SIGNAL("activated(int)"), self.fn)
        else:
            self.notifier.activated.connect(self.fn)
Esempio n. 11
0
    def drawMap(self):
        if self.logging and self.online:
            self.logfh = open(self.logFileName, "w")

        if self.online:

            #TODO: make selection of BT devices
            self.fh = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
            #self.fh.setblocking(False)
            try:
                #self.fh.connect((self.deviceAddress.deviceId, 1)) #("00:0D:B5:31:58:58", 1))
                self.fh.connect((self.online, 1))  #("00:0D:B5:31:58:58", 1))
                #assign socket notifier
                self.notifier = QtCore.QSocketNotifier(
                    self.fh.fileno(), QtCore.QSocketNotifier.Read)
                self.connect(self.notifier, QtCore.SIGNAL("activated(int)"),
                             self.readBTData)
            except bluetooth.btcommon.BluetoothError, ex:
                print "Error: %s" % ex
Esempio n. 12
0
 def __init__(self):
     
     QtGui.QMainWindow.__init__(self)
     
     self.logging = True
     self.logFileName = "d:\pygps.log"
     self.online = True
     
     self.setGeometry(0, 0, 512, 512)
     self.setWindowTitle('PyGps')
     self.renderArea = RenderArea(self)
     self.setCentralWidget(self.renderArea)
     self.olddata = ""
     self.maxDopAllowed = "6"
     #add zoom buttons
     
     #assign slots
     
     #center the main window in the desktop
     self.center()
     
     if self.logging and self.online:
         self.logfh = open(self.logFileName, "w")
     
     if self.online:
     
         #TODO: make selection of BT devices
         self.fh = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
         #self.fh.setblocking(False)
         try:
             self.fh.connect(("00:0D:B5:31:58:58", 1))
             #assign socket notifier
             self.notifier = QtCore.QSocketNotifier(self.fh.fileno(), QtCore.QSocketNotifier.Read)
             self.connect(self.notifier, QtCore.SIGNAL("activated(int)"), self.readBTData)
         except bluetooth.btcommon.BluetoothError, ex:
             print "Error: %s" % ex
Esempio n. 13
0
    def __init__(self, parent=None):

        QtGui.QWidget.__init__(self, parent)

        self.sysPath = os.path.join(sys.path[0], "")

        self.logging = True
        self.logFileName = self.sysPath + "_pygps.log"
        self.online = False

        self.maxZoom = 16

        self.setGeometry(0, 0, 512, 512)
        self.setWindowTitle('PyGps')
        self.deviceAddress = Bluetooth_Search(self)
        #render area
        self.renderArea = RenderArea(self)
        self.renderArea.move(0, 0)

        #label lat lon
        self.label_latlon = QtGui.QLabel(self)
        self.label_latlon.setMinimumSize(135, 45)
        self.label_latlon.move(0, 0)
        self.label_latlon.show()

        #zoom buttons
        self.zoomin_button = self.createButton("+", QtGui.QColor("white"),
                                               self.zoomIn)
        self.zoomout_button = self.createButton("-", QtGui.QColor("white"),
                                                self.zoomOut)

        #zoom panel - zoom buttons container
        self.zoom_panel = QtGui.QLabel(self)
        self.zoom_panel.setMinimumSize(40, 60)
        zoom_layout = QtGui.QVBoxLayout()
        zoom_layout.addWidget(self.zoomin_button)
        zoom_layout.addWidget(self.zoomout_button)
        self.zoom_panel.setLayout(zoom_layout)
        self.zoom_panel.move(0, 60)
        self.zoom_panel.show()

        self.settings_panel = QtGui.QLabel(self)
        self.settings_panel.setMinimumSize(40, 40)
        self.settings_panel.setAlignment(QtCore.Qt.AlignVCenter
                                         | QtCore.Qt.AlignCenter)
        self.settings_panel.setPixmap(
            QtGui.QPixmap("./32px-Crystal_Clear_action_configure.png"))
        size = self.geometry()
        self.settings_panel.move(size.width() - 40, 0)
        self.settings_panel.show()

        self.speed_panel = QtGui.QLabel(self)
        self.speed_panel.setMinimumSize(160, 35)
        self.speed_panel.setAlignment(QtCore.Qt.AlignVCenter
                                      | QtCore.Qt.AlignRight)
        #print self.speed_panel.alignment()
        self.speed_panel.setObjectName("speed")
        self.speed_panel.move(size.width() / 2 - 75, size.height() - 35)

        self.olddata = ""

        #add zoom buttons

        #assign slots

        #center the main window in the desktop
        self.center()

        if self.logging and self.online:
            self.logfh = open(self.logFileName, "w")

        if self.online:

            #TODO: make selection of BT devices
            self.fh = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
            #self.fh.setblocking(False)
            try:
                self.fh.connect((self.deviceAddress.deviceId,
                                 1))  #("00:0D:B5:31:58:58", 1))
                #assign socket notifier
                self.notifier = QtCore.QSocketNotifier(
                    self.fh.fileno(), QtCore.QSocketNotifier.Read)
                self.connect(self.notifier, QtCore.SIGNAL("activated(int)"),
                             self.readBTData)
            except bluetooth.btcommon.BluetoothError, ex:
                print "Error: %s" % ex
Esempio n. 14
0
 def _attach(self, source):
     super(_StderrWrapper, self)._attach(source)
     self._notifier = QtCore.QSocketNotifier(self._source.fileno(),
                                             QtCore.QSocketNotifier.Read)
     self._notifier.activated.connect(self._process_output)
Esempio n. 15
0
    def __init__(self, picard_args, unparsed_args, localedir, autoupdate):
        # Set the WM_CLASS to 'MusicBrainz-Picard' so desktop environments
        # can use it to look up the app
        QtGui.QApplication.__init__(self,
                                    ['MusicBrainz-Picard'] + unparsed_args)
        self.__class__.__instance = self

        config._setup(self)

        self._cmdline_files = picard_args.FILE
        self._autoupdate = autoupdate
        self._debug = False

        # FIXME: Figure out what's wrong with QThreadPool.globalInstance().
        # It's a valid reference, but its start() method doesn't work.
        self.thread_pool = QtCore.QThreadPool(self)

        # Use a separate thread pool for file saving, with a thread count of 1,
        # to avoid race conditions in File._save_and_rename.
        self.save_thread_pool = QtCore.QThreadPool(self)
        self.save_thread_pool.setMaxThreadCount(1)

        if not sys.platform == "win32":
            # Set up signal handling
            # It's not possible to call all available functions from signal
            # handlers, therefore we need to set up a QSocketNotifier to listen
            # on a socket. Sending data through a socket can be done in a
            # signal handler, so we use the socket to notify the application of
            # the signal.
            # This code is adopted from
            # https://qt-project.org/doc/qt-4.8/unix-signals.html

            # To not make the socket module a requirement for the Windows
            # installer, import it here and not globally
            import socket
            self.signalfd = socket.socketpair(socket.AF_UNIX,
                                              socket.SOCK_STREAM, 0)

            self.signalnotifier = QtCore.QSocketNotifier(
                self.signalfd[1].fileno(), QtCore.QSocketNotifier.Read, self)
            self.signalnotifier.activated.connect(self.sighandler)

            signal.signal(signal.SIGHUP, self.signal)
            signal.signal(signal.SIGINT, self.signal)
            signal.signal(signal.SIGTERM, self.signal)

        # Setup logging
        self.debug(picard_args.debug or "PICARD_DEBUG" in os.environ)
        log.debug("Starting Picard from %r", os.path.abspath(__file__))
        log.debug("Platform: %s %s %s", platform.platform(),
                  platform.python_implementation(), platform.python_version())
        log.debug("Versions: %s", versions.as_string())
        log.debug("Configuration file path: %r", config.config.fileName())

        # TODO remove this before the final release
        if sys.platform == "win32":
            olduserdir = "~\\Local Settings\\Application Data\\MusicBrainz Picard"
        else:
            olduserdir = "~/.picard"
        olduserdir = os.path.expanduser(olduserdir)
        if os.path.isdir(olduserdir):
            log.info("Moving %r to %r", olduserdir, USER_DIR)
            try:
                shutil.move(olduserdir, USER_DIR)
            except:
                pass
        log.debug("User directory: %r", os.path.abspath(USER_DIR))

        # for compatibility with pre-1.3 plugins
        QtCore.QObject.tagger = self
        QtCore.QObject.config = config
        QtCore.QObject.log = log

        check_io_encoding()

        # Must be before config upgrade because upgrade dialogs need to be
        # translated
        setup_gettext(localedir, config.setting["ui_language"], log.debug)

        upgrade_config()

        self.xmlws = XmlWebService()

        load_user_collections()

        # Initialize fingerprinting
        self._acoustid = acoustid.AcoustIDClient()
        self._acoustid.init()

        # Load plugins
        self.pluginmanager = PluginManager()
        if hasattr(sys, "frozen"):
            self.pluginmanager.load_plugindir(
                os.path.join(os.path.dirname(sys.argv[0]), "plugins"))
        else:
            mydir = os.path.dirname(os.path.abspath(__file__))
            self.pluginmanager.load_plugindir(os.path.join(mydir, "plugins"))
            self.pluginmanager.load_plugindir(
                os.path.join(mydir, os.pardir, "contrib", "plugins"))

        if not os.path.exists(USER_PLUGIN_DIR):
            os.makedirs(USER_PLUGIN_DIR)
        self.pluginmanager.load_plugindir(USER_PLUGIN_DIR)
        self.pluginmanager.query_available_plugins()

        self.acoustidmanager = AcoustIDManager()
        self.browser_integration = BrowserIntegration()

        self.files = {}
        self.clusters = ClusterList()
        self.albums = {}
        self.release_groups = {}
        self.mbid_redirects = {}
        self.unmatched_files = UnmatchedFiles()
        self.nats = None
        self.window = MainWindow()
        self.exit_cleanup = []
        self.stopping = False
Esempio n. 16
0
 def start(self, callback, *args, **kw):
     super(Io, self).start(callback, *args)
     self._handle = QtCore.QSocketNotifier(self._fd, self._events,
                                           self.loop._loop)
     self._handle.activated.connect(self._poll_cb)
     self._handle.setEnabled(True)