當前位置: 首頁>>代碼示例>>Python>>正文


Python Movie.generate_new_name方法代碼示例

本文整理匯總了Python中movie.Movie.generate_new_name方法的典型用法代碼示例。如果您正苦於以下問題:Python Movie.generate_new_name方法的具體用法?Python Movie.generate_new_name怎麽用?Python Movie.generate_new_name使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在movie.Movie的用法示例。


在下文中一共展示了Movie.generate_new_name方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: load_movies_run

# 需要導入模塊: from movie import Movie [as 別名]
# 或者: from movie.Movie import generate_new_name [as 別名]
 def load_movies_run(self, filepaths):
     renaming_rule = utils.preferences.value("renaming_rule").toString()
     # loop on file paths
     for filepath in filepaths:
         # set loading label text, show current file name
         self.ui.label_loading.setText(QApplication.translate('GUI', "Getting information from ")\
                                        + os.path.split(filepath)[1])
         # create a new movie object
         movie = Movie(filepath)
         # generate new movie name based on renaming rule
         movie.generate_new_name(renaming_rule)
         # add movie to list
         self.movies.append(movie)
         # insert a new row in movie table
         self.ui.table_movies.insertRow(self.ui.table_movies.rowCount())
         # create a table item with original movie file name
         item_original_name = QTableWidgetItem(movie.original_file_name())
         item_original_name.setForeground(QBrush(Qt.black))
         self.ui.table_movies.setItem(self.ui.table_movies.rowCount() - 1, 0, item_original_name)
         # create a table item with new movie file name
         item_new_name = QTableWidgetItem(movie.new_file_name())
         item_new_name.setForeground(QBrush(Qt.black))
         self.ui.table_movies.setItem(self.ui.table_movies.rowCount() - 1, 1, item_new_name)
     self.load_movies_finished.emit()
開發者ID:meloi,項目名稱:almoviesrenamer,代碼行數:26,代碼來源:gui.py

示例2: RenamingRuleDialog

# 需要導入模塊: from movie import Movie [as 別名]
# 或者: from movie.Movie import generate_new_name [as 別名]

#.........這裏部分代碼省略.........
        """
        populate renaming rule by rule read from settings
        """

        renaming_rule = utils.preferences.value("renaming_rule").toString()
        # split rule
        rules = renaming_rule.split('.')
        # if rule is empty, reset it to 'title'
        if rules[0] == '':
            rules[0] = Movie.TITLE
            renaming_rule = Movie.TITLE
            utils.preferences.setValue("renaming_rule", renaming_rule)
        visual_rule = []
        # loop on rules
        for rule in rules:
            visual_rule.append(self.RENAMING_TO_VISUAL_RULE[rule])
        self.ui.list_visual_rule.addItems(visual_rule)

    def update_representations(self):
        duration_index = utils.preferences.value("duration_representation").toInt()[0]
        duration_representation = PreferencesDialog.DURATION_REPRESENTATIONS[duration_index]
        self.ui.label_duration_representation.setText(duration_representation)

        language_index = utils.preferences.value("language_representation").toInt()[0]
        language_representation = PreferencesDialog.LANGUAGE_REPRESENTATIONS[language_index]
        self.ui.label_language_representation.setText(language_representation)

        separator_index = utils.preferences.value("words_separator").toInt()[0]
        separator_representation = PreferencesDialog.WORDS_SEPARATORS_REPRESENTATIONS[separator_index]
        self.ui.label_separator_representation.setText(separator_representation)

    def update_example_movie(self, renaming_rule):
        # generate new name for example movie
        example_movie_new_name = self.example_movie.generate_new_name(renaming_rule)
        # show it on label
        self.ui.label_example_movie_name.setText(example_movie_new_name)

    def rule_changed(self, parent = None, start = None, end = None):
        """
        called when renaming rule changes
        
        creates and saves new renaming rule, and generate the movie example's new name
        """

        rule = []
        for index in range(self.ui.list_visual_rule.count()):
            text = self.ui.list_visual_rule.item(index).text()
            # when an item is moved inside the list_visual_rule, firstly 
            # a new empty item is inserted into the destination location, then 
            # the item from source location is deleted. that function is called 
            # for both events (insertion and deletion), and when is called for
            # the insertion event after a list items move, the list contains an empty item,
            # which is a kind of error. 
            if text != '':
                rule.append(self.VISUAL_TO_RENAMING_RULE[text])
        # creates renaming rule
        renaming_rule = '.'.join(rule)
        #save renaming rule on settings
        utils.preferences.setValue("renaming_rule", renaming_rule)
        #update example movie
        self.update_example_movie(renaming_rule)

    def remove_rule(self):
        """
        removes selected rule
        """
開發者ID:meloi,項目名稱:almoviesrenamer,代碼行數:70,代碼來源:gui.py


注:本文中的movie.Movie.generate_new_name方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。