-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprint_codes.spr
122 lines (93 loc) · 3.55 KB
/
print_codes.spr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# Print-codes
#
# Application to input, generate and print a number of bar or QR codes.
# value -> code_string -> code -> filename ->
# Do command on filename count times.
# Our workspace. Initialize will copy into place.
# clear will reset it.
# Set 'code-with' to be bq/with-bc or bq/with-qr to
# automatically create the right type. Barcode or
# QR code respectively.
#
# input-count provides a new prompt so pushing that
# on the with stack gives the final with-space for
# the shell loop to happen.
# setup the data.
with /config
'
print-codes:
workspace:
# do barcodes by default
code-with: bq/with-bc
# They have a serial number, so make it more personal
input_please: "Please enter a serial number to encode."
# another place so we can have another prompt to get count.
input-count:
input_please: "How many copies would you like to print?"
count: 1
# parameters that get used as we go along. Just so it's doc'd.
value: null
code_string: null
code: null
filename: null
command: null
help:
print-codes-help:
Print-Codes
A set of functions to give a dialog process for
a number to encode as either a barcode or QRcode, Prompting
based on platform for the print command to print the resulting
code file any number of times.
Setting 'command' and filename would allow for skipping the
printer choice dialog. Use ui/format-filename-command to combine them.
The value of code-with should be function to evaluate which will setup the
proper with data structure defining the options required by the
bq module. bq/with-bc and bq/with-qr are provided by barqr.
The code-with to determine the code type can also be
set with bq/code-type-menu, which should return a
function to set the with stack for the code type.
Initialize should be placed in the startup hooks so that it
only runs once if it is used with a repeating process.
The with stack is setup so that ui/get-filename-command will
find ~/platform in /config/print_commands
The print-codes function will Print a bar or QR code a given
number of times. This Expects values in the with stack to be set
appropriately, as in using bq/with-qr or bq/with-bc to set the
values for code generation and saving. The value of code-with is
used by Initialize to ensure this.
The following steps are taken.
* Prompt for a serial number
* Encode the serial number as barcode or qrcode.
* Save the code as a file.
* Prompt for a printer command.
* Format the command using ~filename as the format argument.
* Prompt for number of times to print.
* Loop count times to execute the print command.
# get out of /config/print-codes
pop-with
# End of Data
# Give ourselves a namespace
new-ns pc "Print Bar and QR codes" Print-Codes
def help "Help for print-codes."
show /config/help/print-codes-help
def clear
"Initialize the print-codes work space to that of config."
set . `~/config/print-codes/workspace
def initialize
"Initialize the print-codes workspace, setup the with stack.
evaluate code-with to set the code type."
'
- ui/with-ui
- with /print-codes
- pc/clear
# - bq/code-type-menu
- eval .code-with
- with /print-codes
def print-codes
"Present dialogs to input a serial number, encode it as a bar or QR code,
save it as a file, then print it some number of times."
'
- bq/get-gen-save-code
- ui/get-print-command
- ui/get-count-loop-command
- pc/clear