Skip to content

PerryWerneck/python3-tn3270

Repository files navigation

Python Extension Module for TN3270 Access

Provide python3 objects to remote control an active pw3270 window or to direct access a TN3270 host using lib3270.

License: GPL v3 CodeQL WinPackage build result

Installation

Download from open build service Download from github releases

Examples

Getting module version

#!/usr/bin/python
#-*- coding: utf-8

import tn3270

print("Using py3270 Version " + tn3270.version() + " revision " + tn3270.revision())

Getting pw3270 version

#!/usr/bin/python
#-*- coding: utf-8

import tn3270

session = tn3270.Session(":a")

print("Using PW3270 version " + session.version + " revision " + session.revision)

Connecting first pw3270 window to host (if not connected), getting contents

#!/usr/bin/python
#-*- coding: utf-8

import tn3270

session = tn3270.Session(":a")

if session.reconnect.try_activate():
	print("Reconnecting to host")
	session.wait(10)

print(session)

Connecting to host by url, getting some information.

#!/usr/bin/python
#-*- coding: utf-8

import tn3270

# Get TN3270 headless object
session = tn3270.Session("")

# Connect to host with 10 seconds timeout
session.connect("tn3270://localhost:3270",10)

# Show connection state.
print("Cstate: " + str(session.cstate))
print("Width: " + str(session.width))
print("Connected: " + str(session.connected))

# Show cursor position
print(session.cursor)

# Search for string on terminal
print(session.find("Host"))

# Count string
print(session.count("Host"))

# Get 38 characters at position 14,22
print(session.get(14,22,38))

session.disconnect()

input("Press enter to exit")

Building from sources

Linux

  1. Install libipc3270-devel

  2. Get python-tn3270 sources from git

    git clone https://github.com/PerryWerneck/python-tn3270.git ./python-tn3270
  3. Build the extension using setup.py

    cd python-tn3270
    python setup.py build
  4. Install extension

    python setup.py install

Windows (With MSVC & Python SetupTools)

  1. Download and install Visual Studio Build Tools (https://visualstudio.microsoft.com/pt-br/downloads/)

  2. Get python-tn3270 sources from git

    git clone https://github.com/PerryWerneck/python-tn3270.git ./python-tn3270
  3. Download and unpack libipc3270 pre-compiled image

    wget https://github.com/PerryWerneck/libipc3270/releases/download/5.5/msvc-libipc3270.zip
    7z x msvc-libipc3270.zip -y -oipc3270
  4. Build the extension using setup.py

    cd python-tn3270
    python setup.py build
  5. Install extension

    python setup.py install
  6. Build windows installer (optional)

    python setup.py bdist_wininst