dialogbind 0.9.2 → 0.9.3

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dialogbind.rb +116 -13
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9ed51e7dcb44cdf7a12cf95ae59c426ca4230375d26a6dc8d5cd59a0981ad43a
4
- data.tar.gz: 0eddf7c630417b1ec4196bedc7adf936e1f94e3a010a39bd1a86f76833a62d27
3
+ metadata.gz: 0cc13b581cce68d335c1cf660187dea9c6a9d3d3429e1d3737bab775787f0834
4
+ data.tar.gz: 33dfce0084709de26c7b3213bf5a97a8db19c07dc285cf3848d928d604236ef7
5
5
  SHA512:
6
- metadata.gz: 9d9cbc6cf6112ae17e409587aa5f86ea119f9fa334478d6fa2edeb112c66ddb1d715c3c4400793d00e5faf509084b4f2d84d07bbfb8b87b62f8203324c35e881
7
- data.tar.gz: 545bfe457b2abc9cada9f68ddcbce8b57d5702de6eeb2a1ce135f55fa7cbae8e5438d3c699917a31db0411a3f7fc6493d1d1b9e27ac6a867e7b0f61f578dc0a8
6
+ metadata.gz: 53bf0c4557f64fb2f534c17f753ba8e44bbd7855082e099861bae3711013352eabfb2796838cb36bd608f372aadb81d44cc5456f602044dcad51120593de0e33
7
+ data.tar.gz: b8d45642cfa13ea453d1ed27b86998df97a5ed8e15bc57fcd0ba97ef3cac03255ac8702c2d928730429c0454251629cd598f0ab91a27bf836f747be512b0d242
data/lib/dialogbind.rb CHANGED
@@ -8,7 +8,7 @@
8
8
  require 'fiddle/import'
9
9
 
10
10
  $dialogbind_macos_script_cmd = ''
11
- $dialogbind_version = '0.9.2'
11
+ $dialogbind_version = '0.9.3'
12
12
 
13
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.
14
14
  def zenity(arg)
@@ -34,22 +34,37 @@ def zenity(arg)
34
34
  end
35
35
 
36
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
37
+ module Win32NativeBindings
38
38
  # based on https://gist.github.com/Youka/3ebbdfd03454afa7d0c4
39
- extend Fiddle::Importer
39
+ if $dialogbind_dialog_backend == 'win32' then
40
+ extend Fiddle::Importer
40
41
 
41
- dlload 'user32'
42
- typealias 'HANDLE', 'void*'
43
- typealias 'HWND', 'HANDLE'
44
- typealias 'LPCSTR', 'const char*'
45
- typealias 'UINT', 'unsigned int'
42
+ dlload 'user32'
43
+ dlload 'winmm'
44
+ typealias 'HANDLE', 'void*'
45
+ typealias 'HWND', 'HANDLE'
46
+ typealias 'LPCSTR', 'const char*'
47
+ typealias 'UINT', 'unsigned int'
48
+ typealias 'BOOL', 'int'
49
+ typealias 'HMODULE', 'void*'
50
+ typealias 'DWORD', 'unsigned long'
46
51
 
47
- extern 'int MessageBoxA(HWND, LPCSTR, LPCSTR, UINT)'
52
+ extern 'int MessageBox(HWND, LPCSTR, LPCSTR, UINT)'
53
+ extern 'BOOL PlaySound(LPCTSTR, HMODULE, DWORD)'
54
+ else
55
+ def MessageBox(arg1, arg2, arg3, arg4)
56
+ return
57
+ end
58
+
59
+ def PlaySound(arg1, arg2, arg3)
60
+ return 1
61
+ end
62
+ end
48
63
  end
49
64
 
50
65
  # 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
66
  def win32_msgbox(text, title='DialogBind', buttons=0)
52
- return Win32NativeMessageBox::MessageBoxA(nil, text, title, buttons)
67
+ return Win32NativeBindings::MessageBox(nil, text, title, buttons)
53
68
  end
54
69
 
55
70
  # 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.
@@ -152,7 +167,7 @@ def guiyesno(text, title='DialogBind')
152
167
  return true
153
168
  end
154
169
  elsif $dialogbind_dialog_backend == 'win32' then
155
- retv_msgbox = win32_msgbox(text, title, 4)
170
+ retv_msgbox = win32_msgbox(text, title, 36)
156
171
  return (retv_msgbox == 6)
157
172
  else
158
173
  raise 'The selected backend does not support question message boxes.'
@@ -173,7 +188,7 @@ def guierror(text, title='DialogBind')
173
188
  elsif $dialogbind_dialog_backend == 'macos' then
174
189
  return macdialog(text, [ 'OK' ], 'dialog', true)
175
190
  elsif $dialogbind_dialog_backend == 'win32' then
176
- return win32_msgbox('Error. ' + text, title, 0)
191
+ return win32_msgbox(text, title, 16)
177
192
  else
178
193
  raise 'The selected backend does not support question message boxes.'
179
194
  end
@@ -219,7 +234,7 @@ def guilicense(file, title='DialogBind')
219
234
  system('open -e "' + file.gsub('"', "\\\"") + '"')
220
235
  return guiyesno('Do you accept the terms of the license agreement?', title)
221
236
  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)
237
+ retv_msgbox = win32_msgbox("Do you accept the terms of the license agreement below?\n\n" + File.read(file), title, 36)
223
238
  return (retv_msgbox == 6)
224
239
  else
225
240
  raise 'The selected backend does not support license message boxes.'
@@ -278,3 +293,91 @@ def guiselect(entries, text='Choose one of the items below:', title='DialogBind'
278
293
  end
279
294
  return nil
280
295
  end
296
+
297
+ # DialogBindSystemSounds is a module providing default DialogBind sound IDs to functions like guisound.
298
+ module DialogBindSystemSounds
299
+ None = 0
300
+ Success = 1
301
+ Error = 2
302
+ Attention = 3
303
+ end
304
+
305
+ def nativesoundplay(sound_path)
306
+ unix_cmd_optimized_path = sound_path.gsub('"', "\\\"")
307
+ if $dialogbind_dialog_backend == 'win32' then
308
+ Win32NativeBindings::PlaySound(sound_path, nil, SND_SYNC)
309
+ elsif $dialogbind_dialog_backend == 'macos' then
310
+ system('afplay "' + unix_cmd_optimized_path + '" > /dev/null 2>&1')
311
+ else
312
+ if system('command -v play > /dev/null 2>&1') then
313
+ system('play "' + unix_cmd_optimized_path + '" > /dev/null 2>&1')
314
+ elsif system('command -v paplay > /dev/null 2>&1') then
315
+ system('paplay "' + unix_cmd_optimized_path + '" > /dev/null 2>&1')
316
+ elsif system('command -v canberra-gtk-play > /dev/null 2>&1') then
317
+ system('canberra-gtk-play -f "' + unix_cmd_optimized_path + '" > /dev/null 2>&1')
318
+ elsif system('command -v mpv > /dev/null 2>&1') then
319
+ system('mpv "' + unix_cmd_optimized_path + '" > /dev/null 2>&1')
320
+ elsif system('command -v mplayer > /dev/null 2>&1') then
321
+ system('mplayer "' + unix_cmd_optimized_path + '" > /dev/null 2>&1')
322
+ else
323
+ system('xdg-open "' + unix_cmd_optimized_path + '"')
324
+ end
325
+ end
326
+ end
327
+
328
+ def linuxsound(sound_v)
329
+ sound_theme = '/usr/share/sounds/freedesktop/stereo'
330
+ sound_theme_success = sound_theme + '/complete.oga'
331
+ sound_theme_error = sound_theme + '/dialog-error.oga'
332
+ sound_theme_attention = sound_theme + '/window-attention.oga'
333
+ if File.directory?(sound_theme) == false then
334
+ return
335
+ end
336
+ if sound_v == DialogBindSystemSounds::Success then
337
+ nativesoundplay(sound_theme_success)
338
+ elsif sound_v == DialogBindSystemSounds::Error then
339
+ nativesoundplay(sound_theme_error)
340
+ else
341
+ nativesoundplay(sound_theme_attention)
342
+ end
343
+ end
344
+
345
+ # Plays the default system sounds.
346
+ #
347
+ # @param sound_v [DialogBindSystemSounds] the sound to play. Available values are DialogBindSystemSounds::Success,
348
+ # DialogBindSystemSounds::Error and DialogBindSystemSounds::Attention. Specifying DialogBindSystemSounds::None will
349
+ # do nothing.
350
+ # @return [Object] nothing
351
+ def guisound(sound_v)
352
+ if sound_v == DialogBindSystemSounds::None then
353
+ return
354
+ end
355
+ if $dialogbind_dialog_backend != 'macos' && $dialogbind_dialog_backend != 'win32' then
356
+ linuxsound(sound_v)
357
+ return
358
+ end
359
+ constant_sound_success = '/System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds/system/burn complete.aif'
360
+ constant_sound_error = '/System/Library/Sounds/Funk.aiff'
361
+ constant_sound_attention = '/System/Library/PrivateFrameworks/FindMyDevic.framework/Versions/A/Resources/fmd_sound.aiff'
362
+ if File.exists?(constant_sound_attention) == false then
363
+ constant_sound_attention = constant_sound_success
364
+ end
365
+ if File.exists?(constant_sound_success) == false then
366
+ constant_sound_success = constant_sound_error
367
+ end
368
+ if $dialogbind_dialog_backend == 'win32' then
369
+ constant_sound_success = 'c:/Windows/Media/tada.wav'
370
+ constant_sound_error = 'c:/Windows/Media/Windows Error.wav'
371
+ if File.exists?(constant_sound_error) == false then
372
+ constant_sound_error = 'c:/Windows/Media/chord.wav'
373
+ end
374
+ constant_sound_attention = 'c:/Windows/Media/chimes.wav'
375
+ end
376
+ if sound_v == DialogBindSystemSounds::Success then
377
+ nativesoundplay(constant_sound_success)
378
+ elsif sound_v == DialogBindSystemSounds::Error then
379
+ nativesoundplay(constant_sound_error)
380
+ else
381
+ nativesoundplay(constant_sound_attention)
382
+ end
383
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dialogbind
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim K
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-21 00:00:00.000000000 Z
11
+ date: 2019-07-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -42,5 +42,5 @@ signing_key:
42
42
  specification_version: 4
43
43
  summary: DialogBind provides a Ruby API that wraps around Linux and macOS message
44
44
  box-generating tools. As of version 0.9.2, Windows is also supported. See https://gitlab.com/timkoi/dialogbind/blob/master/README.md
45
- for documentation.
45
+ for documentation. Updates for this library are released frequently.
46
46
  test_files: []