tuikit/application.py
changeset 13 19ebde2fd594
parent 11 762513aacc87
child 15 c55b4749e562
equal deleted inserted replaced
12:bb7d41be0c44 13:19ebde2fd594
     1 # -*- coding: utf-8 -*-
     1 # -*- coding: utf-8 -*-
     2 
     2 
     3 import curses
       
     4 import curses.wrapper
     3 import curses.wrapper
     5 import logging
     4 import logging
     6 import time
     5 import time
     7 import math
     6 import math
     8 
     7 
     9 from .container import Container
     8 from .container import Container
    10 from .backend_curses import BackendCurses
     9 from .backend_curses import BackendCurses
    11 
    10 
    12 
    11 
    13 class TopWindow(Container):
    12 class TopWindow(Container):
       
    13     
       
    14     '''Top window of an application. Covers entire screen.'''
       
    15     
    14     def __init__(self):
    16     def __init__(self):
       
    17         '''Create top window.'''
    15         Container.__init__(self)
    18         Container.__init__(self)
    16 
    19 
    17         self.focuswidget = None
    20         self.focuswidget = None
    18 
    21 
    19         self.top = self
    22         self.top = self
    68             else:
    71             else:
    69                 to[0] = newt
    72                 to[0] = newt
    70 
    73 
    71 
    74 
    72 class Application:
    75 class Application:
       
    76     
       
    77     '''Application class. Defines main loop.'''
       
    78        
    73     def __init__(self):
    79     def __init__(self):
       
    80         '''Create application.'''
       
    81         
       
    82         '''Top window.'''
    74         self.top = TopWindow()
    83         self.top = TopWindow()
    75         self.quit = False
    84         self.quit = False
       
    85         
       
    86         '''Renderer class, i.e. BackendCurses.'''
    76         self.screen = None
    87         self.screen = None
    77 
    88 
    78         self.log = logging.getLogger('tuikit')
    89         self.log = logging.getLogger('tuikit')
    79         self.log.setLevel(logging.DEBUG)
    90         self.log.setLevel(logging.DEBUG)
    80         handler = logging.FileHandler('./tuikit.log')
    91         handler = logging.FileHandler('./tuikit.log')
    83         self.log.addHandler(handler)
    94         self.log.addHandler(handler)
    84         self.log.info('start')
    95         self.log.info('start')
    85 
    96 
    86 
    97 
    87     def start(self):
    98     def start(self):
       
    99         '''Start application. Runs main loop.'''
    88         curses.wrapper(self.mainloop)
   100         curses.wrapper(self.mainloop)
    89 
   101 
    90 
   102 
    91     def terminate(self):
   103     def terminate(self):
       
   104         '''Terminate application.'''
    92         self.quit = True
   105         self.quit = True
    93 
   106 
    94 
   107 
    95     def mainloop(self, screen):
   108     def mainloop(self, screen):
       
   109         '''The main loop.'''
    96         self.screen = BackendCurses(screen)
   110         self.screen = BackendCurses(screen)
    97         self.applytheme()
   111         self.applytheme()
    98         self.top.width, self.top.height = self.screen.width, self.screen.height
   112         self.top.width, self.top.height = self.screen.width, self.screen.height
    99         self.top.emit('resize')
   113         self.top.emit('resize')
   100 
   114 
   127         screen.setcolor('window:controls-active',  'cyan on blue, bold')
   141         screen.setcolor('window:controls-active',  'cyan on blue, bold')
   128         screen.setcolor('button',                  'black on white')
   142         screen.setcolor('button',                  'black on white')
   129         screen.setcolor('button-active',           'black on cyan')
   143         screen.setcolor('button-active',           'black on cyan')
   130         screen.setcolor('menu',                    'black on cyan')
   144         screen.setcolor('menu',                    'black on cyan')
   131         screen.setcolor('menu-active',             'white on cyan, bold')
   145         screen.setcolor('menu-active',             'white on cyan, bold')
       
   146