pygobject gtk4,尝试打印

问题描述 投票:0回答:0

我正在尝试打印我的 windows 应用程序,实际上缺少信息,所有示例都在 gtk3 中 我能够打印一个hello world ,但不能打印我的windows 我正在使用 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")

printing pygobject gtk4
© www.soinside.com 2019 - 2024. All rights reserved.