'Construct the text based on the entered content in the widget.'

def process_text(self, array=True):

    if array:
        prefix = 'np.array([['
    else:
        prefix = 'np.matrix([['
    suffix = ']])'
    values = self._widget.text().strip()
    if (values != ''):
        exp = (('(\\s*)' + ROW_SEPARATOR) + '(\\s*)')
        values = re.sub(exp, ROW_SEPARATOR, values)
        values = re.sub('\\s+', '    ', values)
        values = re.sub(']$', '', values)
        values = re.sub('^\\[', '', values)
        values = re.sub((ROW_SEPARATOR + '*$'), '', values)
        values = values.replace('    ', ELEMENT_SEPARATOR)
        new_values = []
        rows = values.split(ROW_SEPARATOR)
        nrows = len(rows)
        ncols = []
        for row in rows:
            new_row = []
            elements = row.split(ELEMENT_SEPARATOR)
            ncols.append(len(elements))
            for e in elements:
                num = e
                if (num in NAN_VALUES):
                    num = 'np.nan'
                if self._force_float:
                    try:
                        num = str(float(e))
                    except:
                        pass
                new_row.append(num)
            new_values.append(ELEMENT_SEPARATOR.join(new_row))
        new_values = ROW_SEPARATOR.join(new_values)
        values = new_values
        if (len(set(ncols)) == 1):
            self._valid = True
        else:
            self._valid = False
        if (nrows == 1):
            prefix = prefix[:(-1)]
            suffix = suffix.replace(']])', '])')
        offset = self._offset
        braces = BRACES.replace('    ', ('\n' + ('    ' * ((offset + len(prefix)) - 1))))
        values = values.replace(ROW_SEPARATOR, braces)
        text = '{0}{1}{2}'.format(prefix, values, suffix)
        self._text = text
    else:
        self._text = ''
    self.update_warning()
