Skip to content

Conversation

@Dealman
Copy link

@Dealman Dealman commented Nov 28, 2022

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
Copy link
Author

Dealman commented Nov 28, 2022

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
Copy link
Owner

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 cameroncros changed the base branch from master to dev November 29, 2022 07:11
# Attempt to parse potential thumbnail
if event_id == "printing_started" and self.get_gcode_format(data["path"]):
self._logger.info("Print appears to have a thumbnail, trying to parse")
print_thumbnail = self.get_thumbnail_cura(data["path"])
Copy link
Owner

Choose a reason for hiding this comment

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

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

Traceback (most recent call last):
  File "/home/cameron/Projects/OctoPrint-DiscordRemote-Dealman/testenv/lib/python3.10/site-packages/octoprint/plugin/__init__.py", line 273, in call_plugin
    result = getattr(plugin, method)(*args, **kwargs)
  File "/home/cameron/Projects/OctoPrint-DiscordRemote-Dealman/testenv/lib/python3.10/site-packages/octoprint/util/__init__.py", line 1694, in wrapper
    return f(*args, **kwargs)
  File "/home/cameron/Projects/OctoPrint-DiscordRemote-Dealman/octoprint_discordremote/__init__.py", line 311, in on_event
    return self.notify_event("startup")
  File "/home/cameron/Projects/OctoPrint-DiscordRemote-Dealman/octoprint_discordremote/__init__.py", line 462, in notify_event
    return self.send_message(event_id, tmp_config["message"].format(**data), tmp_config["with_snapshot"], print_thumbnail)
UnboundLocalError: local variable 'print_thumbnail' referenced before assignment

Copy link
Owner

Choose a reason for hiding this comment

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

Something like:

        # Attempt to parse potential thumbnail
        print_thumnail = None
        if event_id == "printing_started" and self.get_gcode_format(data["path"]):
            self._logger.info("Print appears to have a thumbnail, trying to parse")
            print_thumbnail = self.get_thumbnail_cura(data["path"])

@cameroncros
Copy link
Owner

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
Copy link
Author

Dealman commented Nov 29, 2022

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
Copy link
Owner

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

That sounds like a reasonable solution.

@cameroncros cameroncros force-pushed the dev branch 7 times, most recently from b3800b9 to eb986ae Compare April 18, 2023 16:47
@cameroncros cameroncros force-pushed the dev branch 3 times, most recently from 6b6a3bc to 9653879 Compare June 30, 2023 01:17
@Manichee
Copy link

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

@cameroncros
Copy link
Owner

cameroncros commented Sep 19, 2023 via email

@Dealman
Copy link
Author

Dealman commented Sep 19, 2023

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. 😃 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants