Esempio n. 1
0
    def Exit(self):        
        if not self.isWindowModified():
            return 0
            # sys.exit()
        else:
            msg = QMessageBox()
            msg.setIcon(QMessageBox.Information)

            msg.setText("Salir sin guardar")
            msg.setInformativeText("Todos los cambios se perderan")
            msg.setWindowTitle("Advertencia")
            
            # msg.addButton(QMessageBox.Discard)
            # msg.addButton(QMessageBox.Save )
            # msg.addButton(QMessageBox.Cancel)
            
            msg.setStandardButtons(QMessageBox.Save| QMessageBox.Discard| QMessageBox.Cancel)
            msg.setDefaultButton(QMessageBox.Save)
            # msg.buttonClicked.connect(Check)
            
            buttonY = msg.button(QMessageBox.Save)
            buttonY.setText('Guardar')
            buttonN = msg.button(QMessageBox.Discard)
            buttonN.setText('Descartar')
            buttonO = msg.button(QMessageBox.Cancel)
            buttonO.setText('Cancelar')
            
            if msg.exec():
                if msg.buttonRole(msg.clickedButton())== 2:
                    #print("Discard")
                    return 2
                elif msg.buttonRole(msg.clickedButton()) == 0:
                    # i.text() == "Save    
                    #print("Save")
                    self.Save()
                    # sys.exit()
                    return 0
                elif msg.buttonRole(msg.clickedButton()) == 1:
                    #i.text() == "cancel"
                    print("cancel")
                    print(False)
                    return 1
Esempio n. 2
0
 def on_boardButton_clicked(self):
     msg = QMessageBox()
     msg.setText("Please choose the game mode!")
     msg.setWindowTitle("Enjoy the game with computer :)")
     msg.addButton(QPushButton('Easy Mode'), QMessageBox.AcceptRole)
     msg.addButton(QPushButton('Hard Mode'), QMessageBox.YesRole)
     msg.addButton(QPushButton('Med Mode'), QMessageBox.NoRole)
     msg.exec_()
     result = msg.buttonRole(msg.clickedButton())
     if result == QMessageBox.YesRole:
         self.Hard_Mode()
     elif result == QMessageBox.NoRole:
         self.Med_Mode()
     else:
         self.Easy_Mode()
Esempio n. 3
0
    def _download_current_subtitle(self):
        if self.finished():
            return
        rsub = self._rsubtitles[self._curr_sub_i]
        destinationPath = self._state.calculate_download_path(
            rsub,
            self._create_choose_target_subtitle_path_cb(),
            conflict_free=False)
        if not destinationPath:
            self._callback.cancel()
            self.info(_('Download canceled'),
                      _('Downloading has been canceled'))
            return

        log.debug('Trying to download subtitle "{}"'.format(destinationPath))

        while True:
            self._callback.update(self._curr_sub_i, destinationPath,
                                  self._curr_sub_i + 1, len(self._rsubtitles))
            if self.finished():
                break

            # Check for write access for file and folder
            if not os.access(str(destinationPath), os.W_OK) and not os.access(
                    str(destinationPath.parent), os.W_OK):
                warningBox = QMessageBox(
                    QMessageBox.Warning, _('Error write permission'),
                    _('{} cannot be saved.\nCheck that the folder exists and you have write-access permissions.'
                      ).format(destinationPath),
                    QMessageBox.Retry | QMessageBox.Discard, self._parent)

                saveAsButton = warningBox.addButton(_('Save as...'),
                                                    QMessageBox.ActionRole)
                boxExecResult = warningBox.exec_()
                if boxExecResult == QMessageBox.Retry:
                    continue
                elif boxExecResult == QMessageBox.Abort:
                    return
                else:
                    clickedButton = warningBox.clickedButton()
                    if clickedButton is None:
                        return
                    elif clickedButton == saveAsButton:
                        newFilePath, t = QFileDialog.getSaveFileName(
                            self._parent, _('Save subtitle as...'),
                            str(destinationPath), 'All (*.*)')
                        if not newFilePath:
                            self._callback.cancel()
                            return
                        destinationPath = Path(newFilePath)
                        continue
                    else:
                        log.debug(
                            'Unknown button clicked: result={}, button={}, role: {}'
                            .format(boxExecResult, clickedButton,
                                    warningBox.buttonRole(clickedButton)))
                        return

            if destinationPath.exists():
                if self._skip_all:
                    return
                elif self._replace_all:
                    pass
                else:
                    fileExistsBox = QMessageBox(
                        QMessageBox.Warning, _('File already exists'),
                        '{localLbl}: {local}\n\n{remoteLbl}: {remote}\n\n{question}'
                        .format(
                            localLbl=_('Local'),
                            local=destinationPath,
                            remoteLbl=_('remote'),
                            remote=rsub.get_filename(),
                            question=_('How would you like to proceed?'),
                        ), QMessageBox.NoButton, self._parent)
                    skipButton = fileExistsBox.addButton(
                        _('Skip'), QMessageBox.ActionRole)
                    skipAllButton = fileExistsBox.addButton(
                        _('Skip all'), QMessageBox.ActionRole)
                    replaceButton = fileExistsBox.addButton(
                        _('Replace'), QMessageBox.ActionRole)
                    replaceAllButton = fileExistsBox.addButton(
                        _('Replace all'), QMessageBox.ActionRole)
                    saveAsButton = fileExistsBox.addButton(
                        _('Save as...'), QMessageBox.ActionRole)
                    cancelButton = fileExistsBox.addButton(
                        _('Cancel'), QMessageBox.ActionRole)
                    fileExecResult = fileExistsBox.exec_()

                    clickedButton = fileExistsBox.clickedButton()
                    if clickedButton == skipButton:
                        return
                    elif clickedButton == skipAllButton:
                        self._skip_all = True
                        return
                    elif clickedButton == replaceButton:
                        pass
                    elif clickedButton == replaceAllButton:
                        self._replace_all = True
                    elif clickedButton == saveAsButton:
                        suggestedDestinationPath = self._state.calculate_download_path(
                            rsub,
                            self._create_choose_target_subtitle_path_cb(),
                            conflict_free=True)
                        fileName, t = QFileDialog.getSaveFileName(
                            None, _('Save subtitle as...'),
                            str(suggestedDestinationPath), 'All (*.*)')
                        if not fileName:
                            return
                        destinationPath = Path(fileName)
                        continue
                    elif clickedButton == cancelButton:
                        self._callback.cancel()
                        return
                    else:
                        log.debug(
                            'Unknown button clicked: result={}, button={}, role: {}'
                            .format(fileExecResult, clickedButton,
                                    fileExistsBox.buttonRole(clickedButton)))
                        return
            break

        try:
            log.debug('Downloading subtitle to "{}"'.format(destinationPath))
            download_callback = ProgressCallback()  # FIXME
            local_sub = rsub.download(
                destinationPath,
                self._state.providers.get(rsub.get_provider()).provider,
                download_callback)

            if self._parent_add:
                super_parent = rsub.get_super_parent(VideoFile)
                if super_parent:
                    super_parent.add_subtitle(local_sub, priority=True)

            self._downloaded_subtitles.append(rsub)
        except ProviderConnectionError:
            log.debug('Unable to download subtitle "{}"'.format(
                rsub.get_filename()),
                      exc_info=sys.exc_info())
            QMessageBox.about(
                self._parent, _('Error'),
                _('Unable to download subtitle "{subtitle}"').format(
                    subtitle=rsub.get_filename()))
            self._callback.finish()
Esempio n. 4
0
    def generate_plugin(self):
        logging.info("=============== GENERATING PLUGIN ===============")

        if not get_config().get("PATHS", "installFolder"):
            QMessageBox.information(
                self, "Folder missing",
                "Installation folder not set, please specify one")
            if not self.set_install_folder():
                QMessageBox.warning(
                    self, "Folder missing",
                    "No installation folder specified. Aborting")
                return

        name = get_config().get("CONFIG", "lastName") or get_config().get(
            "PLUGIN", "name")
        plugin_name, ok = QInputDialog.getText(self,
                                               "Plugin Name",
                                               "Enter the plugin name",
                                               text=name)

        if ok:
            if plugin_name:

                get_config().set("CONFIG", "lastName", plugin_name)
                save_config()
                path_plugin_folder = get_config().get("PATHS", "installFolder") + "/" + \
                                     plugin_name + "/" + \
                                     get_config().get("PATHS", "pluginFolder")
                """
                path_plugin_install = get_config().get("PATHS", "installFolder") + "/" + \
                                      plugin_name + "/" + \
                                      get_config().get("PATHS", "pluginInstall")
                create_dir(path_plugin_install)
                
                # File allowing the plugin to be recognized by OSA
                file = open(path_plugin_install + "/" + get_config().get("PLUGIN", "osplug") + ".osplug", "w")
                file.close()
                """

                create_dir(path_plugin_folder)

                logging.info("Plugin destination : " + path_plugin_folder)

                xml_root = self.treeAnimFiles.to_xml(plugin_name)

                with open(path_plugin_folder + plugin_name + ".myo",
                          "w") as file:
                    data = ET.tostring(xml_root, "unicode")
                    file.write(data)

                msg_box = QMessageBox()
                msg_box.setWindowTitle("Results")
                msg_box.setIcon(QMessageBox.Information)
                msg_box.setText("Plugin Generation Done !\n"
                                "----- Plugin path -----\n" +
                                path_plugin_folder)
                msg_box.addButton(QPushButton("Open Folder"),
                                  QMessageBox.ActionRole)
                msg_box.addButton(QPushButton("Ok"), QMessageBox.YesRole)
                msg_box.exec_()

                if msg_box.buttonRole(
                        msg_box.clickedButton()) == QMessageBox.ActionRole:
                    os.startfile(os.path.realpath(path_plugin_folder))

            else:
                QMessageBox.warning(self, "Abort", "Enter valid name")