dialogbind 0.9.1 → 0.9.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/dialogbind.rb +78 -2
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 381f74289047af6aa93e6a28daeb6a1da99102c39dd098b3d6c384bf94dbc520
|
|
4
|
+
data.tar.gz: a006ae717ed3253bb8fb623550ef691c1bfb69af5c9c877249a0466e5b816a51
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '089eacd34517bcead4fc0716cb074849f49219a5f0d475a1a06d1b28eb2f1abbfd42d24a7429c675b7b7be821c083403fab66ca71646f3f3e09067abdbe5301b'
|
|
7
|
+
data.tar.gz: f30f98c3d6b179526d85aa4d9a30f93c4fc0932c793565b94c9863e174e044a2ffb9ad405ff42a04b0ee517255896095d955e301f59c16c75a2beaf68e4afe75
|
data/lib/dialogbind.rb
CHANGED
|
@@ -5,9 +5,12 @@
|
|
|
5
5
|
# Copyright (C) Tim K 2018-2019 <timprogrammer@rambler.ru>.
|
|
6
6
|
# Licensed under MIT License.
|
|
7
7
|
|
|
8
|
+
require 'fiddle/import'
|
|
9
|
+
|
|
8
10
|
$dialogbind_macos_script_cmd = ''
|
|
9
|
-
$dialogbind_version = '0.9.1'
|
|
11
|
+
$dialogbind_version = '0.9.1.1'
|
|
10
12
|
|
|
13
|
+
# Function used internally in DialogBind to run Zenity from Ruby code. Please do not use this function directly as its API and behaviour might change in any release.
|
|
11
14
|
def zenity(arg)
|
|
12
15
|
args_total = ''
|
|
13
16
|
arg.keys.each do |key|
|
|
@@ -30,6 +33,26 @@ def zenity(arg)
|
|
|
30
33
|
return system('zenity ' + args_total)
|
|
31
34
|
end
|
|
32
35
|
|
|
36
|
+
# Internal module binding Win32 API MessageBox to Ruby. While it can be used directly, it is not recommended to do so to maintain your app's portability.
|
|
37
|
+
module Win32NativeMessageBox
|
|
38
|
+
# based on https://gist.github.com/Youka/3ebbdfd03454afa7d0c4
|
|
39
|
+
extend Fiddle::Importer
|
|
40
|
+
|
|
41
|
+
dlload 'user32'
|
|
42
|
+
typealias 'HANDLE', 'void*'
|
|
43
|
+
typealias 'HWND', 'HANDLE'
|
|
44
|
+
typealias 'LPCSTR', 'const char*'
|
|
45
|
+
typealias 'UINT', 'unsigned int'
|
|
46
|
+
|
|
47
|
+
extern 'int MessageBoxA(HWND, LPCSTR, LPCSTR, UINT)'
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Function used internally in DialogBind to run Win32 MessageBoxA from Ruby code. Please do not use this function directly as its API and behaviour might change in any release.
|
|
51
|
+
def win32_msgbox(text, title='DialogBind', buttons=0)
|
|
52
|
+
return Win32NativeMessageBox::MessageBoxA(nil, text, title, buttons)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Function used internally in DialogBind to run XMessage from Ruby code. Please do not use this function directly as its API and behaviour might change in any release.
|
|
33
56
|
def xmessage(arg, buttons={ 'OK' => 0 }, file=false)
|
|
34
57
|
build_cmd = 'xmessage -center -buttons "'
|
|
35
58
|
first = true
|
|
@@ -49,6 +72,7 @@ def xmessage(arg, buttons={ 'OK' => 0 }, file=false)
|
|
|
49
72
|
return system(build_cmd)
|
|
50
73
|
end
|
|
51
74
|
|
|
75
|
+
# Function used internally in DialogBind to run AppleScript ``display dialog`` from Ruby code. Please do not use this function directly as its API and behaviour might change in any release.
|
|
52
76
|
def macdialog(text, buttons=['OK'], type='dialog', error=false, dryrun=false)
|
|
53
77
|
text_fixed = text.gsub("!", "").gsub("'", '').gsub('"', '').gsub('$', '')
|
|
54
78
|
cmd = "osascript -e 'tell app \"System Events\" to display " + type + ' "' + text_fixed + '"'
|
|
@@ -68,11 +92,13 @@ def macdialog(text, buttons=['OK'], type='dialog', error=false, dryrun=false)
|
|
|
68
92
|
return false
|
|
69
93
|
end
|
|
70
94
|
|
|
71
|
-
$dialogbind_available_backends = [ 'xmessage', 'zenity', 'macos' ]
|
|
95
|
+
$dialogbind_available_backends = [ 'xmessage', 'zenity', 'macos', 'win32' ]
|
|
72
96
|
$dialogbind_dialog_backend = 'xmessage'
|
|
73
97
|
|
|
74
98
|
if system('command -v zenity > /dev/null 2>&1') then
|
|
75
99
|
$dialogbind_dialog_backend = 'zenity'
|
|
100
|
+
elsif ENV.keys.include?('OS') && ENV['OS'] == 'Windows_NT' then
|
|
101
|
+
$dialogbind_dialog_backend = 'win32'
|
|
76
102
|
elsif `uname`.gsub("\n", "") == 'Darwin' then
|
|
77
103
|
$dialogbind_dialog_backend = 'macos'
|
|
78
104
|
end
|
|
@@ -84,6 +110,11 @@ if $dialogbind_available_backends.include?($dialogbind_dialog_backend) == false
|
|
|
84
110
|
raise 'Dialog backend "' + $dialogbind_dialog_backend + '" is not available. Available frontends: ' + $dialogbind_available_backends.join(', ')
|
|
85
111
|
end
|
|
86
112
|
|
|
113
|
+
# Shows a simple message box (or information message box when using Zenity backend).
|
|
114
|
+
#
|
|
115
|
+
# @param text [String] the text that should be displayed in a message box
|
|
116
|
+
# @param title [String] an optional parameter specifying the title of the message box. Ignored on macOS.
|
|
117
|
+
# @return [Boolean] true on success, false if something went wrong
|
|
87
118
|
def guiputs(text, title='DialogBind')
|
|
88
119
|
if $dialogbind_dialog_backend == 'xmessage' then
|
|
89
120
|
return xmessage(text, { 'OK' => 0 })
|
|
@@ -91,6 +122,9 @@ def guiputs(text, title='DialogBind')
|
|
|
91
122
|
return zenity({ 'info' => nil, 'title' => title, 'text' => text })
|
|
92
123
|
elsif $dialogbind_dialog_backend == 'macos' then
|
|
93
124
|
return macdialog(text)
|
|
125
|
+
elsif $dialogbind_dialog_backend == 'win32' then
|
|
126
|
+
win32_msgbox(text, title, 0)
|
|
127
|
+
return true
|
|
94
128
|
else
|
|
95
129
|
puts title + ': ' + text
|
|
96
130
|
return true
|
|
@@ -98,6 +132,11 @@ def guiputs(text, title='DialogBind')
|
|
|
98
132
|
return false
|
|
99
133
|
end
|
|
100
134
|
|
|
135
|
+
# Shows a question message box with "Yes" and "No" buttons.
|
|
136
|
+
#
|
|
137
|
+
# @param text [String] the text that should be displayed in a message box
|
|
138
|
+
# @param title [String] an optional parameter specifying the title of the message box. Ignored on macOS.
|
|
139
|
+
# @return [Boolean] true if the user presses yes, false if the user pressed no
|
|
101
140
|
def guiyesno(text, title='DialogBind')
|
|
102
141
|
if $dialogbind_dialog_backend == 'xmessage' then
|
|
103
142
|
return xmessage(text, { 'Yes' => 0, 'No' => 1})
|
|
@@ -112,12 +151,20 @@ def guiyesno(text, title='DialogBind')
|
|
|
112
151
|
if output.split(':')[1].downcase == 'yes' then
|
|
113
152
|
return true
|
|
114
153
|
end
|
|
154
|
+
elsif $dialogbind_dialog_backend == 'win32' then
|
|
155
|
+
retv_msgbox = win32_msgbox(text, title, 4)
|
|
156
|
+
return (retv_msgbox == 6)
|
|
115
157
|
else
|
|
116
158
|
raise 'The selected backend does not support question message boxes.'
|
|
117
159
|
end
|
|
118
160
|
return false
|
|
119
161
|
end
|
|
120
162
|
|
|
163
|
+
# Shows an error message box with only single OK button.
|
|
164
|
+
#
|
|
165
|
+
# @param text [String] the text that should be displayed in a message box
|
|
166
|
+
# @param title [String] an optional parameter specifying the title of the message box. Ignored on macOS.
|
|
167
|
+
# @return [Boolean] true on success, false if something went wrong
|
|
121
168
|
def guierror(text, title='DialogBind')
|
|
122
169
|
if $dialogbind_dialog_backend == 'xmessage' then
|
|
123
170
|
return xmessage('ERROR. ' + text, { 'OK' => 0 })
|
|
@@ -125,12 +172,20 @@ def guierror(text, title='DialogBind')
|
|
|
125
172
|
return zenity('error' => nil, 'title' => title, 'text' => text)
|
|
126
173
|
elsif $dialogbind_dialog_backend == 'macos' then
|
|
127
174
|
return macdialog(text, [ 'OK' ], 'dialog', true)
|
|
175
|
+
elsif $dialogbind_dialog_backend == 'win32' then
|
|
176
|
+
return win32_msgbox('Error. ' + text, title, 0)
|
|
128
177
|
else
|
|
129
178
|
raise 'The selected backend does not support question message boxes.'
|
|
130
179
|
end
|
|
131
180
|
return false
|
|
132
181
|
end
|
|
133
182
|
|
|
183
|
+
# Shows either a buttonless message box with the specified text or a progress message box with the specified text. Does not work on Windows.
|
|
184
|
+
# This function is not async, just like all other functions, so you should actually start it in a seperate thread.
|
|
185
|
+
#
|
|
186
|
+
# @param text [String] the text that should be displayed in a message box
|
|
187
|
+
# @param title [String] an optional parameter specifying the title of the message box. Ignored on macOS.
|
|
188
|
+
# @return [Boolean] true on success, false if something went wrong
|
|
134
189
|
def guiprogress(text='Please wait...', title='DialogBind')
|
|
135
190
|
if $dialogbind_dialog_backend == 'xmessage' then
|
|
136
191
|
return xmessage(text, { })
|
|
@@ -145,6 +200,11 @@ def guiprogress(text='Please wait...', title='DialogBind')
|
|
|
145
200
|
return false
|
|
146
201
|
end
|
|
147
202
|
|
|
203
|
+
# Shows a message box containing the license agreement that is stored in the specified file.
|
|
204
|
+
#
|
|
205
|
+
# @param file [String] the file that contains the licensing terms
|
|
206
|
+
# @param title [String] an optional parameter specifying the title of the message box. Ignored on macOS.
|
|
207
|
+
# @return [Boolean] true if the user accepts the terms of the license agreement or false if not
|
|
148
208
|
def guilicense(file, title='DialogBind')
|
|
149
209
|
if File.exists?(file) == false then
|
|
150
210
|
guierror('File "' + file + '" does not exist.', title)
|
|
@@ -154,6 +214,13 @@ def guilicense(file, title='DialogBind')
|
|
|
154
214
|
return xmessage(file, { 'Accept' => 0, 'Decline' => 1 }, true)
|
|
155
215
|
elsif $dialogbind_dialog_backend == 'zenity' then
|
|
156
216
|
return zenity({ 'text-info' => nil, 'title' => title, 'filename' => file, 'checkbox' => 'I have read and accepted the terms of the license agreement.' })
|
|
217
|
+
elsif $dialogbind_dialog_backend == 'macos' then
|
|
218
|
+
macdialog('Right now, the license agreement will be shown in TextEdit. Close TextEdit using Command-Q to continue,', ['OK'])
|
|
219
|
+
system('open -e "' + file.gsub('"', "\\\"") + '"')
|
|
220
|
+
return guiyesno('Do you accept the terms of the license agreement?', title)
|
|
221
|
+
elsif $dialogbind_dialog_backend == 'win32' then
|
|
222
|
+
retv_msgbox = win32_msgbox("Do you accept the terms of the license agreement below?\n\n" + File.read(file), title, 4)
|
|
223
|
+
return (retv_msgbox == 6)
|
|
157
224
|
else
|
|
158
225
|
raise 'The selected backend does not support license message boxes.'
|
|
159
226
|
return false
|
|
@@ -171,6 +238,12 @@ def entry2buttonshash(entries)
|
|
|
171
238
|
return hash
|
|
172
239
|
end
|
|
173
240
|
|
|
241
|
+
# Shows either a message box with buttons matching the items specified in the array ``entries`` or a list message box.
|
|
242
|
+
#
|
|
243
|
+
# @param entries [Array] an array of strings that should be displayed as list in a message box. More than two items are currently not supported.
|
|
244
|
+
# @param text [String] the text that should be displayed in a message box
|
|
245
|
+
# @param title [String] an optional parameter specifying the title of the message box. Ignored on macOS.
|
|
246
|
+
# @return [String] the selected string or nil on cancel
|
|
174
247
|
def guiselect(entries, text='Choose one of the items below:', title='DialogBind')
|
|
175
248
|
if entries.length > 2 then
|
|
176
249
|
raise 'More than 2 entries for guiselect are not supported by xmessage.'
|
|
@@ -199,6 +272,9 @@ def guiselect(entries, text='Choose one of the items below:', title='DialogBind'
|
|
|
199
272
|
return nil
|
|
200
273
|
end
|
|
201
274
|
return output.split(':')[1]
|
|
275
|
+
else
|
|
276
|
+
raise 'The selected backend does not support license message boxes.'
|
|
277
|
+
return false
|
|
202
278
|
end
|
|
203
279
|
return nil
|
|
204
280
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dialogbind
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.9.1
|
|
4
|
+
version: 0.9.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tim K
|
|
@@ -41,5 +41,6 @@ rubygems_version: 3.0.4
|
|
|
41
41
|
signing_key:
|
|
42
42
|
specification_version: 4
|
|
43
43
|
summary: DialogBind provides a Ruby API that wraps around Linux and macOS message
|
|
44
|
-
box-generating tools.
|
|
44
|
+
box-generating tools. As of version 0.9.2, Windows is also (partially) supported.
|
|
45
|
+
See https://gitlab.com/timkoi/dialogbind/blob/master/README.md for documentation.
|
|
45
46
|
test_files: []
|