Implement create_from_commandline() for GAppInfo on macOS
I need help figuring out what I have to do to make the print preview work in GTK3 apps on macOS. I know that an external program is being called for that and that this can be configured with the gtk-print-preview-command
setting. But no matter what I do, it doesn't work, which leads me to believe that I'm missing something else here.
I'm using a small Python program for testing purposes (original source here) which I can run on both Linux and macOS. For comparability I'm using Firefox as preview program.
my modified test program
#!/usr/bin/env python3
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('Poppler', '0.18')
from gi.repository import GObject, Gtk, Poppler
class MyApp():
def __init__(self):
settings = Gtk.Settings.get_default()
# works on Linux
# Gtk.Settings.get_default().set_property("gtk-print-preview-command", "firefox %f")
# fails on macOS
Gtk.Settings.get_default().set_property("gtk-print-preview-command", "/Applications/Firefox.app/Contents/MacOS/firefox %f")
self.window = Gtk.Window()
button = Gtk.Button()
button.set_label("Click me")
self.window.add(button)
self.window.show_all()
self.window.connect("destroy", Gtk.main_quit)
button.connect("clicked", self.on_button_clicked)
self.operation = Gtk.PrintOperation()
self.operation.connect('begin-print', self.begin_print, None)
self.operation.connect('draw-page', self.draw_page, None)
# self.operation.connect('preview', self.preview, None)
self.doc = Poppler.Document.new_from_file("file:///Users/rene/Desktop/testfile.pdf")
def begin_print(self, operation, print_ctx, print_data):
operation.set_n_pages(self.doc.get_n_pages())
def draw_page(self, operation, print_ctx, page_num, print_data):
cr = print_ctx.get_cairo_context()
page = self.doc.get_page(page_num)
page.render(cr)
def preview(self, operation, preview, print_ctx, parent, print_data):
print("PREVIEW")
return True
def on_button_clicked(self, button):
result = self.operation.run(Gtk.PrintOperationAction.PRINT_DIALOG, self.window)
app = MyApp()
Gtk.main()
These are the error messages in the terminal:
** (printdlg.py:20299): WARNING **: 17:54:10.363: Couldn't connect to D-Bus system bus, Verbindung ist gescheitert: No such file or directory
(printdlg.py:20299): GLib-GIO-CRITICAL **: 17:54:12.970: g_app_info_launch: assertion 'G_IS_APP_INFO (appinfo)' failed
/Users/Shared/work/mibap-0.69/printdlg.py:50: Warning: g_object_unref: assertion 'G_IS_OBJECT (object)' failed
result = self.operation.run(Gtk.PrintOperationAction.PRINT_DIALOG, self.window)
I don't know if the D-Bus one is relevant (I don't have D-Bus installed), but the other one comes directly from the code that is supposed to launch the external program.
Edited by René de Hesselle