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.get("service") # In newer versions of Qt, setting the model invokes the currentChanged signal, # but the selection is -1. So, just do nothing here. if not self.selected_template: return # Assign a new unique id for each template selected self.generateUniqueFolder() # Loop through params for param in animation.get("params", []): log.info('Using parameter %s: %s' % (param["name"], 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 = QPlainTextEdit() widget.setPlainText(_(param["default"]).replace("\\n", "\n")) 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"] not in ("image", "video"): continue fileName = os.path.basename(file.data["path"]) fileExtension = os.path.splitext(fileName)[1] if fileExtension.lower() in (".svg"): continue 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 if not param["values"]: widget.addItem(_("No Files Found"), "") widget.setEnabled(False) elif param["type"] == "color": # add value to dictionary color = QColor(param["default"]) if "diffuse_color" in param.get("name"): self.params[param["name"]] = [color.redF(), color.greenF(), color.blueF(), color.alphaF()] else: self.params[param["name"]] = [color.redF(), color.greenF(), color.blueF()] widget = QPushButton() widget.setText("") widget.setStyleSheet("background-color: {}".format(param["default"])) widget.clicked.connect(functools.partial(self.color_button_clicked, widget, param)) # Add Label and Widget to the form if (widget and label): self.win.settingsContainer.layout().addRow(label, widget) elif (label): self.win.settingsContainer.layout().addRow(label) # Enable interface self.enable_interface() # Init slider values self.init_slider_values()
def Populate(self, filter=""): """Populate all preferences and tabs""" # get translations app = get_app() _ = app._tr # Delete all tabs and widgets self.DeleteAllTabs() self.category_names = {} self.category_tabs = {} self.category_sort = {} self.visible_category_names = {} # Loop through settings and find all unique categories for item in self.settings_data: category = item.get("category") setting_type = item.get("type") sort_category = item.get("sort") # Indicate sorted category if sort_category: self.category_sort[category] = sort_category if setting_type != "hidden": # Load setting if category not in self.category_names: self.category_names[category] = [] # Create scrollarea scroll_area = QScrollArea(self) scroll_area.setWidgetResizable(True) scroll_area.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) scroll_area.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) scroll_area.setMinimumSize(675, 100) # Create tab widget and layout layout = QVBoxLayout() tabWidget = QWidget(self) tabWidget.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) tabWidget.setLayout(layout) scroll_area.setWidget(tabWidget) # Add tab self.tabCategories.addTab(scroll_area, _(category)) self.category_tabs[category] = tabWidget # Append translated title item["title_tr"] = _(item.get("title")) # Append settings into correct category self.category_names[category].append(item) # Loop through each category setting, and add them to the tabs for category in dict(self.category_tabs).keys(): tabWidget = self.category_tabs[category] filterFound = False # Get list of items in category params = self.category_names[category] if self.category_sort.get(category): # Sort this category by translated title params.sort(key=operator.itemgetter("title_tr")) # Loop through settings for each category for param in params: # Is filter found? if filter and (filter.lower() in _(param["title"]).lower() or filter.lower() in _(category).lower()): filterFound = True elif not filter: filterFound = True else: filterFound = False # Visible Category if filterFound: self.visible_category_names[category] = tabWidget # Create Label widget = None extraWidget = None label = QLabel() label.setText(_(param["title"])) label.setToolTip(_(param["title"])) if param["type"] == "spinner": # create QDoubleSpinBox widget = QDoubleSpinBox() widget.setMinimum(float(param["min"])) widget.setMaximum(float(param["max"])) widget.setValue(float(param["value"])) widget.setSingleStep(1.0) widget.setToolTip(param["title"]) widget.valueChanged.connect(functools.partial(self.spinner_value_changed, param)) if param["type"] == "spinner-int": # create QDoubleSpinBox widget = QSpinBox() widget.setMinimum(int(param["min"])) widget.setMaximum(int(param["max"])) widget.setValue(int(param["value"])) widget.setSingleStep(1) widget.setToolTip(param["title"]) widget.valueChanged.connect(functools.partial(self.spinner_value_changed, param)) elif param["type"] == "text" or param["type"] == "browse": # create QLineEdit widget = QLineEdit() widget.setText(_(param["value"])) widget.textChanged.connect(functools.partial(self.text_value_changed, widget, param)) if param["type"] == "browse": # Add filesystem browser button extraWidget = QPushButton(_("Browse...")) extraWidget.clicked.connect(functools.partial(self.selectExecutable, widget, param)) elif param["type"] == "bool": # create spinner widget = QCheckBox() if param["value"] is True: widget.setCheckState(Qt.Checked) else: widget.setCheckState(Qt.Unchecked) widget.stateChanged.connect(functools.partial(self.bool_value_changed, widget, param)) elif param["type"] == "dropdown": # create spinner widget = QComboBox() # Get values value_list = param["values"] # Overwrite value list (for profile dropdown) if param["setting"] == "default-profile": value_list = [] # Loop through profiles for profile_folder in [info.USER_PROFILES_PATH, info.PROFILES_PATH]: for file in os.listdir(profile_folder): # Load Profile and append description profile_path = os.path.join(profile_folder, file) profile = openshot.Profile(profile_path) value_list.append({ "name": profile.info.description, "value": profile.info.description }) # Sort profile list value_list.sort(key=operator.itemgetter("name")) # Overwrite value list (for audio device list dropdown) if param["setting"] == "playback-audio-device": value_list = [] # Loop through audio devices value_list.append({"name": "Default", "value": ""}) for audio_device in get_app().window.preview_thread.player.GetAudioDeviceNames(): value_list.append({ "name": "%s: %s" % ( audio_device.type, audio_device.name), "value": audio_device.name, }) # Overwrite value list (for language dropdown) if param["setting"] == "default-language": value_list = [] # Loop through languages for locale, language, country in get_all_languages(): # Load Profile and append description if language: lang_name = "%s (%s)" % (language, locale) value_list.append({ "name": lang_name, "value": locale }) # Sort profile list value_list.sort(key=operator.itemgetter("name")) # Add Default to top of list value_list.insert(0, { "name": _("Default"), "value": "Default" }) # Overwrite value list (for hardware acceleration modes) os_platform = platform.system() if param["setting"] == "hw-decoder": for value_item in list(value_list): v = value_item["value"] # Remove items that are operating system specific if os_platform == "Darwin" and v not in ("0", "5", "2"): value_list.remove(value_item) elif os_platform == "Windows" and v not in ("0", "3", "4"): value_list.remove(value_item) elif os_platform == "Linux" and v not in ("0", "1", "2", "6"): value_list.remove(value_item) # Remove hardware mode items which cannot decode the example video log.debug("Preparing to test hardware decoding: %s" % (value_list)) for value_item in list(value_list): v = value_item["value"] if (not self.testHardwareDecode(value_list, v, 0) and not self.testHardwareDecode(value_list, v, 1)): value_list.remove(value_item) log.debug("Completed hardware decoding testing") # Replace %s dropdown values for hardware acceleration if param["setting"] in ("graca_number_en", "graca_number_de"): for card_index in range(0, 3): # Test each graphics card, and only include valid ones if card_index in self.hardware_tests_cards and self.hardware_tests_cards.get(card_index): # Loop through valid modes supported by this card for mode in self.hardware_tests_cards.get(card_index): # Add supported graphics card for each mode (duplicates are okay) if mode == 0: # cpu only value_list.append({ "value": card_index, "name": _("No acceleration"), "icon": mode }) else: # hardware accelerated value_list.append({ "value": card_index, "name": _("Graphics Card %s") % (card_index + 1), "icon": mode }) if os_platform in ["Darwin", "Windows"]: # Disable graphics card selection for Mac and Windows (since libopenshot # only supports device selection on Linux) widget.setEnabled(False) widget.setToolTip(_("Graphics card selection not supported in %s") % os_platform) # Add normal values box_index = 0 for value_item in value_list: k = value_item["name"] v = value_item["value"] i = value_item.get("icon", None) # Override icons for certain values # TODO: Find a more elegant way to do this icon = None if k == "Linux VA-API" or i == 1: icon = QIcon(":/hw/hw-accel-vaapi.svg") elif k == "Nvidia NVDEC" or i == 2: icon = QIcon(":/hw/hw-accel-nvdec.svg") elif k == "Linux VDPAU" or i == 6: icon = QIcon(":/hw/hw-accel-vdpau.svg") elif k == "Windows D3D9" or i == 3: icon = QIcon(":/hw/hw-accel-dx.svg") elif k == "Windows D3D11" or i == 4: icon = QIcon(":/hw/hw-accel-dx.svg") elif k == "MacOS" or i == 5: icon = QIcon(":/hw/hw-accel-vtb.svg") elif k == "Intel QSV" or i == 7: icon = QIcon(":/hw/hw-accel-qsv.svg") elif k == "No acceleration" or i == 0: icon = QIcon(":/hw/hw-accel-none.svg") # add dropdown item if icon: widget.setIconSize(QSize(60, 18)) widget.addItem(icon, _(k), v) else: widget.addItem(_(k), v) # select dropdown (if default) if v == param["value"]: widget.setCurrentIndex(box_index) box_index = box_index + 1 widget.currentIndexChanged.connect(functools.partial(self.dropdown_index_changed, widget, param)) # Add Label and Widget to the form if (widget and label and filterFound): # Add minimum size label.setMinimumWidth(180) label.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred) widget.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred) # Create HBox layout layout_hbox = QHBoxLayout() layout_hbox.addWidget(label) layout_hbox.addWidget(widget) if (extraWidget): layout_hbox.addWidget(extraWidget) # Add widget to layout tabWidget.layout().addLayout(layout_hbox) elif (label and filterFound): # Add widget to layout tabWidget.layout().addWidget(label) # Add stretch to bottom of layout tabWidget.layout().addStretch() # Delete all tabs and widgets self.DeleteAllTabs(onlyInVisible=True)