<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># -------------------------------------------------------------------------
# MAX VEL OVERRIDE actions
# -------------------------------------------------------------------------

class max_velocity:
    """Max Velocity Group"""
    @staticmethod
    def set(value):
        """Max Velocity Override Set Value"""
        CMD.maxvel(float(value) / 60)
        #rapid mods
    
    @staticmethod
    def reset():
        """Max Velocity Override Reset Value"""
        CMD.maxvel(INFO.maxVelocity() / 60)

    @staticmethod
    def zero():
        # Sets MAX_VELO to 75% of max from ini file settings
        """MAX_VELO_5%"""
        c_val = (INFO.maxVelocity() / 60) # Get current MV static param from ini
        set_val = 5
        CMD.maxvel(float(set_val))

    @staticmethod
    def twentyfive():
        # Sets MAX_VELO to 75% of max from ini file settings
        """MAX_VELO_25%"""
        c_val = (INFO.maxVelocity() / 60) # Get current MV static param from ini
        set_val = c_val * .25
        CMD.maxvel(float(set_val))

    @staticmethod
    def fifty():
        # Sets MAX_VELO to 50% of max from ini file settings
        """MAX_VELO_50%"""
        c_val = (INFO.maxVelocity() / 60) # Get current MV static param from ini
        set_val = c_val * .5
        CMD.maxvel(float(set_val))

    @staticmethod
    def seventyfive():
        # Sets MAX_VELO to 75% of max from ini file settings
        """MAX_VELO_75%"""
        c_val = (INFO.maxVelocity() / 60) # Get current MV static param from ini
        set_val = c_val * .75
        CMD.maxvel(float(set_val))

    @staticmethod
    def hundred():
        # Sets MAX_VELO to 100% of max from ini file settings
        # Used because reset disbales the button when not ready. Preserve UI look and feel for the group.
        """MAX_VELO_100%"""
        c_val = (INFO.maxVelocity() / 60) # Get current MV static param from ini
        set_val = c_val * 1
        CMD.maxvel(float(set_val))

        #end rapid mod

def _max_velocity_ok(value=100, widget=None):
    if STAT.task_state == linuxcnc.STATE_ON:
        ok = True
        msg = ""
    else:
        ok = False
        msg = "Machine must be ON to set max velocity"

    _max_velocity_ok.msg = msg

    if widget is not None:
        widget.setEnabled(ok)
        widget.setStatusTip(msg)
        widget.setToolTip(msg)

    return ok

def _max_velocity_bindOk(value=100, widget=None):

    # This will work for any widget
    STATUS.task_state.onValueChanged(lambda: _max_velocity_ok(widget=widget))

    try:
        # these will only work for QSlider or QSpinBox
        widget.setMinimum(0)
        widget.setMaximum(INFO.maxVelocity())

        try:
            widget.setSliderPosition(INFO.maxVelocity())
            STATUS.max_velocity.onValueChanged(
                lambda v: widget.setSliderPosition(v * 60))

        except AttributeError:
            widget.setValue(INFO.maxVelocity())
            STATUS.max_velocity.onValueChanged(
                lambda v: widget.setValue(v * 60))

    except AttributeError:
        pass
    except:
        LOG.exception('Error in max_velocity bindOk')

max_velocity.set.ok = max_velocity.reset.ok = _max_velocity_ok
max_velocity.set.bindOk = max_velocity.reset.bindOk = _max_velocity_bindOk


</pre></body></html>