printdialog

package
v0.3.19 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 42 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package printdialog is the shell's dev.stubbe.lys.Print1 host (lys-shell services/print and shell/print): the print dialog and spooler behind the portal backend's Print.

Index

Constants

View Source
const (
	ServiceName = "dev.stubbe.lys.Print1"
	ServicePath = dbus.ObjectPath("/dev/stubbe/lys/Print")
)

D-Bus identity (wayle-ipc print.rs).

Variables

This section is empty.

Functions

func SuggestedOutput

func SuggestedOutput(env xdg.Env, home, format string) (string, error)

SuggestedOutput is where Print to File proposes to write, GTK's default: output.<format> in env's documents directory, else the home directory. The error reports a user-dirs.dirs that cannot say where the documents directory is; the path is then the one in home.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client calls the shell's print host; Prepare waits on the user.

func NewClient

func NewClient(conn *dbus.Conn) *Client

NewClient addresses the host over conn.

func (*Client) Dismiss

func (c *Client) Dismiss(ctx context.Context, handle string) error

Dismiss takes down the dialog showing for the request at handle.

func (*Client) Prepare

func (c *Client) Prepare(ctx context.Context, caller portaldialogs.Caller, r PrepareRequest) (granted bool, settings []Setting, setup PageSetup, token uint32, err error)

Prepare shows the dialog.

func (*Client) Print

func (c *Client) Print(ctx context.Context, caller portaldialogs.Caller, title string, document dbus.UnixFD, token uint32) (sent bool, err error)

Print spools document, which stays the caller's to close.

type Daemon

type Daemon struct {
	// contains filtered or unexported fields
}

Daemon serves a Host as dev.stubbe.lys.Print1.

func NewDaemon

func NewDaemon(host Host) *Daemon

NewDaemon wraps the host for export.

func (*Daemon) Dismiss

func (d *Daemon) Dismiss(handle string) *dbus.Error

Dismiss takes down the dialog showing for the request at handle.

func (*Daemon) Export

func (d *Daemon) Export(conn *dbus.Conn) (func(), error)

Export serves the interface under its name; the returned release drops the name.

func (*Daemon) Prepare

Prepare shows the dialog.

func (*Daemon) Print

func (d *Daemon) Print(c portaldialogs.Caller, title string, document dbus.UnixFD, token uint32) (bool, *dbus.Error)

Print spools document.

type Deps

type Deps struct {
	// Config is the live config (the print animation).
	Config func() *config.Config
	// Open maps the dialog; Invoke runs on the UI loop; KeySym reads
	// its keys through the seat's keymap.
	Open   func(dialogsurface.Spec) (Window, error)
	Invoke func(func())
	KeySym keys.Translator
	// Font shapes the text; Sheet styles the surface, the labels'
	// and entries' ink included.
	Font  render.Font
	Sheet *widget.Stylesheet
	// CUPS is the scheduler the queues, their state and the jobs go
	// through (*ipp.Client).
	CUPS Scheduler
	// LPOptions is the user's lpoptions file, whose Default names the
	// printer they chose over the scheduler's; "" for none.
	LPOptions string
	// RefreshEvery is how often the selected printer's state is read
	// again while the dialog is open.
	RefreshEvery time.Duration
	// DNSSD browses the network for driverless printers while the
	// dialog is open; nil, or a nil client while the system bus is not
	// up, lists the CUPS queues alone. Device reads a network printer's
	// attributes at its own URI (ipp.DeviceAttributes).
	DNSSD  func() *dnssd.Client
	Device func(ctx context.Context, uri string) (ipp.Printer, error)
	// PickOutput lets the user choose the file Print to File writes
	// (the shell's file chooser), starting from suggested, and calls
	// chosen with its path on the loop; never on a cancel. It returns
	// at once.
	PickOutput func(suggested string, chosen func(path string))
	// PresetsFile keeps the form each app last confirmed for each
	// printer; "" keeps them in memory.
	PresetsFile string
	// Home is the home directory, for the suggested output file.
	Home string
	// User names the job's owner.
	User string
}

Deps are the dialog's collaborators.

type Dialog

type Dialog struct {
	// contains filtered or unexported fields
}

Dialog is the dev.stubbe.lys.Print1 host: one dialog showing one request; requests arriving meanwhile wait their turn, and dismissing a request cancels it, showing or waiting. Prepare and Print may be called from any goroutine; the UI runs on the loop.

func New

func New(d Deps) *Dialog

New builds the host; nothing maps until a request.

func (*Dialog) Dismiss

func (h *Dialog) Dismiss(handle string)

Dismiss cancels the request at handle: the dialog showing for it is taken down, a waiting one never shows. Another request's dialog stays.

func (*Dialog) Prepare

Prepare shows the printer picker and settings form for the request; a confirmed one is stashed under the returned token, a random one only the same app can print with, until it expires.

func (*Dialog) Print

func (h *Dialog) Print(c portaldialogs.Caller, title string, document *os.File, token uint32) bool

Print spools document to the printer the app prepared under token, once; token 0 shows the dialog first. A token another app prepared, or one expired, prints nothing. The dialog owns and closes the document.

type Host

type Host interface {
	// Prepare lets the user pick a printer and settings for the
	// request and stashes them under the returned token, for that app
	// alone; granted is false on a cancel or when the request is
	// dismissed.
	Prepare(portaldialogs.Caller, PrepareRequest) (granted bool, settings []Setting, setup PageSetup, token uint32)
	// Print spools document (a PDF the host takes ownership of) to the
	// printer the app prepared under token, or, without a token,
	// through the dialog first; it reports whether it was sent.
	Print(c portaldialogs.Caller, title string, document *os.File, token uint32) bool
	// Dismiss takes down the dialog showing for the request at handle.
	Dismiss(handle string)
}

Host shows the dialog and spools the jobs.

type PageSetup

type PageSetup struct {
	PPDName, Name, DisplayName                       string
	Width, Height                                    float64
	MarginTop, MarginBottom, MarginLeft, MarginRight float64
	Orientation                                      string
}

PageSetup is a GtkPageSetup: the paper's GTK and display names, its size and margins in millimetres, and the orientation; (sssddddddss), PPDName first.

type PrepareRequest

type PrepareRequest struct {
	Title                            string
	Settings                         []Setting
	PageSetup                        PageSetup
	AcceptLabel                      string
	HasCurrentPage, HasSelectedPages bool
	OutputFormats                    []string
}

PrepareRequest is what an app asks a print dialog with, (sa(ss) (sssddddddss)sbbas): the job title, its current settings and page setup to start from, the confirm button's label ("" for Print), whether it can print just its current page or a selection, and the formats it can write for Print to File (none means pdf).

type Scheduler added in v0.3.15

type Scheduler interface {
	Printers(ctx context.Context) ([]ipp.Printer, error)
	Default(ctx context.Context) (string, error)
	Printer(ctx context.Context, name string) (ipp.Printer, error)
	Print(ctx context.Context, j ipp.Job) (int32, error)
	CreateLocalPrinter(ctx context.Context, deviceURI, name string) (string, error)
}

Scheduler is what the dialog asks CUPS: the queues, the default destination, one queue's state, and a job to spool.

type Setting

type Setting struct{ Key, Value string }

Setting is one flat print-setting key/value pair.

type Window

type Window interface{ Close() }

Window is the overlay surface the dialog maps (app.LayerWindow).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL