Ejemplo n.º 1
0
 def print_headers(self):
     '''Print the headers for the displayed data.
     
     header[0] - The width of this column. header[1] and header[2] are
                 trimmed to this size
     header[1] - The internationalized text for the left window
     header[2] - The internationalized text for the right window
     
     '''
     self.left_header_string = []
     self.right_header_string = []
     for header in self.headers:
         left_header_str = header[1]
         right_header_str = header[2]
         # Trim the header to fit in the column width,
         # splitting columns with at least 1 space
         # Pad with extra space(s) to align the columns
         left_header_str = fit_text_truncate(left_header_str,
                                             header[0]-1, just="left")
         self.left_header_string.append(left_header_str)
         right_header_str = fit_text_truncate(right_header_str,
                                             header[0]-1, just="left")
         self.right_header_string.append(right_header_str)
     self.left_header_string = " ".join(self.left_header_string)
     self.right_header_string = " ".join(self.right_header_string)
     logging.debug(self.left_header_string)
     self.add_text(self.left_header_string, 0, DiskWindow.SCROLL_PAD)
     right_win_offset = (self.win_width + DiskWindow.DEAD_ZONE +
                         DiskWindow.SCROLL_PAD)
     self.add_text(self.right_header_string, 0, right_win_offset)
     self.window.hline(1, DiskWindow.SCROLL_PAD, curses.ACS_HLINE,
                       textwidth(self.left_header_string))
     self.window.hline(1, right_win_offset, curses.ACS_HLINE,
                       textwidth(self.right_header_string))
     self.no_ut_refresh()
Ejemplo n.º 2
0
 def __init__(self, main_win):
     super(DiskScreen, self).__init__(main_win)
     if platform.processor() == "i386":
         self.found_text = DiskScreen.FOUND_x86
         self.proposed_text = DiskScreen.PROPOSED_x86
     else:
         self.found_text = DiskScreen.FOUND_SPARC
         self.proposed_text = DiskScreen.PROPOSED_SPARC
     
     disk_header_text = []
     for header in DiskScreen.DISK_HEADERS:
         header_str = fit_text_truncate(header[1], header[0]-1, just="left")
         disk_header_text.append(header_str)
     self.disk_header_text = " ".join(disk_header_text)
     max_note_size = DiskScreen.DISK_HEADERS[6][0]
     self.too_small_text = DiskScreen.TOO_SMALL[:max_note_size]
     max_disk_size = SliceInfo.MAX_VTOC.size_as("tb")
     too_big_warn = DiskScreen.TOO_BIG_WARN % max_disk_size
     self.too_big_warn = too_big_warn[:max_note_size]
     self.disk_warning_too_big = \
         DiskScreen.DISK_WARNING_TOOBIG % max_disk_size
     
     self.one_disk_used = False
     self.disks = []
     self.existing_pools = []
     self.disk_win = None
     self.disk_detail = None
     self.num_targets = 0
     self.td_handle = None
     self._size_line = None
     self.selected_disk = 0
     self._minimum_size = None
     self._recommended_size = None
     self.do_copy = False # Flag indicating if install_profile.disks
Ejemplo n.º 3
0
 def __init__(self, main_win):
     super(DiskScreen, self).__init__(main_win)
     if platform.processor() == "i386":
         self.found_text = DiskScreen.FOUND_x86
         self.proposed_text = DiskScreen.PROPOSED_x86
     else:
         self.found_text = DiskScreen.FOUND_SPARC
         self.proposed_text = DiskScreen.PROPOSED_SPARC
     
     disk_header_text = []
     for header in DiskScreen.DISK_HEADERS:
         header_str = fit_text_truncate(header[1], header[0]-1, just="left")
         disk_header_text.append(header_str)
     self.disk_header_text = " ".join(disk_header_text)
     max_note_size = DiskScreen.DISK_HEADERS[5][0]
     self.too_small_text = DiskScreen.TOO_SMALL[:max_note_size]
     max_disk_size = SliceInfo.MAX_VTOC.size_as("tb")
     too_big_warn = DiskScreen.TOO_BIG_WARN % max_disk_size
     self.too_big_warn = too_big_warn[:max_note_size]
     self.disk_warning_too_big = \
         DiskScreen.DISK_WARNING_TOOBIG % max_disk_size
     
     self.disks = []
     self.existing_pools = []
     self.disk_win = None
     self.disk_detail = None
     self.num_targets = 0
     self.td_handle = None
     self._size_line = None
     self.selected_disk = 0
     self._minimum_size = None
     self._recommended_size = None
     self.do_copy = False # Flag indicating if install_profile.disk
Ejemplo n.º 4
0
    def __init__(self, main_win):
        super(ZpoolScreen, self).__init__(main_win)

        pool_header_text = []
        for header in ZpoolScreen.POOL_HEADERS:
            header_str = fit_text_truncate(header[1],
                                           header[0] - 1,
                                           just="left")
            pool_header_text.append(header_str)
        self.pool_header_text = " ".join(pool_header_text)

        self.existing_pools = []
        self.num_targets = 0
        max_note_size = ZpoolScreen.POOL_HEADERS[2][0]
        self.too_small_text = ZpoolScreen.TOO_SMALL[:max_note_size]
        self._size_line = None
        self.selected_pool = 0
        self._minimum_size = None
        self._recommended_size = None
        self.pool_win = None

        max_field = max(textwidth(ZpoolScreen.BE_LABEL),
                        textwidth(ZpoolScreen.BE_NAME_EMPTY_ERROR),
                        textwidth(ZpoolScreen.BE_NAME_UNALLOWED_ERROR),
                        textwidth(ZpoolScreen.NO_POOLS))

        self.max_text_len = int((self.win_size_x - ZpoolScreen.BE_SCREEN_LEN -
                                 ZpoolScreen.ITEM_OFFSET) / 2)
        self.text_len = min(max_field + 1, self.max_text_len)
        self.list_area = WindowArea(1, self.text_len, 0,
                                    ZpoolScreen.ITEM_OFFSET)

        self.edit_area = WindowArea(1, ZpoolScreen.BE_SCREEN_LEN + 1, 0,
                                    self.text_len)
        err_x_loc = 2
        err_width = (self.text_len + ZpoolScreen.BE_SCREEN_LEN)
        self.error_area = WindowArea(1, err_width + 1, 0, err_x_loc)
        self.be_name_list = None
        self.be_name_edit = None
        self.be_name_err = None

        self.boot_configuration_item = None
        self.do_copy = False  # Flag indicating if install_profile.pool_name
Ejemplo n.º 5
0
    def add_text(self,
                 text,
                 start_y=0,
                 start_x=0,
                 max_chars=None,
                 centered=False):
        '''Add a single line of text to the window
        
        'text' must fit within the specified space, or it will be truncated
        
        '''
        win_y, win_x = self.window.getmaxyx()
        logging.log(
            LOG_LEVEL_INPUT, "start_y=%d, start_x=%d, max_chars=%s, "
            "centered=%s, win_max_x=%s, win_max_y=%s", start_y, start_x,
            max_chars, centered, win_x, win_y)
        max_x = self.window.getmaxyx()[1] - self.border_size[1]
        start_x += self.border_size[1]

        abs_max_chars = max_x - start_x
        if max_chars is None:
            max_chars = abs_max_chars
        else:
            max_chars = min(max_chars, abs_max_chars)

        text = fit_text_truncate(text, max_chars)

        if centered:
            start_x = (max_x - textwidth(text)) / 2 + start_x

        text = unicode(text)
        text = text.encode(get_encoding())
        logging.log(
            LOG_LEVEL_INPUT, "calling addstr with params start_y=%s,"
            "start_x=%s, text=%s", start_y, start_x, text)
        self.window.addstr(start_y, start_x, text)
        self.no_ut_refresh()
Ejemplo n.º 6
0
 def test_fit_text_truncate(self):
     ''' test fit_text_truncate() '''
     c0 = '\u3042'  # 2 columns
     c1 = '\u3044'  # 2 columns
     c2 = '\u3046'  # 2 columns
     c3 = '\u3048'  # 2 columns
     s = c0 + c1 + c2 + c3
     # no justification
     self.assertEqual(fit_text_truncate(s, 9), s[:4])
     self.assertEqual(fit_text_truncate(s, 8), s[:4])
     self.assertEqual(fit_text_truncate(s, 7), s[:3])
     self.assertEqual(fit_text_truncate(s, 6), s[:3])
     self.assertEqual(fit_text_truncate(s, 5), s[:2])
     self.assertEqual(fit_text_truncate(s, 4), s[:2])
     self.assertEqual(fit_text_truncate(s, 3), s[:1])
     self.assertEqual(fit_text_truncate(s, 2), s[:1])
     self.assertEqual(fit_text_truncate(s, 1), s[:0])
     self.assertEqual(fit_text_truncate(s, 0), s[:0])
     # justify to left
     self.assertEqual(fit_text_truncate(s, 9, just=LEFT), s[:4] + ' ')
     self.assertEqual(fit_text_truncate(s, 8, just=LEFT), s[:4])
     self.assertEqual(fit_text_truncate(s, 7, just=LEFT), s[:3] + ' ')
     self.assertEqual(fit_text_truncate(s, 6, just=LEFT), s[:3])
     self.assertEqual(fit_text_truncate(s, 5, just=LEFT), s[:2] + ' ')
     self.assertEqual(fit_text_truncate(s, 4, just=LEFT), s[:2])
     self.assertEqual(fit_text_truncate(s, 3, just=LEFT), s[:1] + ' ')
     self.assertEqual(fit_text_truncate(s, 2, just=LEFT), s[:1])
     self.assertEqual(fit_text_truncate(s, 1, just=LEFT), s[:0] + ' ')
     self.assertEqual(fit_text_truncate(s, 0, just=LEFT), s[:0])
     # justify to right
     self.assertEqual(fit_text_truncate(s, 9, just=RIGHT), ' ' + s[:4])
     self.assertEqual(fit_text_truncate(s, 8, just=RIGHT), s[:4])
     self.assertEqual(fit_text_truncate(s, 7, just=RIGHT), ' ' + s[:3])
     self.assertEqual(fit_text_truncate(s, 6, just=RIGHT), s[:3])
     self.assertEqual(fit_text_truncate(s, 5, just=RIGHT), ' ' + s[:2])
     self.assertEqual(fit_text_truncate(s, 4, just=RIGHT), s[:2])
     self.assertEqual(fit_text_truncate(s, 3, just=RIGHT), ' ' + s[:1])
     self.assertEqual(fit_text_truncate(s, 2, just=RIGHT), s[:1])
     self.assertEqual(fit_text_truncate(s, 1, just=RIGHT), ' ' + s[:0])
     self.assertEqual(fit_text_truncate(s, 0, just=RIGHT), s[:0])
     # justify to center
     self.assertEqual(fit_text_truncate(s, 12, just=CENTER),
                      ' ' * 2 + s[:4] + ' ' * 2)
     self.assertEqual(fit_text_truncate(s, 11, just=CENTER),
                      ' ' + s[:4] + ' ' * 2)
     self.assertEqual(fit_text_truncate(s, 10, just=CENTER),
                      ' ' + s[:4] + ' ')
     self.assertEqual(fit_text_truncate(s, 9, just=CENTER), s[:4] + ' ')
     self.assertEqual(fit_text_truncate(s, 8, just=CENTER), s[:4])
     self.assertEqual(fit_text_truncate(s, 7, just=CENTER), s[:3] + ' ')
     self.assertEqual(fit_text_truncate(s, 6, just=CENTER), s[:3])
     self.assertEqual(fit_text_truncate(s, 5, just=CENTER), s[:2] + ' ')
     self.assertEqual(fit_text_truncate(s, 4, just=CENTER), s[:2])
     self.assertEqual(fit_text_truncate(s, 3, just=CENTER), s[:1] + ' ')
     self.assertEqual(fit_text_truncate(s, 2, just=CENTER), s[:1])
     self.assertEqual(fit_text_truncate(s, 1, just=CENTER), s[:0] + ' ')
     self.assertEqual(fit_text_truncate(s, 0, just=CENTER), s[:0])