Пример #1
0
    def _updater_(self):
        chk = casting()
        if chk.ip == '127.0.0.1' or None:  # We verify the local IP.
            self.updateready.emit('None')
        else:
            try:
                from mkchromecast.version import __version__
                import requests
                response = requests.get(url).text.split(',')

                for e in response:
                    if 'tag_name' in e:
                        version = e.strip('"tag_name":')
                        break

                if version > __version__:
                    print('Version %s is available to download' % version)
                    self.updateready.emit(version)
                else:
                    print('You are up to date.')
                    self.updateready.emit('False')
            except UnboundLocalError:
                self.updateready.emit('error1')
            except requests.exceptions.ConnectionError:
                self.updateready.emit('error1')

        self.upcastfinished.emit()
Пример #2
0
    def _search_cast_(self):
        # This should fix the error socket.gaierror making the system tray to
        # be closed.
        try:
            self.cc = casting()
            self.cc.initialize_cast()
            self.cc.availablecc()
        except socket.gaierror:
            if debug is True:
                print(
                    colors.warning(
                        ':::Threading::: Socket error, CC set to 0'))
            pass
        except TypeError:
            pass
        except OSError:
            self.cc.availablecc = []

        if len(self.cc.availablecc) == 0 and tray is True:
            availablecc = []
            self.intReady.emit(availablecc)
            self.finished.emit()
        else:
            availablecc = self.cc.availablecc
            self.intReady.emit(availablecc)
            self.finished.emit()
Пример #3
0
    def _play_cast_(self):
        if os.path.exists(configf):
            print(colors.warning(':::Threading::: Configuration file exists.'))
            print(colors.warning(':::Threading::: Using defaults set there.'))
            config.read(configf)
            backend = ConfigSectionMap('settings')['backend']
            print(':::Threading backend::: %s.' % backend)
        else:
            backend = mkchromecast.__init__.backend
        global cast
        if backend == 'node':
            stream()
        else:
            try:
                reload(mkchromecast.audio)
            except NameError:
                from imp import reload
                reload(mkchromecast.audio)
            mkchromecast.audio.main()
        if platform == 'Linux':
            # We create the sink only if it is not available
            if check_sink() is False:
                create_sink()

        start = casting()
        start.initialize_cast()
        try:
            start.get_cc()
            start.play_cast()
            cast = start.cast
            # Let's change inputs at the end to avoid muting sound too early.
            # For Linux it does not matter given that user has to select sink
            # in pulse audio.  Therefore the sooner it is available, the
            # better.
            if platform == 'Darwin':
                inputdev()
                outputdev()
            self.pcastready.emit('_play_cast_ success')
        except AttributeError:
            self.pcastready.emit('_play_cast_ failed')
        self.pcastfinished.emit()
Пример #4
0
    def __init__(self):
        self.cc = casting()
        signal.signal(signal.SIGINT, signal.SIG_DFL)
        self.cast = None
        self.stopped = False
        self.played = False
        self.pcastfailed = False
        self.read_config()

        """
        These dictionaries are used to set icons' colors
        """
        self.google = {
                'black': 'google',
                'blue': 'google_b',
                'white': 'google_w'
                }
        self.google_working = {
                'black': 'google_working',
                'blue': 'google_working_b',
                'white': 'google_working_w'
                }
        self.google_nodev = {
                'black': 'google_nodev',
                'blue': 'google_nodev_b',
                'white': 'google_nodev_w'
                }

        """
        This is used when searching for cast devices
        """
        self.obj = mkchromecast.tray_threading.Worker()  # no parent!
        self.thread = QThread()  # no parent!

        self.obj.intReady.connect(self.onIntReady)
        self.obj.moveToThread(self.thread)
        self.obj.finished.connect(self.thread.quit)
        self.thread.started.connect(self.obj._search_cast_)

        """
        This is used when one clicks on cast device
        """
        self.objp = mkchromecast.tray_threading.Player()  # no parent!
        self.threadplay = QThread()  # no parent!

        self.objp.moveToThread(self.threadplay)
        self.objp.pcastready.connect(self.pcastready)
        self.objp.pcastfinished.connect(self.threadplay.quit)
        self.threadplay.started.connect(self.objp._play_cast_)

        """
        This is used when one clicks on the updater
        """
        self.objup = mkchromecast.tray_threading.Updater()  # no parent!
        self.threadupdater = QThread()  # no parent!

        self.objup.moveToThread(self.threadupdater)
        self.objup.updateready.connect(self.updateready)
        self.objup.upcastfinished.connect(self.threadupdater.quit)
        self.threadupdater.started.connect(self.objup._updater_)

        self.app = QtWidgets.QApplication(sys.argv)
        """
        This is to determine the scale factor.
        """
        screen_resolution = self.app.desktop().screenGeometry()
        self.width = screen_resolution.width()
        self.height = screen_resolution.height()
        if self.height > 1280:
            self.scale_factor = 2
        else:
            self.scale_factor = 1

        if debug is True:
            print(':::systray::: Screen resolution: ', self.width, self.height)
        # This avoid the QMessageBox to close parent processes.
        self.app.setQuitOnLastWindowClosed(False)

        if hasattr(QtCore.Qt, 'AA_UseHighDpiPixmaps'):
            self.app.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps)
            if debug is True:
                print(':::systray::: High-DPI screen detected...')

        self.w = QWidget()

        # This is useful when launching from git repo
        if os.path.exists('images/' +
                          self.google[self.colors] + '.icns') is True:
            self.icon = QtGui.QIcon()
            if platform == 'Darwin':
                self.icon.addFile(
                    'images/' +
                    self.google[self.colors] +
                    '.icns'
                    )
            else:
                self.icon.addFile(
                    'images/' +
                    self.google[self.colors] +
                    '.png'
                    )
        else:
            self.icon = QtGui.QIcon()
            if platform == 'Linux':
                self.icon.addFile(
                    '/usr/share/mkchromecast/images/' +
                    self.google[self.colors] +
                    '.png'
                    )
            else:
                self.icon.addFile(self.google[self.colors] +
                                  '.icns')
        super(QtWidgets.QMainWindow, self).__init__()
        self.createUI()
Пример #5
0
def recasting():
    start = casting()
    start.initialize_cast()
    start.get_cc()
    start.play_cast()
    return