-
Notifications
You must be signed in to change notification settings - Fork 0
Making a Program for PyTerm
I'm opening up the opportunity to make programs for PyTerm 2. However, they will need to be in the "PyTerm standardized form" as a program. Here's the basics to making a program.
Quick note: This document is based off of PyTerm 2's API scheme. For PyTerm 1, you cannot submit applications.
If you need help, or get confused at any point, please create an issue, and tag it with [API HELP], and I'll do my best to help!
This page is incomplete. There's A LOT to type here.
PyTerm has a few main requirements for making your own program.
When making your own program, you'll need a few mandatory variables.
The first is your program name, in a shortened, "slug" like format.
If my program was called "Super Amazing Game 2", I'd make the slug-like name superamazinggame2. Long names like such aren't ideal, but are acceptable, at the least. This slug-like name: sag2 would be much more acceptable, as it's shorter.
Second, is your program's version number, as a global variable. All version variables end up always looking like such:
slugname_ver = "versionnumber"
Confused? It's okay. Let's say I have a program called "Weather Machine", with the slug weathermachine, and it's on version 2.1. My global version variable for such would be:
weathermachine_ver = "2.1"
If my version number was instead something like 20170101, the global variable would be:
weathermachine_ver = "20170101"
If my program name was "Super Awesome Game 2", with the slug 'sag2', and it's on version 2.0, my global version variable would look like this:
sag2_ver = "2.0"
You'll need to define these version variables in the boot of PyTerm, and in pytermvars.py, in the root directory of PyTerm.
It's important to know that when your program is launched, the mandatory header will pose the version number defined in your global variable as:
Launching program: Your Program Name (version versionnumberhere)
In Weather Machine's case, with the 20170101 version, it'll look like this:
Launching program: Weather Machine (version 20170101)
Based off of the names of HTML's header and footer, these lines of code are what you need to put before and after you execute your program.
The header lines are basically this:
print("Launching program: Guide to headers (version " + gth_ver + ")")
print("")
All the header is doing is calling your program name (and version number), along with printing 1 line of whitespace.
In your program, be sure to replace gth_ver with your program's version number variable.
After these two lines, you'll have 10 lines to write your program (if your program is 10+ lines, see the next section below).
For the footer, it's even simpler.
print("")
continue
All we're doing is printing a line of whitespace, and going back to the command input. All in all, this is what your header/footer combined should look like. In this example, my program is named "Finishing off", with the slug of fo, and the version slug of fo_ver
HEADER > print("Launching program: Finishing off (version " + fo_ver + ")")
HEADER > print("")
CODE HERE/EXTERNAL CALL
FOOTER > print("")
FOOTER > continue
Any program that has more than 10 lines of code (excluding headers/footers) must be in an external program. A program like this one:
HEADER > print("Launching program: Shutdown PyTerm (version " + shutdown_ver + ")")
HEADER > print("")
print("Shutting down...")
cmd = ""
sys.exit()
Is OK to not have it called externally, as it's only a few lines of code. However, larger programs MUST be called externally.
When it comes to your file structure, your program will have a place in the "assets" folder. If my program's slug was "testtest", my own folder for that program would be assets//testtest. The location of your folder is based on your slug, not your program name.
When calling programs externally, your program should end up looking a lot like this:
HEADER > print("Launching program: Setup PyTerm (version " + setup_ver + ")")
HEADER > print("")
EXTERNAL CALL> exec(open("assets//essential//setup.py").read())
FOOTER > print("")
FOOTER > continue
Confused? Here's an example where my program is called "External Calls", slug ec, version slug ec_ver.
My working directory would become assets//ec//
If you're making your own program, it's not a good idea to have your filesystem calls (in pterm.py, or in your program) look something like this:
this\is\a\folder
or...
this/is/a/folder
Many issues and complications will pop-up. In the first example, that'll only work on Windows. With the second example, some characters will trigger Python to not call the filesystem properly. Instead, have your calls look a little something like this:
this//is//a//folder
The double slashes ensure calls work across platforms, and that special characters won't get in the way of filesystem calls.
This is fun! Submitting your program. Make sure you've followed the mandatory API guidelines above, and there's a few other things to do.
You'll need to get your program in the elif loop. help will always be the first reserved command. If my program was called "I submit programs", slug isp, version variable isp_ver, with the script located at assets//isp//isp.py, this is entirely what your code in pterm.py would look like.
TABBED IN 1X > elif cmd == "isp":
TABBED IN 2X > print("Launching program: I submit programs (version + isp_ver + ")")
TABBED IN 2X > print("")
TABBED IN 2X > exec(open("assets//isp//isp.py").read())
TABBED IN 2X > print("")
TABBED IN 2X > continue