Example #1
0
    def wizard(self, page_txt_obj=None, sh_class=cli.Cli):
        """
        Interactively populates the Polynomial.
        """
        self.list_ = []
        menu2 = PlainList(['add monomial term', 'DONE'])
        menu2.label = 'Polynomial Wizard'
        while True:
            sel2 = cli.Cli.make_page(
                'Polynomial', page_txt_obj, lambda: sh_class.list_menu(menu2))
            if sel2 == 1:

                # Add monomial term
                print('')  # pylint: disable=C0325
                coef_str = ''
                while len(coef_str) == 0:
                    coef_str = sh_class.input('coefficient?')
                coef = float(coef_str)
                pow_str = ''
                while len(pow_str) == 0:
                    pow_str = sh_class.input('power?')
                pow_ = float(pow_str)
                self.list_.append(Term(coef, pow_))
                menu2.label = str(self)
                self.dict.clear()
                for index in range(len(self)):
                    exponent = self.list_[index].exp
                    if exponent in list(self.dict.keys()):
                        self.dict[exponent] += self.list_[index].coef
                    else:
                        self.dict[exponent] = self.list_[index].coef
            elif sel2 == 2:
                break
Example #2
0
    def open_p_file(cls, filename=None):
        """
        Loads a pickle file.  Prompts user for a file name if one is not
        provided.

        obj = cls.open_p_file()
        obj = cls.open_p_file(filename)
        """
        if cls.interface in ['bash', 'sh']:
            cls.print_header('FILE: Open a pickle file')
        if filename != None:
            pass
        else:
            if cls.interface == 'Tk':
                filename = tkFileDialog.askopenfilename(
                    parent=cls.main_window, title='Choose a file', filetypes=[(
                    'Pickle files', '*.p')])
            else:
                file_list = os.listdir(os.getcwd())
                pickle_list = [_file for _file in file_list if _file.endswith(
                    '.p')]

                #Prompt user for a filename, if none given
                open_menu = PlainList(pickle_list)
                open_menu.label = 'Choose a file to open:'
                filename = pickle_list[cls.list_menu(open_menu) - 1]
        a_file = open(filename, 'rb')
        return pickle.load(a_file)