× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



based on what I read here it sounds like its can replace RPG on as/400.. I
am not able to test it need some help.. if this is all doable mayb be we
can convince new generation to use AS/400 with Python :)

http://www.iseriespython.com/examples/printing.htm

Printing

Printing on the AS/400 can be a little tougher than on other platforms, so
this module was created to provide a standard interface for almost RPG
level of control over the output:


-

import os,sys,time
import string,types
import locale
import db2
-

class Printer:

def __init__(self,\
pagelength = 59,\
pagewidth = 132,\
header = '',\
footer = '',\
padding = 7,\
output = 'PRINT',\
paginate = 'TOPRIGHT',\
programid = '',\
regionname = '',\
regionpos = 'TOPLEFT',\
branchname = '',\
branchpos = 'TOPLEFT'\
):
self.pagelength = pagelength
self.pagewidth = pagewidth
self.header = header
self.footer = footer
self.padding = padding
self.output = output
self.paginate = paginate
self.programid = programid
self.regionname = regionname
self.regionpos = regionpos
self.branchname = branchname
self.branchpos = branchpos
self.page = 1
self.line = 1
self.CheckHeaders()
self.linecount = []
locale.setlocale(locale.LC_ALL,'/QSYS.LIB/EN_US.LOCALE')

def DrawFields(self,fields):
#
# DRAW A SERIES OF FIELDS ON A LINE
#
# EXPECTS TO SEE 2-LEVEL ARRAY LIKE:
# [ [ 'PART NUMBER',20], ['QUANTITY',7] ]
#
# ALIGNMENT PARAMETER IS OPTIONAL:
# [ [ 'PART NUMBER',20], ['QUANTITY',7,'RIGHT'] ]
# Valid values for alignment: LEFT,RIGHT,CENTER,CURRENCY
text = []
for field in fields:
val = field[0]
pad = field[1]
align = 'LEFT'
if len(field) > 2:
align = string.upper(field[2])
if align == 'CURRENCY':
align = 'RIGHT'
try:
val = locale.format('%.02f',val,3)
except:
pass
if type(val) != types.StringType:
val = str(val)
align = 'RIGHT'



#
# DRAW THE FIELD
#

if align == 'LEFT':
nval = string.ljust(val,pad)
elif align == 'CENTER':
nval = string.center(val,pad)
else:
nval = string.rjust(val,pad)
text.append(nval)
self.Print(string.join(text,' '))



def CheckHeaders(self):
self.headersize = 0
self.footersize = 0
if self.header:
if self.header[-1] == '\n':
self.header = self.header[:-1]
self.headersize = string.count(self.header,'\n') -1

if self.footer:
if self.footer[-1] == '\n':
self.footer = self.footer[:-1]
self.footersize = string.count(self.footer,'\n')



def PageBreak(self):

#
# SKIP THE REST OF THE EXISTING PAGE
#

leftofpage =
(self.pagelength-(self.headersize+self.footersize+self.padding))-self.line
for row in range(0,leftofpage+4):
if self.line >=
(self.pagelength-self.headersize)-self.footersize:
break
self.Gen('')
self.DrawFooter()



def Print(self, text = ''):

#
# PRINT A LINE OF TEXT
#

if text:
if text[-1] != '\n':
text += '\n'

if self.line == 1:
self.DrawHeader()
elif self.line >=
self.pagelength-(self.headersize+self.footersize+self.padding):
self.PageBreak()
self.DrawHeader()
self.Gen(text)



def SetHeader(self,header):
self.header = header
self.CheckHeaders()



def SetFooter(self,footer):
self.footer = footer
self.CheckFooters()



def DrawHeader(self):
x = 0
headers = string.split(self.header,'\n')
for h in headers:
if h != '\n':
th = h

#
# CENTER THE HEADER
#

if th == '-':
th = string.ljust(' ',self.pagewidth)
th = string.replace(th,' ','-')
else:
th = string.center(th,self.pagewidth-1)
if x == 0:
if self.paginate == 'TOPRIGHT':
pn = string.rjust(str(self.page),5)
th = th[:-10] + 'PAGE: ' + pn
if self.programid != '':
y = len(self.programid) + 1
th = self.programid + th[y:]
elif self.paginate == 'TOPLEFT':
pn = string.rjust(str(self.page),5)
th = 'PAGE: ' + pn + th[10:]
if self.programid != '':
y = -(len(self.programid) + 1)
th = th[:y] + self.programid
elif x == 1:
if self.regionname != '':
if self.regionpos == 'TOPLEFT':
y = len(self.regionname) + 1
th = self.regionname + th[y:]
elif self.regionpos == 'TOPRIGHT':
y = len(self.regionname) + 1
th = th[y:] + self.regionname
if self.branchname != '':
if self.branchpos == 'TOPLEFT':
y = len(self.branchname) + 1
th = self.branchname + th[y:]
elif self.branchpos == 'TOPRIGHT':
y = len(self.branchname) + 1
th = th[y:] + self.branchname
self.Gen(th)
x += 1



def DrawFooter(self):
x = 0
footers = string.split(self.footer,'\n')
for f in footers:
if f != '\n':
#
# CENTER THE FOOTER
#

th = string.center(f,self.pagewidth)
if x == 0:
if self.paginate == 'BOTTOMRIGHT':
pn = string.rjust(str(self.page),5)
th = th[:-10] + 'PAGE: ' + pn
elif self.paginate == 'BOTTOMLEFT':
pn = string.rjust(str(self.page),5)
th = 'PAGE: ' + pn + th[10:]
self.Gen(th)
x += 1
self.linecount.append([self.page,self.line])
self.page += 1
self.line = 1



def Gen(self,text):

#
# GENERATE A SINGLE LINE OF OUTPUT
#

if text:
if text[-1] != '\n':
text += '\n'
if self.output == 'PRINT':
sys.stdout.write(text)
self.line += 1
return


Usage:

Let's say you save the above in a module called myPrinter.

Then you would have this in your application code:


import myPrinter


def PrintMyReport(results):

#

# CREATE THE PRINTER OBJECT

#

h = "This is my report"

p = "MYPROG.py"

b = "Calgary"

w = 176

Printer =
myPrinter.Printer(header=h,programid=p,branchname=b,pagewidth=w)

Printer.DrawFields([[ 'LN' , 3 , 'RIGHT'],\
[ 'Product Number' , 24 ],\
[ 'Q/S' , 5 , 'RIGHT'],\
[ 'Unit Cost' , 10 , 'RIGHT'] ])

#

# EXAMPLE ONLY: By this point, your report results would be
generated,
# and placed in the "results" variable below.
#

for each in results:

ln = each[0]
pn = each[1]
qs = each[2]
uc = each[3]
Printer.DrawFields([[ ln , 3,'RIGHT'],\
[ pn , 24 ],\
[ qs , 5,'RIGHT'],\
[ uc , 10,'RIGHT']])


On Fri, Jan 13, 2017 at 7:31 AM, Kevin Bucknum <Kevin@xxxxxxxxxxxxxxxxxxx>
wrote:

Printer files and DSPF's sounds like you want to replace RPG
interactive/reporting programs. Python is not going to be your choice if
you want green screen interactive. Python's strengths (at least in what
I've found uses for) is in reporting to formats like excel or pdf. Look
at this thread from a while back where we talk about accessing files.
http://archive.midrange.com/opensource/201607/msg00042.html




Kevin Bucknum
Senior Programmer Analyst
MEDDATA/MEDTRON
Tel: 985-893-2550

-----Original Message-----
From: MIDRANGE-L [mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of
Mohammad Tanveer
Sent: Friday, January 13, 2017 8:01 AM
To: Midrange Systems Technical Discussion
Subject: Re: Python on iSeries

I was wondering if there are some good working examples with File I/Os
.
may be with printer files and DSPF? Python looks like good old DOS
based QBASIC to me with some advance features...I am trying to practice
it using www.codecademy.com for python

On Fri, Jan 13, 2017 at 5:16 AM, Pete Helgren <pete@xxxxxxxxxx> wrote:

I couldn't remember how far back iSeriesPython went so I chickened out

and qualified it with "Open Source products provided by IBM" ....

Thanks for weighing in.

Pete Helgren
www.petesworkshop.com
GIAC Secure Software Programmer-Java
Twitter - Sys_i_Geek IBM_i_Geek

On 1/12/2017 5:26 PM, John Yeung wrote:

On Thu, Jan 12, 2017 at 3:09 PM, Pete Helgren <pete@xxxxxxxxxx>
wrote:

You may want to post over on the Open Source list (
opensource@xxxxxxxxxxxx)
. There are several folks who use Python regularly on that list,
although they may also be lurking here. And, just to be clear an
"iSeries" won't be able to run the current Open Source products
provided by IBM because an iSeries is no longer a supported model.
But an IBM i running a Power 6 or better processor and 7.1 or higher

of the IBM i OS should do just fine....

All true, but it is also possible he was talking about iSeriesPython,

which runs on everything from V5R3 on up. (I am aware of older
versions that have been used in production on V4R4 machines, but I
don't know how you would go about getting those older versions
today.)

John Y.


--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing

list To post a message email: MIDRANGE-L@xxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take
a moment to review the archives at
http://archive.midrange.com/midrange-l.

Please contact support@xxxxxxxxxxxx for any subscription related
questions.

Help support midrange.com by shopping at amazon.com with our affiliate
link: http://amzn.to/2dEadiD

--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list To post a message email: MIDRANGE-L@xxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take a
moment to review the archives at http://archive.midrange.com/midrange-l.

Please contact support@xxxxxxxxxxxx for any subscription related
questions.

Help support midrange.com by shopping at amazon.com with our affiliate
link: http://amzn.to/2dEadiD
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.

Please contact support@xxxxxxxxxxxx for any subscription related
questions.

Help support midrange.com by shopping at amazon.com with our affiliate
link: http://amzn.to/2dEadiD


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.