Purpose Starting a standalone Python program from GuiXT
Solution
Bundle the Python script into an .exe file and call it using
Start
Example
Create your Python script.
Python Script:
Python
import sys
from openpyxl import Workbook
def write_data_to_excel(csv_data, output_path="output.xlsx"):
values = csv_data.split(',')
data = [
{
'region': values[i], 'sales': values[i+1]
} for i in range(0, len(values), 2)
]
wb = Workbook()
ws = wb.active
ws.column_dimensions['A'].width = 30
ws.column_dimensions['B'].width = 20
for k, row in enumerate(data, start=1):
ws.cell(row=k, column=1, value=row['region'])
ws.cell(row=k, column=2, value=row['sales'])
wb.save(output_path)
def main():
if len(sys.argv) < 2:
print("No data to write!")
sys.exit()
if len(sys.argv) > 2:
write_data_to_excel(sys.argv[1], sys.argv[2])
else:
write_data_to_excel(sys.argv[1])
if __name__=="__main__":
main()
Use PyInstaller to bundle your Python script into an .exe file.
Copy the resulting folder to your GuiXT files folder.
CMD
pyinstaller write_excel.py
After installing, the Python script can be called from GuiXT.
GuiXT Script:
GuiXT
Set V[region.1] "Americas"
Set V[sales.1] "2584"
Set V[region.2] "Europe"
Set V[sales.2] "1228"
Set V[region.3] "Asia"
Set V[sales.3] "1628"
// The data needs to be put into a format the Python script can
// accept as a parameter
// This format ultimately depends on your Python script
Set V[rows] 3
Set V[row] 1
Set V[salesRegions] ""
label loop
if not V[row>&V[rows]]
if not V[row=1]
Set V[salesRegions] "&V[salesRegions],"
endif
Set V[salesRegions] "&V[salesRegions]&V[region.&V[row]],&V[sales.&V[row]]"
Set V[row] &V[row] + 1
goto loop
endif
// Ensure that the path points to the location of
// the executable you created with PyInstaller
Start "path/to/write_excel.exe" parameters="&V[salesRegions]"