Example #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 \
          + ")"
Example #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 \
      + ")"
Example #3
0
 def has_in_params(self):
     """
 Does any command have hidden params that are not run-mode?
 This must be command by command, it can't be just over the aggregate parameter list.
 """
     for command in self.command_list:
         # Assume all macros access hidden params
         # TODO take all this special case code out, just ask the command and have subclasses.
         if macros.is_macro(command.name):
             return True
         else:
             # Not a macro, look at the params for this command
             # Alternatively we could call the pdb for the pdefs
             if parse_params.count_nonrunmode_hidden_params(self.param_list.get_parms_for(command.position)):
                 return True
     return False
Example #4
0
def append_gimp_internal_procedures(plugindb):
    '''
  Supplement given dictionary with a subset of gimp internal procedures.
  Subset is: only those most useful to plugin creators.
  
  Cases for whether internal procedure have menupath presence in Gimp menus:
  
  - No : we fabricate a menu item.
  - Yes: no programmatic way to discern, we hand coded corresponding Gimp menu item.
  
  Minimal procedure descriptors: having at least:
  
  - the attribute declared in viewspec: menupath
  - imagetype
  
  Pygimp pdb does not expose the imagetype as attribute of a PDB function.
  gimp-procedural-db-query also does not return the imagetype.
  Imagetype blank or "*" means available for all image types.
  TODO decide whether some internal procedures have imagetype contraints.
  gimp-flatten does not apply when there IS no alpha, and throws an exception?
  '''
    for menupath, procname in map_procedures.menu_to_procname.items():
        if procname in plugindb:
            print "Supplemental menu ", menupath, " is duplicate path to plugin ", procname
            # But go ahead and add it

        if macros.is_macro(procname):
            plugindb[procname] = Procedure(
                procname,
                "bar",
                "bar",
                "bar",  # accel, loc, time all unknown
                menupath,  # <= from the map
                imagetype="",  # unknown
                blurb=macros.get_blurb(procname)  # lookup
            )
        else:  # Gimp internal procedure
            # Many fields unknown for PDB procedures that are not plugins
            plugindb[procname] = Procedure(
                procname,
                "bar",
                "bar",
                "bar",  # accel, loc, time all unknown
                menupath,  # <= from the map
                imagetype="",  # unknown
                blurb=gimpfu.pdb[procname].proc_blurb  # lookup
            )
Example #5
0
 def has_in_params(self):
     '''
 Does any command have hidden params that are not run-mode?
 This must be command by command, it can't be just over the aggregate parameter list.
 '''
     for command in self.command_list:
         # Assume all macros access hidden params
         # TODO take all this special case code out, just ask the command and have subclasses.
         if macros.is_macro(command.name):
             return True
         else:
             # Not a macro, look at the params for this command
             # Alternatively we could call the pdb for the pdefs
             if parse_params.count_nonrunmode_hidden_params(
                     self.param_list.get_parms_for(command.position)):
                 return True
     return False
Example #6
0
def append_gimp_internal_procedures(plugindb):
  '''
  Supplement given dictionary with a subset of gimp internal procedures.
  Subset is: only those most useful to plugin creators.
  
  Cases for whether internal procedure have menupath presence in Gimp menus:
  
  - No : we fabricate a menu item.
  - Yes: no programmatic way to discern, we hand coded corresponding Gimp menu item.
  
  Minimal procedure descriptors: having at least:
  
  - the attribute declared in viewspec: menupath
  - imagetype
  
  Pygimp pdb does not expose the imagetype as attribute of a PDB function.
  gimp-procedural-db-query also does not return the imagetype.
  Imagetype blank or "*" means available for all image types.
  TODO decide whether some internal procedures have imagetype contraints.
  gimp-flatten does not apply when there IS no alpha, and throws an exception?
  '''
  for menupath, procname in map_procedures.menu_to_procname.items():
    if procname in plugindb :
      print "Supplemental menu ", menupath, " is duplicate path to plugin ", procname
      # But go ahead and add it

    if macros.is_macro(procname):
      plugindb[procname] = Procedure(procname, 
        "bar", "bar", "bar", # accel, loc, time all unknown
        menupath, # <= from the map
        imagetype="", # unknown
        blurb = macros.get_blurb(procname) # lookup
        )
    else: # Gimp internal procedure
      # Many fields unknown for PDB procedures that are not plugins
      plugindb[procname] = Procedure(procname, 
        "bar", "bar", "bar", # accel, loc, time all unknown
        menupath, # <= from the map
        imagetype="", # unknown
        blurb = gimpfu.pdb[procname].proc_blurb # lookup
        )
Example #7
0
 def is_macro(self):
     # TODO refactor using classes
     return macros.is_macro(self.name)
Example #8
0
 def is_macro(self):
     # TODO refactor using classes
     return macros.is_macro(self.name)