Esempio n. 1
0
    def display_help(self):
        '''Display the single file help screen'''
        # customize header
        help_header = "%s: %s"
        logging.debug("self.screen is =%s", self.screen)
        if self.screen in self.help_dict:
            help_header = help_header % (_("Help"),
                                         self.help_dict[self.screen][1])
            help_text = self.get_help_text(self.help_dict[self.screen][0])
        else:
            help_header = help_header % (_("Help"), _("Not Available"))
            help_text = _("Help for this screen is not available")

        self.main_win.set_header_text(help_header)

        help_text = convert_paragraph(help_text, self.win_size_x - 5)
        logging.debug("help_text #lines=%d, text is \n%s", len(help_text),
                      help_text)
        area = WindowArea(x_loc=0,
                          y_loc=1,
                          scrollable_lines=(len(help_text) + 1))
        area.lines = self.win_size_y - 1
        area.columns = self.win_size_x
        self.scroll_region = ScrollWindow(area, window=self.center_win)
        self.scroll_region.add_paragraph(help_text, start_x=(area.x_loc + 3))
        self.center_win.activate_object(self.scroll_region)
Esempio n. 2
0
 def get_log_data(self):
     '''Attempt to read in the install log file. If an error occurs,
     the log_data is set to a string explaining the cause, if possible.
     
     '''
     if self.log_data is None:
         log_file = None
         try:
             try:
                 log_file = open(self.install_profile.log_location)
                 log_data = log_file.read()
             except (OSError, IOError), error:
                 self.log_data = _("Could not read log file:\n\t%s") % \
                                 error.strerror
         finally:
             if log_file is not None:
                 log_file.close()
         max_chars = self.win_size_x - 4
         self.log_data = convert_paragraph(log_data, max_chars)
     return self.log_data
Esempio n. 3
0
 def add_paragraph(self,
                   text,
                   start_y=0,
                   start_x=0,
                   max_y=None,
                   max_x=None):
     '''Add a block of text to the window
     
     Add a paragraph to the screen. If a string is passed in, it is
     converted using convert_paragraph. If a list of strings is passed in,
     each string will fit in the space alloted (long lines will be
     truncated). Any lines that would be printed past max_y will not be
     printed.
     
     The number of lines used is returned.
     
     '''
     logging.log(
         LOG_LEVEL_INPUT, "add_paragraph: start_y=%d, start_x=%d, "
         "max_y=%s, max_x=%s", start_y, start_x, max_y, max_x)
     win_size_y, win_size_x = self.window.getmaxyx()
     start_y += self.border_size[0]
     if max_y is None:
         max_y = win_size_y - start_y - self.border_size[0]
     if max_x is None:
         max_x = win_size_x
     max_chars = max_x - start_x - self.border_size[1] * 2
     y_index = start_y
     if isinstance(text, basestring):
         text = convert_paragraph(text, max_chars)
     for line in text:
         logging.log(LOG_LEVEL_INPUT, "add_paragraph:add_text: y_index=%d, "
                     "line=%s\n", y_index, line)
         self.add_text(line, y_index, start_x, max_chars)
         y_index += 1
         if y_index > max_y + start_y:
             logging.warn(
                 "Could not fit all text in space for the "
                 "paragraph. Last line:\n%s", line)
             break
     return y_index - start_y
Esempio n. 4
0
 def _show(self):
     '''Prepare a text summary from the install_profile and display it
     to the user in a ScrollWindow
     
     '''
     y_loc = 1
     y_loc += self.center_win.add_paragraph(SummaryScreen.PARAGRAPH, y_loc)
     
     y_loc += 1
     summary_text = self.build_summary()
     # Wrap the summary text, accounting for the INDENT (used below in
     # the call to add_paragraph)
     max_chars = self.win_size_x - SummaryScreen.INDENT - 1
     summary_text = convert_paragraph(summary_text, max_chars)
     area = WindowArea(x_loc=0, y_loc=y_loc,
                       scrollable_lines=(len(summary_text)+1))
     area.lines = self.win_size_y - y_loc
     area.columns = self.win_size_x
     scroll_region = ScrollWindow(area, window=self.center_win)
     scroll_region.add_paragraph(summary_text, start_x=SummaryScreen.INDENT)
     
     self.center_win.activate_object(scroll_region)
Esempio n. 5
0
    def test_convert_paragraph(self):
        ''' test convert_paragraph() '''
        c0 = '\u3042'  # 2 columns
        c1 = '\u3044'  # 2 columns
        c2 = ' '  # 1 column (white space)
        c3 = '\u3046'  # 2 columns
        c4 = '\u3048'  # 2 columns
        s = c0 + c1 + c2 + c3 + c4

        if if_wrap_on_whitespace():
            self.assertEqual(convert_paragraph(s, 10), [s])
            self.assertEqual(convert_paragraph(s, 9), [s])
            self.assertEqual(convert_paragraph(s, 8), [s[:3], s[3:].lstrip()])
            self.assertEqual(convert_paragraph(s, 7), [s[:3], s[3:].lstrip()])
            self.assertEqual(convert_paragraph(s, 6), [s[:3], s[3:].lstrip()])
            self.assertEqual(convert_paragraph(s, 5), [s[:3], s[3:].lstrip()])
            self.assertEqual(convert_paragraph(s, 4), [s[:2], s[2:].lstrip()])
        else:
            self.assertEqual(convert_paragraph(s, 10), [s])
            self.assertEqual(convert_paragraph(s, 9), [s])
            self.assertEqual(convert_paragraph(s, 8), [s[:4], s[4:].lstrip()])
            self.assertEqual(convert_paragraph(s, 7), [s[:4], s[4:].lstrip()])
            self.assertEqual(convert_paragraph(s, 6), [s[:3], s[3:].lstrip()])
            self.assertEqual(convert_paragraph(s, 5), [s[:3], s[3:].lstrip()])
            self.assertEqual(convert_paragraph(s, 4), [s[:2], s[2:].lstrip()])