Skip to content

Commit 4c7af05

Browse files
committed
Adding Profile search button to Preferences for easier filtering and searching for a default profile
1 parent c95e9a9 commit 4c7af05

File tree

1 file changed

+57
-2
lines changed

1 file changed

+57
-2
lines changed

src/windows/preferences.py

+57-2
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ def Populate(self, filter=""):
255255

256256
# create spinner
257257
widget = QComboBox()
258+
widget.setSizeAdjustPolicy(QComboBox.AdjustToMinimumContentsLengthWithIcon)
258259

259260
# Get values
260261
value_list = param["values"]
@@ -275,6 +276,12 @@ def Populate(self, filter=""):
275276
"value": profile.info.description
276277
})
277278

279+
# Add test button
280+
extraWidget = QPushButton()
281+
extraWidget.setToolTip(_("Search Profiles"))
282+
extraWidget.setIcon(QIcon(":/icons/Humanity/mimes/16/video-x-generic.svg"))
283+
extraWidget.clicked.connect(functools.partial(self.btnBrowseProfiles_clicked, widget))
284+
278285
# Overwrite value list (for audio device list dropdown)
279286
if param["setting"] == "playback-audio-device":
280287
value_list = []
@@ -339,8 +346,8 @@ def Populate(self, filter=""):
339346
# Add normal values
340347
box_index = 0
341348
for value_item in value_list:
342-
k = value_item["name"]
343-
v = value_item["value"]
349+
k = value_item.get("name")
350+
v = value_item.get("value")
344351
i = value_item.get("icon", None)
345352

346353
# Translate dropdown item (if needed)
@@ -550,6 +557,54 @@ def dropdown_index_changed(self, widget, param, index):
550557
# Check for restart
551558
self.check_for_restart(param)
552559

560+
def btnBrowseProfiles_clicked(self, widget):
561+
"""Search profile button clicked"""
562+
# Get current selection profile object
563+
profile_description = widget.currentData()
564+
565+
# Find matching profile path
566+
matching_profile_path = None
567+
for profile_folder in [info.USER_PROFILES_PATH, info.PROFILES_PATH]:
568+
for file in reversed(sorted(os.listdir(profile_folder))):
569+
# Load Profile and append description
570+
matching_profile_path = os.path.join(profile_folder, file)
571+
if os.path.isdir(matching_profile_path):
572+
continue
573+
profile = openshot.Profile(matching_profile_path)
574+
if profile.info.description == profile_description:
575+
break
576+
577+
# Load matching profile
578+
current_profile = openshot.Profile(matching_profile_path)
579+
580+
# Show dialog (init to current selection)
581+
from windows.profile import Profile
582+
log.debug("Showing profile dialog")
583+
win = Profile(current_profile.Key())
584+
# Run the dialog event loop - blocking interaction on this window during this time
585+
result = win.exec_()
586+
587+
profile = win.selected_profile
588+
if result == QDialog.Accepted and profile:
589+
590+
# select the project's current profile
591+
profile_index = self.getVideoProfileIndex(widget, profile)
592+
if profile_index != -1:
593+
# Re-select project profile (if found in list)
594+
widget.setCurrentIndex(profile_index)
595+
else:
596+
# Previous profile not in list, so
597+
# default to first profile in list
598+
widget.setCurrentIndex(0)
599+
600+
def getVideoProfileIndex(self, widget, profile):
601+
"""Get the index of a profile name or profile key (-1 if not found)"""
602+
for index in range(widget.count()):
603+
combo_profile_description = widget.itemData(index)
604+
if profile.info.description == combo_profile_description:
605+
return index
606+
return -1
607+
553608
def testHardwareDecode(self, widget, param, btn):
554609
"""Test specific settings for hardware decode"""
555610
all_decoders = param.get("values", [])

0 commit comments

Comments
 (0)