Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVG thumbnail renderer #442

Closed
wants to merge 103 commits into from
Closed

Conversation

Tyrannicodin
Copy link
Contributor

@Tyrannicodin Tyrannicodin commented Sep 4, 2024

Adds an SVG renderer for thumbnails using Qt's QSvgRenderer that writes to a QImage that is written onto a QBuffer that PIL can then read as an image. However, it does have an issue that I have been unable to resolve: Sometimes thumbnails seem to write over each other or otherwise be corrupted (no affect on the actual files though). I think it's due to the QPainter painting in a thread, but I'm not sure.
You can see an example of this problem below:

Image no longer relevant

Creepler13 and others added 30 commits June 13, 2024 10:59
* Ability to drop local files in to TagStudio to add to library

* Added renaming option to drop import

* Improved readability and switched to pathLib

* format

* Apply suggestions from code review

Co-authored-by: yed podtrzitko <[email protected]>

* Revert Change

* Update tagstudio/src/qt/modals/drop_import.py

Co-authored-by: yed podtrzitko <[email protected]>

* Added support for folders

* formatting

* Progress bars added

* Added Ability to Drag out of window

* f

* format

* Ability to drop local files in to TagStudio to add to library

* Added renaming option to drop import

* Improved readability and switched to pathLib

* format

* Apply suggestions from code review

Co-authored-by: yed podtrzitko <[email protected]>

* Revert Change

* Update tagstudio/src/qt/modals/drop_import.py

Co-authored-by: yed podtrzitko <[email protected]>

* Added support for folders

* formatting

* Progress bars added

* Added Ability to Drag out of window

* f

* format

* format

* formatting and refactor

* format again

* formatting for mypy

* convert lambda to func for clarity

* mypy fixes

* fixed dragout only worked on selected

* Refactor typo, Add license

* Reformat QMessageBox

* Disable drops when no library is open

---------

Co-authored-by: yed podtrzitko <[email protected]>
Co-authored-by: Travis Abendshien <[email protected]>
…oDev#289)

* fix: python complaining about backslashes inside f-string expressions
refactor excessively long f-string into separate variables

* fix: missing f on f-string

* Format with Ruff
* Update thumb_renderer.py

Included support for rendering blender thumbnails

* Add files via upload

Add functions that get the thumbnail's data

* Update thumb_renderer.py

* Update blender_thumbnailer.py

* Update thumb_renderer.py

* Update thumb_renderer.py

Changed where imports are according to feedback

* Update thumb_renderer.py

Changed blender thumbnail function name to reduce ambiguity

* Update blender_thumbnailer.py

Updated function name

* Update blender_thumbnailer.py

* Update blender_thumbnailer.py

Ruff format

* Update thumb_renderer.py

Ruff format

* Update constants.py

Add .blend1, 2, 3 etc file support

* Update blender_thumbnailer.py

Refactor to follow requested changes

* Update thumb_renderer.py

More refactoring

* Update blender_thumbnailer.py

Ruff format

* Update thumb_renderer.py

Ruff format
* use list widget for selecting fields to add

* fix(ui): allow list widget resizing
* Fixed merge conflicts

* fixed format?

* Improve readability (Apply suggestions from code review)

Co-authored-by: yed podtrzitko <[email protected]>

* bug fix: Copy last selected not first

* Fix copy entanglement; Fix paste overwriting

* Change multi-selection copy to merge data

- Multi-selection copy now merges fields of all selected entries
- Action states are now handled

---------

Co-authored-by: yed podtrzitko <[email protected]>
Co-authored-by: Travis Abendshien <[email protected]>
* Add font thumbnail preview support

* Add multiple font sizes to thumbnail

* Ruff reformat

* Ruff reformat

* Added Metadata to info

* Change the way thumbnails are structured

* Small performance improvement

* changed Metadata display structure

* added copyright notice to added file

* fix(ui): dynamically scale font previews; add .woff2, .ttc

---------

Co-authored-by: Travis Abendshien <[email protected]>
- Fix RAW images not being loaded correctly in the preview panel
- Fix trying to read size data from null images
- Refactor `os.stat` to `<Path object>.stat()`
- Remove unnecessary upper/lower conversions
- Improve encoding compatibility beyond UTF-8 when reading text files
- Code cleanup
@Tyrannicodin Tyrannicodin marked this pull request as ready for review September 4, 2024 09:43
Copy link
Collaborator

@eivl eivl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once comments are addressed I approve.

@eivl
Copy link
Collaborator

eivl commented Sep 4, 2024

@CyanVoxel I wonder if a future change would make sense, add a context manager so that it handles the buildup and teardown of thumbnails.

@CyanVoxel CyanVoxel added Type: Enhancement New feature or request Type: UI/UX User interface and/or user experience labels Sep 4, 2024
CyanVoxel and others added 3 commits September 7, 2024 00:59
…#472)

* fix(PreviewPanel): Use birthtime for creation time

st_ctime does not provide accurate creation time on MacOS, and as of
Python 3.12 is deprecated for Windows. On these two platforms use
st_birthtime, but fall back to st_ctime on linux.

* mypy errors
* fix(ThumbRenderer): Use audio icon when no ffmpeg

When ffmpeg is missing, Popen raises a FileNotFound error. This would
be caught as an Unlinked file and use the broken file icon. The
exception is now caught and a more appropriate exception is raised in
its place.

* ruff formatting
@CyanVoxel CyanVoxel added this to the Alpha v9.5 (Post-SQL) milestone Sep 8, 2024
@CyanVoxel CyanVoxel mentioned this pull request Sep 9, 2024
3 tasks
CyanVoxel and others added 3 commits September 9, 2024 12:09
The cutoff for how many files get sorted also changes to 150,000.
* fix(QtDriver): Retain filter on directory refresh

* ruff formatting
* feat: increase file scanning performance

* fix: correct typo in comment

* refactor: use `continue` in place of nested `ifs`
@yedpodtrzitko
Copy link
Collaborator

nice work, but as always - when adding a new feature, please add a test.

For this one having some sample .svg image alongside the test, and then compare the output via syrupy that it really provides the expected output. I made a similar test in some other project, so it could look something like this:

from syrupy.extensions.image import PNGImageSnapshotExtension


def test_svg_to_png(snapshot):
    file_path = Path(__file__).parent / "fixtures" / "sample.svg"

    png_image = ThumbRenderer(...)._image_vector_thumb(file_path, 600)
    assert png_image.read() == snapshot(extension_class=PNGImageSnapshotExtension)

@yedpodtrzitko
Copy link
Collaborator

also what's the git branch thumbnails? Wouldnt be better to aim this either to the Alpha-9.4 or main?

Copy link
Collaborator

@yedpodtrzitko yedpodtrzitko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.


# Create an image to draw the svg to and a painter to do the drawing
image: QImage = QImage(size, size, QImage.Format.Format_ARGB32)
image.fill("#00000000")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would make it a bit more readable:

Suggested change
image.fill("#00000000")
image.fill(Qt.transparent)

image.save(buffer, "PNG")

# Load the image from the buffer
im: Image.Image = Image.open(BytesIO(buffer.data().data()))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
im: Image.Image = Image.open(BytesIO(buffer.data().data()))
im: Image.Image = Image.open(BytesIO(buffer.data()))

seakrueger and others added 3 commits September 13, 2024 17:25
* feat: Warn user if FFmpeg is not installed

Creates a Warning dialog on startup if the program cannot find FFmpeg or
FFprobe in the PATH. Other interactions with the program are blocked
until the issue is either ignore or resolved.

* docs: Add FFmpeg installation guide

* ruff formatting

* chore: Cleanup missing logic and warning message

* chore: Remove custom icon

Per QT docs, handling custom iconPixmap requires multiple icons per
platform. Easier to just use universal, default warning icon (yellow
triangle)

* fix: Ignore dialog with X button

* fix: Move startup checks after CI

* chore: Unreverse install check logic

* doc: Improve docs formatting

* docs: Point help url to new docs sites

* Remove ffmpeg docs page

* Use which from python stdlib
@CyanVoxel CyanVoxel changed the base branch from thumbnails to Alpha-v9.4 September 15, 2024 08:44
@CyanVoxel
Copy link
Member

I'm moved this PR from the deprecated thumbnails branch to Alpha-v9.4, which is the branch that thumbnails was eventually merged into. However the v9.4.x releases are now feature frozen and are now solely reserved for bugfixes. This means that after the changes from thumbnails are ported to main that I'll once again be moving the target for this PR over to there as a v9.5 feature.

Sorry for the disruption, and thank you for your patience.

@CyanVoxel CyanVoxel changed the base branch from Alpha-v9.4 to main October 7, 2024 22:19
CyanVoxel added a commit that referenced this pull request Oct 14, 2024
* feat: add svg thumbnail support

Co-Authored-By: Tyrannicodin <[email protected]>

* flip `svg.isValid()` logic check

* tests: add test comparing svg to png snapshot

Co-Authored-By: yed <[email protected]>

---------

Co-authored-by: Tyrannicodin <[email protected]>
Co-authored-by: yed <[email protected]>
@CyanVoxel
Copy link
Member

I've ported this functionality to main via #540, thank you for your contribution with this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement New feature or request Type: UI/UX User interface and/or user experience
Projects
None yet
Development

Successfully merging this pull request may close these issues.