def test_no_ut_refresh(self): '''Ensure deep_refresh is updating nested window screen location ''' scroll_win = ScrollWindow(WindowArea(60, 70, 0, 0, scrollable_columns=75), color_theme=ColorTheme(force_bw=True)) scroll_win.window = MockInnerWin() scroll_win.area.lower_right_y = 20 scroll_win.area.lower_right_x = 20 myscroll = ScrollWindow(WindowArea(10, 10, 0, 0, scrollable_columns=15), color_theme=ColorTheme(force_bw=True)) myscroll.window = MockInnerWin() myscroll.area.lower_right_y = 16 myscroll.area.lower_right_x = 18 scroll_win.objects.append(myscroll) scroll_win.area.y_loc = 3 scroll_win.area.x_loc = 5 abs_y = 12 abs_x = 15 scroll_win.latest_yx = (abs_y, abs_x) scroll_win.no_ut_refresh() self.assertEquals(myscroll.latest_yx[0], scroll_win.area.y_loc + abs_y) self.assertEquals(myscroll.latest_yx[1], scroll_win.area.x_loc + abs_x)
def _show(self): ''' called upon display of a screen ''' super(NSAltChooser, self)._show() y_loc = self._paint_opening() LOGGER.debug(self.nameservice) # allow the user to select an alternate name service area = WindowArea(x_loc=0, y_loc=y_loc, scrollable_lines=len(NameService.USER_CHOICE_LIST) + 1) area.lines = self.win_size_y - (y_loc + 1) area.columns = self.win_size_x self.scroll_region = ScrollWindow(area, window=self.center_win) # add the entries to the screen menu_item_max_width = self.win_size_x - NameService.SCROLL_SIZE for idx, nsn in enumerate(NameService.USER_CHOICE_LIST): y_loc += 1 hilite = min(menu_item_max_width, textwidth(nsn) + 1) win_area = WindowArea(1, hilite, idx, INDENT) ListItem(win_area, window=self.scroll_region, text=nsn, data_obj=nsn) # finalize positioning self.main_win.do_update() self.center_win.activate_object(self.scroll_region) self.scroll_region.activate_object_force(self.cur_nschoice_idx, force_to_top=True)
def _show(self): # The _show method will not only create the four desired EditFields, # but restore saved state as well. win_area = WindowArea(lines=1, columns=40, y_loc=1, x_loc=1) edit_area = WindowArea(lines=1, columns=20, y_loc=0, x_loc=10) for field_num in range(4): win_area.y_loc += 1 field_label = "%s: " % field_num list_item = ListItem(win_area, window=self.center_win, text=field_label) # Grab the saved text for the field (assume it's been saved for # now; *how* to go about saving it is below) field_text = self.saved_text[field_num] # And then set that as the text for the field edit_field = EditField(edit_area, window=list_item, text=field_text) # Save a reference to the field so other methods can access # their data: self.fields[field_num] = edit_field # Since this series of fields also acts as a selectable list, # the current selection can be restored as well by changing which # object is active: self.center_win.activate_object(self.current_selection)
def _show(self): ''' called upon display of a screen ''' super(NSDNSChooser, self)._show() y_loc = self._paint_opening() LOGGER.debug(self.nameservice) # allow the user to choose DNS or not ynlist = [_('Configure DNS'), _('Do not configure DNS')] area = WindowArea(x_loc=0, y_loc=y_loc, scrollable_lines=len(ynlist) + 1) area.lines = self.win_size_y - (y_loc + 1) area.columns = self.win_size_x self.scroll_region_dns = ScrollWindow(area, window=self.center_win) # add the entries to the screen for idx, yon in enumerate(ynlist): win_area = WindowArea(1, textwidth(yon) + 1, idx, INDENT) ListItem(win_area, window=self.scroll_region_dns, text=yon, data_obj=yon) # finalize positioning self.main_win.do_update() self.center_win.activate_object(self.scroll_region_dns) self.scroll_region_dns.activate_object_force(self.cur_dnschoice_idx, force_to_top=True)
def test_scrollable_columns(self): '''Test scrollable_columns getter and setter ''' num_cols = 75 my_win = WindowArea(50, num_cols, 0, 0) self.assertEqual(my_win.scrollable_columns, 75) my_win.scrollable_columns = 80 self.assertEqual(my_win.scrollable_columns, 80)
def _init_win(self, window): '''Require at least 70 columns and 6 lines to fit current needs for display of partitions and slices. Builds two inner ScrollWindows for displaying/editing the data. ''' if self.area.columns < 70: raise ValueError("Insufficient space - area.columns < 70") if self.area.lines < 6: raise ValueError("Insufficient space - area.lines < 6") self.win_width = (self.area.columns - DiskWindow.DEAD_ZONE + DiskWindow.SCROLL_PAD) / 2 super(DiskWindow, self)._init_win(window) win_area = WindowArea(self.area.lines - 1, self.win_width, 2, 0) win_area.scrollable_lines = self.area.lines - 2 self.left_win = ScrollWindow(win_area, window=self, add_obj=False) self.left_win.color = None self.left_win.highlight_color = None win_area.x_loc = self.win_width + DiskWindow.DEAD_ZONE win_area.scrollable_lines = 2 * MAX_EXT_PARTS self.right_win = ScrollWindow(win_area, window=self, add_obj=False) self.right_win.color = None self.right_win.highlight_color = None
def _show(self): super(NSNISAuto, self)._show() if self.nameservice.nameservice != 'NIS': raise SkipException y_loc = self._paint_opening() y_loc += self.center_win.add_paragraph(self.intro2, y_loc) y_loc += 1 ynlist = [_('Find one'), _('Specify one')] area = WindowArea(x_loc=0, y_loc=y_loc, scrollable_lines=len(ynlist) + 1) area.lines = self.win_size_y - (y_loc + 1) area.columns = self.win_size_x self.scroll_region = ScrollWindow(area, window=self.center_win) y_loc += 1 # blank line # add the entries to the screen for idx, yon in enumerate(ynlist): y_loc += 1 win_area = WindowArea(lines=1, columns=textwidth(yon) + 1, y_loc=idx, x_loc=INDENT) ListItem(win_area, window=self.scroll_region, text=yon, data_obj=yon) self.main_win.do_update() self.center_win.activate_object(self.scroll_region) self.scroll_region.activate_object_force(self.cur_nisnschoice_idx, force_to_top=True) y_loc += 1 # blank line self.center_win.add_paragraph(self.intro3, y_loc)
def _show(self): super(NSLDAPProxyBindInfo, self)._show() if self.nameservice.nameservice != 'LDAP': raise SkipException if self.nameservice.ldap_proxy_bind == \ NameServiceInfo.LDAP_CHOICE_NO_PROXY_BIND: raise SkipException y_loc = self._paint_opening() y_loc += 1 # blank line self.center_win.add_text(self.title, y_loc, INDENT) y_loc += 1 # edit field on following line since it should be big cols = self.win_size_x - INDENT - 2 area = WindowArea(1, cols, y_loc, INDENT + 2, scrollable_columns=MAXDNLEN + 1) self.ldap_pb_dn = EditField(area, window=self.center_win, text=self.nameservice.ldap_pb_dn, error_win=self.main_win.error_line) # in case of error, tell user what is being validated self.ldap_pb_dn.validate_kwargs['etext'] = _('distinguished name') y_loc += 2 # blank line titlelen = textwidth(self.title2) self.center_win.add_text(self.title2, y_loc, NameService.SCROLL_SIZE) cols = self.win_size_x - titlelen - INDENT - 1 area = WindowArea(1, cols, y_loc, titlelen + INDENT + 1) self.ldap_pb_psw = EditField(area, window=self.center_win, text=self.nameservice.ldap_pb_psw, error_win=self.main_win.error_line, masked=True) self.main_win.do_update() self.center_win.activate_object(self.ldap_pb_dn)
def _show(self): """ create the screen for the user to select a discovery method """ y_loc = 1 y_loc += self.center_win.add_paragraph(DiscoverySelection.PARAGRAPH, y_loc) y_loc += 1 item_area = WindowArea(1, DiscoverySelection.ITEM_MAX_WIDTH, y_loc, 1) self.local = ListItem(item_area, window=self.center_win, text=DiscoverySelection.LOCAL_TEXT) self.local.item_key = "local" self.center_win.add_text(DiscoverySelection.LOCAL_DETAIL, y_loc, DiscoverySelection.ITEM_DESC_OFFSET, self.win_size_x - 3) y_loc += 2 item_area.y_loc = y_loc self.iscsi = ListItem(item_area, window=self.center_win, text=DiscoverySelection.ISCSI_TEXT) self.iscsi.item_key = "iscsi" self.center_win.add_text(DiscoverySelection.ISCSI_DETAIL, y_loc, DiscoverySelection.ITEM_DESC_OFFSET, self.win_size_x - 3) self.main_win.do_update() self.center_win.activate_object(self.current_selection)
def display_help(self): '''Display the single file help screen''' # customize header help_header = "%s: %s" terminalui.LOGGER.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) terminalui.LOGGER.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)
def _show(self): '''Prepare a text summary and display it to the user in a ScrollWindow ''' global LOGGER LOGGER = logging.getLogger(INSTALL_LOGGER_NAME) self.sysconfig = solaris_install.sysconfig.profile.from_engine() y_loc = 1 y_loc += self.center_win.add_paragraph(SummaryScreen.PARAGRAPH, y_loc) y_loc += 1 summary_text = self.build_summary() LOGGER.info("The following configuration is used for " "installation: %s\n", summary_text) # 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)
def _show(self): '''Prepare a text summary and display it to the user in a ScrollWindow ''' global LOGGER LOGGER = logging.getLogger(INSTALL_LOGGER_NAME) self.sysconfig = solaris_install.sysconfig.profile.from_engine() y_loc = 1 y_loc += self.center_win.add_paragraph(SummaryScreen.PARAGRAPH, y_loc) y_loc += 1 summary_text = self.build_summary() LOGGER.info( "The following configuration is used for " "installation: %s\n", summary_text) # 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)
def test_scrollable_lines(self): '''Test scrollable_lines getter and setter ''' print "\nhello" num_lines = 70 my_win = WindowArea(num_lines, 60, 0, 0) self.assertEqual(my_win.scrollable_lines, num_lines) my_win.scrollable_lines = 80 self.assertEqual(my_win.scrollable_lines, 80)
def test_vert_scrollbar_created(self): '''Ensure vertical scrollbar is created or not appropriately''' scroll_win = ScrollWindow(WindowArea(70, 70, 0, 0, scrollable_lines=75), color_theme=ColorTheme(force_bw=True)) self.assertTrue(scroll_win.get_use_vert_scroll_bar()) scroll_win = ScrollWindow(WindowArea(70, 70, 0, 0, scrollable_lines=70), color_theme=ColorTheme(force_bw=True)) self.assertFalse(scroll_win.get_use_vert_scroll_bar())
def _show(self): super(NSLDAPProfile, self)._show() if self.nameservice.nameservice != 'LDAP': raise SkipException if self.nameservice.dns: self.intro = \ _("Specify the name of the LDAP profile to be used to " "configure this system and the host name or IP address of " "the server that contains the profile.") self.title2 = _("Profile server host name or IP address:") else: self.intro = \ _("Specify the name of the LDAP profile to be used to " "configure this system and the IP address of the " "server that contains the profile.") self.title2 = _("Profile server IP address:") self.intro += _(" Enter the LDAP search base.") y_loc = self._paint_opening() maxtitlelen = max(textwidth(self.title), textwidth(self.title2), textwidth(self.title3)) aligned_x_loc = maxtitlelen + INDENT + 1 cols = self.win_size_x - aligned_x_loc self.center_win.add_text(self.title.rjust(maxtitlelen), y_loc, INDENT) area = WindowArea(1, cols, y_loc, aligned_x_loc) self.ldap_profile = EditField(area, window=self.center_win, text=self.nameservice.ldap_profile, error_win=self.main_win.error_line, validate=inc_validate_nowhite_nospecial) # in case of error, tell user what is being validated self.ldap_profile.validate_kwargs['etext'] = _('profile name') y_loc += 1 area = WindowArea(1, cols, y_loc, aligned_x_loc, scrollable_columns=NameService.HOSTNAME_SCREEN_LEN + 1) self.center_win.add_text(self.title2.rjust(maxtitlelen), y_loc, INDENT) # create edit field, validating for host name or IP address depending # on whether DNS was selected self.ldap_ip = EditField(area, window=self.center_win, text=self.nameservice.ldap_ip, error_win=self.main_win.error_line, validate=(incremental_validate_host if self.nameservice.dns else incremental_validate_ip)) # search base y_loc += 1 self.center_win.add_text(self.title3.rjust(maxtitlelen), y_loc, INDENT) area = WindowArea(1, cols, y_loc, aligned_x_loc, scrollable_columns=MAXDNLEN + 1) self.ldap_search_base = EditField(area, window=self.center_win, text=self.nameservice.ldap_search_base, error_win=self.main_win.error_line) self.main_win.do_update() self.center_win.activate_object(self.ldap_ip)
def __init__(self, main_win): global LOGGER if LOGGER is None: LOGGER = logging.getLogger(INSTALL_LOGGER_NAME + ".sysconfig") super(DateTimeScreen, self).__init__(main_win) year_edit_width = DateTimeScreen.YEAR_DIGITS + 1 list_width = DateTimeScreen.MAX_LEN + year_edit_width self.list_area = WindowArea(1, list_width, 0, DateTimeScreen.ITEM_OFFSET) self.year_edit_area = WindowArea(1, year_edit_width, 0, DateTimeScreen.MAX_LEN + 1) other_edit_width = DateTimeScreen.TWO_DIGITS + 1 other_edit_offset = ( DateTimeScreen.MAX_LEN + (DateTimeScreen.YEAR_DIGITS - DateTimeScreen.TWO_DIGITS) + 1) self.edit_area = WindowArea(1, other_edit_width, 0, other_edit_offset) self.info_offset = (DateTimeScreen.ITEM_OFFSET + self.list_area.columns + 1) self.info_width = len(DateTimeScreen.YEAR_FORMAT) err_offset = self.info_offset + self.info_width + 2 err_width = self.win_size_x - err_offset self.err_area = WindowArea(1, err_width, 0, err_offset) self.year_edit = None self.year_err = None self.year_list = None self.month_edit = None self.month_err = None self.month_list = None self.day_edit = None self.day_err = None self.day_list = None self.hour_edit = None self.hour_err = None self.hour_list = None self.minute_edit = None self.minute_err = None self.minute_list = None self.year_is_valid = True self.month_is_valid = True self.date_range_loc = None self.saved_year = None self.saved_month = None self.saved_day = None self.saved_hour = None self.saved_minute = None self.saved_days_in_month = None
def _show(self): '''Display the static paragraph WELCOME_TEXT and all applicable bullet items''' sc_options = get_sc_options_from_doc() max_width = self.win_size_x - WelcomeScreen.INDENT - 1 text = convert_paragraph(WelcomeScreen.WELCOME_TEXT, max_width) # list configuration groups in a comma-separated list with # bullet on first line and indentation on subsequent lines grouplist = list() if configure_group(SC_GROUP_NETWORK): grouplist.append(_("network")) elif configure_group(SC_GROUP_IDENTITY): grouplist.append(_("system hostname")) if configure_group(SC_GROUP_LOCATION): grouplist.append(_("time zone")) if configure_group(SC_GROUP_DATETIME): grouplist.append(_("date and time")) if configure_group(SC_GROUP_USERS): grouplist.append(_("user and root accounts")) if configure_group(SC_GROUP_NS): grouplist.append(_("name services")) grouplist = ", ".join(grouplist) grouplist = convert_paragraph(grouplist, max_width - len(WelcomeScreen.BULLET)) for ln in range(len(grouplist)): if ln == 0: text.append(WelcomeScreen.BULLET + grouplist[ln]) else: text.append(WelcomeScreen.BULLET_INDENT + grouplist[ln]) # display navigation instructions and profile path fmt = {"scprof": sc_options.profile} text.extend(convert_paragraph(WelcomeScreen.NAVIPRO_TEXT % fmt, max_width)) # indent and align while bulletting for bullet in WelcomeScreen.BULLET_ITEMS: btext = convert_paragraph(bullet, max_width - len(WelcomeScreen.BULLET)) for ln in range(len(btext)): if ln == 0: text.append(WelcomeScreen.BULLET + btext[ln]) else: text.append(WelcomeScreen.BULLET_INDENT + btext[ln]) # prepare welcome text in entire window for scrolling area = WindowArea(x_loc=0, y_loc=1, scrollable_lines=(len(text) + 1)) area.lines = self.win_size_y - 1 area.columns = self.win_size_x scroll_region = ScrollWindow(area, window=self.center_win) scroll_region.add_paragraph(text, start_x=WelcomeScreen.INDENT) self.center_win.activate_object(scroll_region)
def _show(self): text = "List Item %s" for num in xrange(1, 10): # When adding subwindows to a screen's center_win, the location # of the subwindow needs to be specified. The location should # be relative to the parent window. y_loc = num x_loc = 1 height = 1 width = 15 win_area = WindowArea(height, width, y_loc, x_loc) # To create a list of selectable items, use ListItems. ListItem # is a thin wrapper around InnerWindow, which supports adding # text to itself in one step. The 'window' parameter specifies # the parent window item_text = text % num list_item = ListItem(win_area, window=self.center_win, text=item_text, centered=True) # After the above loop completes, 'center_win' now has 9 ListItem # 'subwindows.' By default, none are marked as 'active' (i.e., none # have focus). The activate_object() function of InnerWindow fixes # that. (With no parameter, the first ListItem is activated) self.center_win.activate_object()
def test_active_object(self): '''Test that arrow key changes active object''' lines = 4 extra_lines = 9 scroll_win = ScrollWindow(WindowArea(lines, 70, 0, 0, scrollable_lines=lines + extra_lines), color_theme=ColorTheme(force_bw=True)) scroll_win.active_object = 0 myobj0 = MockEditField() myobj0.area = MockInnerWin() myobj0.area.y_loc = 1 myobj0.active = True myobj1 = MockEditField() myobj1.area = MockInnerWin() myobj1.area.y_loc = 3 myobj1.active = False scroll_win.objects.append(myobj0) scroll_win.objects.append(myobj1) key = scroll_win.on_arrow_key(curses.KEY_DOWN) self.assertEquals(key, None) self.assertEquals(scroll_win.active_object, 1)
def _show(self): super(NSDNSServer, self)._show() # check dictionary of screens associated with name service selections if not self.nameservice.dns: raise SkipException y_loc = self._paint_opening() self.dns_server_list = [] find_1st_nonblank = None find_last_nonblank = -1 for i in range(NameServiceInfo.MAXDNSSERV): self.center_win.add_text(self.title, y_loc, INDENT) area = WindowArea(1, MAXIP, y_loc, textwidth(self.title) + INDENT + 1) y_loc += 1 if i < len(self.nameservice.dns_server) and \ self.nameservice.dns_server[i] is not None: text = self.nameservice.dns_server[i] else: text = '' # find first blank field or last non-blank field if text: find_last_nonblank = i elif find_1st_nonblank is None: find_1st_nonblank = i self.dns_server_list += [EditField(area, window=self.center_win, text=text, validate=incremental_validate_ip, error_win=self.main_win.error_line)] self.main_win.do_update() # position cursor on first blank or after last field if find_1st_nonblank is None: idx = min(find_last_nonblank + 1, NameServiceInfo.MAXDNSSERV - 1) else: idx = find_1st_nonblank self.center_win.activate_object(self.dns_server_list[idx])
def test_scroll_down_up_arrow(self): '''Test to scroll down and up with arrow key ''' lines = 4 extra_lines = 9 scroll_win = ScrollWindow(WindowArea(lines, 70, 0, 0, scrollable_lines=lines + extra_lines), color_theme=ColorTheme(force_bw=True)) scroll_win.active_object = None self.assertTrue(scroll_win.at_top()) key = scroll_win.on_arrow_key(curses.KEY_DOWN) self.assertEqual(key, None) self.assertFalse(scroll_win.at_top()) key = scroll_win.on_arrow_key(curses.KEY_UP) self.assertEqual(key, None) self.assertTrue(scroll_win.at_top()) key = scroll_win.on_arrow_key(curses.KEY_UP) self.assertEqual(key, curses.KEY_UP) self.assertTrue(scroll_win.at_top()) scroll_win.scroll(extra_lines - 2) self.assertFalse(scroll_win.at_bottom()) scroll_win.on_arrow_key(curses.KEY_DOWN) self.assertTrue(scroll_win.at_bottom()) scroll_win.scroll(-(extra_lines - 2)) self.assertFalse(scroll_win.at_top()) scroll_win.on_arrow_key(curses.KEY_UP) self.assertTrue(scroll_win.at_top())
def __init__(self, main_win): """ screen object containing iSCSI criteria objects """ global LOGGER LOGGER = logging.getLogger(INSTALL_LOGGER_NAME) super(IscsiScreen, self).__init__(main_win) self.target_ip = None self.target_port = None self.target_lun = None self.target_name = None self._initiator_name = None self.chap_name = None self.chap_password = None self.full_win_width = self.win_size_x - IscsiScreen.DEAD_ZONE self.half_win_width = (self.win_size_x - IscsiScreen.DEAD_ZONE) / 2 self.default_edit = WindowArea(y_loc=0, lines=1, columns=IscsiScreen.CHAP_LEN) self.right_edit = WindowArea(y_loc=0, lines=1, columns=IscsiScreen.MAX_PORT_LEN) self.name_edit = WindowArea(y_loc=0, lines=1, scrollable_columns=IscsiScreen.MAX_NAME_LEN + 1) self.chap_edit = WindowArea(y_loc=0, lines=1, columns=IscsiScreen.CHAP_LEN) self.target_ip_list = None self.target_ip_edit = None self.target_port_list = None self.target_port_edit = None self.target_lun_list = None self.target_lun_edit = None self.target_name_edit = None self.initiator_name_edit = None self.chap_name_edit = None self.chap_password_edit = None # key map dictionary for Target entries self.add_keys = {curses.KEY_LEFT: self.on_arrow_key, curses.KEY_RIGHT: self.on_arrow_key, curses.KEY_DOWN: self.on_arrow_key, curses.KEY_UP: self.on_arrow_key} self.iscsi_obj = None self.is_iscsiboot = is_iscsiboot()
def test_scroll_no_args(self): '''Test that scroll called with no args throws ValueError''' scroll_win = ScrollWindow(WindowArea(70, 70, 0, 0, scrollable_lines=75), color_theme=ColorTheme(force_bw=True)) self.assertTrue(scroll_win.get_use_vert_scroll_bar()) self.assertEquals(scroll_win.current_line[0], 0) self.assertRaises(ValueError, scroll_win.scroll)
def test_horiz_scrollbar_created(self): '''Ensure horizontal scrollbar is created or not appropriately''' scroll_win = ScrollWindow(WindowArea(70, 70, 0, 0, scrollable_columns=75), color_theme=ColorTheme(force_bw=True)) self.assertTrue(scroll_win.get_use_horiz_scroll_bar()) scroll_win = ScrollWindow(WindowArea(70, 70, 0, 0, scrollable_columns=69), color_theme=ColorTheme(force_bw=True)) self.assertFalse(scroll_win.get_use_horiz_scroll_bar())
def _show(self): '''Create a scrollable region and fill it with the install log''' self.center_win.border_size = (0, 0) self.scroll_area = WindowArea(self.win_size_y, self.win_size_x, 0, 0, len(self.get_log_data())) log = ScrollWindow(self.scroll_area, window=self.center_win) log.add_paragraph(self.get_log_data(), 0, 2) self.center_win.activate_object(log)
def test_scroll_one_line(self): '''Test to scroll one line ''' scroll_win = ScrollWindow(WindowArea(70, 70, 0, 0, scrollable_lines=75), color_theme=ColorTheme(force_bw=True)) self.assertTrue(scroll_win.get_use_vert_scroll_bar()) self.assertEquals(scroll_win.current_line[0], 0) scroll_win.scroll(lines=1) self.assertEquals(scroll_win.current_line[0], 1)
def _show(self): super(NSNISIP, self)._show() LOGGER.info("self.nameservice: %s" % self.nameservice) if self.nameservice.nameservice != 'NIS': raise SkipException if self.nameservice.nis_auto == NameServiceInfo.NIS_CHOICE_AUTO: raise SkipException if self.nameservice.dns: self.intro = \ _("Enter the host name or IP address of the name server. " "A host name must have at least 2 characters and can be " "alphanumeric and can contain hyphens. IP " "addresses must contain four sets of numbers separated " "by periods (for example, 129.200.9.1).") self.title = _("Server's host name or IP address:") else: self.intro = \ _("Enter the IP address of the name server. IP " "addresses must contain four sets of numbers separated " "by periods (for example, 129.200.9.1).") self.title = _("Server's IP address:") y_loc = self._paint_opening() self.center_win.add_text(self.title, y_loc, INDENT) aligned_x_loc = textwidth(self.title) + INDENT + 1 cols = self.win_size_x - aligned_x_loc area = WindowArea(1, cols, y_loc, aligned_x_loc) self.center_win.add_text(self.title, y_loc, INDENT) area = WindowArea(1, cols, y_loc, aligned_x_loc, scrollable_columns=NameService.HOSTNAME_SCREEN_LEN + 1) # create edit field, validating for host name or IP address depending # on whether DNS was selected self.nis_ip = EditField( area, window=self.center_win, text=self.nameservice.nis_ip, error_win=self.main_win.error_line, validate=(incremental_validate_host if self.nameservice.dns else incremental_validate_ip)) self.main_win.do_update() self.center_win.activate_object(self.nis_ip)
def _show(self): '''Display the explanatory paragraph and create the DiskWindow''' disk = get_desired_target_disk(self.doc) if disk.label == "VTOC": raise SkipException if disk.whole_disk: LOGGER.debug("disk.whole_disk=True, skip editing") # perform final target validation perform_final_validation(self.doc) raise SkipException part = disk bootable = "" if self.is_x86 and disk.is_boot_disk(): bootable = PartEditScreen.BOOTABLE disk_size_str = locale.format( "%.1f", disk.disk_prop.dev_size.get(Size.gb_units)) + LOCALIZED_GB type_boot_str = PartEditScreen.HEADER_TYPE_BOOTABLE % \ {"type": disk.disk_prop.dev_type, "bootable": bootable} header = self.header_text + disk_size_str + type_boot_str self.main_win.set_header_text(header) y_loc = 1 fmt_dict = {'pool': ROOT_POOL} fmt_dict.update(RELEASE) y_loc += self.center_win.add_paragraph(self.paragraph_text % fmt_dict, y_loc) y_loc += 1 disk_win_area = WindowArea(6, 70, y_loc, 0) self.disk_win = DiskWindow(disk_win_area, part, window=self.center_win, editable=True, error_win=self.main_win.error_line, target_controller=self.tc) y_loc += disk_win_area.lines y_loc += 1 LOGGER.log(LOG_LEVEL_INPUT, "calling addch with params start_y=%s," "start_x=%s, ch=%c", y_loc, self.center_win.border_size[1], DiskWindow.DESTROYED_MARK) self.center_win.window.addch(y_loc, self.center_win.border_size[1], DiskWindow.DESTROYED_MARK, self.center_win.color_theme.inactive) self.center_win.add_text(self.destroy_text, y_loc, 2) self.main_win.do_update() self.center_win.activate_object(self.disk_win)
def init_status_bar(self, y_loc, x_loc, width): '''Initialize the progress bar window and set to 0%''' self.status_bar_width = width status_bar_area = WindowArea(1, width + 3, y_loc, x_loc + 1) self.status_bar = InnerWindow(status_bar_area, window=self.center_win) self.status_bar.window.addch(0, 0, InstallProgress.PROG_BAR_ENDS[0]) self.status_bar.window.addch(0, width + 1, InstallProgress.PROG_BAR_ENDS[1]) self.progress_color = self.center_win.color_theme.progress_bar self.set_status_percent(0)
def display_help_topics(self): '''Display the help topics screen.''' self.main_win.set_header_text(self.help_header) y_loc = 1 y_loc += self.center_win.add_paragraph(self.intro, y_loc, 1, max_x=(self.win_size_x - 1)) y_loc += 1 area = WindowArea(scrollable_lines=(len(self.help_info) + 1), y_loc=y_loc, x_loc=0) terminalui.LOGGER.debug("lines=%s", len(self.help_dict)) area.lines = self.win_size_y - (y_loc + 1) area.columns = self.win_size_x self.scroll_region = ScrollWindow(area, window=self.center_win) # add the entries to the screen terminalui.LOGGER.debug("range=%s", len(self.help_info)) for idx, info in enumerate(self.help_info): # create ListItem for each help topic topic_format = info[1] topic_title = self.help_dict[info[0]][1] help_topic = topic_format % topic_title hilite = min(self.win_size_x, textwidth(help_topic) + 1) list_item = ListItem(WindowArea(1, hilite, idx, 0), window=self.scroll_region, text=help_topic) terminalui.LOGGER.debug("self.screen_last=%s", self.screen_last) if self.screen_last == info[0]: terminalui.LOGGER.debug("Set cur_help_idx = %s", idx) self.cur_help_idx = idx terminalui.LOGGER.debug("beg_y=%d, beg_x=%d", *list_item.window.getbegyx()) self.center_win.activate_object(self.scroll_region) self.scroll_region.activate_object(self.cur_help_idx)
def _show(self): # Set up the three list items... win_area = WindowArea(lines=1, columns=15, y_loc=1, x_loc=1) self.hello_item = ListItem(win_area, window=self.center_win, text="Hello World") win_area.y_loc += 1 self.list_item = ListItem(win_area, window=self.center_win, text="Lists") win_area.y_loc += 1 self.edit_item = ListItem(win_area, window=self.center_win, text="Edit Fields") self.center_win.activate_object()
def _show(self): '''Prepare a text summary from the DOC 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 self.sysconfig = solaris_install.sysconfig.profile.from_engine() 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)
def _show(self): '''Create a list of disks to choose from and create the window for displaying the partition/slice information from the selected disk ''' self.wait_for_disks() discovered_target = self.doc.persistent.get_first_child( \ name=Target.DISCOVERED) LOGGER.debug(discovered_target) if discovered_target is None: self.center_win.add_paragraph(DiskScreen.NO_DISKS, 1, 1, max_x=(self.win_size_x - 1)) return self.disks = discovered_target.get_children(class_type=Disk) if not self.disks: self.center_win.add_paragraph(DiskScreen.NO_TARGETS, 1, 1, max_x=(self.win_size_x - 1)) return if self._image_size is None: try: self._image_size = Size(str(get_image_size(LOGGER)) + \ Size.mb_units) LOGGER.debug("Image_size: %s", self._image_size) except: # Unable to get the image size for some reason, allow # the target controller to use it's default size. LOGGER.debug("Unable to get image size") self._image_size = FALLBACK_IMAGE_SIZE # initialize the target controller so the min/max size for # the installation can be calculated. Explicitly do not # want to select an initial disk at this time in case # none of the disks discovered is usable. The target controller # initialization needs to be done everytime we show the disk selection # screen so the desired target node in the DOC can be re-populated # with information from target discovery. self.tc.initialize(image_size=self._image_size, no_initial_disk=True) # Go through all the disks found and find ones that have # enough space for installation. At the same time, see if any # existing disk is the boot disk. If a boot disk is found, move # it to the front of the list num_usable_disks = 0 boot_disk = None for disk in self.disks: LOGGER.debug("size: %s, min: %s" % \ (disk.disk_prop.dev_size, self.minimum_size)) if disk.disk_prop.dev_size >= self.minimum_size: if disk.is_boot_disk(): boot_disk = disk num_usable_disks += 1 if boot_disk is not None: self.disks.remove(boot_disk) self.disks.insert(0, boot_disk) if num_usable_disks == 0: self.center_win.add_paragraph(DiskScreen.NO_DISKS, 1, 1, max_x=(self.win_size_x - 1)) return self.main_win.reset_actions() self.main_win.show_actions() y_loc = 1 self.center_win.add_text(DiskScreen.PARAGRAPH, y_loc, 1) y_loc += 1 self.center_win.add_text(self.size_line, y_loc, 1) y_loc += 2 self.center_win.add_text(self.disk_header_text, y_loc, 1) y_loc += 1 self.center_win.window.hline(y_loc, self.center_win.border_size[1] + 1, curses.ACS_HLINE, textwidth(self.disk_header_text)) y_loc += 1 disk_win_area = WindowArea(4, textwidth(self.disk_header_text) + 2, y_loc, 0) disk_win_area.scrollable_lines = len(self.disks) + 1 self.disk_win = ScrollWindow(disk_win_area, window=self.center_win) disk_item_area = WindowArea(1, disk_win_area.columns - 2, 0, 1) disk_index = 0 len_type = DiskScreen.DISK_HEADERS[0][0] - 1 len_size = DiskScreen.DISK_HEADERS[1][0] - 1 len_boot = DiskScreen.DISK_HEADERS[2][0] - 1 len_dev = DiskScreen.DISK_HEADERS[3][0] - 1 len_mftr = DiskScreen.DISK_HEADERS[4][0] - 1 for disk in self.disks: disk_text_fields = [] if disk.disk_prop is None or disk.disk_prop.dev_type is None: continue type_field = disk.disk_prop.dev_type[:len_type] type_field = ljust_columns(type_field, len_type) disk_text_fields.append(type_field) disk_size = disk.disk_prop.dev_size.get(Size.gb_units) size_field = locale.format("%*.1f", (len_size, disk_size)) disk_text_fields.append(size_field) if disk.is_boot_disk(): bootable_field = "+".center(len_boot) else: bootable_field = " " * (len_boot) disk_text_fields.append(bootable_field) device_field = disk.ctd[:len_dev] device_field = ljust_columns(device_field, len_dev) disk_text_fields.append(device_field) vendor = disk.disk_prop.dev_vendor if vendor is not None: mftr_field = vendor[:len_mftr] mftr_field = ljust_columns(mftr_field, len_mftr) else: mftr_field = " " * len_mftr disk_text_fields.append(mftr_field) selectable = True if disk.disk_prop.dev_size < self.minimum_size: note_field = self.too_small_text selectable = False elif disk_size > Size(MAX_VTOC).get(Size.gb_units): note_field = self.too_big_warn else: note_field = "" disk_text_fields.append(note_field) disk_text = " ".join(disk_text_fields) disk_item_area.y_loc = disk_index disk_list_item = ListItem(disk_item_area, window=self.disk_win, text=disk_text, add_obj=selectable) disk_list_item.on_make_active = on_activate disk_list_item.on_make_active_kwargs["disk"] = disk disk_list_item.on_make_active_kwargs["disk_select"] = self disk_index += 1 self.disk_win.no_ut_refresh() y_loc += 7 disk_detail_area = WindowArea(6, 70, y_loc, 1) self.disk_detail = DiskWindow(disk_detail_area, self.disks[0], target_controller=self.tc, window=self.center_win) self.main_win.do_update() self.center_win.activate_object(self.disk_win) self.disk_win.activate_object(self.selected_disk_index)
def _show(self): # WindowArea boilerplate list_area = WindowArea(lines=1, columns=40, y_loc=1, x_loc=1) edit_area = WindowArea(lines=1, columns=20, y_loc=0, x_loc=15) # EditFields support per-character validation by passing in # a callback function as the "validate" keyword argument. The function # is called after each keypress with a single parameter, the EditField # in question (from which one can grab the current text). If the # current value is valid, the function should do nothing. If invalid, # a UIMessage exception should be raised. # For the sake of 'flow', the validation functions for this sample # will be defined inline; in general, they should be defined elsewhere # in the file. Finally, remember that, since these functions are # called after each keystroke, they need to be able to handle partially # correct values as well. For example, "2", "25", "255", "255.", # "255.2", "255.25", ..., "255.255.255.0" all would need to be accepted # by a netmask validation function. def digits_only(edit_field): text = edit_field.get_text() if text and not text.isdigit(): raise UIMessage("Only digits allowed!") list_area.y_loc = 1 self.char_list = ListItem(list_area, window=self.center_win, text="validate:") self.char_edit = EditField(edit_area, window=self.char_list, validate=digits_only, error_win=self.main_win.error_line) # The error_win parameter is required to make anything meaningful # display to the user; it should be a reference to an ErrorWindow # object in which to display the message. (self.main_win.error_line # is used here as filler; a more appropriate example follows) list_area.y_loc = 2 # There's nothing too special about creating an ErrorWindow; # it's much like a ListItem or EditField: error_area = WindowArea(lines=1, columns=30, y_loc=2, x_loc=40) self.char2_err = ErrorWindow(error_area, self.center_win) self.char2_list = ListItem(list_area, window=self.center_win, text="validate(2):") self.char2_edit = EditField(edit_area, window=self.char2_list, validate=digits_only, error_win=self.char2_err) # An EditField can also be checked for validity on loss of focus, # by passing a function to the "on_exit" argument # (though care must be taken to also check validity when changing # screens; screen changes don't trigger loss-of-focus checks in the # same way) # The following EditField illustrates such a thing. (An on_exit # function would be an appropriate place to ensure that a user # entered "255.255.255.0" for a netmask, and not just "255.") list_area.y_loc = 3 error_area.y_loc = 3 self.focus_err = ErrorWindow(error_area, self.center_win) self.focus_list = ListItem(list_area, window=self.center_win, text="on_exit:") self.focus_edit = EditField(edit_area, window=self.focus_list, on_exit=digits_only, error_win=self.focus_err) self.center_win.activate_object()
def _show(self): '''Create the list of time zones''' LOGGER.debug("self.screen %s", self.screen) sc_profile = solaris_install.sysconfig.profile.from_engine() if sc_profile.system is None: sc_profile.system = SystemInfo() self.sys_info = sc_profile.system self.cur_country = self.sys_info.tz_country self.cur_continent = self.sys_info.tz_region if self.cur_continent == SystemInfo.UTC and self.screen != "regions": raise SkipException self.center_win.border_size = TimeZone.BORDER_WIDTH if self.screen == TimeZone.LOCATIONS: self.cur_timezone_parent = self.cur_continent elif self.screen == TimeZone.TIMEZONE: self.cur_timezone_parent = self.cur_country LOGGER.debug("cur_continent %s, cur_country %s", self.cur_continent, self.cur_country) y_loc = 1 y_loc += self.center_win.add_paragraph(self.intro, y_loc) y_loc += 1 menu_item_max_width = self.win_size_x - TimeZone.SCROLL_SIZE self.center_win.add_text(self.title, y_loc, TimeZone.SCROLL_SIZE) y_loc += 1 self.center_win.window.hline(y_loc, 3, curses.ACS_HLINE, 40) y_loc += 1 tz_list = self.get_timezones(self.cur_continent, self.cur_country) area = WindowArea(x_loc=0, y_loc=y_loc, scrollable_lines=len(tz_list) + 1) area.lines = self.win_size_y - (y_loc + 1) area.columns = self.win_size_x LOGGER.debug("area.lines=%s, area.columns=%s", area.lines, area.columns) self.scroll_region = ScrollWindow(area, window=self.center_win) utc = 0 if self.screen == TimeZone.REGIONS: utc_area = WindowArea(1, len(TimeZone.UTC_TEXT) + 1, 0, TimeZone.SCROLL_SIZE) utc_item = ListItem(utc_area, window=self.scroll_region, text=TimeZone.UTC_TEXT, data_obj=SystemInfo.UTC) utc = 1 # add the entries to the screen for idx, timezone in enumerate(tz_list): LOGGER.log(LOG_LEVEL_INPUT, "tz idx = %i name= %s", idx, tz_list[idx]) hilite = min(menu_item_max_width, len(timezone) + 1) win_area = WindowArea(1, hilite, idx + utc, TimeZone.SCROLL_SIZE) list_item = ListItem(win_area, window=self.scroll_region, text=timezone, data_obj=timezone) y_loc += 1 self.main_win.do_update() self.center_win.activate_object(self.scroll_region) LOGGER.debug("self.cur_timezone_idx=%s", self.cur_timezone_idx) self.scroll_region.activate_object_force(self.cur_timezone_idx, force_to_top=True)