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) LOGGER.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()
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() terminalui.LOGGER.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 if isinstance(text, unicode): text = text.encode(get_encoding()) terminalui.LOGGER.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()
def __init__(self, main_win, target_controller): """ screen object containing the disk selection choice for the user """ global LOGGER LOGGER = logging.getLogger(INSTALL_LOGGER_NAME) 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 self.gpt_found_text = DiskScreen.FOUND_GPT self.gpt_proposed_text = DiskScreen.PROPOSED_GPT 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) self.max_vtoc_disk_size = (Size(MAX_VTOC)).get(Size.tb_units) self.disk_warning_too_big = \ DiskScreen.DISK_WARNING_TOOBIG % self.max_vtoc_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_index = 0 self._minimum_size = None self._recommended_size = None self.engine = InstallEngine.get_instance() self.doc = self.engine.data_object_cache self.tc = target_controller self._target_discovery_completed = False self._target_discovery_status = InstallEngine.EXEC_SUCCESS self._image_size = None self.iscsi = None self._iscsi_target_discovery_completed = False self._iscsi_target_discovery_status = InstallEngine.EXEC_SUCCESS
def __init__(self, main_win, target_controller): global LOGGER LOGGER = logging.getLogger(INSTALL_LOGGER_NAME) 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 = (Size(MAX_VTOC)).get(Size.tb_units) 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_index = 0 self._minimum_size = None self._recommended_size = None self.engine = InstallEngine.get_instance() self.doc = self.engine.data_object_cache self.tc = target_controller self._target_discovery_completed = False self._target_discovery_status = InstallEngine.EXEC_SUCCESS self._image_size = None
def display_err(self, text): '''Display error 'text'. Will also flash the error text if this box was already visible, to draw the user's attention to the new (or existing) error Restores cursor location after updating ''' cursor_loc = curses.getsyx() self.clear() terminalui.LOGGER.debug("displaying err '%s'", text) self.add_text(fit_text_truncate(text, self.area.columns - 1), centered=self.centered) self.make_active() curses.setsyx(cursor_loc[0], cursor_loc[1]) curses.doupdate() if self.visible: self.flash() self.visible = True
def display_err(self, text): '''Display error 'text'. Will also flash the error text if this box was already visible, to draw the user's attention to the new (or existing) error Restores cursor location after updating ''' cursor_loc = curses.getsyx() self.clear() terminalui.LOGGER.debug("displaying err '%s'", text) self.add_text(fit_text_truncate(text, self.area.columns - 1), centered=self.centered) self.make_active() curses.setsyx(cursor_loc[0], cursor_loc[1]) curses.doupdate() if self.visible: self.flash() self.visible = True
def test_fit_text_truncate(self): ''' test fit_text_truncate() ''' c0 = u'\u3042' # 2 columns c1 = u'\u3044' # 2 columns c2 = u'\u3046' # 2 columns c3 = u'\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] + u' ') self.assertEqual(fit_text_truncate(s, 8, just=LEFT), s[:4]) self.assertEqual(fit_text_truncate(s, 7, just=LEFT), s[:3] + u' ') self.assertEqual(fit_text_truncate(s, 6, just=LEFT), s[:3]) self.assertEqual(fit_text_truncate(s, 5, just=LEFT), s[:2] + u' ') self.assertEqual(fit_text_truncate(s, 4, just=LEFT), s[:2]) self.assertEqual(fit_text_truncate(s, 3, just=LEFT), s[:1] + u' ') self.assertEqual(fit_text_truncate(s, 2, just=LEFT), s[:1]) self.assertEqual(fit_text_truncate(s, 1, just=LEFT), s[:0] + u' ') self.assertEqual(fit_text_truncate(s, 0, just=LEFT), s[:0]) # justify to right self.assertEqual(fit_text_truncate(s, 9, just=RIGHT), u' ' + s[:4]) self.assertEqual(fit_text_truncate(s, 8, just=RIGHT), s[:4]) self.assertEqual(fit_text_truncate(s, 7, just=RIGHT), u' ' + s[:3]) self.assertEqual(fit_text_truncate(s, 6, just=RIGHT), s[:3]) self.assertEqual(fit_text_truncate(s, 5, just=RIGHT), u' ' + s[:2]) self.assertEqual(fit_text_truncate(s, 4, just=RIGHT), s[:2]) self.assertEqual(fit_text_truncate(s, 3, just=RIGHT), u' ' + s[:1]) self.assertEqual(fit_text_truncate(s, 2, just=RIGHT), s[:1]) self.assertEqual(fit_text_truncate(s, 1, just=RIGHT), u' ' + 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), u' ' * 2 + s[:4] + u' ' * 2) self.assertEqual(fit_text_truncate(s, 11, just=CENTER), u' ' + s[:4] + u' ' * 2) self.assertEqual(fit_text_truncate(s, 10, just=CENTER), u' ' + s[:4] + u' ') self.assertEqual(fit_text_truncate(s, 9, just=CENTER), s[:4] + u' ') self.assertEqual(fit_text_truncate(s, 8, just=CENTER), s[:4]) self.assertEqual(fit_text_truncate(s, 7, just=CENTER), s[:3] + u' ') self.assertEqual(fit_text_truncate(s, 6, just=CENTER), s[:3]) self.assertEqual(fit_text_truncate(s, 5, just=CENTER), s[:2] + u' ') self.assertEqual(fit_text_truncate(s, 4, just=CENTER), s[:2]) self.assertEqual(fit_text_truncate(s, 3, just=CENTER), s[:1] + u' ') self.assertEqual(fit_text_truncate(s, 2, just=CENTER), s[:1]) self.assertEqual(fit_text_truncate(s, 1, just=CENTER), s[:0] + u' ') self.assertEqual(fit_text_truncate(s, 0, just=CENTER), s[:0])
def test_fit_text_truncate(self): ''' test fit_text_truncate() ''' c0 = u'\u3042' # 2 columns c1 = u'\u3044' # 2 columns c2 = u'\u3046' # 2 columns c3 = u'\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] + u' ') self.assertEqual(fit_text_truncate(s, 8, just=LEFT), s[:4]) self.assertEqual(fit_text_truncate(s, 7, just=LEFT), s[:3] + u' ') self.assertEqual(fit_text_truncate(s, 6, just=LEFT), s[:3]) self.assertEqual(fit_text_truncate(s, 5, just=LEFT), s[:2] + u' ') self.assertEqual(fit_text_truncate(s, 4, just=LEFT), s[:2]) self.assertEqual(fit_text_truncate(s, 3, just=LEFT), s[:1] + u' ') self.assertEqual(fit_text_truncate(s, 2, just=LEFT), s[:1]) self.assertEqual(fit_text_truncate(s, 1, just=LEFT), s[:0] + u' ') self.assertEqual(fit_text_truncate(s, 0, just=LEFT), s[:0]) # justify to right self.assertEqual(fit_text_truncate(s, 9, just=RIGHT), u' ' + s[:4]) self.assertEqual(fit_text_truncate(s, 8, just=RIGHT), s[:4]) self.assertEqual(fit_text_truncate(s, 7, just=RIGHT), u' ' + s[:3]) self.assertEqual(fit_text_truncate(s, 6, just=RIGHT), s[:3]) self.assertEqual(fit_text_truncate(s, 5, just=RIGHT), u' ' + s[:2]) self.assertEqual(fit_text_truncate(s, 4, just=RIGHT), s[:2]) self.assertEqual(fit_text_truncate(s, 3, just=RIGHT), u' ' + s[:1]) self.assertEqual(fit_text_truncate(s, 2, just=RIGHT), s[:1]) self.assertEqual(fit_text_truncate(s, 1, just=RIGHT), u' ' + 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), u' ' * 2 + s[:4] + u' ' * 2) self.assertEqual(fit_text_truncate(s, 11, just=CENTER), u' ' + s[:4] + u' ' * 2) self.assertEqual(fit_text_truncate(s, 10, just=CENTER), u' ' + s[:4] + u' ') self.assertEqual(fit_text_truncate(s, 9, just=CENTER), s[:4] + u' ') self.assertEqual(fit_text_truncate(s, 8, just=CENTER), s[:4]) self.assertEqual(fit_text_truncate(s, 7, just=CENTER), s[:3] + u' ') self.assertEqual(fit_text_truncate(s, 6, just=CENTER), s[:3]) self.assertEqual(fit_text_truncate(s, 5, just=CENTER), s[:2] + u' ') self.assertEqual(fit_text_truncate(s, 4, just=CENTER), s[:2]) self.assertEqual(fit_text_truncate(s, 3, just=CENTER), s[:1] + u' ') self.assertEqual(fit_text_truncate(s, 2, just=CENTER), s[:1]) self.assertEqual(fit_text_truncate(s, 1, just=CENTER), s[:0] + u' ') self.assertEqual(fit_text_truncate(s, 0, just=CENTER), s[:0])