Skip to content

Commit 3697547

Browse files
committed
Fix orientation for double-sided printing
1 parent 012598e commit 3697547

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

slip39/gui/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -595,12 +595,12 @@ def update_seed_data( event, window, values ):
595595
# We're recovering the BIP-39 Seed Phrase *Entropy*, NOT the derived (decrypted) 512-bit
596596
# Seed Data! So, we don't deal in Passphrases, here. The Passphrase (to encrypt the Seed,
597597
# when "Using BIP-39") is only required to display the correct wallet addresses.
598-
window['-SD-DATA-F-'].update( "BIP-39 Mnemonic to Back Up: " )
598+
window['-SD-DATA-F-'].update( "BIP-39 Mnemonic to Recover or Back Up: " )
599599
window['-SD-DATA-F-'].update( visible=True )
600600
window['-SD-PASS-C-'].update( visible=False )
601601
window['-SD-PASS-F-'].update( visible=False )
602602
elif 'SLIP' in update_seed_data.src:
603-
window['-SD-DATA-F-'].update( "SLIP-39 Mnemonics to Back Up: " )
603+
window['-SD-DATA-F-'].update( "SLIP-39 Mnemonics to Recover or Back Up: " )
604604
window['-SD-DATA-F-'].update( visible=True )
605605
window['-SD-PASS-C-'].update( visible=True )
606606
window['-SD-PASS-F-'].update(
@@ -1532,7 +1532,7 @@ def deficiency( *deficiencies ):
15321532
continue
15331533
name_len = max( len( name ) for name in details )
15341534
status = '\n'.join(
1535-
f"Saved {name}"
1535+
f"{'Print' if printer else 'Saved'}: {name}"
15361536
for name in details
15371537
)
15381538
# Finally, success has been assured; turn off emboldened status line

slip39/layout/pdf.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ def produce_pdf(
235235

236236
# Find the best PDF and orientation, by max of returned cards_pp (cards per page). Assumes
237237
# layout_pdf returns a tuple that can be compared; cards_pp,orientation,... will always sort.
238+
# This card orientation defines the overall orientation of the entire PDF; we'll rotate other
239+
# elements (cover, paper wallets) to match.
238240
page_margin_mm = PAGE_MARGIN * MM_IN
239241
cards_pp,orientation,page_xy,pdf,_ = max(
240242
layout_pdf( card_dim, page_margin_mm, orientation=orientation, paper_format=paper_format )
@@ -335,6 +337,8 @@ def produce_pdf(
335337
cover_sent += "\n".join( slip39_group )
336338
tpl_cover['cover-sent'] = cover_sent
337339

340+
# Add the cover page(s), rotated to match the orientation deduced for the cards. Thus, the
341+
# whole PDF will be printable with the deduced card page orientation.
338342
pdf.add_page()
339343
if orientation.lower().startswith( 'p' ):
340344
tpl_cover.render( offsetx=pdf.epw, rotate=-90.0 )
@@ -520,7 +524,9 @@ def write_pdfs(
520524

521525
# Unless no card_format (False) or paper wallet password specified, produce a PDF containing
522526
# the SLIP-39 mnemonic recovery cards; remember the deduced (<pdf_paper>,<pdf_orient>). If
523-
# we're producing paper wallets, always force portrait orientation for the cards, to match.
527+
# we're producing paper wallets, always force portrait orientation for the cards, to match
528+
# the layout of the paper wallets, so that all page orientations will match; this may result
529+
# in a sub-optimal card layout, but mixing orientations in a PDF confuses some printers.
524530
if card_format is not False or wallet_pwd is not None:
525531
(pdf_paper,pdf_orient),pdf,_ = produce_pdf(
526532
*details,
@@ -547,7 +553,8 @@ def write_pdfs(
547553

548554
if wallet_pwd is not None:
549555
# Deduce the paper wallet size and create a template. All layouts are in specified in
550-
# inches; template dimensions are in mm.
556+
# inches; template dimensions are in mm. Paper wallets are always formatted for
557+
# portrait orientation; we've forced that, above, if paper wallets are desired.
551558
try:
552559
(wall_h,wall_w),wall_margin = WALLET_SIZES[wallet_format.lower() if wallet_format else WALLET]
553560
except KeyError:
@@ -557,8 +564,8 @@ def write_pdfs(
557564
wall_dim = wall.mm()
558565

559566
# Lay out wallets, always in Portrait orientation, defaulting to the Card paper_format
560-
# if it is a standard size (a str, not an (x,y) tuple), otherwise to "Letter" paper. Printers may
561-
# have problems with a PDF mixing Landscape and Portrait, but do it if desired...
567+
# if it is a standard size (a str, not an (x,y) tuple), otherwise to "Letter" paper.
568+
# Rotate the wallets to match the card's orientation (like the cover page).
562569
if wallet_paper is None:
563570
wallet_paper = paper_format if type(paper_format) is str else PAPER
564571

slip39/layout/printer.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,15 @@ def printer_output(
9696
"""
9797
double_sided = True if double_sided is None else bool( double_sided )
9898
if sys.platform == 'darwin':
99-
command = [ '/usr/bin/lpr', '-o', 'sides=one-sided' ]
99+
command = [ '/usr/bin/lpr' ]
100100
command_input = binary
101101

102102
# Find the desired printer's system name; otherwise use default printer
103103
printer_system = None
104104
if printer:
105105
printer_list = list( printers_available() )
106106
for system,human in printer_list:
107-
if human.lower() == printer.lower() or system.lower() == printer.lower():
107+
if ( human and human.lower() == printer.lower() ) or ( system and system.lower() == printer.lower()):
108108
printer_system = system
109109
assert printer_system, \
110110
f"Couldn't locate printer matching {printer!r}, in {', '.join( h for s,h in printer_list )}"
@@ -114,11 +114,18 @@ def printer_output(
114114
command += [ '-o', f"media={paper_format.capitalize()}" ]
115115
if orientation:
116116
# -o orientation-requested=N Specify portrait (3) or landscape (4) orientation
117-
N = { 'p': 3, 'l': 4 }[orientation.lower()[0]]
117+
N = { 'p': 3, 'l': 4 }[orientation.lower()[0]]
118118
command += [ '-o', f"orientation-requested={N}" ]
119119
if double_sided:
120-
# Regardless of desired orientation, layout assumes long-edge double-sided
121-
command += [ '-o', "sides=two-sided-long-edge" ]
120+
# The layout of the *cards* is what determines the "edge" upon which the double-sided
121+
# page is intended to flip. Unless correct, the right QR code won't be on the back!
122+
# Default to long-edge, unless explicitly oriented landscape.
123+
if orientation and orientation.lower().startswith( 'l' ):
124+
command += [ '-o', "sides=two-sided-short-edge" ]
125+
else:
126+
command += [ '-o', "sides=two-sided-long-edge" ]
127+
else:
128+
command += [ '-o', 'sides=one-sided' ]
122129

123130
log.info( f"Printing via: {' '.join( command )}" )
124131
subproc = subprocess.run(

slip39/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__version_info__ = ( 13, 0, 1 )
1+
__version_info__ = ( 13, 0, 2 )
22
__version__ = '.'.join( map( str, __version_info__ ))

0 commit comments

Comments
 (0)