0

I'm quite new to python and I'm trying to put together a little app with npyscreen. Part of this app has a page with a FormControlBox, that reveals a FormControlBox when selected. This second FormControlBox, when selected, reveals some text fields.

The issue I'm having is getting the second FormControlBox to change its value to False if the first one is unselected (making the second hidden). Here is the approach I'm attempting to take in this form class.

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
J. Valerio
  • 13
  • 6

1 Answers1

0

After a bunch of refactoring I was able to solve this utilizing the adjust_widgets() with some background logic to ensure it doesn't fire off too much.

J. Valerio
  • 13
  • 6