Jan-26-2018, 06:03 PM
Hi, i'm beginner in Python, i'm writing my first program.
I want to print some data in table format.
I found this link http://www.pango.org/HelpOnTables but i can't make it's work.
This is my code:
<table>
<tr>
<td>Column 1</td><td>Column 2</td><td>Column 3</td>
<td>Column 1</td><td>Column 2</td><td>Column 3</td>
</tr>
</table>
I want to print some data in table format.
I found this link http://www.pango.org/HelpOnTables but i can't make it's work.
This is my code:
import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk from gi.repository import Pango gi.require_version('PangoCairo', '1.0') from gi.repository import PangoCairo class Print(): def __init__(self, content): self.content = content paper_size = Gtk.PaperSize.new_custom("cc", "cc", 210, 297, Gtk.Unit.MM) page_setup = Gtk.PageSetup() page_setup.set_paper_size(paper_size) page_setup.set_bottom_margin(10, Gtk.Unit.MM) page_setup.set_left_margin(10, Gtk.Unit.MM) page_setup.set_right_margin(10, Gtk.Unit.MM) page_setup.set_top_margin(10, Gtk.Unit.MM) page_setup.set_orientation(Gtk.PageOrientation.PORTRAIT) self.print_operation = Gtk.PrintOperation() self.print_operation.set_n_pages(1) self.print_operation.set_default_page_setup(page_setup) self.print_operation.connect("draw_page", self.draw_page) def draw_page(self, operation, context, page_number): pango_layout = context.create_pango_layout() pango_layout.set_markup(self.content, -1) cairo_context = context.get_cairo_context() PangoCairo.show_layout(cairo_context, pango_layout) def do_print(self): self.print_operation.run(Gtk.PrintOperationAction.PREVIEW, None) test = Print('''|| top left cell || top right cell || || bottom left cell || bottom right cell ||''') test.do_print()But i want something like this:
<table>
<tr>
<td>Column 1</td><td>Column 2</td><td>Column 3</td>
<td>Column 1</td><td>Column 2</td><td>Column 3</td>
</tr>
</table>