I was doing some self education and playing around with ChatGpt and also Textual in Python, which is a text based terminal GUI (TUI) layer. I wanted to see if I could use ChatGpt to create an SSH terminal based UI as a replacement for PDM while also testing the Textual library to create a PASE app with a user interface.
The result is this starter Python app that runs in PASE.
It is not a complete app, but an illustration of the art of the possible for a text based PASE UI app.
It is actually quite useful already for doing quick source edits and compiles from PASE if you don't have access to the IBM 5770WDS tools on a machine.
- Make sure all the IBM i Python 3.13 packages are installed in PASE.
yum install python3.13-* - Create a Python virtual environment.
python3.13 -m venv /pythonenv313
You can use this link if needed to guide you on setting up a Python virtual environment. https://github.com/richardschoen/howtostuff/blob/master/install-python-ibmivirtual-environment.md - For this example we'll assume we've already created a Python virtual environment in directory:
/pythonenv313 - Activate virtual environment
source /pythonenv313/bin/activate - Install ibm acs ODBC driver
pip3.13 install ibmi-access - Install pip requirement
pip3.13 install textual - Run the app:
pdmpython.sh. You may need to tweak this runtime script with your own Python virtual environment name if you didn't use/pythonenv313
I ended up doing two alterations on this app via prompt:
- create me a python base tui app that allows me to specify and library and source file. Then have it list the source members along with source type and text. Allow me to place a E next to a source member to edit it. Allow a B next to the source member to browser it and display it. Option C should compile with the appropriate ibmi compiler. Always put the source member back to the original source file member on save.
rewrite to use pyodbc instead of ibm_db_dbi.
The result was essentially the app here with a few minor tweaks.
A base Python/Textual application intended to run in IBM i PASE.
- Enter an IBM i library and source physical file.
- Press
F5to refresh the list. Assuming your ODBC driver is working as expected the source list should display. - Lists source member, source type, and member text from
QSYS2.SYSPARTITIONSTAT. - Select a row and enter:
Eto editBto browse read-onlyCto compile
- Keyboard shortcuts:
EeditBbrowseCcompile (option 14)F5reload member listCtrl+Qquit
- Saving always writes back to the original
LIBRARY/SOURCEFILE(MEMBER)usingCPYFRMSTMF ... MBROPT(*REPLACE). - Compile command mappings are held in
COMPILE_COMMANDSnear the top ofapp.py.
From a PASE shell:
python3 -m venv .venv
. .venv/bin/activate
python -m pip install -r requirements.txt
python app.pyThe Python environment must have pyodbc, unixODBC, and an IBM i-compatible ODBC driver available. The application uses /QOpenSys/usr/bin/system for CL commands.
By default, the application connects with:
DSN=*LOCAL
Override that setting with the IBMI_ODBC_CONNECTION_STRING environment variable. For example:
export IBMI_ODBC_CONNECTION_STRING='DSN=MYIBMI;UID=MYUSER;PWD=MYPASSWORD'
python app.pyYou can also provide a driver-based connection string if your unixODBC configuration does not define a DSN:
export IBMI_ODBC_CONNECTION_STRING='DRIVER={IBM i Access ODBC Driver};SYSTEM=myibmi.example.com;UID=MYUSER;PWD=MYPASSWORD'The signed-on profile needs authority to:
- Read the source file and members.
- Run
CPYTOSTMFfor browse/edit. - Run
CPYFRMSTMFwith replace authority for saves. - Execute the selected compiler command and create/replace the target object.
The included base mappings cover common source types such as:
- RPGLE / SQLRPGLE
- CLLE / CLP
- CBLLE / SQLCBLLE
- C / CPP
- DSPF / PRTF / PF / LF
- MENU and CMD
Review the mappings for your shop. For example, your RPG command may need DFTACTGRP(*NO), ACTGRP(...), BNDDIR(...), COMMIT(...), or a custom compile command.
The sample CMD mapping is intentionally only a placeholder because CRTCMD requires the command-processing program for your command definition. Replace it with your local standard.