User Tools

Site Tools


python_functions

Python Functions and Procedure Reference

This page is a work in progress and documents what has been implemented thus far. Plans for future developmental work are outlined at the bottom of this page.

Creating a Python Module for Mystic BBS

For BBS modules, you first must import the BBS module:

import mystic_bbs as bbs

This will give you all of the BBS related functions addressable with a bbs. prefix.

Mystic BBS Python Integrated BBS Functions

The following BBS specific functions have so far been implemented:

  • write
  • writeln
  • menucmd
  • getkey
  • shutdown
  • getstr
  • getuser
  • onekey
  • keypressed

Examining testpython.mpy from the Scripts directory provides examples of how functions are used.

testpython.mpy - Mystic 1.12 Alpha 31

##############################################################
## INITIALIZE BBS FUNCTIONS AND DEFINE ANY GLOBAL VARIABLES ##
##############################################################

from mystic_bbs import *

KEY_UP       = chr(72)       # Some keyboard code defines returned by input functions
KEY_DOWN     = chr(80)
KEY_ESCAPE   = chr(27)
KEY_ENTER    = chr(13)
KEY_TAB      = chr(9)
KEY_LEFT     = chr(75)
KEY_RIGHT    = chr(77)

user_deleted = int("00000004")  # user deleted flag from records.pas

thisuser = getuser(0);    # read the currently logged in user into thisuser


################################
## CUSTOM FUNCTION: USER LIST ##
################################

def show_user_list():

	writeln("|15|16|CL|17 Python Demonstration Program > User Listing|$X79 |16|CR")

	count = 1
	user  = getuser(count)
	shown = 0

	while not user is None:

		if not user["flags"] & user_deleted:

			writeln(user["handle"])
			shown = shown + 1

		count = count + 1
		user  = getuser(count)	

	write("|CR|14Listed |15" + str(shown) + " |14user(s)|CR|CR|PA")



################################
## CUSTOM FUNCTION: BOX DEMO  ##
################################

def do_box_demo():

	box = box_options()

	box["header"]  = " Demo Box "
	box["restore"] = False

	writeln(str(box["attr1"]) + "|PN")

	#box_open  (box, 20, 3, 60, 9)
	#box_close (box)


#################################
## CUSTOM FUNCTION: INPUT DEMO ##
#################################

def do_input_demo():

	writeln("|15|16|CL|17 Python Demonstration Program > Input Demo|$X79 |16")

	write('|CR|09Type a string: ');

	input = getstr(11, 40, 120, "Default");

	writeln("|CR|13Enter characters and press |05[|15ESCAPE|15|05] |13when done:|07|CR")

	while not shutdown():

		char, extended = getkey();

		if extended:

			if char == KEY_UP:
				writeln("you pressed up arrow");
			elif char == KEY_DOWN:
				writeln("you pressed down arrow");
			elif char == KEY_LEFT:
				writeln("you pressed left arrow");
			elif char == KEY_RIGHT:
				writeln("you pressed right arrow");
			else:
				writeln("You pressed extended key #" + str(ord(char)))

		else:
			if char == KEY_ESCAPE:
				writeln("you pressed ESCAPE");
				break;
			elif char == KEY_ENTER:
				writeln("you pressed enter");
			elif char == KEY_TAB:
				writeln("you pressed tab");
			else:
				writeln("you pressed character " + char);


################################
## CUSTOM FUNCTION: MAIN MENU ##
################################

def show_main_menu():

	while not shutdown():

		writeln("|15|16|CL|17 Python Demonstration Program > Main Menu|$X79 |16")

		writeln("|CR|15Hello, |14" + thisuser["handle"] + " #" + str(thisuser["id"]) + "|15!  Please     select one of the following options:|CR")
		writeln("  |09(|11I|09) Input Demo")
		writeln("  |09(|11U|09) User List")
		write  ("|CREnter option (|11Q|09/|11Quit|09): |11")

		# get one character input using defined list of valid keys

		char = onekey("IQU", True)

		if char == "I":
			do_input_demo()

		if char == "Q":
			break

		if char ==  "U":
			show_user_list()

		

###################################
## PROGRAM EXECUTION BEGINS HERE ##
###################################

show_main_menu()

writeln("|CR|14Demo complete! |PA");

Planned Python Functions

RETURNS		FUNCTION NAME	PARAMETERS
  
INPUT/OUTPUT:

(none)		clear		(none)
(none)		cleareol	(none)
(char, bool)	getkey		(none)
(string)	getstr		(<mode>byte, <fieldsize>byte, <maxsize>byte, <default>string)
(bool)		getyn		(<text>string, <default>bool)
(none)		gotoxy		(<x>byte, <y>byte)
(bool)		keypressed	(<waitTime>?)  or separate waitKey function with MS timer?
(char)		moreprompt	(none)
(none)		movex		(<x>byte)
(none)		movey		(<x>byte)
(char)		onekey		(<keys>string, <echo>bool)
(char,integer)	onekeyrange	(<keys>string, <min>integer, <max>integer
(none)		out		(string)
(none)		outln		(string)
(none)		pause		(none)
(none)		pipe		(string)
(none)		pipeln		(string)
(none)		purgeinput	(none)
(bool)		showfile	(<file>string, <baudrate>integer, <pause>bool)
(none)		stuffkey	(<keys>string)
(byte)		textattr	(none)
(byte)		wherex		(none)
(byte)		wherey		(none)
(none)		write		(string)
(none)		writeln		(string)
(none)		writexy		(<x>byte, <y>byte, <attr>byte, text<string>)
(none)		writexypipe	(<x>byte, <y>byte, <attr>byte, <pad>byte, text<string>

STRING FUNCTIONS:

(byte)		mcilen		(string)
(string)	mci2str		(string)

MISCELLANOUS / UNSORTED:

(bool)		access		(<acs>string)
(none)		appendtext	(<filename>string, <text>string)
(byte)		getcodepage	(none)
(byte)		getgraphics	(none)
(bool)		ignoregroups	(<optional on or off>bool)  * IF this can be done they do same for codepage, textattr,graphics etc
(string)	getprompt	(<promptnumber>integer)
(none)		hangup		(none)
(none)		log		(<level>byte, <category>char, <text>string)
(none)		menucmd		(<cmd>string, <data>string)
(byte)		node		(none)
(none)		setprompt	(<promptnumber>integer, <text>string)
(bool)		shutdown	(none)
(none)		upgradeuser	(<level>byte)

key missing things TODO:

* 	need to pass paramenters to the program somehow
* 	need formatDate and various conversion functions
*    	thisuser, user, msg areas, msg headers, msg text, file areas, file list
* 	ansi buffer,
* 	msg editor, ansi editor, text editor
* 	box, listbox, screen save/restore, extended input
* 	getattr putattr
* 	getmailstats
* 	getmsgbasestats
* 	helper string functions from MPL?
python_functions.txt · Last modified: 2017/02/16 04:08 by avon