pages, but instead from the fitz.DisplayList of the page. A display list will be stored in a list and looked up by page number. This way, zooming pixmaps and page re-visits will re-use a once-created display list. """ import sys import fitz import PySimpleGUI as sg from binascii import hexlify sg.ChangeLookAndFeel('GreenTan') if len(sys.argv) == 1: rc, fname = sg.GetFileBox('PDF Browser', 'PDF file to open', file_types=(("PDF Files", "*.pdf"),)) if rc is False: sg.MsgBoxCancel('Cancelling') exit(0) else: fname = sys.argv[1] doc = fitz.open(fname) page_count = len(doc) # storage for page display lists dlist_tab = [None] * page_count title = "PyMuPDF display of '%s', pages: %i" % (fname, page_count) def get_page(pno, zoom=0): """Return a PNG image for a document page number. If zoom is other than 0, one of the 4 page quadrants are zoomed-in instead and the corresponding clip returned.
if f_sha in shatab: # uncomment next line to remove duplicate files # os.remove(fname) dup_count += 1 # sg.Print(f'Duplicate file - {f}') # cannot current use sg.Print with Progress Meter continue shatab.append(f_sha) msg = f'{total} Files processed\n'\ f'{dup_count} Duplicates found\n' sg.MsgBox('Duplicate Finder Ended', msg) # ====____====____==== Pseudo-MAIN program ====____====____==== # # This is our main-alike piece of code # # + Starts up the GUI # # + Gets values from GUI # # + Runs DeDupe_folder based on GUI inputs # # ------------------------------------------------------------- # if __name__ == '__main__': source_folder = None rc, source_folder = sg.GetPathBox( 'Duplicate Finder - Count number of duplicate files', 'Enter path to folder you wish to find duplicates in') if rc is True and source_folder is not None: FindDuplicatesFilesInFolder(source_folder) else: sg.MsgBoxCancel('Cancelling', '*** Cancelling ***') exit(0)
def main(): def GetCurrentTime(): ''' Get the current system time in milliseconds :return: milliseconds ''' return int(round(time.time() * 1000)) pback = PlayerGUI() button, values = pback.PlayerChooseSongGUI() if button != 'PLAY!': g.MsgBoxCancel('Cancelled...\nAutoclose in 2 sec...', auto_close=True, auto_close_duration=2) exit(69) if values['device']: midi_port = values['device'][0] else: g.MsgBoxCancel('No devices found\nAutoclose in 2 sec...', auto_close=True, auto_close_duration=2) batch_folder = values['folder'] midi_filename = values['midifile'] # ------ Build list of files to play --------------------------------------------------------- # if batch_folder: filelist = os.listdir(batch_folder) filelist = [ batch_folder + '/' + f for f in filelist if f.endswith(('.mid', '.MID')) ] filetitles = [os.path.basename(f) for f in filelist] elif midi_filename: # an individual filename filelist = [ midi_filename, ] filetitles = [ os.path.basename(midi_filename), ] else: g.MsgBoxError('*** Error - No MIDI files specified ***') exit(666) # ------ LOOP THROUGH MULTIPLE FILES --------------------------------------------------------- # pback.PlayerPlaybackGUIStart( NumFiles=len(filelist) if len(filelist) <= 10 else 10) port = None # Loop through the files in the filelist for now_playing_number, current_midi_filename in enumerate(filelist): display_string = 'Playing Local File...\n{} of {}\n{}'.format( now_playing_number + 1, len(filelist), current_midi_filename) midi_title = filetitles[now_playing_number] # --------------------------------- REFRESH THE GUI ----------------------------------------- # pback.PlayerPlaybackGUIUpdate(display_string) # ---===--- Output Filename is .MID --- # midi_filename = current_midi_filename # --------------------------------- MIDI - STARTS HERE ----------------------------------------- # if not port: # if the midi output port not opened yet, then open it port = mido.open_output(midi_port if midi_port else None) try: mid = mido.MidiFile(filename=midi_filename) except: print( '****** Exception trying to play MidiFile filename = {}***************' .format(midi_filename)) g.MsgBoxError('Exception trying to play MIDI file:', midi_filename, 'Skipping file') continue # Build list of data contained in MIDI File using only track 0 midi_length_in_seconds = mid.length display_file_list = '>> ' + '\n'.join( [f for i, f in enumerate(filelist[now_playing_number:]) if i < 10]) paused = cancelled = next_file = False ######################### Loop through MIDI Messages ########################### while (True): start_playback_time = GetCurrentTime() port.reset() for midi_msg_number, msg in enumerate(mid.play()): #################### GUI - read values ################## if not midi_msg_number % 4: # update the GUI every 4 MIDI messages t = (GetCurrentTime() - start_playback_time) // 1000 display_midi_len = '{:02d}:{:02d}'.format( *divmod(int(midi_length_in_seconds), 60)) display_string = 'Now Playing {} of {}\n{}\n {:02d}:{:02d} of {}\nPlaylist:'.\ format(now_playing_number+1, len(filelist), midi_title, *divmod(t, 60), display_midi_len) # display list of next 10 files to be played. rc = pback.PlayerPlaybackGUIUpdate(display_string + '\n' + display_file_list) else: # fake rest of code as if GUI did nothing rc = PLAYER_COMMAND_NONE if paused: rc = PLAYER_COMMAND_NONE while rc == PLAYER_COMMAND_NONE: # TIGHT-ASS loop waiting on a GUI command rc = pback.PlayerPlaybackGUIUpdate(display_string) time.sleep(.25) ####################################### MIDI send data ################################## port.send(msg) # ------- Execute GUI Commands after sending MIDI data ------- # if rc == PLAYER_COMMAND_EXIT: cancelled = True break elif rc == PLAYER_COMMAND_PAUSE: paused = not paused port.reset() elif rc == PLAYER_COMMAND_NEXT: next_file = True break elif rc == PLAYER_COMMAND_RESTART_SONG: break if cancelled or next_file: break #------- DONE playing the song ------- # port.reset() # reset the midi port when done with the song if cancelled: break exit(69)