Package madgraph :: Package interface :: Module extended_cmd :: Class ControlSwitch
[hide private]
[frames] | no frames]

Class ControlSwitch

source code

 object --+            
          |            
OriginalCmd --+        
              |        
       BasicCmd --+    
                  |    
      SmartQuestion --+
                      |
                     ControlSwitch
Known Subclasses:

A class for asking a question on which program to run.
This is the abstract class

Behavior for each switch can be customize via:
set_default_XXXX() -> set default value
    This is super-seeded by self.default_switch if that attribute is defined (and has a key for XXXX)
get_allowed_XXXX() -> return list of possible value
check_value_XXXX(value) -> return True/False if the user can set such value
switch_off_XXXXX()      -> set it off (called for special mode)
color_for_XXXX(value)   -> return the representation on the screen for value
get_cardcmd_for_XXXX(value)> return the command to run to customize the cards to 
                           match the status
print_options_XXXX()    -> return the text to disply below "other options"
                           default is other possible value (ordered correctly)

consistency_XX_YY(val_XX, val_YY)
    -> XX is the new key set by the user to a new value val_XX
    -> YY is another key set by the user.
    -> return value should be None or "replace_YY" 

consistency_XX(val_XX):
     check the consistency of the other switch given the new status of this one. 
     return a dict {key:replaced_value} or {} if nothing to do
     
user typing "NAME" will result to a call to self.ans_NAME(None)
user typing "NAME=XX" will result to a call to self.ans_NAME('XX')    

Note on case sensitivity:
-------------------------
the XXX is displayed with the case in self.to_control
    but ALL functions should use the lower case version.
for key associated to get_allowed_keys(), 
    if (user) value not in that list.
       -> try to find the first entry matching up to the case
for ans_XXX, set the value to lower case, but if case_XXX is set to True 

Instance Methods [hide private]
 
__init__(self, to_control, motherinstance, *args, **opts)
to_control is a list of ('KEY': 'Choose the shower/hadronization program')
source code
 
special_check_answer_in_input_file(self, line, default)
this is called after the standard check if the asnwer were not valid in particular all input in the auto-completion have been already validated.
source code
 
set_default_switch(self) source code
 
default_switch_for(self, key)
use this if they are no dedicated function for such key
source code
 
set_all_off(self)
set all valid parameter to OFF --call before special keyword--
source code
 
check_value(self, key, value)
return True/False if the value is a correct value to be set by the USER.
source code
 
get_cardcmd(self)
return the list of command that need to be run to have a consistent set of cards with the switch value choosen
source code
 
get_allowed(self, key)
return the list of possible value for key
source code
 
default(self, line, raise_error=False)
Default action if line is not recognized
source code
 
is_case_sensitive(self, key)
check if a key is case sensitive
source code
 
onecmd(self, line, **opt)
ensure to rewrite the function if a call is done directly
source code
 
postcmd(self, stop, line)
Hook method executed just after a command dispatch is finished.
source code
 
set_switch(self, key, value, user=True)
change a switch to a given value
source code
 
remove_inconsistency(self, keys=[]) source code
 
check_consistency(self, key, value)
check the consistency of the new flag with the old ones
source code
 
color_for_value(self, key, switch_value, consistency=True) source code
 
print_options(self, key, keep_default=False) source code
 
do_help(self, line, list_command=False)
dedicated help for the control switch
source code
 
print_help_for_switch(self, line) source code
 
question_formatting(self, nb_col=80, ldescription=0, lswitch=0, lname=0, ladd_info=0, lpotential_switch=0, lnb_key=0, key=None)
should return four lines: 1.
source code
 
create_question(self, help_text=True)
create the question with correct formatting
source code

Inherited from SmartQuestion: __call__, cmdloop, complete_help, completedefault, completenames, emptyline, get_names, preloop, reask

Inherited from BasicCmd: complete, deal_multiple_categories, getTerminalSize, print_suggestions, set_readline_completion_display_matches_hook

Inherited from OriginalCmd: columnize, parseline, postloop, precmd, print_topics

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Static Methods [hide private]

Inherited from BasicCmd: list_completion, path_completion, split_arg

Class Variables [hide private]
  case_sensitive = False
  quit_on = ['0', 'done', 'EOF', '', 'auto']
  green = '\x1b[32m%s\x1b[0m'
  yellow = '\x1b[33m%s\x1b[0m'
  red = '\x1b[31m%s\x1b[0m'
  bold = '\x1b[01m%s\x1b[0m'

Inherited from SmartQuestion: allowpath

Inherited from OriginalCmd: doc_header, doc_leader, identchars, intro, lastcmd, misc_header, nohelp, prompt, ruler, undoc_header, use_rawinput

Properties [hide private]
  answer

Inherited from object: __class__

Method Details [hide private]

__init__(self, to_control, motherinstance, *args, **opts)
(Constructor)

source code 

to_control is a list of ('KEY': 'Choose the shower/hadronization program')

Overrides: object.__init__

special_check_answer_in_input_file(self, line, default)

source code 

this is called after the standard check if the asnwer were not valid in particular all input in the auto-completion have been already validated. (this include all those with ans_xx and the XXXX=YYY for YYY in self.get_allowed(XXXX) We just check here the XXXX = YYYY for YYYY not in self.get_allowed(XXXX) but for which self.check_value(XXXX,YYYY) returns True. We actually allowed XXXX = YYY even if check_value is False to allow case where some module are missing

check_value(self, key, value)

source code 

return True/False if the value is a correct value to be set by the USER. other value than those can be set by the system --like-- Not available. This does not check the full consistency of the switch

default(self, line, raise_error=False)

source code 

Default action if line is not recognized

Overrides: OriginalCmd.default

onecmd(self, line, **opt)

source code 

ensure to rewrite the function if a call is done directly

Overrides: OriginalCmd.onecmd

postcmd(self, stop, line)

source code 

Hook method executed just after a command dispatch is finished.

Overrides: OriginalCmd.postcmd
(inherited documentation)

do_help(self, line, list_command=False)

source code 

dedicated help for the control switch

Overrides: OriginalCmd.do_help

question_formatting(self, nb_col=80, ldescription=0, lswitch=0, lname=0, ladd_info=0, lpotential_switch=0, lnb_key=0, key=None)

source code 
should return four lines:
1. The upper band (typically /========\ 
2. The lower band (typically \========/
3. The line without conflict | %(nb)2d. %(descrip)-20s %(name)5s = %(switch)-10s |
4. The line with    conflict | %(nb)2d. %(descrip)-20s %(name)5s = %(switch)-10s |
# Be carefull to include the size of the color flag for the switch
green/red/yellow are  adding 9 in length 

line should be like '| %(nb)2d. %(descrip)-20s %(name)5s = %(switch)-10s |'

   the total lenght of the line (for defining the upper/lower line)
   available key : nb
                   descrip
                   name
                   switch          # formatted with color + conflict handling
                   conflict_switch # color formatted value from self.inconsistent_keys
                   switch_nc # self.switch without color formatting
                   conflict_switch_nc # self.inconsistent_keys without color formatting
                   add_info


Property Details [hide private]

answer

Get Method:
unreachable.answer(self)