def display_popup(self, message,
                      size_x=None, size_y=None,
                      duration=3,
                      is_input=False,
                      input_size=30,
                      input_value=None):
        """
        Display a centered popup.

        If is_input is False:
         Display a centered popup with the given message during duration seconds
         If size_x and size_y: set the popup size
         else set it automatically
         Return True if the popup could be displayed

        If is_input is True:
         Display a centered popup with the given message and a input field
         If size_x and size_y: set the popup size
         else set it automatically
         Return the input string or None if the field is empty
        """
        # Center the popup
        sentence_list = message.split('\n')
        if size_x is None:
            size_x = len(max(sentence_list, key=len)) + 4
            # Add space for the input field
            if is_input:
                size_x += input_size
        if size_y is None:
            size_y = len(sentence_list) + 4
        screen_x = self.screen.getmaxyx()[1]
        screen_y = self.screen.getmaxyx()[0]
        if size_x > screen_x or size_y > screen_y:
            # No size to display the popup => abord
            return False
        pos_x = int((screen_x - size_x) / 2)
        pos_y = int((screen_y - size_y) / 2)

        # Create the popup
        popup = curses.newwin(size_y, size_x, pos_y, pos_x)

        # Fill the popup
        popup.border()

        # Add the message
        for y, m in enumerate(message.split('\n')):
            popup.addnstr(2 + y, 2, m, len(m))

        if is_input and not WINDOWS:
            # Create a subwindow for the text field
            subpop = popup.derwin(1, input_size, 2, 2 + len(m))
            subpop.attron(self.colors_list['FILTER'])
            # Init the field with the current value
            if input_value is not None:
                subpop.addnstr(0, 0, input_value, len(input_value))
            # Display the popup
            popup.refresh()
            subpop.refresh()
            # Create the textbox inside the subwindows
            self.set_cursor(2)
            self.term_window.keypad(1)
            textbox = GlancesTextbox(subpop, insert_mode=False)
            textbox.edit()
            self.set_cursor(0)
            self.term_window.keypad(0)
            if textbox.gather() != '':
                logger.debug(
                    "User enters the following string: %s" % textbox.gather())
                return textbox.gather()[:-1]
            else:
                logger.debug("User centers an empty string")
                return None
        else:
            # Display the popup
            popup.refresh()
            self.wait(duration * 1000)
            return True
def display_popup ( self , message , size_x = None , size_y = None , duration = 3 , is_input = False , input_size = 30 , input_value = None ) : sentence_list = message . split ( '\n' ) if size_x is None : size_x = len ( max ( sentence_list , key = len ) ) + 4 if is_input : size_x += input_size if size_y is None : size_y = len ( sentence_list ) + 4 screen_x = self . screen . getmaxyx ( ) [ 1 ] screen_y = self . screen . getmaxyx ( ) [ 0 ] if size_x > screen_x or size_y > screen_y : return False pos_x = int ( ( screen_x - size_x ) / 2 ) pos_y = int ( ( screen_y - size_y ) / 2 ) popup = curses . newwin ( size_y , size_x , pos_y , pos_x ) popup . border ( ) for y , m in enumerate ( message . split ( '\n' ) ) : popup . addnstr ( 2 + y , 2 , m , len ( m ) ) if is_input and not WINDOWS : subpop = popup . derwin ( 1 , input_size , 2 , 2 + len ( m ) ) subpop . attron ( self . colors_list [ 'FILTER' ] ) if input_value is not None : subpop . addnstr ( 0 , 0 , input_value , len ( input_value ) ) popup . refresh ( ) subpop . refresh ( ) self . set_cursor ( 2 ) self . term_window . keypad ( 1 ) textbox = GlancesTextbox ( subpop , insert_mode = False ) textbox . edit ( ) self . set_cursor ( 0 ) self . term_window . keypad ( 0 ) if textbox . gather ( ) != '' : logger . debug ( "User enters the following string: %s" % textbox . gather ( ) ) return textbox . gather ( ) [ : - 1 ] else : logger . debug ( "User centers an empty string" ) return None else : popup . refresh ( ) self . wait ( duration * 1000 ) return True
Display a centered popup.

        If is_input is False:
         Display a centered popup with the given message during duration seconds
         If size_x and size_y: set the popup size
         else set it automatically
         Return True if the popup could be displayed

        If is_input is True:
         Display a centered popup with the given message and a input field
         If size_x and size_y: set the popup size
         else set it automatically
         Return the input string or None if the field is empty