editw is set to after function but widget doesnt get focus

269 views
Skip to first unread message

Hombre del saco

unread,
Mar 27, 2018, 6:43:26 PM3/27/18
to npyscreen
Hello!

first of all sorry for my english:

I am getting fun with npyscreen but i have one problem: I have one Form with widgets and when I press a button I want to get focus to first item, this is my code:


def function_excel(self):
self.grid.values = []
items = self.parentApp.myExcel.read_wb_interface()
for x in items:
cola = self.parentApp.myDatabase.get_record(x)
self.grid.values.append(cola)
self.grid.display()  
self.editw = 0  
self.label.value = str(self.editw)
self.label.update()


When I exit to the function I know that editw its in 0 (label show it) but dont get focus, button is still highlight on yellow, and if I press TAB focus pass to next item to editw=0, so its correct.

I tried to self.display() after self.editw = 0, but nothin happens

anyone could help me? 

Regards

Hombre del saco

unread,
Mar 28, 2018, 5:00:10 AM3/28/18
to npyscreen
Ok i got It! I didnt see a previous topic that speaks about It, here the solution:

Add value 'False' on atribute '.editing' in my button before a exit the function!

Later I Will post my code.

Regards!

Hombre del saco

unread,
Mar 28, 2018, 9:48:20 AM3/28/18
to npyscreen
Hi again! ok.. Now I am in the computer, I dont know how the hell i didnt notice to other topic that talks about this so...

Here is the code:

def focus_on_first(self):
    self.editw = 0         
    self.editing = False

and i call the function when I need and works! 

Regards!

Alex S

unread,
May 3, 2019, 11:15:07 PM5/3/19
to npyscreen
Greetings,

This is something obvious, so apologies for the ignorant question. Based on the below snippet, can you advise how I can fix this example to get focus on 'Field 2'. I still want Fields 1-3 to be editable, but I want the focus and .editing to start at a specific field:

import npyscreen
class TestApp(npyscreen.NPSApp):
    def main(self):
        F  = npyscreen.Form(name = "I want to change the initial focus and edit Field 2")
        f0 = F.add(npyscreen.TitleText, name = '# widg:', editable = False)
        f1  = F.add(npyscreen.TitleText, name = "Field 1:")
        f2  = F.add(npyscreen.TitleText, name = "Field 2:")
        f3  = F.add(npyscreen.TitleText, name = "Field 3:")
        no_of_widgets = len(F._widgets__)
        F._widgets__[0].value = str(no_of_widgets)
        for i in range(1, no_of_widgets): F._widgets__[i].value = str(i)

        f1.editing = False # 1) does not stop f1 from being edited

        F.editw = 2 # 2) does not change focus to f2

        F.edit()
if __name__ == "__main__": TestApp().run()
Reply all
Reply to author
Forward
0 new messages