Jump to content

JJFX

Member
  • Posts

    6
  • Joined

  • Last visited

Personal Information

  • 3D printer
    Other 3D printer

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

JJFX's Achievements

0

Reputation

  1. No problem, it is a bit convoluted. Basically I was trying to accomplish something like the 'value' of "klipper_retract_speed" below. Since this doesn't seem possible, I was looking for a way to do it after the fact in Python. "klipper_retraction_speed": { "label": "Retraction Speed", "description": "...", "type": "float", "unit": "mm/s", "default_value": 0, "value": "retraction_speed", "children": { "klipper_retract_speed": { "label": "Retract Speed", "description": "...", "type": "float", "unit": "mm/s", "default_value": 0, "value": "klipper_retraction_speed" if hasUserValue('klipper_retraction_speed') else "retraction_retract_speed", }, Hopefully that makes sense. Admittedly, I'm realizing I should just take a break and reevaluate. It would make more sense to remove parent settings and simply avoid situations like this entirely. I'm curious if there is a way to do it but I think I'm making things unnecessarily complicated. Apologies for wasting your time.
  2. Thank you Aldo, I don't think my question was very clear. If I understand correctly, I believe you're referring to the initial setting definition. My issue is that I've already defined the inheritance for such settings. In this example, the initial values are defined by Cura's retraction settings but I'm trying to change the inheritance in Python after the user modifies a value as described above. "klipper_retraction_speed": { "label": "Retraction Speed", "description": "The speed in mm/s which...", "type": "float", "unit": "mm/s", "default_value": 0, "value": "retraction_speed", "minimum_value": "0", "minimum_value_warning": "5 if klipper_retract_speed >= 1 or klipper_retract_prime_speed >= 1 else 0", "maximum_value_warning": "99", "enabled": "resolveOrValue('machine_firmware_retract')", "settable_per_mesh": false, "settable_per_extruder": true, "children": { "klipper_retract_speed": { "label": "Retract Speed", "description": "The speed at which...", "type": "float", "unit": "mm/s", "default_value": 0, "value": "retraction_retract_speed", "minimum_value": "0", "minimum_value_warning": "5 if klipper_retract_speed >= 1 else 0", "maximum_value_warning": "99", "enabled": "resolveOrValue('machine_firmware_retract')", "settable_per_mesh": false, "settable_per_extruder": true }, So my question is, is there way to easily adjust the value in Python so it's recognized as an expression or is this simply too unorthodox? If there is, there are a few other situations where I'd like to implement this as well. For reference, here is the repo for the plugin I'm working on. I truly appreciate the help!
  3. The plugin I'm developing adds a number of new settings to a new settings category. Some of them mirror other Cura settings by default and I'd like to change their relations once a user has modified a value. For example, if the user defines a parent setting I'd like its children to now automatically follow the modified parent instead of their initial value function. Setting the value property seems to only accept defined values and I'm hitting a wall trying to get around this without needing to remaking setting definitions every time. To clarify, here's a basic example of what I'd like to do... ## Following onExtruderSettingChanged function: extruder_stack = self._application.getExtruderManager().getActiveExtruderStack() is_user_value = extruder_stack.hasUserValue(setting) if setting == "klipper_retraction_speed" and is_user_value: for child in ["klipper_retract_speed", "klipper_retract_prime_speed"]: extruder_stack.setProperty(child, 'value', "klipper_retraction_speed") I'm currently using a crude workaround that detects the change, compares previous values then manually sets the children to the parent value but this isn't ideal and a bit buggy. I suspect there's an obvious solution I'm overlooking but this one is getting the best of me :) I'd greatly appreciate any insight, thanks! JJ
  4. Haha! What, was that your bat signal?! I mention your name, go grab a snack and by the time I get back you've already completely put my hours of work to shame. However, using Application threw an error so I did need to fix something! This works and it's a painfully easy solution... because of course it is! from PyQt6.QtCore import QUrl # Use PyQt5 for older Cura versions from UM.Qt.Bindings.Theme import Theme theme = Theme.getInstance() detail_level = "default" icon_name = "test" icon_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "icons", "test.svg") theme._icons[detail_level][icon_name] = QUrl.fromLocalFile(icon_path) A bit of a moot point now but I thought my solution was safe specifically because it wasn't changing the user's preference. It should only be reading the existing theme name so it can inherit it through my 'stub' theme file. The only preference it could set was to the default theme if there wasn't an active theme anyway. Thanks for the help!
  5. Thanks for the reply Cuq! I actually saw your post but since my plugin doesn't need to use qml I don't believe I could really solve it this way without adding more complexity. I did initially attempt to use QUrl but that was pointless. I'm fairly confident now there's no way to use any file path for the setting parameter because when the theme loads it only obtains icons after confirming the existence of a theme.json file. Then it simply looks for an icons folder using that same path. However... after spending entirely too much time on this and nearly giving up, I found a solution! I'll try to break it down for the sake of the next person... Basically, there must be a folder in the plugin directory with a 'theme.json' and an '/icons/default' directory containing any new icons. I'm using other resources so I simply added a 'themes' folder to a 'resources' directory. The theme.json can contain any necessary data but must at least include metadata with an "inherits" property. Any name is fine because it'll immediately get changed anyway. Stripping it down this much does ensure Cura will throw an error if it's ever used as a normal theme file. { "metadata": { "inherits": "cura-light" } } Here's my proof of concept to get it working: # Directory containing theme.json: /resources/themes # Directory containing icons: /resources/themes/icons/default # "icon" param must be the filename without the extension (e.g. Awesome.svg = "Awesome"). # Additional module requried to force a theme to load from a path from UM.Qt.Bindings.Theme import Theme # Path to 'resources' dir resource_path = os.path.join(os.path.dirname(__file__), 'resources') self._updateTheme(resource_path) def _updateTheme(self, theme_path: str) -> None: application = CuraApplication.getInstance() preferences = application.getPreferences() # Get name of current theme or set to default if none exist preferences.addPreference('general/theme', application.default_theme) current_theme_name = preferences.getValue('general/theme') # Path to 'theme.json' resource_theme = os.path.join(theme_path, 'themes', 'theme.json') with open(resource_theme) as f: metadata = json.load(f) # Empty theme used only for metadata metadata['metadata']['inherits'] = current_theme_name with open(resource_theme, 'w') as f: json.dump(metadata, f, indent = 4) # Rewrite with current theme to inherit # Force load inherited theme so Cura will include local resources Theme.getInstance().load(path = os.path.join(theme_path, 'themes')) The most critical part being the last line which forces the local theme to load. I assume it wasn't intended to be used this way, it would be nice if Cura just honored the items in a plugin's resource path . This should allow a user to even continue using a custom theme without issue. It could certainly be improved and the theme.json file could even get created by the function so there's no chance of getting deleted. This is usually about the time I realize fieldOfView had a far more efficient solution to my problem but unless that happens, perhaps the setting parameter documentation should be updated :)
  6. I've written a plugin for Cura that creates a new setting category and adds a number of special settings to it. Everything is functioning as intended (after a lot of trial and error) but I haven't figured out how to get Cura to read a custom category icon from the plugin folder. The only way I've been able to get it working is by including a Resources search path, adding the icon to the appropriate folder in a local themes directory and creating a theme.json that just inherits a default theme. The only new file in the directory is my icon but Cura doesn't seem to want to read it without using a new theme. This isn't really a practical solution just to get an icon working. Of course adding the icon directly to the master files works but that's not a good idea either. The settings properties documentation indicates the "icon" property accepts a file path but if that's still true I can't figure out what it's looking for. There's also this comment in the Themes file under getIcon() indicating there's fallback behavior to load icons from a plugin folder. I'd very much appreciate if someone could point me in the right direction. Hopefully there's a simple solution I've missed. Thanks!
×
×
  • Create New...