コード例 #1
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),
        ])
コード例 #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

        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),
        ])
コード例 #3
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),
        ])
コード例 #4
0
ファイル: TUI_spec.py プロジェクト: astrom-tom/SPARTAN
    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'
コード例 #5
0
    def create_config(self,
                      menu_id,
                      cfg_id,
                      type,
                      description,
                      long_description=None,
                      **kwargs):
        fields = self.menu_forms[menu_id]['config_fields']
        fields[cfg_id] = {
            'form': menu_id,
            'type': type,
            'description': description,
            'long_description': long_description,
        }

        # Do a wrap, with maximum width of total form length
        long_list = None
        if long_description:
            long_list = []
            # 10 is darn arbitrary number
            wrapper = textwrap.TextWrapper(replace_whitespace=False,
                                           width=self.cols - 10)
            # Arbitrary 10 here. Totally random number.
            long_descr = ' '.join(long_description).splitlines()
            for s in long_descr:
                long_list += wrapper.wrap(s)

        selected = None
        if 'selected' in kwargs:
            selected = kwargs['selected']

        if type == 'array':
            add_ctrl_id = 'array-control-add/' + cfg_id
            add_ctrl_descr = 'Add array item...'
            add_ctrl_long = 'Adds item into the \'{}\' array'.format(
                description)

            fields[add_ctrl_id] = {
                'form': menu_id,
                'type': 'array-control-add',
                'description': add_ctrl_descr,
                'long_description': [add_ctrl_long],
                'dependee': cfg_id,
                'last-value': ''
            }

            fields[add_ctrl_id]['option'] = \
                npyscreen.OptionFreeText(add_ctrl_descr, documentation=[ add_ctrl_long ])
            fields[cfg_id]['option'] = \
                npyscreen.OptionMultiChoice(description, choices=selected, documentation=long_list)
            fields[cfg_id]['array-control-parent'] = add_ctrl_id
            fields[cfg_id]['last-value'] = []

        elif type == 'enum':
            fields[cfg_id]['single'] = kwargs['single']
            if kwargs['single']:
                fields[cfg_id]['option'] = \
                    npyscreen.OptionSingleChoice(description, choices=kwargs['values'],
                        documentation=long_list)

                # Change value a bit, to fit npyscreen needs
                if selected != None:
                    selected = [selected]
            else:
                fields[cfg_id]['option'] = \
                    npyscreen.OptionMultiChoice(description, choices=kwargs['values'])
            fields[cfg_id]['last-value'] = []
        elif type == 'integer':
            fields[cfg_id]['option'] = \
                npyscreen_int_option(description)
            fields[cfg_id]['last-value'] = ''
        else:
            fields[cfg_id]['option'] = \
                npyscreen.OptionFreeText(description)
            fields[cfg_id]['last-value'] = ''

        if selected:
            fields[cfg_id]['option'].value = selected
            fields[cfg_id]['last-value'] = selected

        self.update_form(menu_id)