Пример #1
0
 def call_check_thread(self, window_key, command_key, args):
     if self.check_thread(window_key):
         is_alive = 'alive'
     else:
         is_alive = 'not alive'
     commands.print_warning(self.termticker_dict['input_window'],
                            'Thread is ' + is_alive + '. Press ' + \
                            'any key to continue.')
Пример #2
0
 def call_exit_thread(self, window_key, command_key, args):
     self.exit_thread(window_key) 
     commands.print_warning(self.termticker_dict['input_window'],
                            window_key + ' thread has been killed. ' + \
                            'Press any key to continue.')
Пример #3
0
def start_terminal_ticker(stdscr):

    # Set up windows
    window_dict  = ui.set_window_parameters()
    input_window = window_dict['input']
    
    for name, window in window_dict.items():
        if name is not 'input':
            window.border()
            window.addstr(0, 0, name)
            window.refresh()
            window.scrollok(True)

    # Get dict stuff
    commands_dict = commands.set_commands_dict()
    connection = sqlite3.connect('term_ticker.db',
                                 check_same_thread=False)
    twitter_keys = twitter_tools.read_keys()

    # Create a global dict to pass stuff around the threads
    # and to pass the lock/queues when completing commands
    termticker_dict = {
        'connection'         : connection,
        'input_window'       : input_window,
        'lock'               : threading.Lock(),
        'twitter_keys'       : twitter_keys,
        'window_dict'        : window_dict
    }

    # Create threads
    term_threads = thread_manager.TermTickerThreadManager(termticker_dict)
    threads = ['twitter_thread', 'rss_thread']
    for thread in threads:
        term_threads.add_thread(thread)

    application_running = True

    while application_running:
        try:
            curses.noecho()
            input_window.keypad(1)
            input_edit = curses.textpad.Textbox(input_window)
            input_edit.edit()
            message = input_edit.gather().strip()
            window_key, command_key, args = commands.parse_input_text(message)
            if window_key in window_dict:
                if command_key in commands_dict[window_key]:
                    commands_dict[window_key][command_key](termticker_dict,
                                                           window_key,
                                                           args)
                elif command_key in term_threads.commands_dict:
                    term_threads.commands_dict[command_key](window_key,
                                                            command_key,
                                                            args)
                else:
                    commands.print_warning(input_window, 
                                           'Command does not exist. \
                                           Press any key to continue')
            elif window_key == 'all' and command_key == 'quit':
                application_running = False
            else:
                commands.print_warning(input_window, 
                                       'Window does not exist. \
                                       Press any key to continue')
            # elif window_key == 'all':
            #     all_commands[command_key](args)
            input_window.clear()
        except KeyboardInterrupt:
            return
    
    curses.endwin()
    connection.close()