i m trying to print my windows app , there is a lack of information actually , and all examples are in gtk3 i was able to print an hello world , but not my windows i m using gnome builder
from gi.repository import Adw
from gi.repository import Gtk
@Gtk.Template(resource_path='/org/gnome/Example/window.ui')
class TestprintWindow(Adw.ApplicationWindow):
__gtype_name__ = 'TestprintWindow'
button = Gtk.Template.Child()
def __init__(self, **kwargs):
super().__init__(**kwargs)
@Gtk.Template.Callback()
def on_button_clicked(self, button):
print('Botão pressionado.')
self.print_dialog()
def print_dialog(self):
# Create a print operation
print_operation = Gtk.PrintOperation()
print_operation.set_n_pages(1)
# Connect to the begin-print signal to set up the print job
print_operation.connect("begin-print", self.on_begin_print)
# Connect to the draw-page signal to render the content to be printed
print_operation.connect("draw-page", self.on_draw_page)
# Run the print dialog and print the content
print_operation.run(Gtk.PrintOperationAction.PRINT_DIALOG, None)
def on_begin_print(self,print_operation, print_context):
# Set up the page layout
page_setup = print_context.get_page_setup()
def on_draw_page(self, print_operation,print_context, page_number):
# Render the content to be printed
cr = print_context.get_cairo_context()
cr.set_source_rgb(0, 0, 0)
cr.set_font_size(20)
cr.move_to(50, 50)
cr.show_text("Hello World9")