Esempio n. 1
0
 def __init__(self):
     self._reads = {}
     self._writes = {}
     self._notifiers = {}
     self._timer = QTimer()
     self._timer.setSingleShot(True)
     self._timer.timeout.connect(self.iterate_qt)
     if QCoreApplication.instance() is None:
         # Application Object has not been started yet
         self.qApp = QCoreApplication([])
         self._ownApp = True
     else:
         self.qApp = QCoreApplication.instance()
         self._ownApp = False
     self._blockApp = None
     posixbase.PosixReactorBase.__init__(self)
Esempio n. 2
0
 def __init__(self):
     self._reads = {}
     self._writes = {}
     self._notifiers = {}
     self._timer = QTimer()
     self._timer.setSingleShot(True)
     self._timer.timeout.connect(self.iterate_qt)
     if QCoreApplication.instance() is None:
         # Application Object has not been started yet
         self.qApp = QCoreApplication([])
         self._ownApp = True
     else:
         self.qApp = QCoreApplication.instance()
         self._ownApp = False
     self._blockApp = None
     posixbase.PosixReactorBase.__init__(self)
Esempio n. 3
0
    def getConfiguration(self):
        iniPath = self._getConfigurationFilePath()
        self._parseConfigFile(iniPath)
        #
        # Watch out for the method self._overrideConfigWithArgs when you're adding custom multi-word command line arguments
        #
        if self._config['language']:
            setLanguage(self._config['language'])
        self._argparser = argparse.ArgumentParser(description=getMessage("argument-description"),
                                         epilog=getMessage("argument-epilog"))
        self._argparser.add_argument('--no-gui', action='store_true', help=getMessage("nogui-argument"))
        self._argparser.add_argument('-a', '--host', metavar='hostname', type=str, help=getMessage("host-argument"))
        self._argparser.add_argument('-n', '--name', metavar='username', type=str, help=getMessage("name-argument"))
        self._argparser.add_argument('-d', '--debug', action='store_true', help=getMessage("debug-argument"))
        self._argparser.add_argument('-g', '--force-gui-prompt', action='store_true', help=getMessage("force-gui-prompt-argument"))
        self._argparser.add_argument('--no-store', action='store_true', help=getMessage("no-store-argument"))
        self._argparser.add_argument('-r', '--room', metavar='room', type=str, nargs='?', help=getMessage("room-argument"))
        self._argparser.add_argument('-p', '--password', metavar='password', type=str, nargs='?', help=getMessage("password-argument"))
        self._argparser.add_argument('--player-path', metavar='path', type=str, help=getMessage("player-path-argument"))
        self._argparser.add_argument('--language', metavar='language', type=str, help=getMessage("language-argument"))
        self._argparser.add_argument('file', metavar='file', type=lambda s: unicode(s, 'utf8'), nargs='?', help=getMessage("file-argument"))
        self._argparser.add_argument('--clear-gui-data', action='store_true', help=getMessage("clear-gui-data-argument"))
        self._argparser.add_argument('-v', '--version', action='store_true', help=getMessage("version-argument"))
        self._argparser.add_argument('_args', metavar='options', type=str, nargs='*', help=getMessage("args-argument"))
        args = self._argparser.parse_args()
        if args.version:
            print getMessage("version-message").format(version, milestone)
            sys.exit()
        self._overrideConfigWithArgs(args)
        if not self._config['noGui']:
            try:
	            from syncplay.vendor.Qt import QtWidgets, IsPySide, IsPySide2
	            from syncplay.vendor.Qt.QtCore import QCoreApplication
	            from syncplay.vendor import qt5reactor
	            if not (IsPySide2 or IsPySide):
	                raise ImportError
	            if QCoreApplication.instance() is None:
	              self.app = QtWidgets.QApplication(sys.argv)
	            qt5reactor.install()
	            if isMacOS():
	                import appnope
	                appnope.nope()
            except ImportError:
                print getMessage("unable-import-gui-error")
                self._config['noGui'] = True
        if self._config['file'] and self._config['file'][:2] == "--":
            self._config['playerArgs'].insert(0, self._config['file'])
            self._config['file'] = None
        # Arguments not validated yet - booleans are still text values
        if self._config['language']:
            setLanguage(self._config['language'])
        if (self._config['forceGuiPrompt'] == "True" or not self._config['file']) and not self._config['noGui']:
            self._forceGuiPrompt()
        self._checkConfig()
        self._saveConfig(iniPath)
        if self._config['file']:
            self._config['loadedRelativePaths'] = self._loadRelativeConfiguration()
        if self._config['language']:
            setLanguage(self._config['language'])
        return self._config
Esempio n. 4
0
 def getConfiguration(self):
     iniPath = self._getConfigurationFilePath()
     self._parseConfigFile(iniPath)
     #
     # Watch out for the method self._overrideConfigWithArgs when you're adding custom multi-word command line arguments
     #
     if self._config['language']:
         setLanguage(self._config['language'])
     self._argparser = argparse.ArgumentParser(
         description=getMessage("argument-description"),
         epilog=getMessage("argument-epilog"))
     self._argparser.add_argument('--no-gui',
                                  action='store_true',
                                  help=getMessage("nogui-argument"))
     self._argparser.add_argument('-a',
                                  '--host',
                                  metavar='hostname',
                                  type=str,
                                  help=getMessage("host-argument"))
     self._argparser.add_argument('-n',
                                  '--name',
                                  metavar='username',
                                  type=str,
                                  help=getMessage("name-argument"))
     self._argparser.add_argument('-d',
                                  '--debug',
                                  action='store_true',
                                  help=getMessage("debug-argument"))
     self._argparser.add_argument(
         '-g',
         '--force-gui-prompt',
         action='store_true',
         help=getMessage("force-gui-prompt-argument"))
     self._argparser.add_argument('--no-store',
                                  action='store_true',
                                  help=getMessage("no-store-argument"))
     self._argparser.add_argument('-r',
                                  '--room',
                                  metavar='room',
                                  type=str,
                                  nargs='?',
                                  help=getMessage("room-argument"))
     self._argparser.add_argument('-p',
                                  '--password',
                                  metavar='password',
                                  type=str,
                                  nargs='?',
                                  help=getMessage("password-argument"))
     self._argparser.add_argument('--player-path',
                                  metavar='path',
                                  type=str,
                                  help=getMessage("player-path-argument"))
     self._argparser.add_argument('--language',
                                  metavar='language',
                                  type=str,
                                  help=getMessage("language-argument"))
     self._argparser.add_argument('file',
                                  metavar='file',
                                  type=str,
                                  nargs='?',
                                  help=getMessage("file-argument"))
     self._argparser.add_argument(
         '--clear-gui-data',
         action='store_true',
         help=getMessage("clear-gui-data-argument"))
     self._argparser.add_argument('-v',
                                  '--version',
                                  action='store_true',
                                  help=getMessage("version-argument"))
     self._argparser.add_argument('_args',
                                  metavar='options',
                                  type=str,
                                  nargs='*',
                                  help=getMessage("args-argument"))
     args = self._argparser.parse_args()
     if args.version:
         print(getMessage("version-message").format(version, milestone))
         sys.exit()
     self._overrideConfigWithArgs(args)
     if not self._config['noGui']:
         try:
             from syncplay.vendor.Qt import QtWidgets, IsPySide, IsPySide2
             from syncplay.vendor.Qt.QtCore import QCoreApplication
             from syncplay.vendor import qt5reactor
             if not (IsPySide2 or IsPySide):
                 raise ImportError
             if QCoreApplication.instance() is None:
                 self.app = QtWidgets.QApplication(sys.argv)
             qt5reactor.install()
             if isMacOS():
                 import appnope
                 appnope.nope()
         except ImportError:
             try:
                 from twisted.trial import unittest
             except:
                 print(getMessage("unable-import-twisted-error"))
                 sys.exit()
             print(getMessage("unable-import-gui-error"))
             self._config['noGui'] = True
     if self._config['file'] and self._config['file'][:2] == "--":
         self._config['playerArgs'].insert(0, self._config['file'])
         self._config['file'] = None
     # Arguments not validated yet - booleans are still text values
     if self._config['language']:
         setLanguage(self._config['language'])
     if (self._config['forceGuiPrompt'] == "True"
             or not self._config['file']) and not self._config['noGui']:
         self._forceGuiPrompt()
     self._checkConfig()
     self._saveConfig(iniPath)
     if self._config['file']:
         self._config[
             'loadedRelativePaths'] = self._loadRelativeConfiguration()
     if self._config['language']:
         setLanguage(self._config['language'])
     return self._config
Esempio n. 5
0
class QtReactor(posixbase.PosixReactorBase):
    # implements(IReactorFDSet)

    def __init__(self):
        self._reads = {}
        self._writes = {}
        self._notifiers = {}
        self._timer = QTimer()
        self._timer.setSingleShot(True)
        self._timer.timeout.connect(self.iterate_qt)
        if QCoreApplication.instance() is None:
            # Application Object has not been started yet
            self.qApp = QCoreApplication([])
            self._ownApp = True
        else:
            self.qApp = QCoreApplication.instance()
            self._ownApp = False
        self._blockApp = None
        posixbase.PosixReactorBase.__init__(self)

    def _add(self, xer, primary, type):
        """
        Private method for adding a descriptor from the event loop.

        It takes care of adding it if  new or modifying it if already added
        for another state (read -> read/write for example).
        """
        if xer not in primary:
            primary[xer] = TwistedSocketNotifier(None, self, xer, type)

    def addReader(self, reader):
        """Add a FileDescriptor for notification of data available to read."""
        self._add(reader, self._reads, QSocketNotifier.Read)

    def addWriter(self, writer):
        """Add a FileDescriptor for notification of data available to write."""
        self._add(writer, self._writes, QSocketNotifier.Write)

    def _remove(self, xer, primary):
        """
        Private method for removing a descriptor from the event loop.

        It does the inverse job of _add, and also add a check in case of the fd
        has gone away.
        """
        if xer in primary:
            notifier = primary.pop(xer)
            notifier.shutdown()

    def removeReader(self, reader):
        """Remove a Selectable for notification of data available to read."""
        self._remove(reader, self._reads)

    def removeWriter(self, writer):
        """Remove a Selectable for notification of data available to write."""
        self._remove(writer, self._writes)

    def removeAll(self):
        """Remove all selectables, and return a list of them."""
        return self._removeAll(self._reads, self._writes)

    def getReaders(self):
        return self._reads.keys()

    def getWriters(self):
        return self._writes.keys()

    def callLater(self, howlong, *args, **kargs):
        rval = super(QtReactor, self).callLater(howlong, *args, **kargs)
        self.reactorInvocation()
        return rval

    def reactorInvocation(self):
        self._timer.stop()
        self._timer.setInterval(0)
        self._timer.start()

    def _iterate(self, delay=None, fromqt=False):
        """See twisted.internet.interfaces.IReactorCore.iterate."""
        self.runUntilCurrent()
        self.doIteration(delay, fromqt=fromqt)

    iterate = _iterate

    def iterate_qt(self, delay=None):
        self.iterate(delay=delay, fromqt=True)

    def doIteration(self, delay=None, fromqt=False):
        """This method is called by a Qt timer or by network activity on a file descriptor"""
        if not self.running and self._blockApp:
            self._blockApp.quit()
        self._timer.stop()
        if delay is None:
            delay = 0
        delay = max(delay, 1)
        if not fromqt:
            self.qApp.processEvents(QEventLoop.AllEvents, delay * 1000)
        timeout = self.timeout()
        if timeout is not None:
            self._timer.setInterval(timeout * 1000)
            self._timer.start()

    def runReturn(self, installSignalHandlers=True):
        self.startRunning(installSignalHandlers=installSignalHandlers)
        self.reactorInvocation()

    def run(self, installSignalHandlers=True):
        if self._ownApp:
            self._blockApp = self.qApp
        else:
            self._blockApp = QEventLoop()
        self.runReturn()
        self._blockApp.exec_()
        if self.running:
            self.stop()
            self.runUntilCurrent()
Esempio n. 6
0
class QtReactor(posixbase.PosixReactorBase):
    # implements(IReactorFDSet)

    def __init__(self):
        self._reads = {}
        self._writes = {}
        self._notifiers = {}
        self._timer = QTimer()
        self._timer.setSingleShot(True)
        self._timer.timeout.connect(self.iterate_qt)
        if QCoreApplication.instance() is None:
            # Application Object has not been started yet
            self.qApp = QCoreApplication([])
            self._ownApp = True
        else:
            self.qApp = QCoreApplication.instance()
            self._ownApp = False
        self._blockApp = None
        posixbase.PosixReactorBase.__init__(self)

    def _add(self, xer, primary, type):
        """
        Private method for adding a descriptor from the event loop.

        It takes care of adding it if  new or modifying it if already added
        for another state (read -> read/write for example).
        """
        if xer not in primary:
            primary[xer] = TwistedSocketNotifier(None, self, xer, type)

    def addReader(self, reader):
        """Add a FileDescriptor for notification of data available to read."""
        self._add(reader, self._reads, QSocketNotifier.Read)

    def addWriter(self, writer):
        """Add a FileDescriptor for notification of data available to write."""
        self._add(writer, self._writes, QSocketNotifier.Write)

    def _remove(self, xer, primary):
        """
        Private method for removing a descriptor from the event loop.

        It does the inverse job of _add, and also add a check in case of the fd
        has gone away.
        """
        if xer in primary:
            notifier = primary.pop(xer)
            notifier.shutdown()

    def removeReader(self, reader):
        """Remove a Selectable for notification of data available to read."""
        self._remove(reader, self._reads)

    def removeWriter(self, writer):
        """Remove a Selectable for notification of data available to write."""
        self._remove(writer, self._writes)

    def removeAll(self):
        """Remove all selectables, and return a list of them."""
        return self._removeAll(self._reads, self._writes)

    def getReaders(self):
        return self._reads.keys()

    def getWriters(self):
        return self._writes.keys()

    def callLater(self, howlong, *args, **kargs):
        rval = super(QtReactor, self).callLater(howlong, *args, **kargs)
        self.reactorInvocation()
        return rval

    def reactorInvocation(self):
        self._timer.stop()
        self._timer.setInterval(0)
        self._timer.start()

    def _iterate(self, delay=None, fromqt=False):
        """See twisted.internet.interfaces.IReactorCore.iterate."""
        self.runUntilCurrent()
        self.doIteration(delay, fromqt=fromqt)

    iterate = _iterate

    def iterate_qt(self, delay=None):
        self.iterate(delay=delay, fromqt=True)

    def doIteration(self, delay=None, fromqt=False):
        """This method is called by a Qt timer or by network activity on a file descriptor"""
        if not self.running and self._blockApp:
            self._blockApp.quit()
        self._timer.stop()
        if delay is None:
            delay = 0
        delay = max(delay, 1)
        if not fromqt:
            self.qApp.processEvents(QEventLoop.AllEvents, delay * 1000)
        t = self.timeout()
        if t is None:
            timeout = 0.01
        else:
            timeout = min(t, 0.01)
        self._timer.setInterval(timeout * 1000)
        self._timer.start()

    def runReturn(self, installSignalHandlers=True):
        self.startRunning(installSignalHandlers=installSignalHandlers)
        self.reactorInvocation()

    def run(self, installSignalHandlers=True):
        if self._ownApp:
            self._blockApp = self.qApp
        else:
            self._blockApp = QEventLoop()
        self.runReturn()
        self._blockApp.exec_()
        if self.running:
            self.stop()
            self.runUntilCurrent()