Exemple #1
0
class UiMain(QMainWindow):
    """ The main gui interface, invokes all windows and ties everything
     together
    """
    def __init__(self):
        """ automatically called __init__ function """

        super(UiMain, self).__init__()

        # initialize all the variables that are going to be defined in the
        # future
        self.update_dialog = None
        self.update_dialog_lbl = None
        self.app_select_box = None
        self.selector_lbl = None
        self.current_playing_lbl = None
        self.current_playing = None
        self.misc_messages = None
        self.start_btn = None
        self.output_dir_lbl = None
        self.select_output_dir_btn = None
        self.output_cur_dir_lbl = None
        self.active_items_list = None
        self.inactive_items_list = None
        self.switch_active_item_button_off = None
        self.switch_active_item_button_on = None
        self.switch_output_split_btn = None
        self.switch_output_split_lbl = None

        # initialize the system tray
        # self.system_tray = QSystemTrayIcon(self)
        # self.system_tray.setIcon(QIcon(resource_path('icon.png')))
        # self.system_tray.show()
        # self.system_tray.setToolTip('SMG')
        # self.system_tray.activated.connect(self.on_systray_activated)

        # initialize the main window
        self.setObjectName('self')
        self.setWindowTitle('SMG - By Azeirah')
        self.resize(400, 250)

        # Gives the self an icon
        self.setWindowIcon(QIcon(resource_path('icon.png')))

        # create the tabs
        # the tab widget itself
        self.tabbed_windows = QTabWidget(self)
        self.tabbed_windows.resize(400, 300)

        # tab 1, contains the music player selection
        self.music_players = QFrame()

        # tab 2, contains options
        self.options = QFrame()
        self.tabbed_windows.addTab(self.music_players, 'Music players')
        self.tabbed_windows.addTab(self.options, 'Options')

        # initializes the two tabs, with all the code down below
        self.tab_music_players()
        self.tab_options()

        # shows the main window
        self.show()

        # self.update()
        CheckUpdateThread = Thread(target=self.update)
        CheckUpdateThread.setName('CheckUpdateThread')
        CheckUpdateThread.run()

    def closeEvent(self, event):
        """ an automatically called function when the program is about to
        close.
        """
        # Stops all Threads. These would continue to run in the background
        # Even if the window was closed.
        Main.running = False
        # close the ZuneNowPlaying.exe process
        if Constants.SUBP:
            Constants.SUBP.kill()

    def changeEvent(self, event):
        # if event.type() == QEvent.WindowStateChange:
        #     if self.isMinimized():
        #         event.ignore()
        #         self.hide()
        #         self.system_tray.showMessage('Running', 'Running in the
        #           background.')
        #         return

        super(UiMain, self).changeEvent(event)

    def on_systray_activated(self, reason):
        if reason == QSystemTrayIcon.DoubleClick:
            self.show()

    @staticmethod
    def toggle_split(event):
        # 0 = Qt.Unchecked The item is unchecked.
        # 1 = Qt.PartiallyChecked The item is partially checked. Items in
        # hierarchical models may be partially checked if some, but not all,
        # of
        # their children are checked.
        # 2 = Qt.Checked The item is checked.
        if event == 0:
            Constants.OPTIONS['splitText'] = False
        elif event == 2:
            Constants.OPTIONS['splitText'] = True

    def update(self):
        """ Checks a webpage for current version, compares this to built-in
        current versions, and shows update dialog if necessary
        """
        try:
            ver = urlopen('http://league-insanity.tk/Azeirah_content/version')\
                .read()
        except IOError:
            # if for some reason it couldn't retrieve the version, set it to
            # automatically ignore the update: False
            ver = False
        if not float(VERSION) >= float(ver):
            self.popup = QDialog(self)
            self.popup.setModal(True)
            self.popup.setGeometry(200, 100, 500, 100)
            self.popup.show()

            self.popup_text = QLabel(self.popup)
            self.popup_text.setGeometry(5, 5, 500, 30)
            self.popup_text.setOpenExternalLinks(True)
            self.popup_text.show()
            self.popup_text.setText(
                """There is an update available. Run update.exe or <a href='https://sourceforge.net/projects/obsmusicstreamd'>download the update manually</a>"""
            )
            # reply = QMessageBox.question(Constants.UI, 'Message',
            #                              "Do you want to update?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
            # if reply == QMessageBox.Yes:
            #     import atexit
            #     import subprocess

            #     def runUpdater():
            #         import time
            #         time.sleep(3)
            #         subprocess.Popen(resource_path('update.exe'))
            #     atexit.register(runUpdater)
            #     sys.exit()

            #     Constants.update_dialog = QWidget()
            #     Constants.update_dialog.resize(350, 100)
            #     Constants.update_dialog.setWindowIcon(QIcon(resource_path\
            #         ('icon.png')))
            #     Constants.update_dialog.setWindowTitle('Updater')
            #     Constants.update_dialog_lbl = QLabel(Constants.update_dialog)
            #     Constants.update_dialog_lbl.setGeometry(10, 40, 340, 12)
            #     Constants.update_dialog.show()

            #     updateThread = Thread(target = update.update)
            #     updateThread.setName('updateThread')
            #     updateThread.start()

    def tab_music_players(self):
        """ Everything inside the Music players tab gets created here."""
        # self.music_players
        # Creates the box with all the music players inside of it
        self.app_select_box = QComboBox(self.music_players)
        self.app_select_box.setGeometry(135, 10, 150, 25)
        # Whenever you change the application, it runs the selectnewapp func
        self.app_select_box.activated[str].connect(self.select_new_app)

        # Creates the label for the selection combobox
        self.selector_lbl = QLabel(self.music_players)
        self.selector_lbl.setGeometry(10, 10, 150, 25)
        self.selector_lbl.setText('Select your music player: ')

        # Creates the label for the current playing song (and the current
        # playing song label)
        self.current_playing_lbl = QLabel(self.music_players)
        self.current_playing_lbl.setGeometry(10, 45, 150, 25)
        self.current_playing_lbl.setText('Current playing song: ')

        self.current_playing = QLabel(self.music_players)
        self.current_playing.setGeometry(117, 45, 250, 25)
        self.current_playing.setText(Misc.noSongPlaying)

        # Creates a label which displays any additional messages
        self.misc_messages = QLabel(self.music_players)
        self.misc_messages.setGeometry(10, 80, 390, 24)
        self.misc_messages.setText(Misc.misc_message())
        self.misc_messages.setOpenExternalLinks(True)

        # adds all the music players into the combobox
        self.app_select_box.addItem(None)
        for item in Constants.ACTIVEITEMS:
            if item == '__name__' or item == 'active':
                continue
            self.app_select_box.addItem(item)

        # creates the start button
        self.start_btn = QPushButton(self.music_players)
        self.start_btn.setGeometry(75, 120, 250, 35)
        self.start_btn.setText('Start')

        # links the start button to the self.start function
        QObject.connect(
            self.start_btn, SIGNAL("clicked()"),
            lambda: Thread(target=self.start, name='startbutton').start())

    def tab_options(self):
        """ Everything inside the Options tab gets created here. """
        # self.options

        # This section is for selecting output dir
        # Creates the output dir label
        self.output_dir_lbl = QLabel(self.options)
        self.output_dir_lbl.setGeometry(10, 10, 125, 15)
        self.output_dir_lbl.setText('Change Output Directory: ')

        # Creates the output dir button
        self.select_output_dir_btn = QPushButton(self.options)
        self.select_output_dir_btn.setGeometry(137, 8, 30, 20)
        self.select_output_dir_btn.setText('...')

        # Creates the output dir currentdir Lineedit
        self.output_cur_dir_lbl = QLineEdit(self.options)
        self.output_cur_dir_lbl.setGeometry(170, 6, 210, 25)
        self.output_cur_dir_lbl.setReadOnly(True)
        self.output_cur_dir_lbl.setText(
            Constants.CONFIG.get('directories', 'current_song'))

        # when the '...' button is clicked, show a dialog (fire func
        # disp_dialog)
        QObject.connect(self.select_output_dir_btn, SIGNAL("clicked()"),
                        self.disp_dialog)

        # This section is for selecting what players you use
        # The box with all the active players
        self.active_items_list = QListWidget(self.options)
        self.active_items_list.setGeometry(10, 40, 150, 100)

        # The box with all the inactive players
        self.inactive_items_list = QListWidget(self.options)
        self.inactive_items_list.setGeometry(230, 40, 150, 100)
        # Populate the two boxes with active and inactive items
        for item in Constants.ACTIVEITEMS:
            if item == '__name__' or item == 'active':
                continue
            self.active_items_list.addItem(item)
        for item in Constants.INACTIVEITEMS:
            if item == '__name__' or item == 'active':
                continue
            self.inactive_items_list.addItem(item)

        # The buttons responsible for switching
        # off button
        self.switch_active_item_button_off = QPushButton(self.options)
        self.switch_active_item_button_off.setText('->'.decode('utf-8'))
        # Makes the -> readable and clear
        self.switch_active_item_button_off.setFont(QFont('SansSerif', 17))
        self.switch_active_item_button_off.setGeometry(175, 55, 40, 30)
        # on button
        self.switch_active_item_button_on = QPushButton(self.options)
        self.switch_active_item_button_on.setText('<-'.decode('utf-8'))
        # makes <- readable and clear
        self.switch_active_item_button_on.setFont(QFont('SansSerif', 17))
        self.switch_active_item_button_on.setGeometry(175, 90, 40, 30)

        QObject.connect(self.switch_active_item_button_on, SIGNAL("clicked()"),
                        self.switch_item_on)
        QObject.connect(self.switch_active_item_button_off,
                        SIGNAL("clicked()"), self.switch_item_off)

        # A button to toggle the split output in half option. It's a temporary
        # fix for the Foobar double output problem.
        self.switch_output_split_btn = QCheckBox(self.options)
        self.switch_output_split_btn.setCheckState(Qt.CheckState.Unchecked)
        self.switch_output_split_btn.setGeometry(10, 140, 40, 30)
        self.switch_output_split_btn.stateChanged.connect(self.toggle_split)

        # The label for the split toggle
        self.switch_output_split_lbl = QLabel(self.options)
        self.switch_output_split_lbl.setText(
            "Split the output text in half (don't use this if you don't need it)"
        )
        self.switch_output_split_lbl.setGeometry(30, 140, 300, 30)

    def switch_item_on(self):
        """ Switches items (musicapps) on """
        try:
            # If an item from the active box is selected
            # Remove it and place it inside the inactive box
            item_taken = self.inactive_items_list.takeItem(
                self.inactive_items_list.currentRow())
            self.active_items_list.addItem(item_taken)
            active_items = {}
            inactive_items = {}
            for i in range(self.active_items_list.count()):
                active_items[self.active_items_list.item(i).text()] =\
                    ITEMS[self.active_items_list.item(i).text()
                          .encode('utf-8')]
            for i in range(self.inactive_items_list.count()):
                inactive_items[self.inactive_items_list.item(i).text()] =\
                    ITEMS[self.inactive_items_list.item(i).text()
                          .encode('utf-8')]
            Constants.ACTIVE_ITEMS = active_items
            Constants.INACTIVE_ITEMS = inactive_items
            # clear the selection combobox
            self.app_select_box.clear()
            # Repopulate the combobox
            self.app_select_box.addItem(None)
            for item in active_items:
                self.app_select_box.addItem(item)
            Constants.CONFIG.set('active', item_taken.text(),
                                 ITEMS[item_taken.text()])
            Constants.CONFIG.remove_option('inactive', item_taken.text())
            # Updates the config file to be up to date with activeItems
            Constants.CONFIG.update()
        except:
            raise

    def switch_item_off(self):
        """ Switches items (musicapps) off """
        try:
            # If an item from the inactive box is selected.
            # Remove it and place it inside the active box
            item_taken = self.active_items_list.takeItem(
                self.active_items_list.currentRow())
            self.inactive_items_list.addItem(item_taken)
            # update activeItems
            active_items = {}
            inactive_items = {}
            for i in range(self.active_items_list.count()):
                active_items[self.active_items_list.item(i).text()] =\
                    ITEMS[self.active_items_list.item(i).text()
                          .encode('utf-8')]
            for i in range(self.inactive_items_list.count()):
                inactive_items[self.inactive_items_list.item(i).text()] =\
                    ITEMS[self.inactive_items_list.item(i).text()
                          .encode('utf-8')]
            Constants.ACTIVE_ITEMS = active_items
            Constants.INACTIVE_ITEMS = inactive_items
            # clear the selection combobox
            self.app_select_box.clear()
            # Repopulate the combobox
            self.app_select_box.addItem(None)
            for item in active_items:
                self.app_select_box.addItem(item)
            # Updates the active items Constants property
            Constants.CONFIG.set('inactive', item_taken.text(),
                                 ITEMS[item_taken.text()])
            Constants.CONFIG.remove_option('active', item_taken.text())
            # Updates the config file to be up to date with activeItems
            Constants.CONFIG.update()
        except:
            raise

    def disp_dialog(self):
        """  displays the dialog which select a directory for output. """
        fname = QFileDialog.getExistingDirectory()
        Constants.CONFIG.set('directories', 'current_song', fname)
        self.output_cur_dir_lbl.setText(
            Constants.CONFIG.get('directories', 'current_song'))

    def select_new_app(self, text):
        """ Sets the new application to check for """
        try:
            Main.selectedProgram = ITEMS[text]
        except KeyError:
            # catches the empty option, it's obviously not in the dict
            pass
        # custom message for zune
        if Main.selectedProgram == 'zune':
            self.misc_messages.setText(Misc.ZuneNotification)
        # custom message for webplayers which require the groovemarklet
        elif text.find('*'):
            self.misc_messages.setText(Misc.GetGroovemarklet)

    def start(self):
        """ When the start button is pressed, start the main program loop """
        if Main.selectedProgram:
            if not Main.running:
                self.start_btn.setText('Stop')
                Main.running = True
                try:
                    pythoncom.CoInitializeEx(pythoncom.COINIT_MULTITHREADED)
                except pythoncom.com_error:
                    # already initialized.
                    pass
                thread = Thread(target=Main.enumWindows, name='enumWindows')
                thread.run()
            else:
                self.start_btn.setText('Start')
                Main.running = False
                self.set_playing(Misc.noSongPlaying)
                Wr.write('')

    def set_playing(self, title=''):
        """ Sets the text of the label of what song is playing """
        # print 'setting title: ', title
        self.current_playing.setText(title)
Exemple #2
0
class UiMain(QMainWindow):

    """ The main gui interface, invokes all windows and ties everything
     together
    """

    def __init__(self):
        """ automatically called __init__ function """

        super(UiMain, self).__init__()

        # initialize all the variables that are going to be defined in the
        # future
        self.update_dialog = None
        self.update_dialog_lbl = None
        self.app_select_box = None
        self.selector_lbl = None
        self.current_playing_lbl = None
        self.current_playing = None
        self.misc_messages = None
        self.start_btn = None
        self.output_dir_lbl = None
        self.select_output_dir_btn = None
        self.output_cur_dir_lbl = None
        self.active_items_list = None
        self.inactive_items_list = None
        self.switch_active_item_button_off = None
        self.switch_active_item_button_on = None
        self.switch_output_split_btn = None
        self.switch_output_split_lbl = None

        # initialize the system tray
        # self.system_tray = QSystemTrayIcon(self)
        # self.system_tray.setIcon(QIcon(resource_path('icon.png')))
        # self.system_tray.show()
        # self.system_tray.setToolTip('SMG')
        # self.system_tray.activated.connect(self.on_systray_activated)

        # initialize the main window
        self.setObjectName('self')
        self.setWindowTitle('SMG - By Azeirah')
        self.resize(400, 250)

        # Gives the self an icon
        self.setWindowIcon(QIcon(resource_path('icon.png')))

        # create the tabs
        # the tab widget itself
        self.tabbed_windows = QTabWidget(self)
        self.tabbed_windows.resize(400, 300)

        # tab 1, contains the music player selection
        self.music_players = QFrame()

        # tab 2, contains options
        self.options = QFrame()
        self.tabbed_windows.addTab(self.music_players, 'Music players')
        self.tabbed_windows.addTab(self.options, 'Options')

        # initializes the two tabs, with all the code down below
        self.tab_music_players()
        self.tab_options()

        # shows the main window
        self.show()
        
    def closeEvent(self, event):
        """ an automatically called function when the program is about to
        close.
        """
        # Stops all Threads. These would continue to run in the background
        # Even if the window was closed.
        Main.running = False
        # close the ZuneNowPlaying.exe process
        if Constants.SUBP:
            Constants.SUBP.kill()

    def changeEvent(self, event):
        # if event.type() == QEvent.WindowStateChange:
        #     if self.isMinimized():
        #         event.ignore()
        #         self.hide()
        #         self.system_tray.showMessage('Running', 'Running in the
        #           background.')
        #         return

        super(UiMain, self).changeEvent(event)

    def on_systray_activated(self, reason):
        if reason == QSystemTrayIcon.DoubleClick:
            self.show()

    @staticmethod
    def toggle_split(event):
        # 0 = Qt.Unchecked The item is unchecked.
        # 1 = Qt.PartiallyChecked The item is partially checked. Items in
        # hierarchical models may be partially checked if some, but not all,
        # of
        # their children are checked.
        # 2 = Qt.Checked The item is checked.
        if event == 0:
            Constants.OPTIONS['splitText'] = False
        elif event == 2:
            Constants.OPTIONS['splitText'] = True

    def update(self):
        """ Checks a webpage for current version, compares this to built-in
        current versions, and shows update dialog if necessary
        """
        try:
            ver = urlopen('http://league-insanity.tk/Azeirah_content/version')\
                .read()
        except IOError:
            # if for some reason it couldn't retrieve the version, set it to
            # automatically ignore the update: False
            ver = False
        if not float(VERSION) >= float(ver):
            self.popup = QDialog(self)
            self.popup.setModal(True)
            self.popup.setGeometry(200, 100, 500, 100)
            self.popup.show()

            self.popup_text = QLabel(self.popup)
            self.popup_text.setGeometry(5, 5, 500, 30)
            self.popup_text.setOpenExternalLinks(True)
            self.popup_text.show()
            self.popup_text.setText(
                """There is an update available. Run update.exe or <a href='https://sourceforge.net/projects/obsmusicstreamd'>download the update manually</a>""")
            # reply = QMessageBox.question(Constants.UI, 'Message',
            #                              "Do you want to update?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
            # if reply == QMessageBox.Yes:
            #     import atexit
            #     import subprocess

            #     def runUpdater():
            #         import time
            #         time.sleep(3)
            #         subprocess.Popen(resource_path('update.exe'))
            #     atexit.register(runUpdater)
            #     sys.exit()

            #     Constants.update_dialog = QWidget()
            #     Constants.update_dialog.resize(350, 100)
            #     Constants.update_dialog.setWindowIcon(QIcon(resource_path\
            #         ('icon.png')))
            #     Constants.update_dialog.setWindowTitle('Updater')
            #     Constants.update_dialog_lbl = QLabel(Constants.update_dialog)
            #     Constants.update_dialog_lbl.setGeometry(10, 40, 340, 12)
            #     Constants.update_dialog.show()

            #     updateThread = Thread(target = update.update)
            #     updateThread.setName('updateThread')
            #     updateThread.start()

    def tab_music_players(self):
        """ Everything inside the Music players tab gets created here."""
        # self.music_players
        # Creates the box with all the music players inside of it
        self.app_select_box = QComboBox(self.music_players)
        self.app_select_box.setGeometry(135, 10, 150, 25)
        # Whenever you change the application, it runs the selectnewapp func
        self.app_select_box.activated[str].connect(self.select_new_app)

        # Creates the label for the selection combobox
        self.selector_lbl = QLabel(self.music_players)
        self.selector_lbl.setGeometry(10, 10, 150, 25)
        self.selector_lbl.setText('Select your music player: ')

        # Creates the label for the current playing song (and the current
        # playing song label)
        self.current_playing_lbl = QLabel(self.music_players)
        self.current_playing_lbl.setGeometry(10, 45, 150, 25)
        self.current_playing_lbl.setText('Current playing song: ')

        self.current_playing = QLabel(self.music_players)
        self.current_playing.setGeometry(117, 45, 250, 25)
        self.current_playing.setText(Misc.noSongPlaying)

        # Creates a label which displays any additional messages
        self.misc_messages = QLabel(self.music_players)
        self.misc_messages.setGeometry(10, 80, 390, 24)
        self.misc_messages.setText(Misc.misc_message())
        self.misc_messages.setOpenExternalLinks(True)

        # adds all the music players into the combobox
        self.app_select_box.addItem(None)
        for item in Constants.ACTIVEITEMS:
            if item == '__name__' or item == 'active':
                continue
            self.app_select_box.addItem(item)

        # creates the start button
        self.start_btn = QPushButton(self.music_players)
        self.start_btn.setGeometry(75, 120, 250, 35)
        self.start_btn.setText('Start')

        # links the start button to the self.start function
        QObject.connect(self.start_btn, SIGNAL("clicked()"),
                        lambda: Thread(target=self.start, name='startbutton').start())

    def tab_options(self):
        """ Everything inside the Options tab gets created here. """
        # self.options

        # This section is for selecting output dir
        # Creates the output dir label
        self.output_dir_lbl = QLabel(self.options)
        self.output_dir_lbl.setGeometry(10, 10, 125, 15)
        self.output_dir_lbl.setText('Change Output Directory: ')

        # Creates the output dir button
        self.select_output_dir_btn = QPushButton(self.options)
        self.select_output_dir_btn.setGeometry(137, 8, 30, 20)
        self.select_output_dir_btn.setText('...')

        # Creates the output dir currentdir Lineedit
        self.output_cur_dir_lbl = QLineEdit(self.options)
        self.output_cur_dir_lbl.setGeometry(170, 6, 210, 25)
        self.output_cur_dir_lbl.setReadOnly(True)
        self.output_cur_dir_lbl.setText(Constants.CONFIG.
                                        get('directories', 'current_song'))

        # when the '...' button is clicked, show a dialog (fire func
        # disp_dialog)
        QObject.connect(self.select_output_dir_btn, SIGNAL("clicked()"),
                        self.disp_dialog)

        # This section is for selecting what players you use
        # The box with all the active players
        self.active_items_list = QListWidget(self.options)
        self.active_items_list.setGeometry(10, 40, 150, 100)

        # The box with all the inactive players
        self.inactive_items_list = QListWidget(self.options)
        self.inactive_items_list.setGeometry(230, 40, 150, 100)
        # Populate the two boxes with active and inactive items
        for item in Constants.ACTIVEITEMS:
            if item == '__name__' or item == 'active':
                continue
            self.active_items_list.addItem(item)
        for item in Constants.INACTIVEITEMS:
            if item == '__name__' or item == 'active':
                continue
            self.inactive_items_list.addItem(item)

        # The buttons responsible for switching
        # off button
        self.switch_active_item_button_off = QPushButton(self.options)
        self.switch_active_item_button_off.setText('->'.decode('utf-8'))
        # Makes the -> readable and clear
        self.switch_active_item_button_off.setFont(QFont('SansSerif', 17))
        self.switch_active_item_button_off.setGeometry(175, 55, 40, 30)
        # on button
        self.switch_active_item_button_on = QPushButton(self.options)
        self.switch_active_item_button_on.setText('<-'.decode('utf-8'))
        # makes <- readable and clear
        self.switch_active_item_button_on.setFont(QFont('SansSerif', 17))
        self.switch_active_item_button_on.setGeometry(175, 90, 40, 30)

        QObject.connect(self.switch_active_item_button_on, SIGNAL
                       ("clicked()"), self.switch_item_on)
        QObject.connect(self.switch_active_item_button_off, SIGNAL
                       ("clicked()"), self.switch_item_off)

        # A button to toggle the split output in half option. It's a temporary
        # fix for the Foobar double output problem.
        self.switch_output_split_btn = QCheckBox(self.options)
        self.switch_output_split_btn.setCheckState(Qt.CheckState.Unchecked)
        self.switch_output_split_btn.setGeometry(10, 140, 40, 30)
        self.switch_output_split_btn.stateChanged.connect(self.toggle_split)

        # The label for the split toggle
        self.switch_output_split_lbl = QLabel(self.options)
        self.switch_output_split_lbl.setText(
            "Split the output text in half (don't use this if you don't need it)")
        self.switch_output_split_lbl.setGeometry(30, 140, 300, 30)

    def switch_item_on(self):
        """ Switches items (musicapps) on """
        try:
            # If an item from the active box is selected
            # Remove it and place it inside the inactive box
            item_taken = self.inactive_items_list.takeItem(
                self.inactive_items_list.currentRow())
            self.active_items_list.addItem(item_taken)
            active_items = {}
            inactive_items = {}
            for i in range(self.active_items_list.count()):
                active_items[self.active_items_list.item(i).text()] =\
                    ITEMS[self.active_items_list.item(i).text()
                          .encode('utf-8')]
            for i in range(self.inactive_items_list.count()):
                inactive_items[self.inactive_items_list.item(i).text()] =\
                    ITEMS[self.inactive_items_list.item(i).text()
                          .encode('utf-8')]
            Constants.ACTIVE_ITEMS = active_items
            Constants.INACTIVE_ITEMS = inactive_items
            # clear the selection combobox
            self.app_select_box.clear()
            # Repopulate the combobox
            self.app_select_box.addItem(None)
            for item in active_items:
                self.app_select_box.addItem(item)
            Constants.CONFIG.set('active', item_taken.text(),
                                 ITEMS[item_taken.text()])
            Constants.CONFIG.remove_option('inactive', item_taken.text())
            # Updates the config file to be up to date with activeItems
            Constants.CONFIG.update()
        except:
            raise

    def switch_item_off(self):
        """ Switches items (musicapps) off """
        try:
            # If an item from the inactive box is selected.
            # Remove it and place it inside the active box
            item_taken = self.active_items_list.takeItem(
                self.active_items_list.currentRow())
            self.inactive_items_list.addItem(item_taken)
            # update activeItems
            active_items = {}
            inactive_items = {}
            for i in range(self.active_items_list.count()):
                active_items[self.active_items_list.item(i).text()] =\
                    ITEMS[self.active_items_list.item(i).text()
                          .encode('utf-8')]
            for i in range(self.inactive_items_list.count()):
                inactive_items[self.inactive_items_list.item(i).text()] =\
                    ITEMS[self.inactive_items_list.item(i).text()
                          .encode('utf-8')]
            Constants.ACTIVE_ITEMS = active_items
            Constants.INACTIVE_ITEMS = inactive_items
            # clear the selection combobox
            self.app_select_box.clear()
            # Repopulate the combobox
            self.app_select_box.addItem(None)
            for item in active_items:
                self.app_select_box.addItem(item)
            # Updates the active items Constants property
            Constants.CONFIG.set('inactive', item_taken.text(),
                                 ITEMS[item_taken.text()])
            Constants.CONFIG.remove_option('active', item_taken.text())
            # Updates the config file to be up to date with activeItems
            Constants.CONFIG.update()
        except:
            raise

    def disp_dialog(self):
        """  displays the dialog which select a directory for output. """
        fname = QFileDialog.getExistingDirectory()
        Constants.CONFIG.set('directories', 'current_song', fname)
        self.output_cur_dir_lbl.setText(Constants.CONFIG.
                                        get('directories', 'current_song'))

    def select_new_app(self, text):
        """ Sets the new application to check for """
        try:
            Main.selectedProgram = ITEMS[text]
        except KeyError:
            # catches the empty option, it's obviously not in the dict
            pass
        # custom message for zune
        if Main.selectedProgram == 'zune':
            self.misc_messages.setText(Misc.ZuneNotification)
        # custom message for webplayers which require the groovemarklet
        elif text.find('*'):
            self.misc_messages.setText(Misc.GetGroovemarklet)

    def start(self):
        """ When the start button is pressed, start the main program loop """
        if Main.selectedProgram:
            if not Main.running:
                self.start_btn.setText('Stop')
                Main.running = True
                try:
                    pythoncom.CoInitializeEx(pythoncom.COINIT_MULTITHREADED)
                except pythoncom.com_error:
                    # already initialized.
                    pass
                thread = Thread(
                    target=Main.enumWindows, name='enumWindows')
                thread.run()
            else:
                self.start_btn.setText('Start')
                Main.running = False
                self.set_playing(Misc.noSongPlaying)
                Wr.write('')

    def set_playing(self, title=''):
        """ Sets the text of the label of what song is playing """
        # print 'setting title: ', title
        self.current_playing.setText(title)
Exemple #3
0
class Form(QDialog):
    def __init__(self, term, state, parent=None):
        super().__init__(parent)
        Lib.prepareModalDialog(self)
        self.addingText = term
        self.state = state
        ListWidgetItem.model = state.model
        ListWidgetItem.refresh = self.refresh
        self.buttons = []
        self.createWidgets()
        self.layoutWidgets()
        self.createConnections()
        self.setWindowTitle("Edit Groups — {}".format(
            QApplication.applicationName()))
        self.refresh()
        settings = QSettings()
        self.updateToolTips(
            bool(
                int(
                    settings.value(Gopt.Key.ShowDialogToolTips,
                                   Gopt.Default.ShowDialogToolTips))))

    def createWidgets(self):
        self.listWidget = QListWidget()
        self.buttonLayout = QVBoxLayout()
        self.linkButton = None
        for icon, text, slot, tip in ((":/add.svg", "&Add", self.add, """\
<p><b>Add</b> (Alt+A)</p><p>Add a new Normal Group.</p>"""), (":/edit.svg",
                                                              "&Rename",
                                                              self.rename, """\
<p><b>Rename</b> (Alt+R)</p><p>Rename the current Group.</p>"""),
                                      (":/grouplink.svg", "&Link", self.link,
                                       """\
<p><b>Link</b> (Alt+L)</p><p>Change the current group into a Linked
Group.</p>
<p>This means that the pages of every entry in this group will be merged
and synchronized, and any future changes to the pages of any entries in
this group will be propagated to all the other entries in this
group to keep them all synchronized.</p>"""), (":/groups.svg", "&Unlink",
                                               self.unlink, """\
<p><b>Unlink</b> (Alt+U)</p><p>Change the current group into a Normal
(unlinked) Group. If the linked group
has entries, the <b>Delete Linked Group</b> dialog will pop up.</p>"""),
                                      (":/groupset.svg", "&View",
                                       self.viewGroup, """\
<p><b>View</b> (Alt+V)</p><p>View the current group in the Filtered
View.</p>"""), (":/delete.svg", "&Delete", self.delete, """\
<p><b>Delete</b> (Alt+D)</p><p>Remove entries from the current normal group
and then delete the group. If the current group is a linked group that
has entries, the <b>Delete Linked Group</b> dialog will pop up.</p>"""),
                                      (":/help.svg", "Help", self.help, """\
Help on the Groups dialog"""), (":/dialog-close.svg", "&Close", self.accept,
                                """\
<p><b>Close</b></p><p>Close the dialog.</p>""")):
            button = QPushButton(QIcon(icon), text)
            button.setFocusPolicy(Qt.NoFocus)
            if text in {"&Close", "Help"}:
                self.buttonLayout.addStretch()
            else:
                self.buttons.append(button)
            self.buttonLayout.addWidget(button)
            button.clicked.connect(slot)
            self.tooltips.append((button, tip))
            if text == "&Link":
                self.linkButton = button
                button.setEnabled(False)
            elif text == "&Unlink":
                self.unlinkButton = button
                button.setEnabled(False)
        self.tooltips.append((self.listWidget, "List of Groups"))

    def layoutWidgets(self):
        layout = QHBoxLayout()
        layout.addWidget(self.listWidget)
        layout.addLayout(self.buttonLayout)
        self.setLayout(layout)

    def createConnections(self):
        self.listWidget.currentRowChanged.connect(self.updateUi)

    def updateUi(self):
        for button in self.buttons:
            button.setEnabled(True)
        item = self.listWidget.currentItem()
        if item is not None:
            gid = item.data(Qt.UserRole)
            self.linkButton.setEnabled(self.state.model.safeToLinkGroup(gid))
            self.unlinkButton.setEnabled(self.state.model.isLinkedGroup(gid))

    def refresh(self, *, text=None, index=None):
        self.listWidget.clear()
        for row, (gid, name,
                  linked) in enumerate(self.state.model.allGroups()):
            item = ListWidgetItem(name)
            item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEditable
                          | Qt.ItemIsEnabled)
            item.setBackground(self.palette().base() if row %
                               2 else self.palette().alternateBase())
            item.setData(Qt.UserRole, gid)
            item.setIcon(
                QIcon(":/grouplink.svg" if linked else ":/groups.svg"))
            self.listWidget.addItem(item)
        if self.listWidget.count():
            self.listWidget.setCurrentRow(0)
            if index is not None:
                self.listWidget.setCurrentRow(index)
            elif text is not None:
                for i in range(self.listWidget.count()):
                    if self.listWidget.item(i).text() == text:
                        self.listWidget.setCurrentRow(i)
                        break
        self.updateUi()

    def add(self):
        item = ListWidgetItem(self.addingText, adding=True)
        item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEditable
                      | Qt.ItemIsEnabled)
        self.listWidget.insertItem(0, item)
        self.listWidget.setCurrentRow(0)
        for button in self.buttons:
            button.setEnabled(False)
        self.listWidget.editItem(item)

    def rename(self):
        item = self.listWidget.currentItem()
        if item is not None:
            for button in self.buttons:
                button.setEnabled(False)
            self.listWidget.editItem(item)

    def link(self):
        item = self.listWidget.currentItem()
        if item is not None:
            gid = item.data(Qt.UserRole)
            if not self.state.model.safeToLinkGroup(gid):
                return  # Should never happen
            self.state.model.linkGroup(gid)
            self.refresh(index=self.listWidget.currentRow())

    def unlink(self):
        item = self.listWidget.currentItem()
        if item is not None:
            gid = item.data(Qt.UserRole)
            if not self.state.model.groupMemberCount(gid):
                self.state.model.unlinkGroup(gid)
            else:
                with Lib.Qt.DisableUI(self, forModalDialog=True):
                    form = Forms.DeleteOrUnlink.Form("Unlink", gid, self.state,
                                                     self)
                    form.exec_()
            self.refresh(index=self.listWidget.currentRow())

    def viewGroup(self):
        item = self.listWidget.currentItem()
        if item:
            self.state.viewFilteredPanel.setGroup(item)

    def delete(self):  # No need to restore focus widget
        row = self.listWidget.currentRow()
        item = self.listWidget.item(row)
        if item is None:
            return
        gid = item.data(Qt.UserRole)
        for button in self.buttons:
            button.setEnabled(False)
        deleteItem = False
        if (not self.state.model.isLinkedGroup(gid)
                or not self.state.model.groupMemberCount(gid)):
            with Lib.Qt.DisableUI(self, forModalDialog=True):
                reply = QMessageBox.question(
                    self,
                    "Delete Group — {}".format(QApplication.applicationName()),
                    "<p>Delete Group “{}”?</p>".format(item.text()),
                    QMessageBox.Yes | QMessageBox.No)
            if reply == QMessageBox.Yes:
                self.state.model.deleteGroup(gid)
                deleteItem = True
        else:
            with Lib.Qt.DisableUI(self, forModalDialog=True):
                form = Forms.DeleteOrUnlink.Form("Delete", gid, self.state,
                                                 self)
                deleteItem = form.exec_()
        if deleteItem:
            item = self.listWidget.takeItem(row)
            del item
        self.updateUi()

    def help(self):
        self.state.help("xix_ref_dlg_groups.html")
Exemple #4
0
class Form(QDialog):
    def __init__(self, state, info, parent=None):
        super().__init__(parent)
        Lib.prepareModalDialog(self)
        self.state = state
        ListWidgetItem.info = info
        ListWidgetItem.refresh = self.refresh
        self.info = info
        self.helpPage = info.help
        self.createWidgets()
        self.layoutWidgets()
        self.setWindowTitle("{} — {}".format(self.info.name,
                                             QApplication.applicationName()))
        self.refresh()
        settings = QSettings()
        self.updateToolTips(
            bool(
                int(
                    settings.value(Gopt.Key.ShowDialogToolTips,
                                   Gopt.Default.ShowDialogToolTips))))

    def createWidgets(self):
        self.listWidget = QListWidget()
        self.buttonLayout = QVBoxLayout()
        for icon, text, slot, tip in ((":/add.svg", "&Add", self.add, """\
<p><b>Add</b></p><p>Add an item to the {}
list.</p>""".format(self.info.name)), (":/edit.svg", "&Edit", self.edit, """\
<p><b>Edit</b></p><p>Edit the {} list's current
item.</p>""".format(self.info.name)), (":/delete.svg", "&Remove...",
                                       self.remove, """\
<p><b>Remove</b></p><p>Remove the {} list's current
item.</p>""".format(self.info.name)), (":/help.svg", "Help", self.help, """\
Help on the {} dialog""".format(self.info.name)), (":/dialog-close.svg",
                                                   "&Close", self.accept, """\
<p><b>Close</b></p><p>Close the dialog.</p>""")):
            button = QPushButton(QIcon(icon), text)
            button.setFocusPolicy(Qt.NoFocus)
            if text in {"&Close", "Help"}:
                self.buttonLayout.addStretch()
            self.buttonLayout.addWidget(button)
            button.clicked.connect(slot)
            self.tooltips.append((button, tip))
        self.tooltips.append((self.listWidget, self.info.desc))

    def layoutWidgets(self):
        layout = QHBoxLayout()
        layout.addWidget(self.listWidget)
        layout.addLayout(self.buttonLayout)
        self.setLayout(layout)

    def refresh(self, *, text=None):
        self.listWidget.clear()
        cursor = self.info.db.cursor()
        for row, record in enumerate(cursor.execute(self.info.SELECT)):
            item = ListWidgetItem(record[0])
            item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEditable
                          | Qt.ItemIsEnabled)
            item.setBackground(self.palette().base() if row %
                               2 else self.palette().alternateBase())
            self.listWidget.addItem(item)
        if self.listWidget.count():
            self.listWidget.setCurrentRow(0)
            if text is not None:
                for i in range(self.listWidget.count()):
                    if self.listWidget.item(i).text() == text:
                        self.listWidget.setCurrentRow(i)
                        break

    def add(self):
        item = ListWidgetItem(ADDING)
        item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEditable
                      | Qt.ItemIsEnabled)
        self.listWidget.insertItem(0, item)
        self.listWidget.setCurrentRow(0)
        self.listWidget.editItem(item)

    def edit(self):
        item = self.listWidget.currentItem()
        if item is not None:
            self.listWidget.editItem(item)

    def remove(self):  # No need to restore focus widget
        row = self.listWidget.currentRow()
        item = self.listWidget.item(row)
        if item is None:
            return
        with Lib.Qt.DisableUI(self, forModalDialog=True):
            reply = QMessageBox.question(
                self, "Remove {} — {}".format(self.info.name,
                                              QApplication.applicationName()),
                "Remove {} “{}”?".format(self.info.name, item.text()),
                QMessageBox.Yes | QMessageBox.No)
        if reply == QMessageBox.Yes:
            cursor = self.info.db.cursor()
            cursor.execute(self.info.DELETE, (item.text(), ))
            item = self.listWidget.takeItem(row)
            del item

    def help(self):
        self.state.help(self.helpPage)
Exemple #5
0
class CC_window(QWidget):
    def __init__(self):
        super(CC_window, self).__init__()
        self.version = '0.2'
        glo = QVBoxLayout(self)
        self.Runningo = None
        self.Looping = None
        self.P = CC_thread()
        if name == 'nt':
            ficon = r_path('images\\favicon.png')
            licon = r_path('images\\logo.png')
        else:
            ficon = r_path('images/favicon.png')
            licon = r_path('images/logo.png')
        self.tf = QFont("", 13, QFont.Bold)
        self.sf = QFont("", 10, QFont.Bold)
        self.SelfIinit(QIcon(ficon))
        self.center()
        self.a_btn(licon, glo)
        self.ss_btns(glo)
        self.i_list(glo)
        self.cl_btn(glo)
        self.l_btns(glo)
        self.f_btns(glo)
        self.ds_bar(glo)
        self.setLayout(glo)
        self.activateWindow()
        self.show()

    def SelfIinit(self, icon):
        self.setWindowTitle('chrome-cut ' + self.version)
        self.setGeometry(300, 300, 200, 150)
        self.setMinimumWidth(600)
        self.setMaximumWidth(600)
        self.setMinimumHeight(500)
        self.setMaximumHeight(500)
        # Setting Icon
        self.setWindowIcon(icon)
        QToolTip.setFont(self.sf)

    def msgApp(self, title, msg):
        uinfo = QMessageBox.question(self, title, msg,
                                     QMessageBox.Yes | QMessageBox.No)
        if uinfo == QMessageBox.Yes:
            return 'y'
        if uinfo == QMessageBox.No:
            return 'n'

    def closeEvent(self, event=None):
        if self.P.isRunning():
            response = self.msgApp("Making sure",
                                   "Sure, you want to exit while looping ?")
            if response == 'y':
                if event is not None:
                    event.accept()
                self.P.stop()
                exit(0)
            else:
                if event is not None:
                    event.ignore()
        else:
            if event is not None:
                event.accept()
            exit(0)

    def center(self):
        qrect = self.frameGeometry()
        cp = QDesktopWidget().availableGeometry().center()
        qrect.moveCenter(cp)
        self.move(qrect.topLeft())

    def a_btn(self, icon, glo):
        def show_about():
            Amsg = "<center>All credit reserved to the author of chrome-cut "
            Amsg += " version " + self.version
            Amsg += ", This work is a free, open-source project licensed "
            Amsg += " under Mozilla Public License version 2.0 . <br><br>"
            Amsg += " visit us for more infos and how-tos :<br> "
            Amsg += "<b><a href='https://github.io/mrf345/chrome-cut'> "
            Amsg += "https://github.io/mrf345/chrome-cut </a> </b></center>"
            Amsgb = "About chrome-cut"
            return QMessageBox.about(self, Amsgb, Amsg)

        self.abutton = QPushButton('', self)
        self.abutton.setIcon(QPixmap(icon))
        self.abutton.setIconSize(QSize(500, 100))
        self.abutton.setToolTip('About chrome-cut')
        self.abutton.clicked.connect(show_about)
        glo.addWidget(self.abutton)

    def ss_btns(self, glo):
        self.lebutton = QPushButton('Scan IP address', self)
        self.lebutton.setToolTip(
            'Insert and check if a specific IP is a valid chrome cast')
        self.lebutton.setFont(self.tf)
        self.lebutton.clicked.connect(self.sip_input)
        glo.addWidget(self.lebutton)

    def sip_input(self):
        self.lebutton.setEnabled(False)
        self.s_bar.setStyleSheet(self.s_norm)
        self.s_bar.showMessage('> Checking out the IP ..')
        msg = "<center>Enter suspected IP to check : <br><i><u>Usually it is "
        msg += "on 192.168.what_have_you.188</i></center>"
        text, okPressed = QInputDialog.getText(self, "Scan IP", msg)
        if okPressed and text != '':
            self.setCursor(Qt.BusyCursor)
            ch = is_ccast(text)
            if ch:
                self.il_add([text])
                self.unsetCursor()
                self.lebutton.setEnabled(True)
                return True
            else:
                self.s_bar.setStyleSheet(self.s_error)
                self.s_bar.showMessage(
                    '! Error: inserted IP is not chrome cast device')
                self.unsetCursor()
                self.lebutton.setEnabled(True)
                return True
        self.s_bar.clearMessage()
        self.lebutton.setEnabled(True)
        return True

    def i_list(self, glo):
        self.ci_list = QListWidget()
        self.ci_list.setToolTip("List of discovered devices")
        self.ci_list.setEnabled(False)
        self.setFont(self.sf)
        glo.addWidget(self.ci_list)

    def cl_btn(self, glo):
        self.cle_btn = QPushButton('Clear devices list')
        self.cle_btn.setToolTip("Remove all devices from the list")
        self.cle_btn.setFont(self.sf)
        self.cle_btn.setEnabled(False)
        self.cle_btn.clicked.connect(self.il_add)
        glo.addWidget(self.cle_btn)

    def l_btns(self, glo):
        hlayout = QHBoxLayout()
        self.llo = QCheckBox("Looping")
        self.llo.setToolTip(
            'Automate repeating the smae command on the smae device selected ')
        self.llo.setEnabled(False)
        self.nlo = QLineEdit()
        self.nlo.setPlaceholderText("duration in seconds. Default is 10")
        self.nlo.setEnabled(False)
        self.nlo.setToolTip("Duration of sleep after each loop")
        self.lbtn = QPushButton('Stop')
        self.lbtn.setEnabled(False)
        self.lbtn.setFont(self.tf)
        self.llo.setFont(self.sf)
        self.lbtn.setToolTip("stop on-going command or loop")
        self.llo.toggled.connect(self.loped)
        self.lbtn.clicked.connect(partial(self.inloop_state, out=True))
        hlayout.addWidget(self.llo)
        hlayout.addWidget(self.nlo)
        hlayout.addWidget(self.lbtn)
        glo.addLayout(hlayout)

    def loped(self):
        if self.Looping:
            self.Looping = None
            self.llo.setChecked(False)
            self.nlo.setEnabled(False)
        else:
            self.Looping = True
            self.llo.setChecked(True)
            self.nlo.setEnabled(True)
        return True

    def f_btns(self, glo):
        hlayout = QHBoxLayout()
        self.ksbutton = QPushButton('Kill stream', self)
        self.ksbutton.setToolTip('Kill whetever been streamed')
        self.ksbutton.setFont(self.tf)
        self.ksbutton.clicked.connect(self.k_act)
        self.sbutton = QPushButton('Stream', self)
        self.sbutton.setFont(self.tf)
        self.sbutton.setToolTip('Stream a youtube video')
        self.fbutton = QPushButton('Factory reset', self)
        self.fbutton.setFont(self.tf)
        self.fbutton.setToolTip('Factory reset the device')
        self.fbutton.clicked.connect(self.fr_act)
        self.sbutton.clicked.connect(self.yv_input)
        self.ksbutton.setEnabled(False)
        self.sbutton.setEnabled(False)
        self.fbutton.setEnabled(False)
        hlayout.addWidget(self.ksbutton)
        hlayout.addWidget(self.sbutton)
        hlayout.addWidget(self.fbutton)
        glo.addLayout(hlayout)

    def ch_dur(th=None, dur=10):
        if len(dur) >= 1:
            try:
                dur = int(dur)
            except:
                dur = None
            if dur is None or not isinstance(dur, int):
                self.s_bar.setStyleSheet(self.s_error)
                self.s_bar.showMessage(
                    '! Error: wrong duration entery, only integers')
                return None
        else:
            dur = 10
        return dur

    def k_act(self):
        if self.ci_list.count() >= 1:
            cr = self.ci_list.currentRow()
            if cr is None or cr <= 0:
                cr = 0
            ip = self.ci_list.item(cr).text()
            if self.Looping is not None:
                dur = self.ch_dur(self.nlo.text())
                if dur is None:
                    return True
                self.P = CC_thread(cancel_app, dur, ip)
                self.P.start()
                self.P.somesignal.connect(self.handleStatusMessage)
                self.P.setTerminationEnabled(True)
                self.inloop_state()
                return True
            else:
                ch = cancel_app(ip)
                if ch is None:
                    self.s_bar.setStyleSheet(self.s_error)
                    self.s_bar.showMessage('! Error: failed to kill stream ..')
                else:
                    self.s_bar.setStyleSheet(self.s_norm)
                    self.s_bar.showMessage('# Stream got killed ')
        else:
            self.s_bar.setStyleSheet(self.s_error)
            self.s_bar.showMessage('! Error: No items selected from the list')
            self.eout()
        return True

    def fr_act(self):
        if self.ci_list.count() >= 1:
            cr = self.ci_list.currentRow()
            if cr is None or cr <= 0:
                cr = 0
            ip = self.ci_list.item(cr).text()
            if self.Looping is not None:
                dur = self.ch_dur(self.nlo.text())
                if dur is None:
                    return True
                self.P = CC_thread(reset_cc, dur, ip)
                self.P.start()
                self.P.somesignal.connect(self.handleStatusMessage)
                self.P.setTerminationEnabled(True)
                self.inloop_state()
                return True
            else:
                ch = reset_cc(ip)
                if ch is None:
                    self.s_bar.setStyleSheet(self.s_error)
                    self.s_bar.showMessage(
                        '! Error: failed to factory reset ..')
                else:
                    self.s_bar.setStyleSheet(self.s_norm)
                    self.s_bar.showMessage('# Got factory reseted ')
        else:
            self.s_bar.setStyleSheet(self.s_error)
            self.s_bar.showMessage('! Error: No items selected from the list')
            self.eout()
        return True

    def y_act(self, link=None):
        if self.ci_list.count() >= 1:
            cr = self.ci_list.currentRow()
            if cr is None or cr <= 0:
                cr = 0
            ip = self.ci_list.item(cr).text()
            if self.Looping is not None:
                dur = self.ch_dur(self.nlo.text())
                if dur is None:
                    return True
                self.P = CC_thread(send_app, dur, ip, link)
                self.P.start()
                self.P.somesignal.connect(self.handleStatusMessage)
                self.P.setTerminationEnabled(True)
                self.inloop_state()
                return True
            else:
                ch = reset_cc(ip)
                if ch is None:
                    self.s_bar.setStyleSheet(self.s_error)
                    self.s_bar.showMessage('! Error: failed to stream link ..')
                else:
                    self.s_bar.setStyleSheet(self.s_norm)
                    self.s_bar.showMessage('# Streamed the link ')
        else:
            self.s_bar.setStyleSheet(self.s_error)
            self.s_bar.showMessage('! Error: No items selected from the list')
            self.eout()
        return True

    def yv_input(self):
        text, okPressed = QInputDialog.getText(
            self, "Stream youtube",
            "Enter youtube video link to be streamed :")
        if okPressed and text != '':
            ntext = text.split('?')
            if len(ntext) <= 1:
                self.s_bar.setStyleSheet(self.s_error)
                self.s_bar.showMessage('! Error: Invalid youtube linkd ')
                return False
            ntext = ntext[1]
            if ntext != '' and len(ntext) > 1 and "youtube" in text:
                self.y_act(ntext)
                return True
            else:
                self.s_bar.setStyleSheet(self.s_error)
                self.s_bar.showMessage('! Error: Invalid youtube linkd ')
        return False

    @Slot(object)
    def handleStatusMessage(self, message):
        self.s_bar.setStyleSheet(self.s_loop)
        self.s_bar.showMessage(message)

    def il_add(self, items=[]):
        if len(items) >= 1:
            self.s_bar.setStyleSheet(self.s_norm)
            for i in items:
                fitem = self.ci_list.findItems(i, Qt.MatchExactly)
                if len(fitem) >= 1:
                    self.s_bar.setStyleSheet(self.s_error)
                    self.s_bar.showMessage(
                        '! Error: Device exists in the list')
                else:
                    self.s_bar.setStyleSheet(self.s_norm)
                    self.ci_list.addItem(i)
                    self.s_bar.showMessage('# Device was found and added')
            if not self.P.isRunning():
                self.cle_btn.setEnabled(True)
                self.ci_list.setEnabled(True)
                self.llo.setEnabled(True)
                self.nlo.setEnabled(True)
                self.ksbutton.setEnabled(True)
                self.sbutton.setEnabled(True)
                self.fbutton.setEnabled(True)
        else:
            self.s_bar.setStyleSheet(self.s_norm)
            self.s_bar.showMessage('# Cleard devices list')
            self.ci_list.clear()
            self.cle_btn.setEnabled(False)
            self.ci_list.setEnabled(False)
            self.ksbutton.setEnabled(False)
            self.llo.setEnabled(False)
            self.nlo.setEnabled(False)
            self.sbutton.setEnabled(False)
            self.fbutton.setEnabled(False)
        return True

    def inloop_state(self, out=False):
        if not out:
            self.lbtn.setEnabled(True)
            self.cle_btn.setEnabled(False)
            self.ci_list.setEnabled(False)
            self.ksbutton.setEnabled(False)
            self.llo.setEnabled(False)
            self.nlo.setEnabled(False)
            self.sbutton.setEnabled(False)
            self.fbutton.setEnabled(False)
        else:
            if self.P.isRunning():
                self.P.stop()
            self.lbtn.setEnabled(False)
            self.cle_btn.setEnabled(True)
            self.ci_list.setEnabled(True)
            self.ksbutton.setEnabled(True)
            self.llo.setEnabled(True)
            self.nlo.setEnabled(True)
            self.sbutton.setEnabled(True)
            self.fbutton.setEnabled(True)
            self.s_bar.clearMessage()
        return True

    def ds_bar(self, glo):
        self.s_bar = QStatusBar()
        self.s_error = "QStatusBar{color:red;font-weight:1000;}"
        self.s_loop = "QStatusBar{color:black;font-weight:1000;}"
        self.s_norm = "QStatusBar{color:blue;font-style:italic;"
        self.s_norm += "font-weight:500;}"
        self.s_bar.setStyleSheet(self.s_norm)
        glo.addWidget(self.s_bar)

    def eout(self):
        msgg = "<center>"
        msgg += " Opps, a critical error has occurred, we will be "
        msgg += " grateful if you can help fixing it, by reporting to us "
        msgg += " at : <br><br> "
        msgg += "<b><a href='https://github.io/mrf345/chrome-cut'> "
        msgg += "https://github.io/mrf345/chrome-cut </a></b> </center>"
        mm = QMessageBox.critical(self, "Critical Error", msgg, QMessageBox.Ok)
        exit(0)