Skip to content

Commit

Permalink
Reimplemented the new C++ api calls and fixed related bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
wgergely committed Sep 15, 2024
1 parent 1219ec2 commit 4ac8d0f
Show file tree
Hide file tree
Showing 14 changed files with 513 additions and 174 deletions.
2 changes: 1 addition & 1 deletion bookmarks/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ def refresh(idx=None):
p = model.source_path()
source = '/'.join(p) if p else ''
assets_cache_dir = QtCore.QDir(f'{common.active("root", path=True)}/{common.bookmark_cache_dir}/assets')
if assets_cache_dir.exists():
if not assets_cache_dir.exists():
assets_cache_dir.mkpath('.')
assets_cache_name = common.get_hash(source)
cache = f'{assets_cache_dir.path()}/{assets_cache_name}.cache'
Expand Down
1 change: 1 addition & 0 deletions bookmarks/application_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ def item_generator(self):
) == QtWidgets.QDialog.Rejected:
return
actions.edit_bookmark()
return

for k in sorted(v, key=lambda idx: v[idx]['name']):
yield v[k]
Expand Down
94 changes: 35 additions & 59 deletions bookmarks/common/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,22 @@ def get_binary(binary_name):
"""Binary path getter.
The paths are resolved from the following sources and order:
- active bookmark item's application launcher items
- active bookmark item's app launcher items
- distribution folder's bin directory
- user settings
- environment variables in a ``{PREFIX}_{BINARY_NAME}`` format,
e.g. ``BOOKMARKS_FFMPEG``, or ``BOOKMARKS_RV``. These environment variables
should point to an appropriate executable, e.g.
for example ``BOOKMARKS_FFMPEG``, or ``BOOKMARKS_RV``. These environment variables
should point to an appropriate executable, for example
``BOOKMARKS_FFMPEG=C:/ffmpeg/ffmpeg.exe``
If the environment variable is absent, we'll look at the PATH environment to
If the environment variable is absent, look at the PATH environment to
see if the binary is available there.
Args:
binary_name (str): Name of a binary, lower-case, without spaces. E.g. `aftereffects`, `oiiotool`, `ffmpeg`, etc.
binary_name (str): Name of a binary, lower-case, without spaces. For example, `aftereffects`, `oiiotool`.
Returns:
str: Path to an executable binary, or `None` if the binary is not found in any of the sources.
str: Path to an executable binary, or `None` if the binary isn't found in any of the sources.
"""
# Sanitize the binary name
Expand All @@ -54,31 +55,45 @@ def get_binary(binary_name):
# Sanitize names, so they're all lower-case and without spaces
names = [re.sub(r'\s+', '', v['name']).lower().strip() for v in applications.values()]
if binary_name in names:
# We have a match, return the path
v = applications[names.index(binary_name)]['path']
if v and QtCore.QFileInfo(v).exists():
return v

# Check the user settings for possible values
v = get_user_setting(binary_name)
if v:
if v and QtCore.QFileInfo(v).exists():
return v


# Check the distribution folder for possible values
root = os.environ.get('Bookmarks_ROOT', None)

if root and QtCore.QFileInfo(root).exists():
bin_dir = QtCore.QFileInfo(f'{root}/bin')
if bin_dir.exists():
for entry in os.scandir(bin_dir.filePath()):
try:
if not entry.is_file():
continue
except:
continue

match = re.match(
rf'^{binary_name}$|{binary_name}\..+',
entry.name,
flags=re.IGNORECASE
)
if match:
return QtCore.QFileInfo(entry.path).filePath()

# Check the environment variables for possible values
key = f'{common.product}_{binary_name}'.upper()
if key in os.environ:
v = os.environ[key]
try:
if v and os.path.isfile(v):
return QtCore.QFileInfo(v).filePath()
except:
pass

v = _parse_dist_env(binary_name)
if v:
return v
v = _parse_path_env(binary_name)
v = os.environ.get(key, None)
if v and QtCore.QFileInfo(v).exists():
return QtCore.QFileInfo(v).filePath()

# Check the PATH environment for possible values
v = _parse_path_env(binary_name)
return v


Expand Down Expand Up @@ -107,45 +122,6 @@ def get_user_setting(binary_name):
return None


def _parse_dist_env(binary_name):
from . import env_key
if env_key not in os.environ:
return

v = os.environ[env_key]
if not QtCore.QFileInfo(v).exists():
return

def _scan_dir(v):
if not os.path.isdir(v):
print(f'{v} is not a directory')
return None
for entry in os.scandir(v):
try:
if not entry.is_file():
continue
except:
continue

match = re.match(
rf'^{binary_name}$|{binary_name}\..+',
entry.name,
flags=re.IGNORECASE
)
if match:
return QtCore.QFileInfo(entry.path).filePath()

return None

_v = _scan_dir(v)
if _v:
return _v
_v = _scan_dir(f'{v}/bin')
if _v:
return _v
return None


def _parse_path_env(binary_name):
items = {
os.path.normpath(k.lower()).strip(): QtCore.QFileInfo(k).filePath() for k
Expand Down
2 changes: 2 additions & 0 deletions bookmarks/common/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@
'ffmpeg/preset',
'ffmpeg/size',
'ffmpeg/timecode_preset',
'ffmpeg/sourcecolorspace',
'ffmpeg/targetcolorspace',
'ffmpeg/pushtorv',
),
'akaconvert': (
Expand Down
1 change: 1 addition & 0 deletions bookmarks/common/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import sys
import time

import OpenImageIO
from PySide2 import QtWidgets, QtGui

from .. import common
Expand Down
2 changes: 1 addition & 1 deletion bookmarks/editor/asset_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ def save_changes(self):
"""Saves changes.
"""
# When the asset is not set, we'll create one based on the name set
# When the asset isn't set, create one based on the name set
if not self.asset:
self.create_asset()

Expand Down
15 changes: 10 additions & 5 deletions bookmarks/editor/base_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@
@common.error
@common.debug
def process_image(source):
"""Converts, resizes and loads an image file as a QImage.
"""Converts, resizes, and loads an image file as a QImage.
Args:
source (str): Path to an image file.
Returns:
QImage: The resized QImage, or `None` if the image was not processed
QImage: The resized QImage, or `None` if the image wasn't processed
successfully.
"""
Expand All @@ -45,15 +45,20 @@ def process_image(source):
if not f.dir().mkpath('.'):
raise RuntimeError('Could not create temp folder')

res = bookmarks_openimageio.convert_image(
error = bookmarks_openimageio.convert_image(
source,
destination,
max_size=int(common.thumbnail_size)
source_color_space='',
target_color_space='sRGB',
size=int(common.thumbnail_size)
)
if not res:
if error == 1:
raise RuntimeError('Failed to convert the thumbnail')

# Flush cache
images.ImageCache.flush(source)
images.ImageCache.flush(destination)

image = images.ImageCache.get_image(
destination,
int(common.thumbnail_size),
Expand Down
Loading

0 comments on commit 4ac8d0f

Please sign in to comment.