makeFX.py
This Python file will generate shell code for a JavaFX application with all of the basic methods stubbecd in. Complete instructions are in the comment header. Get yours today.
#!/usr/bin/env python3
from sys import argv
from datetime import datetime
import sys
import os
##################################################
# makeFX.py
# Author: John M. Morrison. Released without warrantee with a GPL v3 license.
# 8 Dec 2021: upgrated to Python 3 and f-strings.
# 9 Sept 2023: allow user to specify date; default is today.
# add full documentation
# Date format must be entered as yyyymmdd.
# usages:
# python makeFX.py filename (default date is today)
# python makeFX.py filename yyyymmdd (specify date)
# usage note: if you are running on UNIX with execute permissions, you can
# omit the "python" in the two commands above if this file is located
# in a directory in your $PATH.
# product:
# a skeleton JavaFX file with a comment header, a default
# constructor, and all of the life-cycle methods
# stubbed in.
##################################################
if len(argv) == 3: #user specified date supplied
date_data = argv[2]
year = date_data[:4]
month = date_data[4:6]
day = date_data[6:8]
date = datetime.fromisoformat(f"{year}-{month}-{day}")
date = date.date()
elif len(argv) == 2:
date = datetime.date(datetime.now()) #default to today
else:
print("Usage: python makeThree.py yyyymmdd")
print("Bailing.... try again.")
quit()
root = argv[1]
print(f"{root}.java, date = {date}")
with open(root + ".java", "w") as fp:
fp.write(f"""/**************************************************
* Author: Morrison
* Date: {date}
**************************************************/
import javafx.application.Application;
import javafx.application.Platform;
import javafx.stage.Stage;
import javafx.scene.Scene;
""")
fp.write(f"public class {root} extends Application\n")
fp.write("{\n")
fp.write(f" public {root}()\n ")
fp.write(r"""
{
}
@Override
public void init()
{
}
@Override
public void start(Stage primary)
{
primary.show();
}
@Override
public void stop()
{
}
}""")