示例#1
0
def make_call_string(commands, position):
    '''
  Make Python code for a call to named procedure or macro, with parameters.
  !!! For internal procedure, plugin, or macro.  But there are subtle differences.
  
  Note that for a plugin,  in the PDB, the first three parameters are always run-mode, image, and drawable.
  But Pygimp requires run-mode as a keyword arg
  '''
    command = commands.get_command_for(position)
    parms = commands.get_parms_for(position)

    # transliterate _ => - in name
    # Because in Python, - is subtraction operator, can't be used in names.
    underbar_name = command.name.replace("-", "_")

    wrapping_type = what_wrapping_type(command, parms)

    if parse_params.has_runmode(parms):
        # PDB procedure of type Plugin except for those whose name begins with 'file-'
        if wrapping_type == WRAPPING_TYPE_LAST:
            run_mode_string = "run_mode=RUN_WITH_LAST_VALS"
        else:
            run_mode_string = "run_mode=RUN_NONINTERACTIVE"
    else:  # PDB procedure of type Internal Procedure or a Plugin whose name begins with 'file-'
        run_mode_string = ""

    # TODO condense this and refactor into a subroutine
    if wrapping_type == WRAPPING_TYPE_DEFERRED:
        # A mix of author-user entered values, and names for deferred parameters.
        # !!! wrapping plugin will be INTERACTIVE, wrapped target will be NONINTERACTIVE
        paramstring = make_actual_nonhidden_params(
            parms)  # WAS make_deferred_params(parms)
    elif wrapping_type == WRAPPING_TYPE_CONSTANT:
        # All settings passed as constants.
        # author-user saw, and optionally changed, settings when creating wrapping plugin.
        # Both wrapping plugin and wrapped target will be NONINTERACTIVE, just "go"
        paramstring = make_actual_nonhidden_params(
            parms)  # WAS make_constant_actual_params(parms)
    elif wrapping_type == WRAPPING_TYPE_LAST:
        # Not Care parameters but tell wrapped to use last values.
        paramstring = make_NC_params(parms)
    else:
        raise RuntimeError, "Unknown wrapping type"

    if macros.is_macro(command.name):
        return generate_macro_call(command.name, parms)
    else:
        '''
    Generic form:  <LHS> = gimp.pdb.<NAME> ( <HIDDEN>, <PARMS>, run_mode=<MODE> )
    '''
        return make_LHS_string(command) \
          + PDB_INVOKE_PREFIX + underbar_name \
          + "( " + make_hidden_params(parms) \
          + paramstring \
          + run_mode_string \
          + ")"
示例#2
0
def make_call_string(commands, position):
  '''
  Make Python code for a call to named procedure or macro, with parameters.
  !!! For internal procedure, plugin, or macro.  But there are subtle differences.
  
  Note that for a plugin,  in the PDB, the first three parameters are always run-mode, image, and drawable.
  But Pygimp requires run-mode as a keyword arg
  '''
  command = commands.get_command_for(position)
  parms = commands.get_parms_for(position)
  
  # transliterate _ => - in name
  # Because in Python, - is subtraction operator, can't be used in names.
  underbar_name = command.name.replace("-", "_")
  
  wrapping_type = what_wrapping_type(command, parms)
  
  if parse_params.has_runmode(parms):
    # PDB procedure of type Plugin except for those whose name begins with 'file-'
    if wrapping_type == WRAPPING_TYPE_LAST:
      run_mode_string = "run_mode=RUN_WITH_LAST_VALS"
    else:
      run_mode_string = "run_mode=RUN_NONINTERACTIVE"
  else: # PDB procedure of type Internal Procedure or a Plugin whose name begins with 'file-'
    run_mode_string = ""
  
  # TODO condense this and refactor into a subroutine
  if wrapping_type == WRAPPING_TYPE_DEFERRED:
    # A mix of author-user entered values, and names for deferred parameters.
    # !!! wrapping plugin will be INTERACTIVE, wrapped target will be NONINTERACTIVE
    paramstring = make_actual_nonhidden_params(parms) # WAS make_deferred_params(parms)
  elif wrapping_type == WRAPPING_TYPE_CONSTANT:
    # All settings passed as constants.
    # author-user saw, and optionally changed, settings when creating wrapping plugin.
    # Both wrapping plugin and wrapped target will be NONINTERACTIVE, just "go"
    paramstring = make_actual_nonhidden_params(parms) # WAS make_constant_actual_params(parms)
  elif wrapping_type == WRAPPING_TYPE_LAST:
    # Not Care parameters but tell wrapped to use last values.
    paramstring = make_NC_params(parms)
  else :
    raise RuntimeError, "Unknown wrapping type"

  if macros.is_macro(command.name):
    return generate_macro_call(command.name, parms)
  else:
    '''
    Generic form:  <LHS> = gimp.pdb.<NAME> ( <HIDDEN>, <PARMS>, run_mode=<MODE> )
    '''
    return make_LHS_string(command) \
      + PDB_INVOKE_PREFIX + underbar_name \
      + "( " + make_hidden_params(parms) \
      + paramstring \
      + run_mode_string \
      + ")"
示例#3
0
def make_hidden_params(wrappedparms):
  '''
  Make a string of actual parameters for hidden parameters of a wrapped plugin.
  !!! Exclude run-mode
  '''
  # For each hidden param (excluding first, which is run_mode), map its type to string for canonical name.
  # tbd more to it, this is a trick, but not adequate?
  # tbd in future, it might be a reference to an earlier name returned from earlier step, ie stacked
  if parse_params.has_runmode(wrappedparms):
    start = 1
  else:
    start = 0
  return comma_separate([str(constantmaps._hidden_actual_map[parm.type]) for parm in parameters.get_parms_hidden(wrappedparms)[start:]])
示例#4
0
def make_hidden_params(wrappedparms):
    '''
  Make a string of actual parameters for hidden parameters of a wrapped plugin.
  !!! Exclude run-mode
  '''
    # For each hidden param (excluding first, which is run_mode), map its type to string for canonical name.
    # tbd more to it, this is a trick, but not adequate?
    # tbd in future, it might be a reference to an earlier name returned from earlier step, ie stacked
    if parse_params.has_runmode(wrappedparms):
        start = 1
    else:
        start = 0
    return comma_separate([
        str(constantmaps._hidden_actual_map[parm.type])
        for parm in parameters.get_parms_hidden(wrappedparms)[start:]
    ])