def __init__(self, monochrome): self.config = Config() self.monochrome = monochrome # Make delay slower os.environ.setdefault("ESCDELAY", self.config.curses.escdelay) # Use the preferred system encoding locale.setlocale(locale.LC_ALL, "") self.encoding = locale.getpreferredencoding().lower() self.screen = curses.initscr() self.screen.nodelay(True) # Flag controls whether we should redraw the screen or not. This is # used to reduce CPU usage in the browsing screen. self.redraw = True min_lines = 12 if self.lines < min_lines: curses.endwin() raise WpmError( "wpm requires at least %d lines in your display" % min_lines) min_cols = 20 if self.columns < min_cols: curses.endwin() raise WpmError( "wpm requires at least %d columns in your display" % min_cols) try: self.screen.keypad(True) curses.noecho() curses.cbreak() curses.start_color() self.set_colors() self.window = curses.newwin(self.lines, self.columns, 0, 0) self.window.keypad(True) self.window.timeout(self.config.curses.window_timeout) self.window.bkgd(" ", Screen.COLOR_BACKGROUND) # Local variables related to quote. TODO: Move this mess to somewhere # else. self.cheight = 0 self.first_key = True self.quote = "" self.quote_author = "" self.quote_columns = 0 self.quote_coords = tuple() self.quote_height = 0 self.quote_id = 0 self.quote_lengths = tuple() self.quote_title = "" except: curses.endwin() raise
def __init__(self, quotes, stats): self.config = Config() self.stats = stats self.average = self.stats.average(self.stats.tag, last_n=10) self.tab_spaces = None # Stats self.position = 0 self.incorrect = 0 self.total_incorrect = 0 self.start = None self.stop = None self._edit = "" self.num_quotes = len(quotes) self.quotes = quotes.random_iterator() self.screen = Screen() self.set_quote(self.quotes.next())
def __init__(self, quotes, stats, cpm_flag, monochrome, hard_flag, redlist_flag, redlist_threshold): self.config = Config() self.stats = stats self.cpm_flag = cpm_flag self.hard_flag = hard_flag self.redlist_flag = redlist_flag self.average = self.stats.average(self.stats.tag, last_n=10) self.tab_spaces = None self.redlist = Quotes.load_redlist() self.redlist_threshold = redlist_threshold if redlist_flag and not self.redlist: print("Redlist is empty") exit(0) # Stats self.position = 0 self.incorrect = 0 self.total_incorrect = 0 self.cheight = 0 self.start = None self.stop = None self._edit = "" self.num_quotes = len(quotes) self.quotes = quotes.random_iterator() if self.redlist_flag: self.quotes.set_indices(self.redlist) self.screen = Screen(monochrome) self.set_quote(self.quotes.next()) self.now = time.time()
def __init__(self, quotes, stats, cpm_flag, monochrome): self.config = Config() self.stats = stats self.cpm_flag = cpm_flag self.average = self.stats.average(self.stats.tag, last_n=10) self.tab_spaces = None # Stats self.position = 0 self.incorrect = 0 self.total_incorrect = 0 self.cheight = 0 self.start = None self.stop = None self._edit = "" self.num_quotes = len(quotes) self.quotes = quotes.random_iterator() self.screen = Screen(monochrome) self.set_quote(self.quotes.next()) self.now = time.time()