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

paneldue: add support for virtual macro folders #342

Closed
wants to merge 3 commits into from

Conversation

OasisOfChaos
Copy link

Added support for custom macro display names and a virtual folder structure.

Signed-off-by: Alex [email protected]

Added support for custom display names and a virtual folder structure.

Signed-off-by:  Alex <[email protected]>
@@ -5,6 +5,7 @@
# This file may be distributed under the terms of the GNU GPLv3 license.

from __future__ import annotations
from xmlrpc.client import boolean
Copy link
Owner

Choose a reason for hiding this comment

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

I believe that this is an unintentional import, likely pulled in from an annotation below.

@@ -38,12 +39,14 @@
MIN_EST_TIME = 10.
INITIALIZE_TIMEOUT = 10.


Copy link
Owner

Choose a reason for hiding this comment

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

Please don't submit changes to whitespace in pull requests. Moonraker follows the same standard as Klipper here, code style and whitespace changes aren't accepted unless they are made by the original author of the module.

self.confirmed_macros: Dict[str, str] = {}
# self.confirmed_macros = {
# "RESTART": "RESTART",
# "FIRMWARE_RESTART": "FIRMWARE_RESTART"}
Copy link
Owner

Choose a reason for hiding this comment

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

I would like to keep the RESTART and FIRMWARE_RESTART as default options.

if cmd == "M98":
script = sgc_func(parts)
else:
script = sgc_func(parts[1:])
Copy link
Owner

Choose a reason for hiding this comment

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

This doesn't appear necessary. In the M98 handler doesn't need parts[0], as that is just the command itself.

@@ -760,6 +773,44 @@ def _run_paneldue_M20(self, arg_p: str, arg_s: int = 0) -> None:
response['files'] = flist
self.write_response(response)

def get_macro_dir(self, path: str, issubdir: boolean):
Copy link
Owner

Choose a reason for hiding this comment

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

The boolean annotation is incorrect here, it should be bool. The return value also needs to be annotated.

for key, value in self.available_macros.items():
if value == macro:
cmd = key
logging.info(f"Trying to run macro '{cmd}'...")
Copy link
Owner

Choose a reason for hiding this comment

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

This should be debug level logging.

@Arksine
Copy link
Owner

Arksine commented Jan 25, 2022

I left some review comments above. At a high level we may need to look into an alternative method of configuration as its possible for macro parameters to contain commas.

Also your signed off line needs to contain your full name.

Thanks.

@OasisOfChaos
Copy link
Author

I've modified my working copy with your comments. It' my first Python project so bear with me please ;-). Also, I'm at about 98% of implementing the new object model that's used in firmware 3.3 and newer. Only things to do is multiple chamber heaters/generic heaters and some more testing with different configurations.

I left some review comments above. At a high level we may need to look into an alternative method of configuration as its possible for macro parameters to contain commas.

True. Was thinking about gcode only and forgot about the Klipper parameters. In my working copy I'm using a '|' now, but if you find this a hacky solution and got another suggestion I can implement that as well.

I thought about a list of key/value pairs under macros: but the delimiters cannot be brackets of course (but {}'s maybe?). This may be confusing for a user and doesn't really fit in the current config methods. Splitting the two into fields may also be a possibility but that can get messy fast, I guess. As of now, I unfortunately don't see an really elegant way of doing this and hope you or someone else does.

@Arksine
Copy link
Owner

Arksine commented Jan 28, 2022

Not a problem. We are a bit limited by the ini file structure here. I think to be reliable we need to set strict requirements on folder names. We could do something like the following:

macros:
  STATUS
  -my sounds
    @"test beep" PANELDUE_BEEP FREQUENCY=500 DURATION=1
  -calibration
    Z_TILT
    @bedmesh BED_MESH_CALIBRATE
    QUAD_GANTRY_LEVEL

In this example, folders must be prefixed by "-" and be on one line. We can identify an alias for a macro with an @. Aliases must either contain no whitespace or be quoted. Honestly it might be better to just restrict it to no whitespace. If no alias is available we fall back on the Macro's primary name.

To my knowledge macros cant start with a - or @, so we shouldn't have any conflicts. Implementation shouldn't be too difficult, parsing the option may need a recursive call to handle subfolders.

With regard to adding support for the new object model, that is ok, however we want that in a different pull request. Also we don't want to break compatibility with the existing model, so either the module needs to autodetect which model to use or it needs to be a config option.

@OasisOfChaos
Copy link
Author

Thanks. I propose to just make quotes mandatory after a '@' alias. That way a user has the freedom to choose whether to use whitespaces or not. Personally, I like spaces in my display instead of underscores or nameswithoutanything ;-)

Would it be acceptable to close this PR and just add this functionality to the version with the new object model and link it to this #95 feature request? BTW, the current version is already fully backwards compatible and will detect what responses to send. I am currently testing with the 3 main versions 1.24, 3.3 and 3.4.0.

@Arksine
Copy link
Owner

Arksine commented Jan 28, 2022

That is fine, I would only ask that changes be separated into commits that clearly define the changes made, ie: a commit for adding virtual folders, a commit for adding 3.x support, etc. I'm guessing that 3.x support is a sizable change.

@OasisOfChaos
Copy link
Author

In this example, folders must be prefixed by "-" and be on one line. We can identify an alias for a macro with an @. Aliases must either contain no whitespace or be quoted. Honestly it might be better to just restrict it to no whitespace. If no alias is available we fall back on the Macro's primary name.

Unfortunately, this is not going to work with the current ConfigHelper class (and the underlying RawConfigParser. Your solution is dependent on multi-level parsing for subdirectories and that is not supported (all spaces are stripped in a very early stage (in RawConfigParser.get()) and will require a significant change imo.

macros:
  STATUS
  /my sounds
    @"test beep" PANELDUE_BEEP FREQUENCY=500 DURATION=1
  /my sounds/subsounds
    @"test beep a" PANELDUE_BEEP FREQUENCY=500 DURATION=1
    @"test beep b" PANELDUE_BEEP FREQUENCY=500 DURATION=1
  /calibration
    Z_TILT
    @bedmesh BED_MESH_CALIBRATE
    QUAD_GANTRY_LEVEL

This would be parsable while retaining the a folder structure and require no change in the ConfigHelper class. It also has the benefit of using the character that is commonly used for directories. Would this be something you can live with?

@Arksine
Copy link
Owner

Arksine commented Jan 29, 2022

You solution looks good. I agree its more clear for users and easier to parse as it doesn't require recursion.

@Arksine
Copy link
Owner

Arksine commented Sep 6, 2024

Since it appears that development on this has stalled, I'm closing this for the time being. Thanks.

@Arksine Arksine closed this Sep 6, 2024
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.

2 participants