当前位置: 首页>>代码示例>>Python>>正文


Python File.filter方法代码示例

本文整理汇总了Python中classes.query.File.filter方法的典型用法代码示例。如果您正苦于以下问题:Python File.filter方法的具体用法?Python File.filter怎么用?Python File.filter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在classes.query.File的用法示例。


在下文中一共展示了File.filter方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_add_file

# 需要导入模块: from classes.query import File [as 别名]
# 或者: from classes.query.File import filter [as 别名]
    def test_add_file(self):
        """ Test the File.save method by adding multiple files """

        # Import additional classes that need the app defined first
        from classes.query import File

        # Find number of files in project
        num_files = len(File.filter())

        # Create file
        r = openshot.DummyReader(openshot.Fraction(24, 1), 640, 480, 44100, 2, 30.0)

        # Parse JSON
        file_data = json.loads(r.Json())

        # Insert into project data
        query_file = File()
        query_file.data = file_data
        query_file.data["path"] = os.path.join(PATH, "images", "openshot.png")
        query_file.data["media_type"] = "image"
        query_file.save()

        self.assertTrue(query_file)
        self.assertEqual(len(File.filter()), num_files + 1)

        # Save the file again (which should not change the total # of files)
        query_file.save()

        self.assertEqual(len(File.filter()), num_files + 1)
开发者ID:JoOngle2,项目名称:openshot-qt,代码行数:31,代码来源:query_tests.py

示例2: test_filter_File

# 需要导入模块: from classes.query import File [as 别名]
# 或者: from classes.query.File import filter [as 别名]
    def test_filter_File(self):
        """ Test the File.filter method """

        # Import additional classes that need the app defined first
        from classes.query import File

        # Find all Files named file1
        files = File.filter(id=TestQueryClass.file_ids[0])
        self.assertTrue(files)

        # Do not find a File
        files = File.filter(id="invalidID")
        self.assertEqual(len(files), 0)
开发者ID:JoOngle2,项目名称:openshot-qt,代码行数:15,代码来源:query_tests.py

示例3: currentChanged

# 需要导入模块: from classes.query import File [as 别名]
# 或者: from classes.query.File import filter [as 别名]
    def currentChanged(self, selected, deselected):
        # Get selected item
        self.selected = selected
        self.deselected = deselected

        # Get translation object
        _ = self.app._tr

        # Clear existing settings
        self.win.clear_effect_controls()

        # Get animation details
        animation = self.get_animation_details()
        self.selected_template = animation["service"]

        # Assign a new unique id for each template selected
        self.generateUniqueFolder()

        # Loop through params
        for param in animation["params"]:
            log.info(param["title"])

            # Is Hidden Param?
            if param["name"] == "start_frame" or param["name"] == "end_frame":
                # add value to dictionary
                self.params[param["name"]] = int(param["default"])

                # skip to next param without rendering the controls
                continue

            # Create Label
            widget = None
            label = QLabel()
            label.setText(_(param["title"]))
            label.setToolTip(_(param["title"]))

            if param["type"] == "spinner":
                # add value to dictionary
                self.params[param["name"]] = float(param["default"])

                # create spinner
                widget = QDoubleSpinBox()
                widget.setMinimum(float(param["min"]))
                widget.setMaximum(float(param["max"]))
                widget.setValue(float(param["default"]))
                widget.setSingleStep(0.01)
                widget.setToolTip(param["title"])
                widget.valueChanged.connect(functools.partial(self.spinner_value_changed, param))

            elif param["type"] == "text":
                # add value to dictionary
                self.params[param["name"]] = _(param["default"])

                # create spinner
                widget = QLineEdit()
                widget.setText(_(param["default"]))
                widget.textChanged.connect(functools.partial(self.text_value_changed, widget, param))

            elif param["type"] == "multiline":
                # add value to dictionary
                self.params[param["name"]] = _(param["default"])

                # create spinner
                widget = QTextEdit()
                widget.setText(_(param["default"]))
                widget.textChanged.connect(functools.partial(self.text_value_changed, widget, param))

            elif param["type"] == "dropdown":
                # add value to dictionary
                self.params[param["name"]] = param["default"]

                # create spinner
                widget = QComboBox()
                widget.currentIndexChanged.connect(functools.partial(self.dropdown_index_changed, widget, param))

                # Add values to dropdown
                if "project_files" in param["name"]:
                    # override files dropdown
                    param["values"] = {}
                    for file in File.filter():
                        if file.data["media_type"] in ("image", "video"):
                            (dirName, fileName) = os.path.split(file.data["path"])
                            (fileBaseName, fileExtension) = os.path.splitext(fileName)

                            if fileExtension.lower() not in (".svg"):
                                param["values"][fileName] = "|".join((file.data["path"], str(file.data["height"]),
                                                                      str(file.data["width"]), file.data["media_type"],
                                                                      str(file.data["fps"]["num"] / file.data["fps"][
                                                                          "den"])))

                # Add normal values
                box_index = 0
                for k, v in sorted(param["values"].items()):
                    # add dropdown item
                    widget.addItem(_(k), v)

                    # select dropdown (if default)
                    if v == param["default"]:
                        widget.setCurrentIndex(box_index)
                    box_index = box_index + 1
#.........这里部分代码省略.........
开发者ID:ghisvail,项目名称:openshot-qt,代码行数:103,代码来源:blender_treeview.py

示例4: update_model

# 需要导入模块: from classes.query import File [as 别名]
# 或者: from classes.query.File import filter [as 别名]
    def update_model(self, clear=True):
        log.info("updating files model.")
        app = get_app()

        # Get window to check filters
        win = app.window
        _ = app._tr

        # Skip updates (if needed)
        if self.ignore_update_signal:
            return

        # Clear all items
        if clear:
            self.model_ids = {}
            self.model.clear()

        # Add Headers
        self.model.setHorizontalHeaderLabels([_("Thumb"), _("Name"), _("Tags"), "", "", ""])

        # Get list of files in project
        files = File.filter()  # get all files

        # add item for each file
        for file in files:
            path, filename = os.path.split(file.data["path"])
            tags = ""
            if "tags" in file.data.keys():
                tags = file.data["tags"]
            name = filename
            if "name" in file.data.keys():
                name = file.data["name"]

            if not win.actionFilesShowAll.isChecked():
                if win.actionFilesShowVideo.isChecked():
                    if not file.data["media_type"] == "video":
                        continue  # to next file, didn't match filter
                elif win.actionFilesShowAudio.isChecked():
                    if not file.data["media_type"] == "audio":
                        continue  # to next file, didn't match filter
                elif win.actionFilesShowImage.isChecked():
                    if not file.data["media_type"] == "image":
                        continue  # to next file, didn't match filter


            if win.filesFilter.text() != "":
                if not win.filesFilter.text().lower() in filename.lower() \
                        and not win.filesFilter.text().lower() in tags.lower() \
                        and not win.filesFilter.text().lower() in name.lower():
                    continue

            # Generate thumbnail for file (if needed)
            if (file.data["media_type"] == "video" or file.data["media_type"] == "image"):
                # Determine thumb path
                thumb_path = os.path.join(info.THUMBNAIL_PATH, "{}.png".format(file.id))

                # Check if thumb exists
                if not os.path.exists(thumb_path):

                    try:
                        # Convert path to the correct relative path (based on this folder)
                        file_path = file.absolute_path()

                        # Reload this reader
                        clip = openshot.Clip(file_path)
                        reader = clip.Reader()

                        # Open reader
                        reader.Open()

                        # Determine if video overlay should be applied to thumbnail
                        overlay_path = ""
                        if file.data["media_type"] == "video":
                            overlay_path = os.path.join(info.IMAGES_PATH, "overlay.png")

                        # Check for start and end attributes (optional)
                        thumbnail_frame = 1
                        if 'start' in file.data.keys():
                            fps = file.data["fps"]
                            fps_float = float(fps["num"]) / float(fps["den"])
                            thumbnail_frame = round(float(file.data['start']) * fps_float) + 1

                        # Save thumbnail
                        reader.GetFrame(thumbnail_frame).Thumbnail(thumb_path, 98, 64, os.path.join(info.IMAGES_PATH, "mask.png"),
                                                     overlay_path, "#000", False)
                        reader.Close()
                        clip.Close()

                    except:
                        # Handle exception
                        msg = QMessageBox()
                        msg.setText(_("{} is not a valid video, audio, or image file.".format(filename)))
                        msg.exec_()
                        continue


            else:
                # Audio file
                thumb_path = os.path.join(info.PATH, "images", "AudioThumbnail.png")

#.........这里部分代码省略.........
开发者ID:JoOngle2,项目名称:openshot-qt,代码行数:103,代码来源:files_model.py


注:本文中的classes.query.File.filter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。