Changeset 27fb3d6 in mainline


Ignore:
Timestamp:
2009-01-21T15:23:36Z (15 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
be8b5d6
Parents:
9a0367f
Message:

fallback to dialog if newt is not available
fallback to plain text if dialog is not available

Location:
tools
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • tools/config.py

    r9a0367f r27fb3d6  
    3535import re
    3636import commands
    37 import snack
     37import xtui
    3838
    3939INPUT = sys.argv[1]
     
    179179        return ' '
    180180
    181 def subchoice(screen, name, choices):
     181def subchoice(screen, name, choices, default):
    182182        "Return choice of choices"
    183183       
    184         maxlen = 0
    185         for choice in choices:
    186                 length = len(choice[0])
    187                 if (length > maxlen):
    188                         maxlen = length
     184        maxkey = 0
     185        for key, val in choices:
     186                length = len(key)
     187                if (length > maxkey):
     188                        maxkey = length
    189189       
    190190        options = []
    191         for choice in choices:
    192                 options.append(" %-*s  %s " % (maxlen, choice[0], choice[1]))
    193        
    194         retval = snack.ListboxChoiceWindow(screen, name, 'Choose value', options)
    195        
    196         if (retval[0] == 'cancel'):
     191        position = None
     192        cnt = 0
     193        for key, val in choices:
     194                if ((default) and (key == default)):
     195                        position = cnt
     196               
     197                options.append(" %-*s  %s " % (maxkey, key, val))
     198                cnt += 1
     199       
     200        (button, value) = xtui.choice_window(screen, name, 'Choose value', options, position)
     201       
     202        if (button == 'cancel'):
    197203                return None
    198204       
    199         return choices[retval[1]][0]
     205        return choices[value][0]
    200206
    201207def check_choices(defaults, ask_names):
    202208        "Check whether all accessible variables have a default"
    203209       
    204         for row in ask_names:
    205                 varname = row[0]
    206                 cond = row[4]
    207                
     210        for varname, vartype, name, choices, cond in ask_names:
    208211                if ((cond) and (not check_condition(cond, defaults, ask_names))):
    209212                        continue
     
    223226        outf.write('#########################################\n\n')
    224227       
    225         for row in ask_names:
    226                 varname = row[0]
    227                 name = row[2]
    228                 cond = row[4]
    229                
     228        for varname, vartype, name, choices, cond in ask_names:
    230229                if ((cond) and (not check_condition(cond, defaults, ask_names))):
    231230                        continue
     
    259258                        return 0
    260259       
    261         screen = snack.SnackScreen()
     260        screen = xtui.screen_init()
    262261        try:
    263262                selname = None
     
    268267                        position = None
    269268                        cnt = 0
    270                         for row in ask_names:
    271                                
    272                                 varname = row[0]
    273                                 vartype = row[1]
    274                                 name = row[2]
    275                                 choices = row[3]
    276                                 cond = row[4]
     269                        for varname, vartype, name, choices, cond in ask_names:
    277270                               
    278271                                if ((cond) and (not check_condition(cond, defaults, ask_names))):
     
    312305                                        raise RuntimeError("Unknown variable type: %s" % vartype)
    313306                               
    314                                 opt2row[cnt] = row
     307                                opt2row[cnt] = (varname, vartype, name, choices)
    315308                               
    316309                                cnt += 1
    317310                       
    318                         retval = snack.ListboxChoiceWindow(screen, 'HelenOS configuration', 'Choose configuration option', options, default = position)
    319                        
    320                         if (retval[0] == 'cancel'):
     311                        (button, value) = xtui.choice_window(screen, 'HelenOS configuration', 'Choose configuration option', options, position)
     312                       
     313                        if (button == 'cancel'):
    321314                                return 'Configuration canceled'
    322315                       
    323                         row = opt2row[retval[1]]
    324                         if (row == None):
    325                                 raise RuntimeError("Error selecting value: %s" % retval[1])
    326                        
    327                         selname = row[0]
    328                         seltype = row[1]
    329                         name = row[2]
    330                         choices = row[3]
    331                        
    332                         if (retval[0] == 'ok'):
     316                        if (not opt2row.has_key(value)):
     317                                raise RuntimeError("Error selecting value: %s" % value)
     318                       
     319                        (selname, seltype, name, choices) = opt2row[value]
     320                       
     321                        if (not defaults.has_key(selname)):
     322                                        default = None
     323                        else:
     324                                default = defaults[selname]
     325                       
     326                        if (button == 'done'):
    333327                                if (check_choices(defaults, ask_names)):
    334328                                        break
    335329                                else:
    336                                         snack.ButtonChoiceWindow(screen, 'Error', 'Some options have still undefined values.', ['Ok']);
     330                                        xtui.error_dialog(screen, 'Error', 'Some options have still undefined values.')
    337331                                        continue
    338332                       
    339333                        if (seltype == 'choice'):
    340                                 defaults[selname] = subchoice(screen, name, choices)
     334                                defaults[selname] = subchoice(screen, name, choices, default)
    341335                        elif ((seltype == 'y/n') or (seltype == 'n/y')):
    342336                                if (defaults[selname] == 'y'):
     
    345339                                        defaults[selname] = 'y'
    346340        finally:
    347                 screen.finish()
     341                xtui.screen_done(screen)
    348342       
    349343        create_output(OUTPUT, defaults, ask_names)
Note: See TracChangeset for help on using the changeset viewer.