Example #1
0
    def copyFiles(self, src, dst, names=None, overwrite=True):
        """ Copy files from src directory to dst directory. Subfolders are ignored.
        If names is provided, copies only files matching those names. Symlinks are not
        copied """
        moDebug("Copying files from {} to {}. Names: {}".format(
            src, dst, names))
        srcDir = QDir(src, "", QDir.IgnoreCase, QDir.Files | QDir.NoSymLinks)
        dstDir = QDir(dst)

        if not srcDir.exists() or not dstDir.exists():
            moWarn("Failed to copy files with non-existant directories")
            return False

        success = True
        if names:
            srcDir.setNameFilters(names)
        fileNames = srcDir.entryList()
        for name in fileNames:
            if dstDir.exists(name):
                if not overwrite:
                    continue
                dstDir.remove(name)
            success = QFile.copy(srcDir.filePath(name), dstDir.filePath(name))
            if not success:
                moWarn('Failed to copy "{}" from "{}" to "{}"'.format(
                    name, src, dst))
        return success
Example #2
0
    def find_qm_files(self):
        trans_dir = QDir(":/resources/translations")
        file_names = trans_dir.entryList(['*.qm'], QDir.Files, QDir.Name)

        gm_files = [trans_dir.filePath(fn) for fn in file_names]

        for i, qmf in enumerate(gm_files):
            self.gm_file_map[i] = qmf
Example #3
0
    def on_btnDir_filePath_clicked(self):
        self.__showBtnInfo(self.sender())
        sous = self.ui.editFile.text()
        if sous == "":
            self.ui.textEdit.appendPlainText("请先选择一个文件")
            return

        parDir = QDir.currentPath()
        dirObj = QDir(parDir)
        text = dirObj.filePath(sous)
        self.ui.textEdit.appendPlainText(text + "\n")
Example #4
0
    def getDownloadPath(self, parent, subtitle):
        video = subtitle.get_parent().get_parent().get_parent()
        downloadFullPath = ""
        settings = QSettings()

        # Creating the Subtitle Filename
        optionSubtitleName = settings.value('options/subtitleName', 'SAME_VIDEO')
        sub_extension = get_extension(subtitle.get_filename().lower())
        if optionSubtitleName == 'SAME_VIDEO':
            subFileName = without_extension(video.get_filepath()) + "." + sub_extension
        elif optionSubtitleName == 'SAME_VIDEOPLUSLANG':
            subFileName = without_extension(video.get_filepath()) + "." + subtitle.get_language().xxx() + "." + sub_extension
        elif optionSubtitleName == 'SAME_VIDEOPLUSLANGANDUPLOADER':
            subFileName = without_extension(video.get_filepath()) + "." + subtitle.get_language().xxx() + "." + subtitle.get_uploader() + "." + sub_extension
        elif optionSubtitleName == 'SAME_ONLINE':
            subFileName = os.path.join(os.path.dirname(video.get_filepath()), subtitle.get_filename())

        # Creating the Folder Destination
        optionWhereToDownload = \
            settings.value("options/whereToDownload", "SAME_FOLDER")
        if optionWhereToDownload == "ASK_FOLDER":
            folderPath = video.get_folderpath()
            dir = QDir(folderPath)
            downloadFullPath = dir.filePath(subFileName)
            downloadFullPath, t = QFileDialog.getSaveFileName(
                parent, _("Save as..."), downloadFullPath, sub_extension)
            log.debug("Downloading to: %r" % downloadFullPath)
        elif optionWhereToDownload == "SAME_FOLDER":
            folderPath = video.get_folderpath()
            dir = QDir(folderPath)
            downloadFullPath = os.path.join(folderPath, subFileName)
            log.debug("Downloading to: %r" % downloadFullPath)
        elif optionWhereToDownload == "PREDEFINED_FOLDER":
            folderPath = settings.value("options/whereToDownloadFolder", "")
            dir = QDir(folderPath)
            downloadFullPath = dir.filePath(subFileName).__str__()
            log.debug("Downloading to: %r" % downloadFullPath)

        return downloadFullPath
Example #5
0
    def saveStamp(self, stamp):
        # make sure we have a stamps directory
        prefs = preferences.Preferences.instance()
        stampsDirectory = prefs.stampsDirectory()
        stampsDir = QDir(stampsDirectory)
        if (not stampsDir.exists() and not stampsDir.mkpath(".")):
            qDebug("Failed to create stamps directory" + stampsDirectory)
            return

        filePath = stampsDir.filePath(stamp.fileName())
        file = QSaveFile(filePath)
        if (not file.open(QIODevice.WriteOnly)):
            qDebug("Failed to open stamp file for writing" + filePath)
            return

        stampJson = stamp.toJson(QFileInfo(filePath).dir())
        file.write(QJsonDocument(stampJson).toJson(QJsonDocument.Compact))
        if (not file.commit()):
            qDebug() << "Failed to write stamp" << filePath
Example #6
0
    def loadDirectory(self, dirName):
        """
        Public method to load the search engine definitions from files.
        
        @param dirName name of the directory to load the files from (string)
        @return flag indicating success (boolean)
        """
        if not QFile.exists(dirName):
            return False

        success = False

        dir = QDir(dirName)
        for name in dir.entryList(["*.xml"]):
            fileName = dir.filePath(name)
            if self.__addEngineByFile(fileName):
                success = True

        return success
Example #7
0
 def loadDirectory(self, dirName):
     """
     Public method to load the search engine definitions from files.
     
     @param dirName name of the directory to load the files from (string)
     @return flag indicating success (boolean)
     """
     if not QFile.exists(dirName):
         return False
     
     success = False
     
     dir = QDir(dirName)
     for name in dir.entryList(["*.xml"]):
         fileName = dir.filePath(name)
         if self.__addEngineByFile(fileName):
             success = True
     
     return success
Example #8
0
 def saveStamp(self, stamp):
     # make sure we have a stamps directory
     prefs = preferences.Preferences.instance()
     stampsDirectory = prefs.stampsDirectory()
     stampsDir = QDir(stampsDirectory)
     if (not stampsDir.exists() and not stampsDir.mkpath(".")):
         qDebug("Failed to create stamps directory" + stampsDirectory)
         return
     
     filePath = stampsDir.filePath(stamp.fileName())
     file = QSaveFile(filePath)
     if (not file.open(QIODevice.WriteOnly)):
         qDebug("Failed to open stamp file for writing" + filePath)
         return
     
     stampJson = stamp.toJson(QFileInfo(filePath).dir())
     file.write(QJsonDocument(stampJson).toJson(QJsonDocument.Compact))
     if (not file.commit()):
         qDebug() << "Failed to write stamp" << filePath
Example #9
0
    def __init__(self, parent=None):
        super().__init__(parent)
        self.translator = QTranslator()
        model = Model(self)
        self.combobox = QComboBox()
        tableview = QTableView()
        tableview.setModel(model)

        lay = QVBoxLayout(self)
        lay.addWidget(self.combobox)
        lay.addWidget(tableview)

        dir_translations = os.fspath(CURRENT_DIRECTORY / "translations")
        trans_dir = QDir(dir_translations)
        self.combobox.addItem("Default")
        for filename in trans_dir.entryList(["*.qm"], QDir.Files, QDir.Name):
            self.combobox.addItem(filename, trans_dir.filePath(filename))

        self.combobox.currentIndexChanged.connect(self.handle_current_index_changed)
Example #10
0
    def saveDirectory(self, dirName):
        """
        Public method to save the search engine definitions to files.
        
        @param dirName name of the directory to write the files to (string)
        """
        dir = QDir()
        if not dir.mkpath(dirName):
            return
        dir.setPath(dirName)

        from .OpenSearchWriter import OpenSearchWriter
        writer = OpenSearchWriter()

        for engine in list(self.__engines.values()):
            name = self.generateEngineFileName(engine.name())
            fileName = dir.filePath(name)

            file = QFile(fileName)
            if not file.open(QIODevice.WriteOnly):
                continue

            writer.write(file, engine)
Example #11
0
 def saveDirectory(self, dirName):
     """
     Public method to save the search engine definitions to files.
     
     @param dirName name of the directory to write the files to (string)
     """
     dir = QDir()
     if not dir.mkpath(dirName):
         return
     dir.setPath(dirName)
     
     from .OpenSearchWriter import OpenSearchWriter
     writer = OpenSearchWriter()
     
     for engine in list(self.__engines.values()):
         name = self.generateEngineFileName(engine.name())
         fileName = dir.filePath(name)
         
         file = QFile(fileName)
         if not file.open(QIODevice.WriteOnly):
             continue
         
         writer.write(file, engine)
Example #12
0
    def beginFinalInit(self):
        """
        @see: startup
        Notice the __init__ method . we just setup the basic widget.
        And after the language , style ,plugins etc had loaded .
        we call this method . 
        
        Never call it unless you know what's it
        """
        #when at linux platform . the icon is not visible at menu .
        for key in self.__actions.keys():
            self.__actions.get(key).setIconVisibleInMenu(True)

        #--------------->>Seeking init <<-----------------#
        # __init__ menu
        self.getMenu("settings").addAction(self.getAction("perferences"))

        #i18n , must restart program to make it in use
        action_languages = QAction(
            QIcon(getPath('iconDir', 'languages.png')),
            QApplication.translate("default", "Languages"), self)
        action_languages.setIconVisibleInMenu(True)
        menu_languages = QMenu(self)

        trans_dir = QDir(getPrccisePath("transDir", "", "coredir"))
        fileNames = trans_dir.entryList(['i18n*.qm'], QDir.Files, QDir.Name)
        qmFiles = [trans_dir.filePath(fn) for fn in fileNames]

        for qmf in qmFiles:
            translator = QTranslator()
            translator.load(qmf)
            action = menu_languages.addAction(
                translator.translate("default", "English"))
            action.triggered.connect(lambda re, locale=translator.translate(
                "default", "locale"): self.__evt_changeLanguage(locale))

        action_languages.setMenu(menu_languages)
        self.getMenu("settings").addAction(action_languages)

        #style menu use signalmapper
        action_style = QAction(QIcon(getPath('iconDir', 'style.png')),
                               QApplication.translate("default", "Style"),
                               self)
        action_style.setIconVisibleInMenu(True)
        menu_style = QMenu(self)
        for style_item in QStyleFactory.keys():
            action = menu_style.addAction(style_item)
            action.triggered.connect(
                lambda re, style_item=style_item: changeStyle(style_item))
        action_style.setMenu(menu_style)
        self.getMenu("settings").addAction(action_style)

        menu_plugin = self.getMenu("plugins")

        menu_plugin.addAction(self.getAction("plguinInfos"))

        menu_plugin.addSeparator()
        menu_plugin.addAction(self.getAction("plguinRequest"))

        #--------------->>Seeking init <<-----------------#
        # __init__ toolbar
        toolBar = self.addToolBar(QApplication.translate("default", "common"))

        toolBar.addAction(self.getAction("perferences"))
        toolBar.addAction(self.getAction("close"))
        toolBar.addAction(self.getAction("gotohome"))
        toolBar.addAction(self.getAction("help"))

        #--------------->>Seeking init <<-----------------#
        # __init__ status bar
        self.statusBar().showMessage("Seeking ...")

        #--------------->>Seeking init <<-----------------#
        #Effects of a loading progress .
        #Results appear in the tab of the interior, the window has no effect on the global
        self.overlay = Overlay(self.centralWidget())
        self.overlay.hide()

        #--------------->>Seeking init <<-----------------#
        #other
        self.emit(SIGNAL('updateWindows()'))
Example #13
0
def stampFilePath(name):
    prefs = preferences.Preferences.instance()
    stampsDir = QDir(prefs.stampsDirectory())
    return stampsDir.filePath(name)
Example #14
0
    def findQmFiles(self):
        trans_dir = QDir(':/translations')
        fileNames = trans_dir.entryList(['*.qm'], QDir.Files, QDir.Name)

        return [trans_dir.filePath(fn) for fn in fileNames]
Example #15
0
    def findQmFiles(self):
        trans_dir = QDir('translations')
        fileNames = trans_dir.entryList(['*.qm'], QDir.Files, QDir.Name)

        return [trans_dir.filePath(fn) for fn in fileNames]
Example #16
0
def stampFilePath(name):
    prefs = preferences.Preferences.instance()
    stampsDir = QDir(prefs.stampsDirectory())
    return stampsDir.filePath(name)
Example #17
0
    def beginFinalInit(self):
        """
        @see: startup
        Notice the __init__ method . we just setup the basic widget.
        And after the language , style ,plugins etc had loaded .
        we call this method . 
        
        Never call it unless you know what's it
        """
        #when at linux platform . the icon is not visible at menu .
        for key in self.__actions.keys():
            self.__actions.get(key).setIconVisibleInMenu(True)
            
        #--------------->>Seeking init <<-----------------#
        # __init__ menu
        self.getMenu("settings").addAction(self.getAction("perferences"))
        
        
        #i18n , must restart program to make it in use
        action_languages = QAction(QIcon(getPath('iconDir','languages.png')),QApplication.translate("default", "Languages"),self)
        action_languages.setIconVisibleInMenu(True)
        menu_languages = QMenu(self)
        
        trans_dir = QDir(getPrccisePath("transDir","","coredir"))
        fileNames = trans_dir.entryList(['i18n*.qm'], QDir.Files,QDir.Name)
        qmFiles = [trans_dir.filePath(fn) for fn in fileNames]
    
        for qmf in qmFiles: 
            translator = QTranslator() 
            translator.load(qmf)
            action = menu_languages.addAction(translator.translate("default", "English"))
            action.triggered.connect(lambda re,locale=translator.translate("default", "locale"):self.__evt_changeLanguage(locale))
        
        action_languages.setMenu(menu_languages)
        self.getMenu("settings").addAction(action_languages)
        
        #style menu use signalmapper
        action_style = QAction(QIcon(getPath('iconDir','style.png')),QApplication.translate("default", "Style"),self)
        action_style.setIconVisibleInMenu(True)
        menu_style = QMenu(self)
        for style_item in QStyleFactory.keys():
            action = menu_style.addAction(style_item)
            action.triggered.connect(lambda re,style_item=style_item:changeStyle(style_item))
        action_style.setMenu(menu_style)
        self.getMenu("settings").addAction(action_style)
        
        menu_plugin = self.getMenu("plugins")
        
        menu_plugin.addAction(self.getAction("plguinInfos"))
        
        menu_plugin.addSeparator()
        menu_plugin.addAction(self.getAction("plguinRequest"))
        
        #--------------->>Seeking init <<-----------------#
        # __init__ toolbar
        toolBar = self.addToolBar(QApplication.translate("default","common"))
        
        toolBar.addAction(self.getAction("perferences"))
        toolBar.addAction(self.getAction("close"))
        toolBar.addAction(self.getAction("gotohome"))
        toolBar.addAction(self.getAction("help"))
        
        #--------------->>Seeking init <<-----------------#
        # __init__ status bar
        self.statusBar().showMessage("Seeking ...")
        
        
        #--------------->>Seeking init <<-----------------#
        #Effects of a loading progress .
        #Results appear in the tab of the interior, the window has no effect on the global
        self.overlay = Overlay(self.centralWidget())
        self.overlay.hide()

        #--------------->>Seeking init <<-----------------#
        #other
        self.emit(SIGNAL('updateWindows()'))