Мое желание состоит в том, что когда я просто нажимаю Enter над любым параметром, содержимое правого поля будет обновляться. Такое же поведение при использовании мыши. Но когда скрипт запускается и нажимает клавишу со стрелкой вниз, поле содержимого обновляется. Я не знаю, что делаю не так.
Вот мой код:
Код: Выделить всё
#! /usr/bin/python3
import npyscreen
class ProgramOptions(npyscreen.BoxTitle):
def __init__(self, *args, **keywords):
super(ProgramOptions, self).__init__(*args, **keywords)
self.entry_widget.when_cursor_moved = self.h_select_option
# self.entry_widget.when_value_edited = self.h_select_option
self.entry_widget.mouse_event = self.h_mouse_event
def h_select_option(self):
selected = self.entry_widget.values[self.entry_widget.cursor_line]
self.parent.update_content(selected)
def h_mouse_event(self):
selected = self.entry_widget.values[self.entry_widget.cursor_line]
self.parent.update_content(selected)
class ContentOption(npyscreen.BoxTitle):
_contained_widget = npyscreen.MultiLine
class MainForm(npyscreen.Form):
def create(self):
self.check_cursor_move = False
y, x = self.useable_space()
self.options = self.add(ProgramOptions,
name="Options",
max_width=x // 6,
relx=2,
rely=2,
)
self.options.entry_widget.values = [
'Option 1', 'Option 2', 'Option 3', 'Option 4']
self.content = self.add(ContentOption,
name="Content",
relx=(x // 6) + 4,
rely=2
)
def update_content(self, option):
# Actualiza el contenido basado en la opción seleccionada
content = f"You selected: {option}\n\nThis is the content for {option}."
self.content.entry_widget.values = content.split('\n')
self.content.display()
# self.display()
def afterEditing(self):
self.parentApp.setNextForm(None)
class TestApp(npyscreen.NPSAppManaged):
def onStart(self):
self.addForm("MAIN", MainForm, name="ROBOT CONFIGURATION")
if __name__ == "__main__":
app = TestApp().run()
Мне хотелось бы получить правильное поведение и знать, как правильно использовать обработчики методов.
Подробнее здесь: https://stackoverflow.com/questions/790 ... -npyscreen