Python Forum
still working on page columnizer
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
still working on page columnizer
#1
i'm still working on a page columnizer.  you call put() passing it short lines, such as names files.  it forms the lines into columns and lines them up straight.  a page is filled with columns from left to right, using however many will fit with the initially specified gutter,  the size of the page is also specified.

i am adding the ability to do a page eject and also a column eject.  this is where i want to get some opinion.  should a page eject and column eject be special cases of the put() call, or should there be different methods?  should i have two methods eject_column() and eject_page(). or just one eject() method with an argument to specify which is being skipped.  are those good names or should they be next(), next_page(), skip(). or skip_page()?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
I would make put and eject different methods. It seems counter-intuitive to eject with a put. As for eject_column and eject_page, it would depend on your object model. If you have page and column objects, I would give them each an eject method. If you have just a document object, I would have different methods. As for eject, next, or skip, I don't really know, because it's not clear to me what any of these methods exactly do. I was assuming ejecting something would get rid of it, delete it. In that case I would call it delete. If it does something else, maybe next or skip is appropriate.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
(May-21-2017, 12:48 PM)ichabod801 Wrote: I would make put and eject different methods. It seems counter-intuitive to eject with a put. As for eject_column and eject_page, it would depend on your object model. If you have page and column objects, I would give them each an eject method. If you have just a document object, I would have different methods. As for eject, next, or skip, I don't really know, because it's not clear to me what any of these methods exactly do. I was assuming ejecting something would get rid of it, delete it. In that case I would call it delete. If it does something else, maybe next or skip is appropriate.

yes, it did seem counter-intuitive to do eject in a put call.  that's a big reason i am asking.  but the logic is easily done alike or in the same place.

i was thinking of supporting form feed as a page eject and vertical tab as a column eject.

what a column eject would mean is that future line puts will be done on the next column.  that would be like putting as many blank/empty lines until the next put of a line puts it on the next column.  the current column is finished.  a page eject goes further such that the next put of a line puts it at the top of the leftmost column of the next page.

now how should this work for ending the output?  .close() seems right.  i should just make this class be as file-like as possible?

how to deal with page output?  currently this class can have a print= option giving the file to print to.  if not set or set to None, then pages are queued and the output queue can be picked up, one page at a time via .get_page().  or maybe i should create a 2nd associated class which is a read mode file-like class where completed pages can be read (possible deadlock issue with this).
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#4
(May-22-2017, 02:19 AM)Skaperen Wrote: what a column eject would mean is that future line puts will be done on the next column. that would be like putting as many blank/empty lines until the next put of a line puts it on the next column. the current column is finished. a page eject goes further such that the next put of a line puts it at the top of the leftmost column of the next page.

Then I would go with next_page() and next_column(), that makes more sense to me. YMMV. You could go for next('page') and next('column'), but I would only do that if expecting a variable containing 'page' or 'column' to be a common occurrence.

Why do you need to close the object? I'm not sure I would implement that at all.

For output, I would just override __str__. Then you can use print() and file.write() normally.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#5
there would be a lot of output in the column and page buffers during the build-up of columns and pages.  if in the middle of that there is no more output to add on to a column or page, there has to be some way to output the last page with the last column with the last little line.  for example:

cx = columnizer(gutter=1,width=15,height=4) ... the first page might look like this for 20 little lines:

Output:
2 11 23 41 59 3 13 29 43 61 5 17 31 47 67 7 19 37 53 71
but if there were only 14 lines to print out, the buffer would be holding little lines up to "43".  the cx.close() at this point would finish the 4th column early and finish the 1st page early so you get:

Output:
2 11 23 41 3 13 29 43 5 17 31 7 19 37
you can't just output columns and pages each time there is a new little line to do cx.put(pr) with.

FYI, the module, run as a command will columnize stdin to stdout using page geometry (gutter width height1 heightx) from the command line args.

.put() data will finish a column or page when the next little line exceeds the page height of the current column or enough completed columns fill out the full width of the current page.  note that output in the middle of a column could do this (makes the column wider and is then too wide to fit on the page).


i wonder if i should make a C version of this ... nah!
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020