chevron_left chevron_right
Login Register invert_colors photo_library


Stay updated and chat with others! - Join the Discord!
Thread Rating:
  • 0 Vote(s) - 0 Average


[Question] Python Curses: Multithreading Input | SOLVED filter_list
Author
Message
[Question] Python Curses: Multithreading Input | SOLVED #1
Okay, I am making a stopwatch that by pressing the up key it adds more and more watch's, right now I only have it running on one.
When the user inputs the up arrow key, another stopwatch is added, this will just be done as an array and for loop.
The issue is, when using Curses, it locks the screen. No other inputs or anything can be interpreted.

I will put a comment on what doesn't work.

Code:
from time import sleep
from curses import wrapper

import curses
import threading


class StopWatch(threading.Thread):
   seconds = 0
   minutes = 0
   hours = 0

   def run(self):
       while True:
           sleep(1)
           StopWatch.seconds = StopWatch.seconds + 1
           if StopWatch.seconds == 60:
               StopWatch.minutes = StopWatch.minutes + 1
               StopWatch.seconds = 1
           if StopWatch.minutes == 60:
               StopWatch.hours = StopWatch.hours + 1
               StopWatch.minutes = 1

# The input here does not work
class GetInput(threading.Thread):
   def run(self):
       while True:
           c = main.stdscr.getch()
           if c == 27:
               break
       exit(main.stdscr)


def main(stdscr):
   curses.echo()
   StopWatch().start()
   GetInput().start()
   while True:
       sleep(0.10)
       stdscr.clear()
       strToDisp = '{} Seconds | {} Minutes | {} Hours'
       strToDisp = strToDisp.format(StopWatch.seconds,
                                    StopWatch.minutes,
                                    StopWatch.hours)
       stdscr.addstr(0, 0, strToDisp)
       stdscr.refresh()
   exit(stdscr)


def exit(stdscr):
   curses.nocbreak()
   stdscr.keypad(False)
   curses.echo()
   curses.endwin()

if __name__ == '__main__':
   stdscr = curses.initscr()
   curses.noecho()
   curses.cbreak()
   stdscr.keypad(True)
   wrapper(main)
(This post was last modified: 04-15-2017, 12:46 AM by ProfessorChill.)

Reply




Messages In This Thread
[Question] Python Curses: Multithreading Input | SOLVED - by ProfessorChill - 04-13-2017, 08:19 PM



Users browsing this thread: 1 Guest(s)