0

the situation is like this: My App is running in a diffrent thread and the main program in another. I want to change values in my npyscreen widgedts from the main screen. I heard about events, but for some reasons the example code does not work.

Just for example. A program that copies files: Two threads one for the npyscreen app and one for the main loop. Whenever a file inside the main loop is done copying a counter in the Application should rise.

import os
import shutil
import npyscreen
import time
from concurrent.futures import ThreadPoolExecutor

def main():
    app = App()
    exec_thread = ThreadPoolExecutor(max_workers=2)
    thread1 = exec_thread.submit(app.run)
    thread2 = exec_thread.submit(main)
    thread2.result()
    time.sleep(2)

def process():
    cwd = os.getcwd()
    dst = f"{cwd}/test2"
    file_list = os.listdir(f"{cwd}/test")

    for file in file_list:
        shutil.copy(f"{cwd}/test/{file}", dst)
        # --------------------------------
        # implement a function that increments the text in the form
        # --------------------------------
    return


class Form(npyscreen.ActionForm):
    def create(self):
        self.cpfiles = self.add(npyscreen.TitleFixedText, name="copied", editable=False, value=str(0))
        self.display()

    def on_ok(self):
        self.parentApp.switchForm(None)


class App(npyscreen.NPSAppManaged):
    def onStart(self):
        self.addForm('MAIN', Form, name="test")

    def onCleanExit(self):
        npyscreen.notify_wait("Goodbye!")


if __name__ == '__main__':
    main()

I know this is oversimplyfied but i can't find a better example.

The example code i tried: https://github.com/npcole/npyscreen/blob/master/TESTING-EVENT-APP.py

TwoStone
  • 16
  • 2

0 Answers0