cameroncros / OctoPrint-DiscordRemote

Discord plugin for OctoPrint
MIT License
68 stars 32 forks source link

Initial Implementation of Thumbnail Parsing #231

Open Dealman opened 1 year ago

Dealman commented 1 year ago

If the with_snapshot option for printing_started is False, it will now try and parse the GCODE for a thumbnail. So far, this is only tested with models sliced using Ultimaker Cura.

image

I wanted to contain this in a separate script to keep the __init__ clean from changes, but I was unable to get it to work due to the file manager. No idea how that thing works, but it will not work in a standalone script, only in __init__.

This most definitely will need some work to support other formats, this could be a very good reference.

Will need some examples and I'll add them myself, to ensure they work. Might ask on some subreddit if I can get some examples.

I've tested with a few various sliced models of my own and it seems to be solid enough. And if it fails to parse the thumbnail, it's caught and snapshot will be None - in other words, no embedded image.

Dealman commented 1 year ago

Eh, thought I'd be able to make 2 separate pull requests. Guess not... 🤦‍♂️

I went ahead and fixed the color parameter issue mentioned in #219. It now supports both an integer value and a string. #FF0000 and FF0000 are both valid now.

cameroncros commented 1 year ago

Eh, thought I'd be able to make 2 separate pull requests. Guess not... man_facepalming

I went ahead and fixed the color parameter issue mentioned in #219. It now supports both an integer value and a string. #FF0000 and FF0000 are both valid now.

I think you can do that, but its not easy with github. If you create a new branch for each feature you want to pull request that usually works.

cameroncros commented 1 year ago

Overall, mostly looks good. Could you look at making the thumbnail an option in the web interface?

image

This should hopefully make it clearer when the thumbnail will be included or not

Dealman commented 1 year ago

initialise print_thumbnail to None at the start of this function, otherwise it will cause unbound errors like:

Huh, I was trying this since I saw you pre-defined snapshot = None, but during my testing I never ran into that error. Maybe it behaves differently when testing via test.sh...? print_thumbnail is also a new parameter of send_message, being either None if it fails to parse a thumbnail, or a (in this case) Base64 string containing a PNG. So I assumed this would kind of already define it? Python is still very new to me and the syntax makes me wanna 🙃🔫

Either way, simple fix! 👍

Overall, mostly looks good. Could you look at making the thumbnail an option in the web interface?

Most certainly, this is something I was considering myself. But how should the logic work if both options are toggled since AFAIK we can only embed one image?

One workaround I can think of would be to use 3x radio buttons; None, Snapshot and Thumbnail?

cameroncros commented 1 year ago

One workaround I can think of would be to use 3x radio buttons; None, Snapshot and Thumbnail?

That sounds like a reasonable solution.

Manichee commented 1 year ago

Any updates on this. I think this would be neat to have on the print start.

cameroncros commented 1 year ago

No update, probably still needs some work to get this into a mergable state. I havent had time to work on it (was kinda hoping someone else would do it :/ )

On Tue, 19 Sept 2023, 6:32 am Manichee, @.***> wrote:

Any updates on this. I think this would be neat to have on the print start.

— Reply to this email directly, view it on GitHub https://github.com/cameroncros/OctoPrint-DiscordRemote/pull/231#issuecomment-1724328934, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAK7FL7RPWB5TISQZLGJKFLX3CVVVANCNFSM6AAAAAASM2CUMU . You are receiving this because you commented.Message ID: @.***>

Dealman commented 1 year ago

Sadly no, my printer has been out of commission for a while and haven't had the energy to fix it. So haven't found much reason to continue working on this.

As far as I can recall, it does work with thumbnails generated by Cura, it's just a simple Base64 encoding.

My issue was the whole web development side of things, a combination of wrapping my head around how Python and Jinja works - so eventually just gave up on that part and moved onto other projects.

If anyone ever picks up on this, here's how I imagine things should go;

  1. User should be able to swap whether to use a Snapshot (camera) or a Thumbnail (embedded in gcode). Ideally this should utilize radio buttons, for example; None, Snapshot and Thumbnail?

  2. I would imagine slicers may generate their thumbnails differently, so potentially necessary to try and figure out which slicer was used and decode accordingly. Potential fallback solution would be to have the user manually select the slicer they use?

I never got around to verifying 2 as I solely used Cura.

I still want to fix my printer, just need to find the time and energy to do so. Once I get it all back up and running, I might return to finally try and implement this properly - unless someone else manages to do so before me. 😃 👍