def __init__(self, screen, tui): self.screen = screen self.tui = tui self.tui.alreadyRegistered = 0 self.server = self.tui.serverURL size = snack._snack.size() toplevel = snack.GridForm(screen, REGISTER_WINDOW.encode('utf-8'), 1, 4) decoded_server = convert_url_from_pune(self.server) url = self.server if decoded_server != self.server: url += " (%s)" % decoded_server login_prompt = LOGIN_PROMPT % url login_label = LOGIN login_tip = LOGIN_TIP label = snack.Textbox(size[0] - 10, 3, login_prompt.encode('utf-8'), scroll=0, wrap=1) toplevel.add(label, 0, 0, anchorLeft=1) grid = snack.Grid(2, 3) label = snack.Label(login_label.encode('utf-8')) grid.setField(label, 0, 0, padding=(0, 0, 1, 0), anchorRight=1) self.userNameEntry = snack.Entry(20) self.userNameEntry.set(tui.userName) grid.setField(self.userNameEntry, 1, 0, anchorLeft=1) label = snack.Label(PASSWORD.encode('utf-8')) grid.setField(label, 0, 1, padding=(0, 0, 1, 0), anchorRight=1) try: self.passwordEntry = snack.Entry(20, password=1) except TypeError: self.passwordEntry = snack.Entry(20, hidden=1) self.passwordEntry.set(tui.password) grid.setField(self.passwordEntry, 1, 1, anchorLeft=1) toplevel.add(grid, 0, 1) label = snack.TextboxReflowed(size[0] - 10, login_tip.encode('utf-8')) toplevel.add(label, 0, 2, anchorLeft=1) # BUTTON BAR self.bb = snack.ButtonBar(screen, [(NEXT.encode('utf-8'), "next"), (BACK.encode('utf-8'), "back"), (CANCEL.encode('utf-8'), "cancel")]) toplevel.add(self.bb, 0, 3, padding=(0, 1, 0, 0), growx=1) self.g = toplevel
def VoteText(self, header, text, buttons=None, watches=None, reflow=False): if not buttons: buttons = ['Ok'] if watches is None: watches = {} with self: btnsbar = snack.ButtonBar(self.__screen, buttons) form = snack.GridForm(self.__screen, header, 1, 2) if text and reflow: textbox = snack.TextboxReflowed(width=TEXT_WIDTH, text=text, flexDown=FLEX_DOWN, flexUp=FLEX_UP) form.add(textbox, 0, 0, padding=(0, 0, 0, 1)) elif text: width, height, scroll = self.__GetWidgetBounds(5, text=text) textbox = snack.Textbox(width, height, text=text, scroll=scroll, wrap=True) form.add(textbox, 0, 0, padding=(0, 0, 0, 1)) form.add(btnsbar, 0, 1, padding=(0, 0, 0, 0)) for watch in watches: form.form.watchFile(watch, 1) ret = form.runOnce() if btnsbar.buttonPressed(ret): return btnsbar.buttonPressed(ret) elif ret in watches: return watches[ret] else: return None
def get_ftp_dest(answers): text = "Please enter the URL for your FTP directory and, optionally, a username and password" url_field = snack.Entry(50) user_field = snack.Entry(16) passwd_field = snack.Entry(16, password=1) url_text = snack.Textbox(11, 1, "URL:") user_text = snack.Textbox(11, 1, "Username:"******"Password:"******"Specify Path", 'getftpdest', 1, 3) bb = snack.ButtonBar(tui.screen, ['Ok', 'Back']) t = snack.TextboxReflowed(50, text) entry_grid = snack.Grid(2, 3) entry_grid.setField(url_text, 0, 0) entry_grid.setField(url_field, 1, 0) entry_grid.setField(user_text, 0, 1) entry_grid.setField(user_field, 1, 1, anchorLeft=1) entry_grid.setField(passwd_text, 0, 2) entry_grid.setField(passwd_field, 1, 2, anchorLeft=1) gf.add(t, 0, 0, padding=(0, 0, 0, 1)) gf.add(entry_grid, 0, 1, padding=(0, 0, 0, 1)) gf.add(bb, 0, 2, growx=1) button = bb.buttonPressed(gf.runOnce()) if button == 'back': return uicontroller.LEFT_BACKWARDS url = url_field.value() if not url.startswith('ftp://'): url = 'ftp://' + url if user_field.value() != '': quoted_user = urllib.quote(user_field.value(), safe='') if passwd_field.value() != '': quoted_passwd = urllib.quote(passwd_field.value(), safe='') answers['dest-address'] = url.replace( '//', '//%s:%s@' % (quoted_user, quoted_passwd), 1) else: answers['dest-address'] = url.replace('//', '//%s@' % quoted_user, 1) else: answers['dest-address'] = url return uicontroller.RIGHT_FORWARDS
def error(self, message): form = snack.GridForm(self._screen, "Error", 1, 3) form.add(snack.TextboxReflowed(40, message), 0, 0) form.add(snack.Textbox(0, 2, ""), 0, 1) form.add(snack.Button("Quit"), 0, 2) form.runOnce()
def __init__(self, screen, tui): self.name = "PackagesWindow" self.screen = screen self.tui = tui size = snack._snack.size() toplevel = snack.GridForm(screen, PACKAGES_WINDOW.encode('utf-8'), 1, 5) self.g = toplevel text = snack.TextboxReflowed(size[0] - 10, PACKAGES_WINDOW_DESC1.encode('utf-8')) toplevel.add(text, 0, 0, anchorLeft=1) self.packagesButton = snack.Checkbox( PACKAGES_WINDOW_DESC2.encode('utf-8'), 1) toplevel.add(self.packagesButton, 0, 1, padding=(0, 1, 0, 1), anchorLeft=1) label = snack.Label(PACKAGES_WINDOW_UNCHECK.encode('utf-8')) toplevel.add(label, 0, 2, anchorLeft=1) #self.packageList = snack.Listbox(size[1]-18, 1, width = size[0]-10) self.packageList = snack.CheckboxTree(size[1] - 18, 1) toplevel.add(self.packageList, 0, 3) # do we need to read the packages from disk? if tui.packageList == []: self.pwin = snack.GridForm(screen, PACKAGES_WINDOW_PKGLIST.encode('utf-8'), 1, 1) self.scale = snack.Scale(40, 100) self.pwin.add(self.scale, 0, 0) self.pwin.draw() self.screen.refresh() getArch = 0 if rhnreg.cfg['supportsExtendedPackageProfile']: getArch = 1 tui.packageList = pkgUtils.getInstalledPackageList(getArch=getArch) self.screen.popWindow() for package in tui.packageList: self.packageList.append( "%s-%s-%s" % (package['name'], package['version'], package['release']), item=package['name'], selected=1) # BUTTON BAR self.bb = snack.ButtonBar(screen, [(NEXT.encode('utf-8'), "next"), (BACK.encode('utf-8'), "back"), (CANCEL.encode('utf-8'), "cancel")]) toplevel.add(self.bb, 0, 4, padding=(0, 1, 0, 0), growx=1)
def _SnackWindow(screen, header, text, items): form = snack.GridForm(screen, header, 1, items + 1) if text: tbox = snack.TextboxReflowed(width=TEXT_WIDTH, text=text, maxHeight=screen.height - 12, flexDown=32, flexUp=0) form.add(tbox, 0, 0, padding=(0, 0, 0, 1)) return form
def __init__(self, screen, tui): self.screen = screen self.tui = tui size = snack._snack.size() toplevel = snack.GridForm(screen, sstr(FINISH_WINDOW), 1, 2) text = snack.TextboxReflowed(size[0] - 11, sstr(FINISH_WINDOW_TEXT_TUI)) toplevel.add(text, 0, 0) # BUTTON BAR self.bb = snack.ButtonBar(screen, [(sstr(_("Finish")), "next")]) toplevel.add(self.bb, 0, 1, padding=(0, 1, 0, 0), growx=1) self.g = toplevel
def __init__(self,Entries,screen,title,columns=1,width=30,ok_button=('Ok',1),cancel_button=('Cancel',0),**kargs): ''' Initialize the form ''' self.width=width self.MsgBox=snack.TextboxReflowed(width,' ') self.Entries=Entries self.EntriesLen=len(Entries) self.columns=columns self.EntriesGrid=snack.Grid(columns *2,self.EntriesLen ) self.Members={} # {<lable-text>:<entry-text-obj>,...} if kargs.get('Buttons',None): self.Buttons=kargs['Buttons'] else: self.Buttons = snack.ButtonBar(screen, (ok_button,cancel_button)) EntriesGrid=self.getEntriesGrid() super(EntryForm,self).__init__(screen,title,Widgets=[self.MsgBox,EntriesGrid,self.Buttons])
def __init__(self, screen, tui): self.screen = screen self.tui = tui size = snack._snack.size() toplevel = snack.GridForm(screen, sstr(SEND_WINDOW), 1, 2) text = snack.TextboxReflowed(size[0] - 15, sstr(SEND_WINDOW_DESC)) toplevel.add(text, 0, 0) # BUTTON BAR self.bb = snack.ButtonBar(screen, [(sstr(NEXT), "next"), (sstr(BACK), "back"), (sstr(CANCEL), "cancel")]) toplevel.add(self.bb, 0, 1, padding=(0, 1, 0, 0), growx=1) self.g = toplevel
def modalGUI(self, message, title, l1, l2): form = snack.GridForm(self.screen, title, 2, 2) textbox = snack.TextboxReflowed(40, message) form.add(textbox, 0, 0) if not l2: b1 = snack.Button(l1) form.add(b1, 0, 1) else: b1 = snack.Button(l1) b2 = snack.Button(l2) form.add(b1, 0, 1) form.add(b2, 1, 1) if form.runOnce() == b1: return 0 else: return 1
def __init__(self, screen, tui): self.name = "FinishWindow" self.screen = screen self.tui = tui size = snack._snack.size() toplevel = snack.GridForm(screen, FINISH_WINDOW.encode('utf-8'), 1, 2) text = snack.TextboxReflowed(size[0] - 11, FINISH_WINDOW_TEXT_TUI.encode('utf-8')) toplevel.add(text, 0, 0) # BUTTON BAR self.bb = snack.ButtonBar(screen, [(_("Finish").encode('utf-8'), "next")]) toplevel.add(self.bb, 0, 1, padding=(0, 1, 0, 0), growx=1) self.g = toplevel
def __init__(self, screen, tui): self.screen = screen self.tui = tui self.name = "SendWindow" size = snack._snack.size() toplevel = snack.GridForm(screen, SEND_WINDOW.encode('utf-8'), 1, 2) text = snack.TextboxReflowed(size[0] - 15, SEND_WINDOW_DESC.encode('utf-8')) toplevel.add(text, 0, 0) # BUTTON BAR self.bb = snack.ButtonBar(screen, [(NEXT.encode('utf-8'), "next"), (BACK.encode('utf-8'), "back"), (CANCEL.encode('utf-8'), "cancel")]) toplevel.add(self.bb, 0, 1, padding=(0, 1, 0, 0), growx=1) self.g = toplevel
def error_dialog(screen, title, msg): "Print error dialog" width = len(msg) if (newt): width = width_fix(screen, width) buttonbar = snack.ButtonBar(screen, ['Ok']) textbox = snack.TextboxReflowed(width, msg) grid = snack.GridForm(screen, title, 1, 2) grid.add(textbox, 0, 0, padding = (0, 0, 0, 1)) grid.add(buttonbar, 0, 1, growx = 1) grid.runOnce() elif (dialog): call_dlg(dlgcmd, '--title', title, '--msgbox', msg, '6', str(width + width_extra)) else: sys.stdout.write("\n%s: %s\n" % (title, msg))
def newDevice(self, mscreen): """ Displays the main screen @screen The snack screen instance """ t = snack.TextboxReflowed(25, _("Which device type do you want to add?")) bb = snack.ButtonBar(mscreen, ((_("Add"), "add"), (_("Cancel"), "cancel"))) li = snack.Listbox(5, width=25, returnExit=1) li.append(_("Ethernet"), ETHERNET) machine = os.uname()[4] if machine == 's390' or machine == 's390x': li.append(_("QETH"), QETH) else: li.append(_("Modem"), MODEM) li.append(_("ISDN"), ISDN) g = snack.GridForm(mscreen, _("Network Configuration"), 1, 3) g.add(t, 0, 0) g.add(li, 0, 1) g.add(bb, 0, 2) res = g.run() mscreen.popWindow() if bb.buttonPressed(res) != 'cancel': todo = li.current() df = getDeviceFactory() dev = None devclass = df.getDeviceClass(todo) devlist = getDeviceList() if not devclass: return -1 dev = devclass() if dev: devlist.append(dev) return dev return -2
def choice_window(screen, title, text, options, position): "Create options menu" maxopt = 0 for option in options: length = len(option) if (length > maxopt): maxopt = length width = maxopt height = len(options) if (newt): width = width_fix(screen, width + width_extra) height = height_fix(screen, height) if (height > 3): large = True else: large = False buttonbar = snack.ButtonBar(screen, ('Done', 'Cancel')) textbox = snack.TextboxReflowed(width, text) listbox = snack.Listbox(height, scroll=large, returnExit=1) cnt = 0 for option in options: listbox.append(option, cnt) cnt += 1 if (position != None): listbox.setCurrent(position) grid = snack.GridForm(screen, title, 1, 3) grid.add(textbox, 0, 0) grid.add(listbox, 0, 1, padding=(0, 1, 0, 1)) grid.add(buttonbar, 0, 2, growx=1) retval = grid.runOnce() return (buttonbar.buttonPressed(retval), listbox.current()) elif (dialog): if (width < 35): width = 35 args = [] cnt = 0 for option in options: args.append(str(cnt + 1)) args.append(option) cnt += 1 kw = {} if (position != None): kw['default-item'] = str(position + 1) status, data = call_dlg(dlgcmd, '--title', title, '--extra-button', '--extra-label', 'Done', '--menu', text, str(height + height_extra), str(width + width_extra), str(cnt), *args, **kw) if (status == 1): return ('cancel', None) try: choice = int(data) - 1 except ValueError: return ('cancel', None) if (status == 0): return (None, choice) return ('done', choice) sys.stdout.write("\n *** %s *** \n%s\n\n" % (title, text)) maxcnt = len(str(len(options))) cnt = 0 for option in options: sys.stdout.write("%*s. %s\n" % (maxcnt, cnt + 1, option)) cnt += 1 sys.stdout.write("\n%*s. Done\n" % (maxcnt, '0')) sys.stdout.write("%*s. Quit\n\n" % (maxcnt, 'q')) while True: if (position != None): sys.stdout.write("Selection[%s]: " % str(position + 1)) else: if (cnt > 0): sys.stdout.write("Selection[1]: ") else: sys.stdout.write("Selection[0]: ") inp = sys.stdin.readline() if (not inp): raise EOFError if (not inp.strip()): if (position != None): return (None, position) else: if (cnt > 0): inp = '1' else: inp = '0' if (inp.strip() == 'q'): return ('cancel', None) try: choice = int(inp.strip()) except ValueError: continue if (choice == 0): return ('done', 0) if (choice < 1) or (choice > len(options)): continue return (None, choice - 1)
def __init__(self, screen, tui): self.tui = tui if not rhnreg.server_supports_eus(): log.log_debug( "Server does not support EUS, skipping OSReleaseWindow") raise WindowSkipException() self.available_channels = rhnreg.getAvailableChannels( tui.userName, tui.password) if len(self.available_channels['channels']) < 1: log.log_debug( "No available EUS channels, skipping OSReleaseWindow") raise WindowSkipException() self.screen = screen self.size = snack._snack.size() self.selectChannel = False toplevel = snack.GridForm(self.screen, SELECT_OSRELEASE.encode('utf-8'), 1, 7) self.g = toplevel self.ostext = snack.TextboxReflowed(self.size[0] - 10, OS_VERSION.encode('utf-8')) toplevel.add(self.ostext, 0, 0, anchorLeft=1) optiontext1 = LIMITED_UPDATES.encode('utf-8') if self.tui.limited_updates_button: self.limited_updates_button = snack.SingleRadioButton(optiontext1, None, isOn=1) else: self.limited_updates_button = snack.SingleRadioButton( optiontext1, None) toplevel.add(self.limited_updates_button, 0, 1, padding=(0, 1, 0, 1), anchorLeft=1) self.sublabel = snack.Label(MINOR_RELEASE.encode('utf-8')) toplevel.add(self.sublabel, 0, 2, anchorLeft=1) self.channelList = snack.Listbox(self.size[1] - 22, 1, width=self.size[0] - 10) toplevel.add(self.channelList, 0, 3) for key, value in sorted(self.available_channels['channels'].items(), key=lambda a: a[0]): if key in self.available_channels['receiving_updates']: value = value + "*" self.channelList.append(" " + value, key) self.tip = snack.TextboxReflowed(self.size[0] - 10, CHANNEL_PAGE_TIP.encode('utf-8')) toplevel.add(self.tip, 0, 4, anchorLeft=1) optiontext2 = ALL_UPDATES.encode('utf-8') if self.tui.all_updates_button: self.all_updates_button = snack.SingleRadioButton( optiontext2, self.limited_updates_button, isOn=1) else: self.all_updates_button = snack.SingleRadioButton( optiontext2, self.limited_updates_button) toplevel.add(self.all_updates_button, 0, 5, padding=(0, 0, 0, 1), anchorLeft=1) #self.warning = snack.TextboxReflowed(self.size[0]-10, # CHANNEL_PAGE_WARNING.encode('utf-8')) #toplevel.add(self.warning, 0, 9, anchorLeft = 1) self.bb = snack.ButtonBar(screen, [(NEXT.encode('utf-8'), "next"), (BACK.encode('utf-8'), "back"), (CANCEL.encode('utf-8'), "cancel")]) toplevel.add(self.bb, 0, 6, growx=1) self.screen.refresh()
def __init__(self, screen, tui): self.screen = screen self.tui = tui size = snack._snack.size() #get the virtualization uuid and set it to other. (virt_uuid, virt_type) = rhnreg.get_virt_info() if not virt_uuid is None: self.tui.other['virt_uuid'] = virt_uuid self.tui.other['virt_type'] = virt_type # read all hardware in tui.hardware = hardware.Hardware() toplevel = snack.GridForm(screen, HARDWARE_WINDOW.encode('utf-8'), 1, 7) text = snack.TextboxReflowed(70, HARDWARE_WINDOW_DESC1.encode('utf-8')) toplevel.add(text, 0, 0, anchorLeft=1) grid = snack.Grid(2, 2) label = snack.Label(_("Profile name:").encode('utf-8')) grid.setField(label, 0, 0, padding=(0, 0, 1, 0), anchorRight=1) self.profileEntry = snack.Entry(40) grid.setField(self.profileEntry, 1, 0, anchorLeft=1) toplevel.add(grid, 0, 1, anchorLeft=1) if tui.includeHardware: self.hardwareButton = snack.Checkbox( HARDWARE_WINDOW_CHECKBOX.encode('utf-8'), isOn=1) else: self.hardwareButton = snack.Checkbox( HARDWARE_WINDOW_CHECKBOX.encode('utf-8')) toplevel.add(self.hardwareButton, 0, 2, padding=(0, 1, 0, 0), anchorLeft=1) label = snack.Label(DESELECT.encode('utf-8')) toplevel.add(label, 0, 3, anchorLeft=1, padding=(0, 0, 0, 1)) grid = snack.Grid(4, 3) hardware_text = '' hardware_text += _("Version: ") + up2dateUtils.getVersion() + " " self.versionLabel = snack.Label(_("Version: ").encode('utf-8')) grid.setField(self.versionLabel, 0, 0, padding=(0, 0, 1, 0), anchorLeft=1) self.versionLabel2 = snack.Label(up2dateUtils.getVersion()) grid.setField(self.versionLabel2, 1, 0, anchorLeft=1) hardware_text += _("CPU model: ") for hw in tui.hardware: if hw['class'] == 'CPU': hardware_text += hw['model'] + "\n" hardware_text += _("Hostname: ") for hw in tui.hardware: if hw['class'] == 'NETINFO': unicode_hostname = idn_pune_to_unicode(hw['hostname']) hardware_text += unicode_hostname + "\n" if tui.profileName != "": self.profileEntry.set(tui.profileName) else: self.profileEntry.set(unicode_hostname.encode('utf-8')) hardware_text += _("CPU speed: ") for hw in tui.hardware: if hw['class'] == 'CPU': hardware_text += _("%d MHz") % hw['speed'] + " " hardware_text += _("IP Address: ") for hw in tui.hardware: if hw['class'] == 'NETINFO': if hw['ipaddr']: hardware_text += hw['ipaddr'] + " " elif hw['ip6addr']: hardware_text += hw['ip6addr'] + " " hardware_text += _("Memory: ") for hw in tui.hardware: if hw['class'] == 'MEMORY': hardware_text += _("%s megabytes") % hw['ram'] tb = snack.TextboxReflowed(80, hardware_text.encode('utf-8')) toplevel.add(tb, 0, 4) self.additionalHWLabel = snack.TextboxReflowed( size[0] - 10, HARDWARE_WINDOW_DESC2.encode('utf-8')) toplevel.add(self.additionalHWLabel, 0, 5, padding=(0, 1, 0, 0), anchorLeft=1) # BUTTON BAR self.bb = snack.ButtonBar(screen, [(NEXT.encode('utf-8'), "next"), (BACK.encode('utf-8'), "back"), (CANCEL.encode('utf-8'), "cancel")]) toplevel.add(self.bb, 0, 6, padding=(0, 1, 0, 0), growx=1) self.g = toplevel
def __init__(self, width, text): BaseWidget.__init__(self) self._widget = snack.TextboxReflowed(width, text)