2018-09-27 20:24:09 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
import sys
|
2018-09-28 18:57:37 +00:00
|
|
|
if sys.version_info[0] >= 3:
|
2018-09-27 20:24:09 +00:00
|
|
|
import PySimpleGUI as sg
|
2018-09-28 18:57:37 +00:00
|
|
|
else:
|
|
|
|
import PySimpleGUI27 as sg
|
|
|
|
|
2018-08-28 23:46:27 +00:00
|
|
|
|
|
|
|
'''
|
|
|
|
Quickly add a GUI to your script!
|
|
|
|
|
|
|
|
This simple script shows a 1-line-GUI addition to a typical Python command line script.
|
|
|
|
|
|
|
|
Previously this script accepted 1 parameter on the command line. When executed, that
|
|
|
|
parameter is read into the variable fname.
|
|
|
|
|
|
|
|
The 1-line-GUI shows a form that allows the user to browse to find the filename. The GUI
|
|
|
|
stores the result in the variable fname, just like the command line parsing did.
|
|
|
|
'''
|
|
|
|
|
|
|
|
if len(sys.argv) == 1:
|
2018-10-15 20:07:23 +00:00
|
|
|
event, (fname,) = sg.Window('My Script').LayoutAndRead([[sg.T('Document to open')],
|
|
|
|
[sg.In(), sg.FileBrowse()],
|
|
|
|
[sg.Open(), sg.Cancel()]])
|
2018-08-28 23:46:27 +00:00
|
|
|
else:
|
|
|
|
fname = sys.argv[1]
|
|
|
|
|
|
|
|
if not fname:
|
2018-09-04 23:43:22 +00:00
|
|
|
sg.Popup("Cancel", "No filename supplied")
|
2018-08-28 23:46:27 +00:00
|
|
|
raise SystemExit("Cancelling: no filename supplied")
|