Python Forum
Help - GTK3 + Pango: Printing data as table format
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help - GTK3 + Pango: Printing data as table format
#1
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:
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>
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  GTK3.0 Color Selection Widget Robib 3 1,943 Nov-04-2021, 04:45 PM
Last Post: Axel_Erfurt
  [Tkinter] modify the html table to include data from tkinter labels rwahdan 0 1,589 Jun-20-2021, 10:33 AM
Last Post: rwahdan
  [GI] Error when I close the interface Glade/GTK3/ Charles25 2 2,112 Jun-16-2020, 07:02 PM
Last Post: Charles25
  Problem with Gtk3 and GLArea gsohler 0 2,166 Aug-12-2019, 07:33 AM
Last Post: gsohler
  [PyQt] How to display multiple data(from 2 different related table) in one cell of QTableWid yangjae 4 4,318 Oct-17-2018, 07:54 AM
Last Post: Larz60+
  [Tkinter] insert table columns data in different textboxes dimvord 4 4,856 Jun-15-2018, 07:40 AM
Last Post: dimvord
  python3 + gtk3 image sequence changos 0 3,269 Apr-24-2017, 04:10 PM
Last Post: changos
  Python minesweeper game gtk3 get label value after click lukassz 0 3,231 Mar-25-2017, 08:14 PM
Last Post: lukassz

Forum Jump:

User Panel Messages

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