-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace XPP with Gtk print dialog and dependencies
Note: system-wide dependencies made available from securedrop-export venv due to the need to access python3-gi. Otherwise it would require too many build dependencies and complexity. Given that python3-gi is already required by some Qubes components, it does not add too many new dependencies.
- Loading branch information
Showing
2 changed files
with
50 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import gi | ||
gi.require_version("Gtk", "4.0") | ||
from gi.repository import Gtk | ||
|
||
import logging | ||
from securedrop_export.print.status import Status | ||
from securedrop_export.exceptions import ExportException | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
def open_print_dialog(file_to_print): | ||
app = PrintDialog(file_to_print) | ||
app.run() | ||
|
||
|
||
class PrintDialog(Gtk.Application): | ||
def __init__(self, file_to_print): | ||
super().__init__(application_id="org.securedrop.PrintDialog") | ||
self.file_to_print = file_to_print | ||
self.connect("activate", self.on_activate) | ||
|
||
def on_activate(self, app): | ||
window = Gtk.Window(application=app) | ||
self.dialog = Gtk.PrintUnixDialog.new("Print Document", window) | ||
self.dialog.connect("response", self.on_response) | ||
self.dialog.show() | ||
window.hide() | ||
|
||
def on_response(self, parent_widget, response_id): | ||
if response_id == Gtk.ResponseType.OK: | ||
print(f"OK") | ||
self.dialog.hide() | ||
settings = self.dialog.get_settings() | ||
printer = self.dialog.get_selected_printer() | ||
page_setup = self.dialog.get_page_setup() | ||
job = Gtk.PrintJob.new("print job", printer, settings, page_setup) | ||
job.set_source_file(self.file_to_print) | ||
job.send(self.on_job_complete, user_data=None) | ||
elif response_id == Gtk.ResponseType.APPLY: # Preview (if available) | ||
pass | ||
elif response_id == Gtk.ResponseType.CANCEL: | ||
# FIXME should this exist or should it simply cancel and not report errors | ||
raise ExportException(sdstatus=Status.ERROR_PRINT, sderror="User canceled dialog") | ||
|
||
def on_job_complete(self, print_job, user_data, error): | ||
if error: | ||
self.quit() | ||
raise ExportException(sdstatus=Status.ERROR_PRINT, sderror=error.message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters