From bdba68ecb0856969db199e61c5a469d34c3159ba Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Thu, 21 Jan 2021 19:00:27 -0500 Subject: [PATCH] Test some more curses --- Adventure Game/adventure_game/main.py | 7 +--- Adventure Game/adventure_game/test_curses.py | 40 ++++++++++++++++++++ 2 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 Adventure Game/adventure_game/test_curses.py diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index 96bc838..265113f 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -1,6 +1,5 @@ import npyscreen - # This application class serves as a wrapper for the initialization of curses # and also manages the actual forms of the application @@ -8,17 +7,15 @@ class MyTestApp(npyscreen.NPSAppManaged): def onStart(self): self.registerForm("MAIN", MainForm()) - # This form class defines the display that will be presented to the user. class MainForm(npyscreen.Form): def create(self): - self.add(npyscreen.TitleText, name="Text:", value="Hellow World!") + self.add(npyscreen.TitleText, name = "Text:", value= "Hellow World!" ) def afterEditing(self): self.parentApp.setNextForm(None) - if __name__ == '__main__': TA = MyTestApp() - TA.run() + TA.run() \ No newline at end of file diff --git a/Adventure Game/adventure_game/test_curses.py b/Adventure Game/adventure_game/test_curses.py new file mode 100644 index 0000000..a02daaf --- /dev/null +++ b/Adventure Game/adventure_game/test_curses.py @@ -0,0 +1,40 @@ +import curses + +# The `screen` is a window that acts as the master window +# that takes up the whole screen. Other windows created +# later will get painted on to the `screen` window. +screen = curses.initscr() + +# lines, columns, start line, start column +my_window = curses.newwin(15, 20, 0, 0) + +# Long strings will wrap to the next line automatically +# to stay within the window +my_window.addstr(4, 4, "Hello from 4,4") +my_window.addstr(5, 15, "Hello from 5,15 with a long string") + +# Print the window to the screen +my_window.refresh() +curses.napms(2000) + +# Clear the screen, clearing my_window contents that were printed to screen +# my_window will retain its contents until my_window.clear() is called. +screen.clear() +screen.refresh() + +# Move the window and put it back on screen +# If we didn't clear the screen before doing this, +# the original window contents would remain on the screen +# and we would see the window text twice. +my_window.mvwin(10, 10) +my_window.refresh() +curses.napms(1000) + +# Clear the window and redraw over the current window space +# This does not require clearing the whole screen, because the window +# has not moved position. +my_window.clear() +my_window.refresh() +curses.napms(1000) + +curses.endwin() \ No newline at end of file