Major update of all demo programs to use new PEP8 bindings, etc
This commit is contained in:
parent
3f7c87c562
commit
7f52778bcc
307 changed files with 19546 additions and 3297 deletions
40
DemoPrograms old/Demo_Base64_Image_Encoder.py
Normal file
40
DemoPrograms old/Demo_Base64_Image_Encoder.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
import PySimpleGUI as sg
|
||||
import os
|
||||
import base64
|
||||
|
||||
'''
|
||||
Base64 Encoder - encodes a folder of PNG files and creates a .py file with definitions
|
||||
'''
|
||||
|
||||
OUTPUT_FILENAME = 'output.py'
|
||||
|
||||
def main():
|
||||
# folder = r'C:\Python\PycharmProjects\GooeyGUI\Uno Cards'
|
||||
folder=''
|
||||
folder = sg.PopupGetFolder('Source folder for images\nImages will be encoded and results saved to %s'%OUTPUT_FILENAME,
|
||||
title='Base64 Encoder',
|
||||
default_path=folder, initial_folder=folder )
|
||||
|
||||
if folder is None or folder == '':
|
||||
sg.PopupCancel('Cancelled - No valid folder entered')
|
||||
return
|
||||
try:
|
||||
namesonly = [f for f in os.listdir(folder) if f.endswith('.png') or f.endswith('.ico') or f.endswith('.gif')]
|
||||
except:
|
||||
sg.PopupCancel('Cancelled - No valid folder entered')
|
||||
return
|
||||
|
||||
outfile = open(os.path.join(folder, OUTPUT_FILENAME), 'w')
|
||||
|
||||
for i, file in enumerate(namesonly):
|
||||
contents = open(os.path.join(folder, file), 'rb').read()
|
||||
encoded = base64.b64encode(contents)
|
||||
outfile.write('\n{} = {}\n\n'.format(file[:file.index(".")], encoded))
|
||||
sg.OneLineProgressMeter('Base64 Encoding', i+1, len(namesonly),key='_METER_')
|
||||
|
||||
outfile.close()
|
||||
sg.Popup('Completed!', 'Encoded %s files'%(i+1))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Add table
Add a link
Reference in a new issue