0

我对 python 很陌生,我正在尝试用 npyscreen 组合一个小应用程序。这个应用程序的一部分有一个带有 FormControlBox 的页面,当被选中时会显示一个 FormControlBox。第二个 FormControlBox 被选中时,会显示一些文本字段。

我遇到的问题是让第二个 FormControlBox 将其值更改为 False 如果第一个未选中(使第二个隐藏)。这是我试图在这个表单类中采用的方法。

class envMenuForm(npyscreen.Form):
    def afterEditing(self):
        # Updating mapping with values set from form creation
        hostConfig["hostname"] = self.hostname.value
        hostConfig["domain"] = self.domain.value
        hostConfig["fqdn"] = self.fqdn.value
        self.parentApp.setNextForm('CEV')

    def create(self):
        # Defining vars from current baseConfig mapping from JSON file
        self.hostname = hostConfig["hostname"]
        self.domain = hostConfig["domain"]
        self.fqdn = hostConfig["fqdn"]

        # Adding text fields with the defaults from the config file
        self.hostname = self.add(npyscreen.TitleText, name = "System Hostname:", value = self.hostname)
        self.domain = self.add(npyscreen.TitleText, name = "System Domain:", value = self.domain)
        self.fqdn = self.add(npyscreen.TitleText, name = "System Fully Qualified Domain Name:", value = self.fqdn)

        self.et0status = self.add(npyscreen.FormControlCheckbox, name="Enable Eth0", value = False)
        self.et0type = self.add(npyscreen.FormControlCheckbox, name = "Configure as Static Address (ignore for DHCP)", value = False)
        self.et0ipaddress = self.add(npyscreen.TitleText, name = "IP Address", value = "127.0.0.1")

        self.et0status.addVisibleWhenSelected(self.et0type)
        self.et0type.addVisibleWhenSelected(self.et0ipaddress)

    def while_editing(self,arg):
        if arg is self.et0type:
            if arg.hidden:
                self.et0type.value = False
4

1 回答 1

0

经过一堆重构后,我能够使用带有一些背景逻辑的 adjust_widgets() 来解决这个问题,以确保它不会触发太多。

于 2018-02-23T23:55:29.900 回答