Curses.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. # Curses-based interfaces
  2. # Copyright (C) 2003-2018 John Goerzen & contributors.
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. from threading import RLock, currentThread, Lock, Event
  18. from collections import deque
  19. import time
  20. import sys
  21. import os
  22. import curses
  23. import logging
  24. from offlineimap.ui.UIBase import UIBase
  25. from offlineimap.threadutil import ExitNotifyThread
  26. import offlineimap
  27. class CursesUtil:
  28. def __init__(self, *args, **kwargs):
  29. # iolock protects access to the
  30. self.iolock = RLock()
  31. self.tframe_lock = RLock()
  32. # tframe_lock protects the self.threadframes manipulation to
  33. # only happen from 1 thread.
  34. self.colormap = {}
  35. """dict, translating color string to curses color pair number"""
  36. def curses_colorpair(self, col_name):
  37. """Return the curses color pair, that corresponds to the color."""
  38. return curses.color_pair(self.colormap[col_name])
  39. def init_colorpairs(self):
  40. """Initialize the curses color pairs available."""
  41. # set special colors 'gray' and 'banner'
  42. self.colormap['white'] = 0 # hardcoded by curses
  43. curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLUE)
  44. self.colormap['banner'] = 1 # color 'banner' for bannerwin
  45. bcol = curses.COLOR_BLACK
  46. colors = ( # name, color, bold?
  47. ('black', curses.COLOR_BLACK, False),
  48. ('blue', curses.COLOR_BLUE, False),
  49. ('red', curses.COLOR_RED, False),
  50. ('purple', curses.COLOR_MAGENTA, False),
  51. ('cyan', curses.COLOR_CYAN, False),
  52. ('green', curses.COLOR_GREEN, False),
  53. ('orange', curses.COLOR_YELLOW, False))
  54. # set the rest of all colors starting at pair 2
  55. i = 1
  56. for name, fcol, bold in colors:
  57. i += 1
  58. self.colormap[name] = i
  59. curses.init_pair(i, fcol, bcol)
  60. def lock(self, block=True):
  61. """Locks the Curses ui thread.
  62. Can be invoked multiple times from the owning thread. Invoking
  63. from a non-owning thread blocks and waits until it has been
  64. unlocked by the owning thread."""
  65. return self.iolock.acquire(block)
  66. def unlock(self):
  67. """Unlocks the Curses ui thread.
  68. Decrease the lock counter by one and unlock the ui thread if the
  69. counter reaches 0. Only call this method when the calling
  70. thread owns the lock. A RuntimeError is raised if this method is
  71. called when the lock is unlocked."""
  72. self.iolock.release()
  73. def exec_locked(self, target, *args, **kwargs):
  74. """Perform an operation with full locking."""
  75. self.lock()
  76. try:
  77. target(*args, **kwargs)
  78. finally:
  79. self.unlock()
  80. def refresh(self):
  81. def lockedstuff():
  82. curses.panel.update_panels()
  83. curses.doupdate()
  84. self.exec_locked(lockedstuff)
  85. def isactive(self):
  86. return hasattr(self, 'stdscr')
  87. class CursesAccountFrame:
  88. """Notable instance variables:
  89. - account: corresponding Account()
  90. - children
  91. - ui
  92. - key
  93. - window: curses window associated with an account
  94. """
  95. def __init__(self, ui, account):
  96. """
  97. :param account: An Account() or None (for eg SyncrunnerThread)"""
  98. self.children = []
  99. self.account = account if account else '*Control'
  100. self.ui = ui
  101. self.window = None
  102. # Curses window associated with this acc.
  103. self.acc_num = None
  104. # Account number (& hotkey) associated with this acc.
  105. self.location = 0
  106. # length of the account prefix string
  107. def drawleadstr(self, secs=0):
  108. """Draw the account status string.
  109. secs tells us how long we are going to sleep."""
  110. sleepstr = '%3d:%02d' % (secs // 60, secs % 60) if secs else 'active'
  111. accstr = '%s: [%s] %12.12s: ' % (self.acc_num, sleepstr, self.account)
  112. def addstr():
  113. try:
  114. self.window.addstr(0, 0, accstr)
  115. except curses.error: # Occurs when the terminal is very small
  116. pass
  117. self.ui.exec_locked(addstr)
  118. self.location = len(accstr)
  119. def setwindow(self, curses_win, acc_num):
  120. """Register an curses win and a hotkey as Account window.
  121. :param curses_win: the curses window associated with an account
  122. :param acc_num: int denoting the hotkey associated with this account."""
  123. self.window = curses_win
  124. self.acc_num = acc_num
  125. self.drawleadstr()
  126. self.ui.exec_locked(self.window.noutrefresh)
  127. # Update the child ThreadFrames
  128. for child in self.children:
  129. child.update(curses_win, self.location, 0)
  130. self.location += 1
  131. def get_new_tframe(self):
  132. """Create a new ThreadFrame and append it to self.children.
  133. :returns: The new ThreadFrame"""
  134. tf = CursesThreadFrame(self.ui, self.window, self.location, 0)
  135. self.location += 1
  136. self.children.append(tf)
  137. return tf
  138. def sleeping(self, sleepsecs, remainingsecs):
  139. """Show how long we are going to sleep and sleep.
  140. :returns: Boolean, whether we want to abort the sleep"""
  141. self.drawleadstr(remainingsecs)
  142. self.ui.exec_locked(self.window.refresh)
  143. time.sleep(sleepsecs)
  144. return self.account.get_abort_event()
  145. def syncnow(self):
  146. """Request that we stop sleeping asap and continue to sync."""
  147. # if this belongs to an Account (and not *Control), set the
  148. # skipsleep pref
  149. if isinstance(self.account, offlineimap.accounts.Account):
  150. self.ui.info("Requested synchronization for acc: %s" % self.account)
  151. self.account.config.set('Account %s' % self.account.name,
  152. 'skipsleep', '1')
  153. class CursesThreadFrame:
  154. """curses_color: current color pair for logging."""
  155. def __init__(self, ui, acc_win, x, y):
  156. """
  157. :param ui: is a Blinkenlights() instance
  158. :param acc_win: curses Account window"""
  159. self.ui = ui
  160. self.window = acc_win
  161. self.x = x
  162. self.y = y
  163. self.curses_color = curses.color_pair(0) # default color
  164. def setcolor(self, color, modifier=0):
  165. """Draw the thread symbol '@' in the specified color
  166. :param color: Curses colorname
  167. :param modifier: Curses modified, such as curses.A_BOLD
  168. """
  169. self.curses_color = modifier | self.ui.curses_colorpair(color)
  170. self.colorname = color
  171. self.display()
  172. def display(self):
  173. def locked_display():
  174. try:
  175. self.window.addch(self.y, self.x, '@', self.curses_color)
  176. except curses.error: # Occurs when the terminal is very small
  177. pass
  178. self.window.refresh()
  179. # lock the curses IO while fudging stuff
  180. self.ui.exec_locked(locked_display)
  181. def update(self, acc_win, x, y):
  182. """Update the xy position of the '.' (and possibly the aframe)."""
  183. self.window = acc_win
  184. self.y = y
  185. self.x = x
  186. self.display()
  187. def std_color(self):
  188. self.setcolor('black')
  189. class InputHandler(ExitNotifyThread):
  190. """Listens for input via the curses interfaces"""
  191. # TODO, we need to use the ugly exitnotifythread (rather than simply
  192. # threading.Thread here, so exiting this thread via the callback
  193. # handler, kills off all parents too. Otherwise, they would simply
  194. # continue.
  195. def __init__(self, ui):
  196. super(InputHandler, self).__init__()
  197. self.char_handler = None
  198. self.ui = ui
  199. self.enabled = Event()
  200. # We will only parse input if we are enabled.
  201. self.inputlock = RLock()
  202. # denotes whether we should be handling the next char.
  203. self.start() # automatically start the thread
  204. def get_next_char(self):
  205. """Return the key pressed or -1.
  206. Wait until `enabled` and loop internally every stdscr.timeout()
  207. msecs, releasing the inputlock.
  208. :returns: char or None if disabled while in here"""
  209. self.enabled.wait()
  210. while self.enabled.is_set():
  211. with self.inputlock:
  212. char = self.ui.stdscr.getch()
  213. if char != -1:
  214. yield char
  215. def run(self):
  216. while True:
  217. char_gen = self.get_next_char()
  218. for char in char_gen:
  219. self.char_handler(char)
  220. # curses.ungetch(char)
  221. def set_char_hdlr(self, callback):
  222. """Sets a character callback handler.
  223. If a key is pressed it will be passed to this handler. Keys
  224. include the curses.KEY_RESIZE key.
  225. callback is a function taking a single arg -- the char pressed.
  226. If callback is None, input will be ignored."""
  227. with self.inputlock:
  228. self.char_handler = callback
  229. # start or stop the parsing of things
  230. if callback is None:
  231. self.enabled.clear()
  232. else:
  233. self.enabled.set()
  234. def input_acquire(self):
  235. """Call this method when you want exclusive input control.
  236. Make sure to call input_release afterwards! While this lockis
  237. held, input can go to e.g. the getpass input."""
  238. self.enabled.clear()
  239. self.inputlock.acquire()
  240. def input_release(self):
  241. """Call this method when you are done getting input."""
  242. self.inputlock.release()
  243. self.enabled.set()
  244. class CursesLogHandler(logging.StreamHandler):
  245. """self.ui has been set to the UI class before anything is invoked"""
  246. def emit(self, record):
  247. log_str = logging.StreamHandler.format(self, record)
  248. color = self.ui.gettf().curses_color
  249. # We must acquire both locks. Otherwise, deadlock can result.
  250. # This can happen if one thread calls _msg (locking curses, then
  251. # tf) and another tries to set the color (locking tf, then curses)
  252. #
  253. # By locking both up-front here, in this order, we prevent deadlock.
  254. self.ui.tframe_lock.acquire()
  255. self.ui.lock()
  256. try:
  257. y, x = self.ui.logwin.getyx()
  258. if y or x:
  259. self.ui.logwin.addch(10) # no \n before 1st item
  260. self.ui.logwin.addstr(log_str, color)
  261. self.ui.logwin.noutrefresh()
  262. self.ui.stdscr.refresh()
  263. finally:
  264. self.ui.unlock()
  265. self.ui.tframe_lock.release()
  266. class Blinkenlights(UIBase, CursesUtil):
  267. """Curses-cased fancy UI.
  268. Notable instance variables self. ....:
  269. - stdscr: THe curses std screen
  270. - bannerwin: The top line banner window
  271. - width|height: The total curses screen dimensions
  272. - logheight: Available height for the logging part
  273. - log_con_handler: The CursesLogHandler()
  274. - threadframes:
  275. - accframes[account]: 'Accountframe'"""
  276. def __init__(self, *args, **kwargs):
  277. super(Blinkenlights, self).__init__(*args, **kwargs)
  278. CursesUtil.__init__(self)
  279. # UTILS
  280. def setup_consolehandler(self):
  281. """Backend specific console handler.
  282. Sets up things and adds them to self.logger.
  283. :returns: The logging.Handler() for console output"""
  284. # create console handler with a higher log level
  285. ch = CursesLogHandler()
  286. # ch.setLevel(logging.DEBUG)
  287. # create formatter and add it to the handlers
  288. self.formatter = logging.Formatter("%(message)s")
  289. ch.setFormatter(self.formatter)
  290. # add the handlers to the logger
  291. self.logger.addHandler(ch)
  292. # the handler is not usable yet. We still need all the
  293. # intialization stuff currently done in init_banner. Move here?
  294. return ch
  295. def isusable(s):
  296. """Returns true if the backend is usable ie Curses works."""
  297. # Not a terminal? Can't use curses.
  298. if not sys.stdout.isatty() and sys.stdin.isatty():
  299. return False
  300. # No TERM specified? Can't use curses.
  301. if not os.environ.get('TERM', None):
  302. return False
  303. # Test if ncurses actually starts up fine. Only do so for
  304. # python>=2.6.6 as calling initscr() twice messing things up.
  305. # see http://bugs.python.org/issue7567 in python 2.6 to 2.6.5
  306. if sys.version_info[0:3] < (2, 6) or sys.version_info[0:3] >= (2, 6, 6):
  307. try:
  308. curses.initscr()
  309. curses.endwin()
  310. except:
  311. return False
  312. return True
  313. def init_banner(self):
  314. self.availablethreadframes = {}
  315. self.threadframes = {}
  316. self.accframes = {}
  317. self.aflock = Lock()
  318. self.stdscr = curses.initscr()
  319. # turn off automatic echoing of keys to the screen
  320. curses.noecho()
  321. # react to keys instantly, without Enter key
  322. curses.cbreak()
  323. # return special key values, eg curses.KEY_LEFT
  324. self.stdscr.keypad(1)
  325. # wait 1s for input, so we don't block the InputHandler infinitely
  326. self.stdscr.timeout(1000)
  327. curses.start_color()
  328. # turn off cursor and save original state
  329. self.oldcursor = None
  330. try:
  331. self.oldcursor = curses.curs_set(0)
  332. except:
  333. pass
  334. self.stdscr.clear()
  335. self.stdscr.refresh()
  336. self.init_colorpairs()
  337. # set log handlers ui to ourself
  338. self._log_con_handler.ui = self
  339. self.setupwindows()
  340. # Settup keyboard handler
  341. self.inputhandler = InputHandler(self)
  342. self.inputhandler.set_char_hdlr(self.on_keypressed)
  343. self.gettf().setcolor('red')
  344. self.info(offlineimap.banner)
  345. def acct(self, *args):
  346. """Output that we start syncing an account (and start counting)."""
  347. self.gettf().setcolor('purple')
  348. super(Blinkenlights, self).acct(*args)
  349. def connecting(self, *args):
  350. self.gettf().setcolor('white')
  351. super(Blinkenlights, self).connecting(*args)
  352. def syncfolders(self, *args):
  353. self.gettf().setcolor('blue')
  354. super(Blinkenlights, self).syncfolders(*args)
  355. def syncingfolder(self, *args):
  356. self.gettf().setcolor('cyan')
  357. super(Blinkenlights, self).syncingfolder(*args)
  358. def skippingfolder(self, *args):
  359. self.gettf().setcolor('cyan')
  360. super(Blinkenlights, self).skippingfolder(*args)
  361. def loadmessagelist(self, *args):
  362. self.gettf().setcolor('green')
  363. super(Blinkenlights, self).loadmessagelist(*args)
  364. def syncingmessages(self, *args):
  365. self.gettf().setcolor('blue')
  366. super(Blinkenlights, self).syncingmessages(*args)
  367. def ignorecopyingmessage(self, *args):
  368. self.gettf().setcolor('red')
  369. super(Blinkenlights, self).ignorecopyingmessage(*args)
  370. def copyingmessage(self, *args):
  371. self.gettf().setcolor('orange')
  372. super(Blinkenlights, self).copyingmessage(*args)
  373. def deletingmessages(self, *args):
  374. self.gettf().setcolor('red')
  375. super(Blinkenlights, self).deletingmessages(*args)
  376. def addingflags(self, *args):
  377. self.gettf().setcolor('blue')
  378. super(Blinkenlights, self).addingflags(*args)
  379. def deletingflags(self, *args):
  380. self.gettf().setcolor('blue')
  381. super(Blinkenlights, self).deletingflags(*args)
  382. def callhook(self, *args):
  383. self.gettf().setcolor('white')
  384. super(Blinkenlights, self).callhook(*args)
  385. # Generic logging functions #
  386. def warn(self, msg, minor=0):
  387. self.gettf().setcolor('red', curses.A_BOLD)
  388. super(Blinkenlights, self).warn(msg)
  389. def threadExited(self, thread):
  390. acc = self.getthreadaccount(thread)
  391. with self.tframe_lock:
  392. if thread in self.threadframes[acc]:
  393. tf = self.threadframes[acc][thread]
  394. tf.setcolor('black')
  395. self.availablethreadframes[acc].append(tf)
  396. del self.threadframes[acc][thread]
  397. super(Blinkenlights, self).threadExited(thread)
  398. def gettf(self):
  399. """Return the ThreadFrame() of the current thread."""
  400. cur_thread = currentThread()
  401. acc = self.getthreadaccount() # Account() or None
  402. with self.tframe_lock:
  403. # Ideally we already have self.threadframes[accountname][thread]
  404. try:
  405. if cur_thread in self.threadframes[acc]:
  406. return self.threadframes[acc][cur_thread]
  407. except KeyError:
  408. # Ensure threadframes already has an account dict
  409. self.threadframes[acc] = {}
  410. self.availablethreadframes[acc] = deque()
  411. # If available, return a ThreadFrame()
  412. if len(self.availablethreadframes[acc]):
  413. tf = self.availablethreadframes[acc].popleft()
  414. tf.std_color()
  415. else:
  416. tf = self.getaccountframe(acc).get_new_tframe()
  417. self.threadframes[acc][cur_thread] = tf
  418. return tf
  419. def on_keypressed(self, key):
  420. # received special KEY_RESIZE, resize terminal
  421. if key == curses.KEY_RESIZE:
  422. self.resizeterm()
  423. return
  424. if key < 1 or key > 255:
  425. return
  426. if chr(key) == 'q':
  427. # Request to quit completely.
  428. self.warn("Requested shutdown via 'q'")
  429. offlineimap.accounts.Account.set_abort_event(self.config, 3)
  430. try:
  431. index = int(chr(key))
  432. except ValueError:
  433. return # Key not a valid number: exit.
  434. if index >= len(self.hotkeys):
  435. # Not in our list of valid hotkeys.
  436. return
  437. # Trying to end sleep somewhere.
  438. self.getaccountframe(self.hotkeys[index]).syncnow()
  439. def sleep(self, sleepsecs, account):
  440. self.gettf().setcolor('red')
  441. self.info("Next sync in %d:%02d" % (sleepsecs / 60, sleepsecs % 60))
  442. return super(Blinkenlights, self).sleep(sleepsecs, account)
  443. def sleeping(self, sleepsecs, remainingsecs):
  444. if not sleepsecs:
  445. # reset color to default if we are done sleeping.
  446. self.gettf().setcolor('white')
  447. accframe = self.getaccountframe(self.getthreadaccount())
  448. return accframe.sleeping(sleepsecs, remainingsecs)
  449. def resizeterm(self):
  450. """Resize the current windows."""
  451. self.exec_locked(self.setupwindows, True)
  452. def mainException(self):
  453. UIBase.mainException(self)
  454. def getpass(self, username, config, errmsg=None):
  455. # disable the hotkeys inputhandler
  456. self.inputhandler.input_acquire()
  457. # See comment on _msg for info on why both locks are obtained.
  458. self.lock()
  459. try:
  460. # s.gettf().setcolor('white')
  461. self.warn(" *** Input Required")
  462. self.warn(" *** Please enter password for user '%s': " %
  463. username)
  464. self.logwin.refresh()
  465. password = self.logwin.getstr()
  466. finally:
  467. self.unlock()
  468. self.inputhandler.input_release()
  469. # We need a str password
  470. if isinstance(password, bytes):
  471. return password.decode(encoding='utf-8')
  472. return password
  473. def setupwindows(self, resize=False):
  474. """Setup and draw bannerwin and logwin.
  475. If `resize`, don't create new windows, just adapt size. This
  476. function should be invoked with CursesUtils.locked()."""
  477. self.height, self.width = self.stdscr.getmaxyx()
  478. self.logheight = self.height - len(self.accframes) - 1
  479. if resize:
  480. if curses.is_term_resized(self.height, self.width):
  481. curses.resizeterm(self.height, self.width)
  482. self.bannerwin.resize(1, self.width)
  483. self.logwin.resize(self.logheight, self.width)
  484. self.stdscr.clear()
  485. self.stdscr.noutrefresh()
  486. else:
  487. self.bannerwin = curses.newwin(1, self.width, 0, 0)
  488. self.logwin = curses.newwin(self.logheight, self.width, 1, 0)
  489. self.draw_bannerwin()
  490. self.logwin.idlok(True) # needed for scrollok below
  491. self.logwin.scrollok(True) # scroll window when too many lines added
  492. self.draw_logwin()
  493. # TODO: Sort the accounts using their name
  494. self.accounts = self.accframes.keys()
  495. pos = self.height - 1
  496. index = 0
  497. self.hotkeys = []
  498. for account in self.accounts:
  499. acc_win = curses.newwin(1, self.width, pos, 0)
  500. self.accframes[account].setwindow(acc_win, index)
  501. self.hotkeys.append(account)
  502. index += 1
  503. pos -= 1
  504. curses.doupdate()
  505. def draw_bannerwin(self):
  506. """Draw the top-line banner line."""
  507. if curses.has_colors():
  508. color = curses.A_BOLD | self.curses_colorpair('banner')
  509. else:
  510. color = curses.A_REVERSE
  511. self.bannerwin.clear() # Delete old content (eg before resizes)
  512. self.bannerwin.bkgd(' ', color) # Fill background with that color
  513. string = "%s %s" % (offlineimap.__productname__,
  514. offlineimap.__version__)
  515. spaces = " " * max(1, (self.width - len(offlineimap.__copyright__)
  516. - len(string) - 1))
  517. string = "%s%s%s" % (string, spaces, offlineimap.__copyright__)
  518. self.bannerwin.addnstr(0, 0, string, self.width - 1, color)
  519. self.bannerwin.noutrefresh()
  520. def draw_logwin(self):
  521. """(Re)draw the current logwindow."""
  522. if curses.has_colors():
  523. color = curses.color_pair(0) # default colors
  524. else:
  525. color = curses.A_NORMAL
  526. self.logwin.move(0, 0)
  527. self.logwin.clear()
  528. self.logwin.bkgd(' ', color)
  529. self.logwin.noutrefresh()
  530. def getaccountframe(self, acc_name):
  531. """Return an AccountFrame() corresponding to acc_name.
  532. Note that the *control thread uses acc_name `None`."""
  533. with self.aflock:
  534. # 1) Return existing or 2) create a new CursesAccountFrame.
  535. if acc_name in self.accframes:
  536. return self.accframes[acc_name]
  537. self.accframes[acc_name] = CursesAccountFrame(self, acc_name)
  538. # update the window layout
  539. self.setupwindows(resize=True)
  540. return self.accframes[acc_name]
  541. def terminate(self, *args, **kwargs):
  542. curses.nocbreak()
  543. self.stdscr.keypad(0)
  544. curses.echo()
  545. curses.endwin()
  546. # need to remove the Curses console handler now and replace with
  547. # basic one, so exceptions and stuff are properly displayed
  548. self.logger.removeHandler(self._log_con_handler)
  549. UIBase.setup_consolehandler(self)
  550. # reset the warning method, we do not have curses anymore
  551. self.warn = super(Blinkenlights, self).warn
  552. # finally call parent terminate which prints out exceptions etc
  553. super(Blinkenlights, self).terminate(*args, **kwargs)
  554. def threadException(self, thread):
  555. # self._log_con_handler.stop()
  556. UIBase.threadException(self, thread)