-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtutorial.go
More file actions
233 lines (214 loc) · 7.58 KB
/
Copy pathtutorial.go
File metadata and controls
233 lines (214 loc) · 7.58 KB
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/*
* Copyright (c) 2013, 2014 Conformal Systems LLC <info@conformal.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
package main
import (
"github.com/conformal/gotk3/gtk"
)
// Using `` for string literals here is too messy, so concat "" strings.
const (
welcomeText = "<b>Welcome to btcgui alpha!</b>\n" +
"\n" +
"The following steps will prepare you to begin using " +
"btcgui.\n" +
"\n" +
"Click Next to open the next tip, or Close to skip the " +
"rest of the tutorial.\n"
disclaimerText = "<b>Disclaimer</b>\n" +
"\n" +
"btcgui is still alpha-level development software and is " +
"not yet ready to replace other Bitcoin wallet software.\n" +
"\n" +
"Running btcgui on the main Bitcoin network is currently " +
"disabled by default until the software has matured.\n" +
"\n" +
"btcgui is primarly written as a Unix GUI, and will be rough " +
"around the edges on other platforms. Development of native " +
"applications for other platforms is planned for the future."
connectText = "<b>Multiprocess Wallet Design</b>\n" +
"\n" +
"btcgui does not store your Bitcoin wallet or create and " +
"send transactions, but instead connects to another program, " +
"btcwallet, for wallet services. Due to this design, btcgui " +
"will not function if disconnected from btcwallet and almost " +
"all btcgui features will be disabled.\n" +
"\n" +
"If btcgui is not currently connected to btcwallet, a " +
"warning message will be displayed in the btcgui statusbar. " +
"If this happens, first check that btcwallet is running and " +
"not blocked behind a firewall. If a connection can still " +
"not be established, it's possible the wrong ports are being " +
"used."
createWalletText = "<b>Creating a Wallet</b>\n" +
"\n" +
"When first connecting a frontend such as btcgui to " +
"btcwallet, a dialog will open asking for a wallet " +
"passphrase. btcwallet does not support wallets with " +
"unencrypted private keys, and will not autogenerate wallets " +
"for this reason.\n" +
"\n" +
"To create this wallet, enter and repeat a passphrase in " +
"the passphrase dialog and press OK. btcwallet will create " +
"the encrypted wallet and begin notifying btcgui of changes " +
"to the wallet, such as new account balances."
receiveText = "<b>Receiving Funds</b>\n" +
"\n" +
"Bitcoins can be received by giving a payment address from " +
"your wallet to other Bitcoin users. Payment addresses can " +
"be managed under the \"Receive Coins\" tab. From this " +
"view, all addresses for your wallet can be viewed and " +
"copied to your clipboard. New addresses can also be " +
"generated if you do not wish to reuse an older address.\n" +
"\n" +
"If neither you nor anyone you know has testnet Bitcoins, " +
"an online Bitcoin testnet faucet can be used to receive " +
"testnet coins.\n" +
"\n" +
"Of the standard script types, btcwallet only supports " +
"receiving Pay to Pubkey Hash transactions. Receiving " +
"from transactions with other standard script types will " +
"be added in later versions."
sendText = "<b>Sending Funds</b>\n" +
"\n" +
"To send Bitcoins to others, open the \"Send Coins\" tab. " +
"Enter the payment addresses and Bitcoin amounts to send " +
"for one or more recipient (adding additional recipients as " +
"needed). A wallet must be unlocked before new " +
"transactions can be created.\n" +
"\n" +
"Currently, btcwallet only creates Pay to Pubkey Hash " +
"transactions. Generating other standard transactions " +
"will be added in later versions."
futureFeaturesText = "<b>Future Features</b>\n" +
"\n" +
"btcgui alpha is still under heavy development and is " +
"missing features needed for an everyday wallet " +
"application.\n" +
"\n" +
"Features like maintaining an address book for others' " +
"addresses and multiple account support are planned for " +
"future versions."
feedbackText = "<b>Feedback is appreciated!</b>\n" +
"\n" +
"Stop by Conformal's " +
"<a href=\"https://opensource.conformal.com/wiki/IRC_server\">IRC server</a> " +
"(channel #btcd) to let us know what you think!"
)
// dialogMessages holds the dialog messages successively shown in the
// tutorial dialog.
var dialogMessages = []string{
welcomeText,
disclaimerText,
connectText,
createWalletText,
receiveText,
sendText,
futureFeaturesText,
feedbackText,
}
// CreateTutorialDialog opens a tutorial dialog explaining usage for a
// first-time user. If appWindow is non-nil, it will be used as the
// parent window of the dialog. If nil, the tutorial dialog will open as
// a top-level window and a new application main window will be created
// and opened after the final tutorial message is shown.
func CreateTutorialDialog(appWindow *gtk.Window) (*gtk.Dialog, error) {
d, err := gtk.DialogNew()
if err != nil {
return nil, err
}
d.SetTitle("btcgui First Start Tutorial")
box, err := d.GetContentArea()
if err != nil {
return nil, err
}
grid, err := gtk.GridNew()
if err != nil {
return nil, err
}
grid.SetOrientation(gtk.ORIENTATION_VERTICAL)
box.Add(grid)
d.SetDefaultGeometry(500, 100)
if appWindow != nil {
d.SetTransientFor(appWindow)
d.SetPosition(gtk.WIN_POS_CENTER_ON_PARENT)
} else {
d.Connect("destroy", func() {
go StartMainApplication()
})
d.SetPosition(gtk.WIN_POS_CENTER)
}
// Add a notebook and tab for each dialog message.
nb, err := gtk.NotebookNew()
if err != nil {
return nil, err
}
// Because the labels added below will wrap and their final minimum
// heights and widths will be absurdly large, first give a size request
// and show the notebook (allocating space for the requested size).
// This will make text wrapping labels size nicely inside the notebook.
nb.SetSizeRequest(500, 100)
nb.Show()
// Create messages and append each in a notebook page.
for _, msg := range dialogMessages {
lbl, err := gtk.LabelNew("")
if err != nil {
return nil, err
}
lbl.SetMarkup(msg)
lbl.SetLineWrap(true)
lbl.Show()
lbl.SetAlignment(0, 0)
nb.AppendPage(lbl, nil)
}
nb.SetShowTabs(false)
grid.Add(nb)
prevPage, err := d.AddButton("_Previous", gtk.RESPONSE_NONE)
if err != nil {
return nil, err
}
prevPage.SetSensitive(false)
nextPage, err := d.AddButton("_Next", gtk.RESPONSE_NONE)
if err != nil {
return nil, err
}
prevPage.Connect("clicked", func() {
nb.PrevPage()
pagen := nb.GetCurrentPage()
if pagen == 0 {
prevPage.SetSensitive(false)
}
nextPage.SetSensitive(true)
})
nextPage.Connect("clicked", func() {
nb.NextPage()
pagen := nb.GetCurrentPage()
if pagen == len(dialogMessages)-1 {
nextPage.SetSensitive(false)
}
prevPage.SetSensitive(true)
})
_, err = d.AddButton("_Close", gtk.RESPONSE_CLOSE)
if err != nil {
return nil, err
}
d.Connect("response", func(_ *gtk.Dialog, rt gtk.ResponseType) {
if rt == gtk.RESPONSE_CLOSE {
// Using w.Close() would be nice but it needs GTK 3.10.
d.Hide()
d.Destroy()
}
})
return d, nil
}