def main(): window = sg.FlexForm('Log window', default_element_size=(30, 2), font=('Helvetica', ' 10'), default_button_element_size=(8, 2), return_keyboard_events=True) layout = \ [ [sg.Multiline(size=(50, 15), key='Log')], [sg.Button('Start', bind_return_key=True, key='_START_'), sg.Button('Exit')] ] window.Layout(layout).Read(timeout=0) appStarted = False # Setup logging and start app logging.basicConfig(level=logging.DEBUG) log_queue = queue.Queue() queue_handler = QueueHandler(log_queue) logger.addHandler(queue_handler) threadedApp = ThreadedApp() # Loop taking in user input and querying queue while True: # Wake every 100ms and look for work event, values = window.Read(timeout=100) if event == '_START_': if not appStarted: threadedApp.start() logger.debug('App started') window.FindElement('_START_').Update(disabled=True) appStarted = True elif event in (None, 'Exit'): break # Poll queue try: record = log_queue.get(block=False) except queue.Empty: pass else: msg = queue_handler.format(record) window.FindElement('Log').Update(msg + '\n', append=True) window.Close() exit()
msgExtensionType = '.png' # Select a directory and read in the IMAGE files from that directory img_files, img_fileNames = crdir.get_img_files(refDirectoryPath, imgExtensionType) # Select a directory and read in the MESSAGE files from that directory msg_files, msg_fileNames = crdir.get_img_files(refDirectoryPath, msgExtensionType) print('msg_fileNames = {}'.format(msg_fileNames)) # #### Image browser #### # create the imageBrowser that returns keyboard events imageBrowser = sg.FlexForm('Image Browser', return_keyboard_events=True, location=(0, 0), use_default_focus=False) # Check to be sure there are images to read try: img = fitz.Pixmap(img_files[0]) # Read first image into PyMuPDF if verbose: print("Reading {}:".format(img_files[0])) except IndexError: # If no images of the correct type could be found: print( '\n > > > > > > > > No "{}" images found in directory "{}". Quitting.\n' .format(imgExtensionType, refDirectoryPath)) exit(0) # create target pixmap blank_pix = fitz.Pixmap(img.colorspace,