Reformat offlineimap/ui/Curses.py
Add some spaces, remove lines,... now format is better (lintian).
This commit is contained in:
parent
1df1a39b11
commit
1b385dfafb
@ -47,20 +47,20 @@ class CursesUtil:
|
||||
"""Initialize the curses color pairs available."""
|
||||
|
||||
# set special colors 'gray' and 'banner'
|
||||
self.colormap['white'] = 0 #hardcoded by curses
|
||||
self.colormap['white'] = 0 # hardcoded by curses
|
||||
curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLUE)
|
||||
self.colormap['banner'] = 1 # color 'banner' for bannerwin
|
||||
|
||||
bcol = curses.COLOR_BLACK
|
||||
colors = ( # name, color, bold?
|
||||
('black', curses.COLOR_BLACK, False),
|
||||
('blue', curses.COLOR_BLUE,False),
|
||||
('blue', curses.COLOR_BLUE, False),
|
||||
('red', curses.COLOR_RED, False),
|
||||
('purple', curses.COLOR_MAGENTA, False),
|
||||
('cyan', curses.COLOR_CYAN, False),
|
||||
('green', curses.COLOR_GREEN, False),
|
||||
('orange', curses.COLOR_YELLOW, False))
|
||||
#set the rest of all colors starting at pair 2
|
||||
# set the rest of all colors starting at pair 2
|
||||
i = 1
|
||||
for name, fcol, bold in colors:
|
||||
i += 1
|
||||
@ -99,6 +99,7 @@ class CursesUtil:
|
||||
def lockedstuff():
|
||||
curses.panel.update_panels()
|
||||
curses.doupdate()
|
||||
|
||||
self.exec_locked(lockedstuff)
|
||||
|
||||
def isactive(self):
|
||||
@ -129,19 +130,20 @@ class CursesAccountFrame:
|
||||
self.location = 0
|
||||
# length of the account prefix string
|
||||
|
||||
def drawleadstr(self, secs = 0):
|
||||
def drawleadstr(self, secs=0):
|
||||
"""Draw the account status string.
|
||||
|
||||
secs tells us how long we are going to sleep."""
|
||||
|
||||
sleepstr = '%3d:%02d'% (secs // 60, secs % 60) if secs else 'active'
|
||||
accstr = '%s: [%s] %12.12s: '% (self.acc_num, sleepstr, self.account)
|
||||
sleepstr = '%3d:%02d' % (secs // 60, secs % 60) if secs else 'active'
|
||||
accstr = '%s: [%s] %12.12s: ' % (self.acc_num, sleepstr, self.account)
|
||||
|
||||
def addstr():
|
||||
try:
|
||||
self.window.addstr(0, 0, accstr)
|
||||
except curses.error as e: # Occurs when the terminal is very small
|
||||
pass
|
||||
|
||||
self.ui.exec_locked(addstr);
|
||||
|
||||
self.location = len(accstr)
|
||||
@ -187,10 +189,11 @@ class CursesAccountFrame:
|
||||
# if this belongs to an Account (and not *Control), set the
|
||||
# skipsleep pref
|
||||
if isinstance(self.account, offlineimap.accounts.Account):
|
||||
self.ui.info("Requested synchronization for acc: %s"% self.account)
|
||||
self.account.config.set('Account %s'% self.account.name,
|
||||
self.ui.info("Requested synchronization for acc: %s" % self.account)
|
||||
self.account.config.set('Account %s' % self.account.name,
|
||||
'skipsleep', '1')
|
||||
|
||||
|
||||
class CursesThreadFrame:
|
||||
"""curses_color: current color pair for logging."""
|
||||
|
||||
@ -203,7 +206,7 @@ class CursesThreadFrame:
|
||||
self.window = acc_win
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.curses_color = curses.color_pair(0) #default color
|
||||
self.curses_color = curses.color_pair(0) # default color
|
||||
|
||||
def setcolor(self, color, modifier=0):
|
||||
"""Draw the thread symbol '@' in the specified color
|
||||
@ -222,6 +225,7 @@ class CursesThreadFrame:
|
||||
except curses.error: # Occurs when the terminal is very small
|
||||
pass
|
||||
self.window.refresh()
|
||||
|
||||
# lock the curses IO while fudging stuff
|
||||
self.ui.exec_locked(locked_display)
|
||||
|
||||
@ -240,10 +244,10 @@ class CursesThreadFrame:
|
||||
class InputHandler(ExitNotifyThread):
|
||||
"""Listens for input via the curses interfaces"""
|
||||
|
||||
#TODO, we need to use the ugly exitnotifythread (rather than simply
|
||||
#threading.Thread here, so exiting this thread via the callback
|
||||
#handler, kills off all parents too. Otherwise, they would simply
|
||||
#continue.
|
||||
# TODO, we need to use the ugly exitnotifythread (rather than simply
|
||||
# threading.Thread here, so exiting this thread via the callback
|
||||
# handler, kills off all parents too. Otherwise, they would simply
|
||||
# continue.
|
||||
def __init__(self, ui):
|
||||
super(InputHandler, self).__init__()
|
||||
self.char_handler = None
|
||||
@ -252,7 +256,7 @@ class InputHandler(ExitNotifyThread):
|
||||
# We will only parse input if we are enabled.
|
||||
self.inputlock = RLock()
|
||||
# denotes whether we should be handling the next char.
|
||||
self.start() #automatically start the thread
|
||||
self.start() # automatically start the thread
|
||||
|
||||
def get_next_char(self):
|
||||
"""Return the key pressed or -1.
|
||||
@ -272,7 +276,7 @@ class InputHandler(ExitNotifyThread):
|
||||
char_gen = self.get_next_char()
|
||||
for char in char_gen:
|
||||
self.char_handler(char)
|
||||
#curses.ungetch(char)
|
||||
# curses.ungetch(char)
|
||||
|
||||
def set_char_hdlr(self, callback):
|
||||
"""Sets a character callback handler.
|
||||
@ -321,7 +325,7 @@ class CursesLogHandler(logging.StreamHandler):
|
||||
self.ui.tframe_lock.acquire()
|
||||
self.ui.lock()
|
||||
try:
|
||||
y,x = self.ui.logwin.getyx()
|
||||
y, x = self.ui.logwin.getyx()
|
||||
if y or x: self.ui.logwin.addch(10) # no \n before 1st item
|
||||
self.ui.logwin.addstr(log_str, color)
|
||||
self.ui.logwin.noutrefresh()
|
||||
@ -330,6 +334,7 @@ class CursesLogHandler(logging.StreamHandler):
|
||||
self.ui.unlock()
|
||||
self.ui.tframe_lock.release()
|
||||
|
||||
|
||||
class Blinkenlights(UIBase, CursesUtil):
|
||||
"""Curses-cased fancy UI.
|
||||
|
||||
@ -356,7 +361,7 @@ class Blinkenlights(UIBase, CursesUtil):
|
||||
|
||||
# create console handler with a higher log level
|
||||
ch = CursesLogHandler()
|
||||
#ch.setLevel(logging.DEBUG)
|
||||
# ch.setLevel(logging.DEBUG)
|
||||
# create formatter and add it to the handlers
|
||||
self.formatter = logging.Formatter("%(message)s")
|
||||
ch.setFormatter(self.formatter)
|
||||
@ -378,7 +383,7 @@ class Blinkenlights(UIBase, CursesUtil):
|
||||
# Test if ncurses actually starts up fine. Only do so for
|
||||
# python>=2.6.6 as calling initscr() twice messing things up.
|
||||
# see http://bugs.python.org/issue7567 in python 2.6 to 2.6.5
|
||||
if sys.version_info[0:3] < (2,6) or sys.version_info[0:3] >= (2,6,6):
|
||||
if sys.version_info[0:3] < (2, 6) or sys.version_info[0:3] >= (2, 6, 6):
|
||||
try:
|
||||
curses.initscr()
|
||||
curses.endwin()
|
||||
@ -476,7 +481,7 @@ class Blinkenlights(UIBase, CursesUtil):
|
||||
self.gettf().setcolor('white')
|
||||
super(Blinkenlights, self).callhook(*args)
|
||||
|
||||
############ Generic logging functions #############################
|
||||
# Generic logging functions #
|
||||
def warn(self, msg, minor=0):
|
||||
self.gettf().setcolor('red', curses.A_BOLD)
|
||||
super(Blinkenlights, self).warn(msg)
|
||||
@ -495,7 +500,7 @@ class Blinkenlights(UIBase, CursesUtil):
|
||||
"""Return the ThreadFrame() of the current thread."""
|
||||
|
||||
cur_thread = currentThread()
|
||||
acc = self.getthreadaccount() #Account() or None
|
||||
acc = self.getthreadaccount() # Account() or None
|
||||
|
||||
with self.tframe_lock:
|
||||
# Ideally we already have self.threadframes[accountname][thread]
|
||||
@ -540,7 +545,7 @@ class Blinkenlights(UIBase, CursesUtil):
|
||||
|
||||
def sleep(self, sleepsecs, account):
|
||||
self.gettf().setcolor('red')
|
||||
self.info("Next sync in %d:%02d"% (sleepsecs / 60, sleepsecs % 60))
|
||||
self.info("Next sync in %d:%02d" % (sleepsecs / 60, sleepsecs % 60))
|
||||
return super(Blinkenlights, self).sleep(sleepsecs, account)
|
||||
|
||||
def sleeping(self, sleepsecs, remainingsecs):
|
||||
@ -565,7 +570,7 @@ class Blinkenlights(UIBase, CursesUtil):
|
||||
# See comment on _msg for info on why both locks are obtained.
|
||||
self.lock()
|
||||
try:
|
||||
#s.gettf().setcolor('white')
|
||||
# s.gettf().setcolor('white')
|
||||
self.warn(" *** Input Required")
|
||||
self.warn(" *** Please enter password for user '%s': " % \
|
||||
username)
|
||||
@ -632,7 +637,7 @@ class Blinkenlights(UIBase, CursesUtil):
|
||||
"""(Re)draw the current logwindow."""
|
||||
|
||||
if curses.has_colors():
|
||||
color = curses.color_pair(0) #default colors
|
||||
color = curses.color_pair(0) # default colors
|
||||
else:
|
||||
color = curses.A_NORMAL
|
||||
self.logwin.move(0, 0)
|
||||
@ -650,7 +655,7 @@ class Blinkenlights(UIBase, CursesUtil):
|
||||
if acc_name in self.accframes: return self.accframes[acc_name]
|
||||
self.accframes[acc_name] = CursesAccountFrame(self, acc_name)
|
||||
# update the window layout
|
||||
self.setupwindows(resize= True)
|
||||
self.setupwindows(resize=True)
|
||||
return self.accframes[acc_name]
|
||||
|
||||
def terminate(self, *args, **kwargs):
|
||||
@ -668,6 +673,5 @@ class Blinkenlights(UIBase, CursesUtil):
|
||||
super(Blinkenlights, self).terminate(*args, **kwargs)
|
||||
|
||||
def threadException(self, thread):
|
||||
#self._log_con_handler.stop()
|
||||
# self._log_con_handler.stop()
|
||||
UIBase.threadException(self, thread)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user