def change_image(screen, size, images, image_index, delta): while True: image_index += delta if image_index >= len(images): image_index = 0 elif image_index < 0: image_index = len(images) - 1 if images[image_index] is not None: break graphics.show_graph(screen, size, images[image_index]) return image_index
try: # image_data, image_size = n1mm_view_graphs.qso_summary_table(size, qso_band_modes) # image_data, image_size = n1mm_view_graphs.qso_rates_table(size, operator_qso_rates) # image_data, image_size = n1mm_view_graphs.qso_operators_graph(size, qso_operators) # image_data, image_size = n1mm_view_graphs.qso_operators_table(size, qso_operators) # image_data, image_size = n1mm_view_graphs.qso_stations_graph(size, qso_stations) # image_data, image_size = n1mm_view_graphs.qso_bands_graph(size, qso_band_modes) # image_data, image_size = n1mm_view_graphs.qso_modes_graph(size, qso_band_modes) image_data, image_size = graphics.qso_rates_chart(size, qsos_per_hour) #base_map = n1mm_view_graphs.create_map() #image_data, image_size = n1mm_view_graphs.draw_map(size, qsos_by_section, base_map) # gc.collect() image = pygame.image.frombuffer(image_data, image_size, 'RGB') graphics.show_graph(screen, size, image) pygame.display.flip() # wait for a key press run = True while run: for event in pygame.event.get(): if event.type == pygame.QUIT: run = False break elif event.type == pygame.KEYDOWN: if event.key == ord('q'): logging.debug('Q key pressed') run = False else: logging.debug('event key=%d', event.key)
def main(): logging.info('dashboard startup') last_qso_timestamp = 0 q = multiprocessing.Queue() process_event = multiprocessing.Event() images = [None] * IMAGE_COUNT try: screen, size = graphics.init_display() except Exception as e: logging.exception('Could not initialize display.', exc_info=e) sys.exit(1) display_size = (size[0], size[1] - graphics.view_font_height) logging.debug('display setup') images[LOGO_IMAGE_INDEX] = pygame.image.load('logo.png') crawl_messages = CrawlMessages(screen, size) update_crawl_message(crawl_messages) proc = multiprocessing.Process(name='image-updater', target=update_charts, args=(q, process_event, display_size)) proc.start() try: image_index = LOGO_IMAGE_INDEX graphics.show_graph(screen, size, images[LOGO_IMAGE_INDEX]) pygame.time.set_timer(pygame.USEREVENT, 1000) run = True paused = False display_update_timer = config.DISPLAY_DWELL_TIME clock = pygame.time.Clock() while run: for event in pygame.event.get(): if event.type == pygame.QUIT: run = False break elif event.type == pygame.USEREVENT: display_update_timer -= 1 if display_update_timer < 1: if paused: graphics.show_graph(screen, size, images[image_index]) else: image_index = change_image(screen, size, images, image_index, 1) display_update_timer = config.DISPLAY_DWELL_TIME update_crawl_message(crawl_messages) elif event.type == pygame.KEYDOWN: if event.key == ord('q'): logging.debug('Q key pressed') run = False elif event.key == ord('n') or event.key == 275: logging.debug('next key pressed') image_index = change_image(screen, size, images, image_index, 1) display_update_timer = config.DISPLAY_DWELL_TIME elif event.key == ord('p') or event.key == 276: logging.debug('prev key pressed') image_index = change_image(screen, size, images, image_index, -1) display_update_timer = config.DISPLAY_DWELL_TIME elif event.key == 302: logging.debug('scroll lock key pressed') if paused: image_index = change_image(screen, size, images, image_index, 1) display_update_timer = config.DISPLAY_DWELL_TIME paused = not paused else: logging.debug('event key=%d', event.key) while not q.empty(): payload = q.get() message_type = payload[0] if message_type == IMAGE_MESSAGE: n = payload[1] image = payload[2] image_size = payload[3] images[n] = pygame.image.frombuffer(image, image_size, IMAGE_FORMAT) logging.debug('received image %d', n) elif message_type == CRAWL_MESSAGE: n = payload[1] message = payload[2] fg = graphics.CYAN bg = graphics.BLACK if len(payload) > 3: fg = payload[3] if len(payload) > 4: bg = payload[4] crawl_messages.set_message(n, message) crawl_messages.set_message_colors(n, fg, bg) crawl_messages.crawl_message() pygame.display.flip() clock.tick(60) pygame.time.set_timer(pygame.USEREVENT, 0) except Exception as e: logging.exception("Exception in main:", exc_info=e) pygame.display.quit() logging.debug('stopping update process') process_event.set() logging.debug('waiting for update process to stop...') proc.join(60) if proc.is_alive(): logging.warning('chart engine did not exit upon request, killing.') proc.terminate() logging.debug('update thread has stopped.') logging.info('dashboard exit')
sys.exit(1) display_size = (size[0], size[1] - graphics.view_font_height) logging.debug('display setup') images[LOGO_IMAGE_INDEX] = pygame.image.load('logo.png') crawl_messages = CrawlMessages(screen, size) update_crawl_message(crawl_messages) proc = multiprocessing.Process(name='image-updater', target=update_charts, args=(q, process_event, display_size)) proc.start() try: image_index = LOGO_IMAGE_INDEX graphics.show_graph(screen, size, images[LOGO_IMAGE_INDEX]) pygame.time.set_timer(pygame.USEREVENT, 1000) run = True paused = False display_update_timer = config.DISPLAY_DWELL_TIME clock = pygame.time.Clock() while run: for event in pygame.event.get(): if event.type == pygame.QUIT: run = False break elif event.type == pygame.USEREVENT: display_update_timer -= 1
def main(): logging.info('dashboard startup') try: screen, size = graphics.init_display() except Exception as e: logging.exception('Could not initialize display.', exc_info=e) sys.exit(1) display_size = (size[0], size[1]) logging.debug('display setup') qso_operators = [] qso_stations = [] qso_band_modes = [] operator_qso_rates = [] qsos_per_hour = [] qsos_by_section = {} logging.debug('load data') db = None cursor = None try: logging.debug('connecting to database') db = sqlite3.connect(config.DATABASE_FILENAME) cursor = db.cursor() logging.debug('database connected') # get timestamp from the last record in the database last_qso_time, message = dataaccess.get_last_qso(cursor) # load qso_operators qso_operators = dataaccess.get_operators_by_qsos(cursor) # load qso_stations -- maybe useless chartjunk qso_stations = dataaccess.get_station_qsos(cursor) # get something else. qso_band_modes = dataaccess.get_qso_band_modes(cursor) # load QSOs per Hour by Operator operator_qso_rates = dataaccess.get_qsos_per_hour_per_operator( cursor, last_qso_time) # load QSO rates per Hour by Band qsos_per_hour, qsos_per_band = dataaccess.get_qsos_per_hour_per_band( cursor) # load QSOs by Section qsos_by_section = dataaccess.get_qsos_by_section(cursor) logging.debug('load data done') except sqlite3.OperationalError as error: logging.exception(error) sys.exit(1) finally: if db is not None: logging.debug('Closing DB') cursor.close() db.close() db = None try: # image_data, image_size = graphics.qso_summary_table(size, qso_band_modes) # image_data, image_size = graphics.qso_rates_table(size, operator_qso_rates) # image_data, image_size = graphics.qso_operators_graph(size, qso_operators) # image_data, image_size = graphics.qso_operators_table(size, qso_operators) # image_data, image_size = graphics.qso_stations_graph(size, qso_stations) # image_data, image_size = graphics.qso_bands_graph(size, qso_band_modes) # image_data, image_size = graphics.qso_modes_graph(size, qso_band_modes) # image_data, image_size = graphics.qso_rates_chart(size, qsos_per_hour) image_data, image_size = graphics.draw_map(size, qsos_by_section) # gc.collect() image = pygame.image.frombuffer(image_data, image_size, 'RGB') graphics.show_graph(screen, size, image) pygame.display.flip() # wait for a key press run = True while run: for event in pygame.event.get(): if event.type == pygame.QUIT: run = False break elif event.type == pygame.KEYDOWN: if event.key == ord('q'): logging.debug('Q key pressed') run = False else: logging.debug('event key=%d', event.key) except Exception as e: logging.exception("Exception in main:", exc_info=e) pygame.display.quit() logging.info('one_chart exit')
display_size = (size[0], size[1] - graphics.view_font_height) logging.debug('display setup') images[LOGO_IMAGE_INDEX] = pygame.image.load('logo.png') crawl_messages = CrawlMessages(screen, size) update_crawl_message(crawl_messages) proc = multiprocessing.Process(name='image-updater', target=update_charts, args=(q, process_event, display_size)) proc.start() try: image_index = LOGO_IMAGE_INDEX graphics.show_graph(screen, size, images[LOGO_IMAGE_INDEX]) pygame.time.set_timer(pygame.USEREVENT, 1000) run = True paused = False display_update_timer = config.DISPLAY_DWELL_TIME clock = pygame.time.Clock() while run: for event in pygame.event.get(): if event.type == pygame.QUIT: run = False break elif event.type == pygame.USEREVENT: display_update_timer -= 1