Exemple #1
0
    def update_form(self, f_id):
        Options = npyscreen.OptionList()
        options = Options.options
        fields = self.menu_forms[f_id]['config_fields']
        fwd_navs = self.menu_forms[f_id]['nav_link_fwd']
        back_navs = self.menu_forms[f_id]['nav_link_back']
        # To preserve order
        navs = fwd_navs + back_navs

        for link in navs:
            options.append(link)

        for id, data in fields.items():
            options.append(data['option'])

        self.menu_forms[f_id]['config_widget'].values = options

        # Help must be loaded, too, but it is unclear where to get it.
        if len(navs) > 0:
            descr = self.get_help_from_navlink(navs[0])
            self.menu_forms[f_id]['help-widget'].value = descr
        elif len(fields) > 0:
            descr = self.get_help_from_field(list(fields.values())[0])
            self.menu_forms[f_id]['help-widget'].value = descr

        # This method is heavy, but redraws entire screen without glitching
        # option list itself (as .display() does)
        self.menu_forms[f_id]['form'].DISPLAY()
Exemple #2
0
    def create(self):

        self.add(npyscreen.FixedText, value="OPTIONS:")
        self.how_exited_handers[
            npyscreen.wgwidget.EXITED_ESCAPE] = self.exit_application

        self.Options = npyscreen.OptionList()
        # just for convenience so we don't have to keep writing Options.options
        options = self.Options.options

        options.append(
            npyscreen.OptionMultiFreeText('Votre message chiffré', value=''))
        options.append(
            npyscreen.OptionSingleChoice(
                'Type de chiffrement', choices=ChiffSymHelper.getAvailable()))
        # options.append(npyscreen.TitlePassword('Votre Mot de passe', value=''))

        self.add(npyscreen.OptionListDisplay,
                 name="Liste d'options",
                 values=options,
                 scroll_exit=True,
                 max_height=2)
        self.pwd = self.add(npyscreen.TitlePassword, name="Mot de passe:")

        self.output = self.add(npyscreen.BoxTitle,
                               name="Sortie de texte:",
                               max_height=4)
        self.output.values = []

        # The menus are created here.
        self.mMain = self.add_menu(name="Menu")
        self.mMain.addItemsFromList([
            ("Retour", self.retour),
        ])
Exemple #3
0
    def config_attr():
        form = npys.ActionPopup(name='Attributes')
        cb_skip_func = form.add(npys.Checkbox, name="Skip functions")
        cb_skip_meth = form.add(npys.Checkbox, name="Skip methods")
        cb_skip_priv = form.add(npys.Checkbox,
                                name="Skip non-public (_xyz, __xyz)")
        cb_skip_dund = form.add(npys.Checkbox, name="Skip dunders (__xyz__)")

        form.add(Separator)
        opt_list = npys.OptionList()
        opt_list.options.append(
            OptionMultiFreeListNarrow("Don't visit instances of"))
        opt_dont_visit = form.add(npys.OptionListDisplay,
                                  values=opt_list.options,
                                  scroll_exit=True,
                                  max_height=None)
        opt_list.options[0].set([
            'bool', 'int', 'float', 'complex', 'bytes', 'bytearray', 'str',
            'dict', 'list', 'set', 'frozenset', 'memoryview', 'type(None)'
        ])

        widgets = SimpleNamespace()
        widgets.cb_skip_func = cb_skip_func
        widgets.cb_skip_meth = cb_skip_meth
        widgets.cb_skip_priv = cb_skip_priv
        widgets.cb_skip_dund = cb_skip_dund
        widgets.opt_dont_visit = opt_dont_visit

        load_subconfig_attr(subconfig, widgets)
        form.on_ok = lambda: store_subconfig_attr(subconfig, widgets)
        form.display()
        form.edit()
Exemple #4
0
    def config_call():
        form = npys.ActionPopup(name='Values returned by callables')
        cb_skip_classes = form.add(npys.Checkbox,
                                   name="Skip classes (__init__)")
        cb_skip_genfunc = form.add(npys.Checkbox,
                                   name="Skip generator functions")

        form.add(Separator)
        opt_list = npys.OptionList()
        opt_list.options.append(
            OptionMultiFreeListNarrow('Skip callables named'))
        opt_skip_callables = form.add(npys.OptionListDisplay,
                                      values=opt_list.options,
                                      scroll_exit=True,
                                      max_height=None)
        opt_list.options[0].set(['exit'])

        widgets = SimpleNamespace()
        widgets.cb_skip_classes = cb_skip_classes
        widgets.cb_skip_genfunc = cb_skip_genfunc
        widgets.cb_skip_genfunc = cb_skip_genfunc
        widgets.opt_skip_callables = opt_skip_callables

        load_subconfig_call(subconfig, widgets)
        form.on_ok = lambda: store_subconfig_call(subconfig, widgets)
        form.display()
        form.edit()
Exemple #5
0
    def create(self):
        self._optionlist = npyscreen.OptionList(filename=self.FILE)

        self._optionlist.options.extend([
            npyscreen.OptionFreeText(
                'FreeText',
                value='',
                documentation='This is some documentation',
            ),
            npyscreen.OptionMultiChoice(
                'MultiChoice',
                choices=['Choice 1', 'Choice 2', 'Choice 3'],
            ),
            npyscreen.OptionFilename('Filename'),
            npyscreen.OptionDate('Date'),
            npyscreen.OptionMultiFreeText(
                'MultilineText',
                value='',
            ),
            npyscreen.OptionMultiFreeList('MultilineList'),
        ])

        self.add(
            npyscreen.OptionListDisplay,
            name="Option List",
            values=self._optionlist.options,
            scroll_exit=True,
            max_height=None,
        )
    def create(self):

        self.add(npyscreen.FixedText, value="OPTIONS:")
        self.how_exited_handers[
            npyscreen.wgwidget.EXITED_ESCAPE] = self.exit_application

        self.Options = npyscreen.OptionList()
        # just for convenience so we don't have to keep writing Options.options
        options = self.Options.options

        self.inFile = self.add(
            npyscreen.TitleFilenameCombo,
            name="Choisir votre message d'entrée (.encrypted ou .signed)",
            label=True)
        options.append(
            npyscreen.OptionSingleChoice(
                'Type de chiffrement', choices=ChiffAsymHelper.getAvailable()))

        self.add(npyscreen.OptionListDisplay,
                 name="Liste d'options",
                 values=options,
                 scroll_exit=True,
                 max_height=2)
        self.keyFile = self.add(npyscreen.TitleFilenameCombo,
                                name="Choisir votre clef privée",
                                label=True)
        self.pwd = self.add(npyscreen.TitlePassword,
                            name="Mot de passe (pour clef privée)")
        self.mode = self.add(npyscreen.TitleSelectOne,
                             max_height=4,
                             value=[
                                 1,
                             ],
                             name="Pick Mode",
                             values=["Décrypter", "Vérifier la signature"],
                             scroll_exit=True)

        self.output = self.add(npyscreen.BoxTitle,
                               name="Sortie de texte:",
                               max_height=6)
        self.output.values = []

        # The menus are created here.
        self.mMain = self.add_menu(name="Menu")
        self.mMain.addItemsFromList([
            ("Retour", self.retour),
        ])
Exemple #7
0
    def main(self):
        Options = npyscreen.OptionList()

        # just for convenience so we don't have to keep writing Options.options
        options = Options.options
        options.append(npyscreen.OptionFilename('Filename', self.default_file))

        options.append(
            npyscreen.OptionFreeText(
                'FreeText',
                value='',
                documentation="This is some documentation."))
        options.append(
            npyscreen.OptionMultiChoice(
                'Multichoice', choices=['Choice 1', 'Choice 2', 'Choice 3']))
        options.append(npyscreen.OptionDate('Date', ))
        options.append(
            npyscreen.OptionMultiFreeText('Multiline Text', value=''))
        options.append(npyscreen.OptionMultiFreeList('Multiline List'))

        try:
            Options.reload_from_file(self.default_file)
        except FileNotFoundError:
            pass

        F = npyscreen.Form(name="Welcome to Npyscreen", )

        ms = F.add(npyscreen.OptionListDisplay,
                   name="Option List",
                   values=options,
                   scroll_exit=True,
                   max_height=None)

        F.edit()

        Options.write_to_file(self.default_file)
Exemple #8
0
    def create(self):

        self.add(npyscreen.FixedText, value="OPTIONS:")
        self.how_exited_handers[
            npyscreen.wgwidget.EXITED_ESCAPE] = self.exit_application

        self.Options = npyscreen.OptionList()
        # just for convenience so we don't have to keep writing Options.options
        options = self.Options.options

        options.append(npyscreen.OptionMultiFreeText('Hash', value=''))
        options.append(
            npyscreen.OptionSingleChoice('Fonction de hachage',
                                         choices=HachageHelper.getAvailable()))

        self.wordListFile = self.add(
            npyscreen.TitleFilenameCombo,
            name="Choisir votre dictionnaire des mots",
            label=True)

        self.add(npyscreen.OptionListDisplay,
                 name="Liste d'options",
                 values=options,
                 scroll_exit=True,
                 max_height=6)

        self.output = self.add(npyscreen.BoxTitle,
                               name="Sortie de texte:",
                               max_height=7)
        self.output.values = []

        # The menus are created here.
        self.mMain = self.add_menu(name="Menu")
        self.mMain.addItemsFromList([
            ("Retour", self.retour),
        ])
Exemple #9
0
    def __init__(self, Log, x, y, SPEC):
        """
        Class constructor creating the form and populating it with widgets
        Parameters:
        ----------
        SPEC:  An Dictionnaey containing the information of each widget 
               It can be empty or coming from an already defined Project
               Format={Spectra directory, Use Full,binning, specz,\
               Funits, Wunits,Skip, Sizeskip,Use BR,Bad Regions}
               Types={str,int,str,int,str,str,int,str,int,str}
        Log:   SPARTAN LOGO to be drawn at the top of the form
                                                                                                                                 
        x,y:   size of the front page of the TUI. The nez page descibed here 
               is drawn on the same size.

        Returns:
        -------
        """

        ##Initialize form and write logo
        self.S = npyscreen.Form(name="SPARTAN Spectroscopic configuration",
                                color='STANDOUT')

        ###Write the Logo
        for i in Log:
            self.S.add(npyscreen.FixedText,value=i,relx=int((x-len(i))/2),editable=False\
                    , color='CURSOR')

        ### Make the 3 boxes
        n = 9  ### Terminal row where we start to draw the boxes
        self.S.add(npyscreen.BoxBasic,name='Spectroscopy', rely=n\
                ,max_width=int(x/2)-1, max_height = int(y/2.5), editable=False, color='DANGER')

        self.S.add(npyscreen.BoxBasic,name='Bad Regions'\
                ,relx=int(x/2)+1,rely=n, max_height = int(y/2.5),editable=False, color='DANGER')
        self.S.add(npyscreen.BoxBasic,name='FIT'\
                ,rely=n+int(y/2.5),editable=False, color='DANGER')

        #### Create the option lists [for F units and W units]
        Options = npyscreen.OptionList()
        options = Options.options
        options.append(npyscreen.OptionSingleChoice('Units (Flux)', \
                choices=specunits().Funitchoice))
        options.append(npyscreen.OptionSingleChoice('Units (Wavelength)', \
                choices=specunits().Wunitchoice))

        #### Create the widgets
        n = 10  ###Terminal row where se start to draw widgets
        SDir=self.S.add(npyscreen.TitleFilenameCombo, name = "Spectra Directory [tab]:",\
                value=SPEC['SDir'],relx=5,rely=n,max_width=int(x/2.5), labelColor='CAUTION')

        Res=self.S.add(npyscreen.TitleText,name='Resolution(Ang):',\
                relx=5,rely=n+int((y-n)/6),max_height=3,max_width=int(x/2-10), \
                value=SPEC['Res'],labelColor='CAUTION')

        ListUNITS=self.S.add(npyscreen.OptionListDisplay, \
                name="Option List",values = options,relx=5,rely=n+2*int((y-n)/6),scroll_exit=True,\
                max_width=int(x/2.5),max_height=int(2), color='CAUTION')

        if type(SPEC['Funit']) == list:
            options[0].set(SPEC['Funit'])
        elif type(SPEC['Funit']) == str:
            options[0].set([SPEC['Funit']])

        if type(SPEC['Wunit']) == list:
            options[1].set(SPEC['Wunit'])
        elif type(SPEC['Wunit']) == str:
            options[1].set([SPEC['Wunit']])

        ###bad regions box

        if SPEC['Skip'].lower() == 'yes':
            SKIP = 1
        elif SPEC['Skip'].lower() == 'no':
            SKIP = 0
        else:
            SKIP = ''


        Skip=self.S.add(npyscreen.TitleSelectOne,  name="Skip edges",\
                values = ["NO","YES"],value=SKIP, scroll_exit=True, labelColor='CAUTION',\
                relx=int(x/2)+5,rely=n,max_height=int(y/15),max_width=int(x/3))

        SSkip=self.S.add(npyscreen.TitleText, name = "Size to skip (AA,obs-f) :", labelColor='CAUTION',\
                value=SPEC['SSkip'],rely=n+int((y-n)/8),relx=int(x/2)+5,max_width=int(x/3))

        if SPEC['UseBR'].lower() == 'yes':
            USEBR = 1
        elif SPEC['UseBR'].lower() == 'no':
            USEBR = 0
        else:
            USEBR = ''

        UseBR=self.S.add(npyscreen.TitleSelectOne,  name="Bad regions",\
                values = ["NO","YES"],value=USEBR, scroll_exit=True, labelColor='CAUTION',\
                relx=int(x/2)+5,rely=n+3*int((y-n)/10),max_height=int(y/15),max_width=int(x/3))

        #self.S.nextrely += 1
        BR = self.S.add(npyscreen.TitleText, name='If Yes, list (rest-f, AA).',\
                value=SPEC['BR'],relx=int(x/2)+5,rely=n+4*int((y-n)/10),max_width=int(x/3),color='CAUTION')

        ###normalisation
        if SPEC['Norm'].lower() == 'mags':
            Norm = 0
        elif SPEC['Norm'].lower() == 'region':
            Norm = 1
        else:
            Norm = 0
        Norm=self.S.add(npyscreen.TitleSelectOne,  name="Nor Dat/Mod",\
                values = ["Magnitude","Regions"],value=Norm, scroll_exit=True, labelColor='CAUTION',\
                relx=5,rely=n+4*int((y-n)/6),max_height=int(y/15),max_width=int(x/3))

        NormReg = self.S.add(npyscreen.TitleText, name='If Region, give l1 & l2 (rest-f ,AA :l1-l2).',\
                  value=SPEC['Norm_reg'],relx=5,rely=n+5*int((y-n)/6),max_width=int(x/3),color='CAUTION')

        ######Multi_spec calibration
        if SPEC['Calib'].lower() == 'yes':
            fitcalib = 1
        elif SPEC['Calib'].lower() == 'no':
            fitcalib = 0
        else:
            fitcalib = 1
        Calib=self.S.add(npyscreen.TitleSelectOne,  name="Fit multi-spec calib",\
                values = ["Yes","No"],value=fitcalib, scroll_exit=True, labelColor='CAUTION',\
                relx=int(x/2)+5,rely=n+4*int((y-n)/6),max_height=int(y/6), max_width = int(x/3))

        ###To let the user interact with the screen
        self.S.edit()

        ###Define the attributes of the class

        self.SDir = SDir.value
        self.Res = Res.value
        self.Funit = options[0].get()
        self.Wunit = options[1].get()
        self.SSkip = SSkip.value
        self.BR = BR.value
        self.Norm_reg = NormReg.value

        if Skip.value[0] == 1:
            self.Skip = 'Yes'
        elif Skip.value[0] == '':
            self.Skip = ''
        elif Skip.value[0] == 0:
            self.Skip = 'No'

        if UseBR.value[0] == 1:
            self.UseBR = 'Yes'
        elif UseBR.value[0] == '':
            self.UseBR = ''
        elif UseBR.value[0] == 0:
            self.UseBR = 'No'

        if Calib.value[0] == 1:
            self.Calib = 'No'
        elif Calib.value[0] == '':
            self.Calib = 'No'
        elif Calib.value[0] == 0:
            self.Calib = 'Yes'

        if Norm.value[0] == 1:
            self.Norm = 'region'
        elif Norm.value[0] == '':
            self.Norm = 'mags'
        elif Norm.value[0] == 0:
            self.Norm = 'mags'
Exemple #10
0
    def create_menu(self,
                    p_menu_id,
                    menu_id,
                    description,
                    long_description=None):
        # If form name is not MAIN and parent ID is not set,
        # then engine trying to create top-level menu.
        if p_menu_id == None and menu_id != 'MAIN':
            p_menu_id = 'MAIN'

        f = self.npyscreen_app.addForm(menu_id,
                                       npyscreen_form,
                                       name=description,
                                       my_f_id=menu_id,
                                       ui=self)

        help = f.add(npyscreen.MultiLineEdit,
                     value='Help screen',
                     max_height=self.rows - self.rely - 5,
                     max_width=self.help_width,
                     relx=self.help_relx,
                     rely=self.rely)
        ms = f.add(npyscreen.OptionListDisplay,
                   name="Option List",
                   values=npyscreen.OptionList().options,
                   scroll_exit=True,
                   begin_entry_at=14,
                   max_height=self.rows - self.rely - 5,
                   max_width=self.options_width,
                   rely=self.rely)

        self.menu_forms[menu_id] = {
            'parent': p_menu_id,
            'form': f,
            'config_widget': ms,
            'description': description,
            'long_description': long_description,
            'help-widget': help,
            'current_line': -1,
        }

        # Empty configuration dict, will be populated in create_config() function
        self.menu_forms[menu_id]['config_fields'] = {}
        self.menu_forms[menu_id]['nav_link_fwd'] = []
        self.menu_forms[menu_id]['nav_link_back'] = []

        if p_menu_id:
            self.menu_forms[p_menu_id]['nav_link_fwd'].append(
                npyscreen_switch_form_option(target_form=menu_id,
                                             name='>>> Go to ',
                                             value=description,
                                             app=f.parentApp), )

            self.menu_forms[menu_id]['nav_link_back'] = [
                npyscreen_switch_form_option(
                    target_form=p_menu_id,
                    name='<<< Back to ',
                    value=self.menu_forms[p_menu_id]['description'],
                    app=f.parentApp),
            ]

            self.update_form(p_menu_id)