glimmer-dsl-libui 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +275 -19
- data/VERSION +1 -1
- data/examples/midi_player.rb +90 -0
- data/glimmer-dsl-libui.gemspec +0 -0
- data/lib/glimmer/dsl/libui/control_expression.rb +1 -3
- data/lib/glimmer/libui/combobox_proxy.rb +42 -0
- data/lib/glimmer/libui/control_proxy.rb +6 -2
- data/lib/glimmer/libui/horizontal_box_proxy.rb +1 -1
- data/lib/glimmer/libui/menu_item_proxy.rb +38 -0
- data/lib/glimmer/libui/vertical_box_proxy.rb +1 -1
- data/lib/glimmer/libui/window_proxy.rb +1 -1
- data/lib/glimmer-dsl-libui.rb +2 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98ea45093e4fa24ad49e896ca02a090c6900f1ddf80e8e592726914746b8c4e0
|
4
|
+
data.tar.gz: 8106d3f232fea6048c38b9ee0c3f93dda9cdaf3cffc7f3c68ac9a1dcf82e9f24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 637a28709c22c93d817b7b59375844d9540253957ae3a236ab802b404d02c939f1fdf01606fd0bc86cb224b8cd424ba9483da87daf30a83daa58d374ea02956c
|
7
|
+
data.tar.gz: b35754ad0c266f931fcf77dca37026a7bd309083835f662f9c5549b43b2d21bbb08d57af3c676bd82b6d1490071c1d86d7f0c8ba3f1416b861919738a67cea6d
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
-
# [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for LibUI 0.0.
|
1
|
+
# [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=85 />](https://github.com/AndyObtiva/glimmer) Glimmer DSL for LibUI 0.0.4
|
2
2
|
## Dependency-Free Ruby Desktop Development GUI Library
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/glimmer-dsl-libui.svg)](http://badge.fury.io/rb/glimmer-dsl-libui)
|
4
4
|
[![Maintainability](https://api.codeclimate.com/v1/badges/ce2853efdbecf6ebdc73/maintainability)](https://codeclimate.com/github/AndyObtiva/glimmer-dsl-libui/maintainability)
|
5
5
|
[![Join the chat at https://gitter.im/AndyObtiva/glimmer](https://badges.gitter.im/AndyObtiva/glimmer.svg)](https://gitter.im/AndyObtiva/glimmer?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
6
6
|
|
7
|
-
[Glimmer DSL for LibUI](https://
|
7
|
+
[Glimmer](https://github.com/AndyObtiva/glimmer) DSL for [LibUI](https://github.com/kojix2/LibUI) is a dependency-free Ruby desktop development GUI library. No need to pre-insta
|
8
|
+
ll any pre-requisites. Just install the gem and have platform-independent GUI that just works!
|
8
9
|
|
9
|
-
The main trade-off against [Glimmer DSL for SWT](https://github.com/AndyObtiva/glimmer-dsl-swt) and [Glimmer DSL for Tk](https://github.com/AndyObtiva/glimmer-dsl-tk) is the fact that [SWT](https://www.eclipse.org/swt/) and [Tk](https://www.tcl.tk/) are more mature than [LibUI](https://github.com/kojix2/LibUI) as GUI toolkits. Still, if there is only a need to build a small simple application, [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) could be a
|
10
|
+
The main trade-off against [Glimmer DSL for SWT](https://github.com/AndyObtiva/glimmer-dsl-swt) and [Glimmer DSL for Tk](https://github.com/AndyObtiva/glimmer-dsl-tk) (all of which have native-looking widgets) is the fact that [SWT](https://www.eclipse.org/swt/) and [Tk](https://www.tcl.tk/) are more mature than [LibUI](https://github.com/kojix2/LibUI) as GUI toolkits. Still, if there is only a need to build a small simple application, [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) could be a good choice due to having zero external dependencies beyond what is included in the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui). Also, just like [Glimmer DSL for Tk](https://github.com/AndyObtiva/glimmer-dsl-tk) (and unlike [Glimmer DSL for SWT](https://github.com/AndyObtiva/glimmer-dsl-swt)), its apps start instantly and have a small memory footprint. [LibUI](https://github.com/kojix2/LibUI) is a promising new GUI toolkit that might prove itself quite worthy in the future.
|
10
11
|
|
11
12
|
[Glimmer DSL for LibUI](https://github.com/AndyObtiva/glimmer-dsl-libui) aims to provide a DSL similar to the [Glimmer DSL for SWT](https://github.com/AndyObtiva/glimmer-dsl-swt) to enable more productive desktop development in Ruby with:
|
12
13
|
- Declarative DSL syntax that visually maps to the GUI widget hierarchy
|
@@ -27,10 +28,10 @@ include Glimmer
|
|
27
28
|
window('hello world', 300, 200, 1).show
|
28
29
|
```
|
29
30
|
|
30
|
-
![glimmer-dsl-libui-basic-window
|
31
|
-
![glimmer-dsl-libui-basic-window
|
31
|
+
![glimmer-dsl-libui-mac-basic-window.png](images/glimmer-dsl-libui-mac-basic-window.png)
|
32
|
+
![glimmer-dsl-libui-linux-basic-window.png](images/glimmer-dsl-libui-linux-basic-window.png)
|
32
33
|
|
33
|
-
NOTE: [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) is in early alpha mode. Please help make better by contributing, adopting for small or low risk projects, and providing feedback. It is still an early alpha, so the more feedback and issues you report the better.
|
34
|
+
NOTE: [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) is in early alpha mode (only supports included examples). Please help make better by contributing, adopting for small or low risk projects, and providing feedback. It is still an early alpha, so the more feedback and issues you report the better.
|
34
35
|
|
35
36
|
Other [Glimmer](https://rubygems.org/gems/glimmer) DSL gems you might be interested in:
|
36
37
|
- [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt): Glimmer DSL for SWT (JRuby Desktop Development GUI Framework)
|
@@ -116,7 +117,7 @@ gem install glimmer-dsl-libui
|
|
116
117
|
Or install via Bundler `Gemfile`:
|
117
118
|
|
118
119
|
```ruby
|
119
|
-
gem 'glimmer-dsl-libui', '~> 0.0.
|
120
|
+
gem 'glimmer-dsl-libui', '~> 0.0.4'
|
120
121
|
```
|
121
122
|
|
122
123
|
Add `require 'glimmer-dsl-libui'` at the top, and then `include Glimmer` into the top-level main object for testing or into an actual class for serious usage.
|
@@ -158,6 +159,37 @@ w.set_title 'aloha'
|
|
158
159
|
puts w.title # => aloha
|
159
160
|
```
|
160
161
|
|
162
|
+
Controls are wrapped as Ruby proxy objects, having a `#libui` method to obtain the wrapped Fiddle pointer object. Ruby proxy objects rely on composition (via [Proxy Design Pattern](https://en.wikipedia.org/wiki/Proxy_pattern)) instead of inheritance to shield consumers from having to deal with lower-level details unless absolutely needed.
|
163
|
+
|
164
|
+
Example (you may copy/paste in [`girb`](#girb-glimmer-irb)):
|
165
|
+
|
166
|
+
```ruby
|
167
|
+
w = window('hello world', 300, 200, 1) # => #<Glimmer::LibUI::WindowProxy:0x00007fde4ea39fb0
|
168
|
+
w.libui # => #<Fiddle::Pointer:0x00007fde53997980 ptr=0x00007fde51352a60 size=0 free=0x0000000000000000>
|
169
|
+
```
|
170
|
+
|
171
|
+
Supported Controls and their Properties / Listeners:
|
172
|
+
- `button`: `text` (`String`) / `on_clicked`
|
173
|
+
- `entry`: `read_only` (`1` or `0`), `text` (`String`) / `on_changed`
|
174
|
+
- `menu`: None / None
|
175
|
+
- `menu_item`: `checked` (`1` or `0`) / `on_clicked`
|
176
|
+
- `msg_box`: None / None
|
177
|
+
- `non_wrapping_multiline_entry`: None / None
|
178
|
+
- `window`: `borderless` (`1` or `0`), `content_size` (width `Numeric`, height `Numeric`), `fullscreen` (`1` or `0`), `margined` (`1` or `0`), `title` (`String`) / `on_closing`, `on_content_size_changed`
|
179
|
+
|
180
|
+
Common Control Properties:
|
181
|
+
- `enabled`
|
182
|
+
- `parent`
|
183
|
+
- `toplevel`
|
184
|
+
- `visible`
|
185
|
+
|
186
|
+
Common Control Operations:
|
187
|
+
- `destroy`
|
188
|
+
- `disable`
|
189
|
+
- `enable`
|
190
|
+
- `hide`
|
191
|
+
- `show`
|
192
|
+
|
161
193
|
## Girb (Glimmer IRB)
|
162
194
|
|
163
195
|
You can run the `girb` command (`bin/girb` if you cloned the project locally):
|
@@ -192,11 +224,11 @@ ruby -r glimmer-dsl-libui -e "require 'examples/basic_window'"
|
|
192
224
|
|
193
225
|
Mac
|
194
226
|
|
195
|
-
![glimmer-dsl-libui-basic-window
|
227
|
+
![glimmer-dsl-libui-mac-basic-window.png](images/glimmer-dsl-libui-mac-basic-window.png)
|
196
228
|
|
197
229
|
Linux
|
198
230
|
|
199
|
-
![glimmer-dsl-libui-basic-window
|
231
|
+
![glimmer-dsl-libui-linux-basic-window.png](images/glimmer-dsl-libui-linux-basic-window.png)
|
200
232
|
|
201
233
|
[LibUI](https://github.com/kojix2/LibUI) Original Version:
|
202
234
|
|
@@ -254,13 +286,13 @@ ruby -r glimmer-dsl-libui -e "require 'examples/basic_button'"
|
|
254
286
|
|
255
287
|
Mac
|
256
288
|
|
257
|
-
![glimmer-dsl-libui-basic-button
|
258
|
-
![glimmer-dsl-libui-basic-button-msg-box
|
289
|
+
![glimmer-dsl-libui-mac-basic-button.png](images/glimmer-dsl-libui-mac-basic-button.png)
|
290
|
+
![glimmer-dsl-libui-mac-basic-button-msg-box.png](images/glimmer-dsl-libui-basic-button-msg-box.png)
|
259
291
|
|
260
292
|
Linux
|
261
293
|
|
262
|
-
![glimmer-dsl-libui-basic-button
|
263
|
-
![glimmer-dsl-libui-basic-button-msg-box
|
294
|
+
![glimmer-dsl-libui-linux-basic-button.png](images/glimmer-dsl-libui-linux-basic-button.png)
|
295
|
+
![glimmer-dsl-libui-linux-basic-button-msg-box.png](images/glimmer-dsl-libui-linux-basic-button-msg-box.png)
|
264
296
|
|
265
297
|
[LibUI](https://github.com/kojix2/LibUI) Original Version:
|
266
298
|
|
@@ -331,13 +363,13 @@ ruby -r glimmer-dsl-libui -e "require 'examples/basic_entry'"
|
|
331
363
|
|
332
364
|
Mac
|
333
365
|
|
334
|
-
![glimmer-dsl-libui-basic-entry
|
335
|
-
![glimmer-dsl-libui-basic-entry-msg-box
|
366
|
+
![glimmer-dsl-libui-mac-basic-entry.png](images/glimmer-dsl-libui-mac-basic-entry.png)
|
367
|
+
![glimmer-dsl-libui-mac-basic-entry-msg-box.png](images/glimmer-dsl-libui-mac-basic-entry-msg-box.png)
|
336
368
|
|
337
369
|
Linux
|
338
370
|
|
339
|
-
![glimmer-dsl-libui-basic-entry
|
340
|
-
![glimmer-dsl-libui-basic-entry-msg-box
|
371
|
+
![glimmer-dsl-libui-linux-basic-entry.png](images/glimmer-dsl-libui-linux-basic-entry.png)
|
372
|
+
![glimmer-dsl-libui-linux-basic-entry-msg-box.png](images/glimmer-dsl-libui-linux-basic-entry-msg-box.png)
|
341
373
|
|
342
374
|
[LibUI](https://github.com/kojix2/LibUI) Original Version:
|
343
375
|
|
@@ -432,11 +464,11 @@ ruby -r glimmer-dsl-libui -e "require 'examples/simple_notepad'"
|
|
432
464
|
|
433
465
|
Mac
|
434
466
|
|
435
|
-
![glimmer-dsl-libui-simple-notepad
|
467
|
+
![glimmer-dsl-libui-mac-simple-notepad.png](images/glimmer-dsl-libui-mac-simple-notepad.png)
|
436
468
|
|
437
469
|
Linux
|
438
470
|
|
439
|
-
![glimmer-dsl-libui-simple-notepad
|
471
|
+
![glimmer-dsl-libui-linux-simple-notepad.png](images/glimmer-dsl-libui-linux-simple-notepad.png)
|
440
472
|
|
441
473
|
[LibUI](https://github.com/kojix2/LibUI) Original Version:
|
442
474
|
|
@@ -484,6 +516,230 @@ window('Notepad', 500, 300, 1) {
|
|
484
516
|
}.show
|
485
517
|
```
|
486
518
|
|
519
|
+
### Midi Player
|
520
|
+
|
521
|
+
This example has pre-requisites:
|
522
|
+
- Install [TiMidity](http://timidity.sourceforge.net) and ensure `timidity` command is in `PATH` (can be installed via [Homebrew](https://brew.sh) on Mac or [apt-get](https://help.ubuntu.com/community/AptGet/Howto) on Linux).
|
523
|
+
- Add `*.mid` files to `~/Music` directory (you may copy the ones included in [sounds](sounds) directory)
|
524
|
+
|
525
|
+
[examples/midi_player.rb](examples/midi_player.rb)
|
526
|
+
|
527
|
+
Run with this command from the root of the project if you cloned the project:
|
528
|
+
|
529
|
+
```
|
530
|
+
ruby -r './lib/glimmer-dsl-libui' examples/midi_player.rb
|
531
|
+
```
|
532
|
+
|
533
|
+
Run with this command if you installed the [Ruby gem](https://rubygems.org/gems/glimmer-dsl-libui):
|
534
|
+
|
535
|
+
```
|
536
|
+
ruby -r glimmer-dsl-libui -e "require 'examples/midi_player'"
|
537
|
+
```
|
538
|
+
|
539
|
+
Mac
|
540
|
+
|
541
|
+
![glimmer-dsl-libui-mac-midi-player.png](images/glimmer-dsl-libui-mac-midi-player.png)
|
542
|
+
![glimmer-dsl-libui-mac-midi-player-version-msg-box.png](images/glimmer-dsl-libui-mac-midi-player-version-msg-box.png)
|
543
|
+
|
544
|
+
Linux
|
545
|
+
|
546
|
+
![glimmer-dsl-libui-linux-midi-player.png](images/glimmer-dsl-libui-linux-midi-player.png)
|
547
|
+
![glimmer-dsl-libui-linux-midi-player-version-msg-box.png](images/glimmer-dsl-libui-linux-midi-player-version-msg-box.png)
|
548
|
+
|
549
|
+
[LibUI](https://github.com/kojix2/LibUI) Original Version:
|
550
|
+
|
551
|
+
```ruby
|
552
|
+
require 'libui'
|
553
|
+
UI = LibUI
|
554
|
+
|
555
|
+
class TinyMidiPlayer
|
556
|
+
VERSION = '0.0.1'
|
557
|
+
|
558
|
+
def initialize
|
559
|
+
UI.init
|
560
|
+
@pid = nil
|
561
|
+
@music_directory = File.expand_path(ARGV[0] || '~/Music/')
|
562
|
+
@midi_files = Dir.glob(File.join(@music_directory, '**/*.mid'))
|
563
|
+
.sort_by { |path| File.basename(path) }
|
564
|
+
at_exit { stop_midi }
|
565
|
+
create_gui
|
566
|
+
end
|
567
|
+
|
568
|
+
def stop_midi
|
569
|
+
if @pid
|
570
|
+
if @th.alive?
|
571
|
+
Process.kill(:SIGKILL, @pid)
|
572
|
+
@pid = nil
|
573
|
+
else
|
574
|
+
@pid = nil
|
575
|
+
end
|
576
|
+
end
|
577
|
+
end
|
578
|
+
|
579
|
+
def play_midi
|
580
|
+
stop_midi
|
581
|
+
if @pid.nil? && @selected_file
|
582
|
+
begin
|
583
|
+
@pid = spawn "timidity #{@selected_file}"
|
584
|
+
@th = Process.detach @pid
|
585
|
+
rescue Errno::ENOENT
|
586
|
+
warn 'Timidty++ not found. Please install Timidity++.'
|
587
|
+
warn 'https://sourceforge.net/projects/timidity/'
|
588
|
+
end
|
589
|
+
end
|
590
|
+
end
|
591
|
+
|
592
|
+
def show_version(main_window)
|
593
|
+
UI.msg_box(main_window,
|
594
|
+
'Tiny Midi Player',
|
595
|
+
"Written in Ruby\n" \
|
596
|
+
"https://github.com/kojix2/libui\n" \
|
597
|
+
"Version #{VERSION}")
|
598
|
+
end
|
599
|
+
|
600
|
+
def create_gui
|
601
|
+
help_menu = UI.new_menu('Help')
|
602
|
+
version_item = UI.menu_append_item(help_menu, 'Version')
|
603
|
+
|
604
|
+
UI.new_window('Tiny Midi Player', 200, 50, 1).tap do |main_window|
|
605
|
+
UI.menu_item_on_clicked(version_item) { show_version(main_window) }
|
606
|
+
|
607
|
+
UI.window_on_closing(main_window) do
|
608
|
+
UI.control_destroy(main_window)
|
609
|
+
UI.quit
|
610
|
+
0
|
611
|
+
end
|
612
|
+
|
613
|
+
UI.new_horizontal_box.tap do |hbox|
|
614
|
+
UI.new_vertical_box.tap do |vbox|
|
615
|
+
UI.new_button('▶').tap do |button1|
|
616
|
+
UI.button_on_clicked(button1) { play_midi }
|
617
|
+
UI.box_append(vbox, button1, 1)
|
618
|
+
end
|
619
|
+
UI.new_button('■').tap do |button2|
|
620
|
+
UI.button_on_clicked(button2) { stop_midi }
|
621
|
+
UI.box_append(vbox, button2, 1)
|
622
|
+
end
|
623
|
+
UI.box_append(hbox, vbox, 0)
|
624
|
+
end
|
625
|
+
UI.window_set_child(main_window, hbox)
|
626
|
+
|
627
|
+
UI.new_combobox.tap do |cbox|
|
628
|
+
@midi_files.each do |path|
|
629
|
+
name = File.basename(path)
|
630
|
+
UI.combobox_append(cbox, name)
|
631
|
+
end
|
632
|
+
UI.combobox_on_selected(cbox) do |ptr|
|
633
|
+
@selected_file = @midi_files[UI.combobox_selected(ptr)]
|
634
|
+
play_midi if @th&.alive?
|
635
|
+
0
|
636
|
+
end
|
637
|
+
UI.box_append(hbox, cbox, 1)
|
638
|
+
end
|
639
|
+
end
|
640
|
+
UI.control_show(main_window)
|
641
|
+
end
|
642
|
+
UI.main
|
643
|
+
UI.quit
|
644
|
+
end
|
645
|
+
end
|
646
|
+
|
647
|
+
TinyMidiPlayer.new
|
648
|
+
```
|
649
|
+
|
650
|
+
[Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
|
651
|
+
|
652
|
+
```ruby
|
653
|
+
require 'glimmer-dsl-libui'
|
654
|
+
|
655
|
+
class TinyMidiPlayer
|
656
|
+
include Glimmer
|
657
|
+
|
658
|
+
VERSION = '0.0.1'
|
659
|
+
|
660
|
+
def initialize
|
661
|
+
@pid = nil
|
662
|
+
@music_directory = File.expand_path(ARGV[0] || '~/Music/')
|
663
|
+
@midi_files = Dir.glob(File.join(@music_directory, '**/*.mid'))
|
664
|
+
.sort_by { |path| File.basename(path) }
|
665
|
+
at_exit { stop_midi }
|
666
|
+
create_gui
|
667
|
+
end
|
668
|
+
|
669
|
+
def stop_midi
|
670
|
+
if @pid
|
671
|
+
if @th.alive?
|
672
|
+
Process.kill(:SIGKILL, @pid)
|
673
|
+
@pid = nil
|
674
|
+
else
|
675
|
+
@pid = nil
|
676
|
+
end
|
677
|
+
end
|
678
|
+
end
|
679
|
+
|
680
|
+
def play_midi
|
681
|
+
stop_midi
|
682
|
+
if @pid.nil? && @selected_file
|
683
|
+
begin
|
684
|
+
@pid = spawn "timidity #{@selected_file}"
|
685
|
+
@th = Process.detach @pid
|
686
|
+
rescue Errno::ENOENT
|
687
|
+
warn 'Timidty++ not found. Please install Timidity++.'
|
688
|
+
warn 'https://sourceforge.net/projects/timidity/'
|
689
|
+
end
|
690
|
+
end
|
691
|
+
end
|
692
|
+
|
693
|
+
def show_version(main_window)
|
694
|
+
msg_box(main_window,
|
695
|
+
'Tiny Midi Player',
|
696
|
+
"Written in Ruby\n" \
|
697
|
+
"https://github.com/kojix2/libui\n" \
|
698
|
+
"Version #{VERSION}")
|
699
|
+
end
|
700
|
+
|
701
|
+
def create_gui
|
702
|
+
menu('Help') { |m|
|
703
|
+
menu_item('Version') {
|
704
|
+
on_clicked do
|
705
|
+
show_version(@main_window)
|
706
|
+
end
|
707
|
+
}
|
708
|
+
}
|
709
|
+
@main_window = window('Tiny Midi Player', 200, 50, 1) {
|
710
|
+
horizontal_box {
|
711
|
+
vertical_box {
|
712
|
+
stretchy 0
|
713
|
+
|
714
|
+
button('▶') {
|
715
|
+
on_clicked do
|
716
|
+
play_midi
|
717
|
+
end
|
718
|
+
}
|
719
|
+
button('■') {
|
720
|
+
on_clicked do
|
721
|
+
stop_midi
|
722
|
+
end
|
723
|
+
}
|
724
|
+
}
|
725
|
+
|
726
|
+
combobox { |c|
|
727
|
+
items @midi_files.map { |path| File.basename(path) }
|
728
|
+
|
729
|
+
on_selected do
|
730
|
+
@selected_file = @midi_files[c.selected]
|
731
|
+
play_midi if @th&.alive?
|
732
|
+
end
|
733
|
+
}
|
734
|
+
}
|
735
|
+
}
|
736
|
+
@main_window.show
|
737
|
+
end
|
738
|
+
end
|
739
|
+
|
740
|
+
TinyMidiPlayer.new
|
741
|
+
```
|
742
|
+
|
487
743
|
## Contributing to glimmer-dsl-libui
|
488
744
|
|
489
745
|
- Check out the latest master to make sure the feature hasn't been
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'glimmer-dsl-libui'
|
4
|
+
|
5
|
+
class TinyMidiPlayer
|
6
|
+
include Glimmer
|
7
|
+
|
8
|
+
VERSION = '0.0.1'
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@pid = nil
|
12
|
+
@music_directory = File.expand_path(ARGV[0] || '~/Music/')
|
13
|
+
@midi_files = Dir.glob(File.join(@music_directory, '**/*.mid'))
|
14
|
+
.sort_by { |path| File.basename(path) }
|
15
|
+
at_exit { stop_midi }
|
16
|
+
create_gui
|
17
|
+
end
|
18
|
+
|
19
|
+
def stop_midi
|
20
|
+
if @pid
|
21
|
+
if @th.alive?
|
22
|
+
Process.kill(:SIGKILL, @pid)
|
23
|
+
@pid = nil
|
24
|
+
else
|
25
|
+
@pid = nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def play_midi
|
31
|
+
stop_midi
|
32
|
+
if @pid.nil? && @selected_file
|
33
|
+
begin
|
34
|
+
@pid = spawn "timidity #{@selected_file}"
|
35
|
+
@th = Process.detach @pid
|
36
|
+
rescue Errno::ENOENT
|
37
|
+
warn 'Timidty++ not found. Please install Timidity++.'
|
38
|
+
warn 'https://sourceforge.net/projects/timidity/'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def show_version(main_window)
|
44
|
+
msg_box(main_window,
|
45
|
+
'Tiny Midi Player',
|
46
|
+
"Written in Ruby\n" \
|
47
|
+
"https://github.com/kojix2/libui\n" \
|
48
|
+
"Version #{VERSION}")
|
49
|
+
end
|
50
|
+
|
51
|
+
def create_gui
|
52
|
+
menu('Help') { |m|
|
53
|
+
menu_item('Version') {
|
54
|
+
on_clicked do
|
55
|
+
show_version(@main_window)
|
56
|
+
end
|
57
|
+
}
|
58
|
+
}
|
59
|
+
@main_window = window('Tiny Midi Player', 200, 50, 1) {
|
60
|
+
horizontal_box {
|
61
|
+
vertical_box {
|
62
|
+
stretchy 0
|
63
|
+
|
64
|
+
button('▶') {
|
65
|
+
on_clicked do
|
66
|
+
play_midi
|
67
|
+
end
|
68
|
+
}
|
69
|
+
button('■') {
|
70
|
+
on_clicked do
|
71
|
+
stop_midi
|
72
|
+
end
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
combobox { |c|
|
77
|
+
items @midi_files.map { |path| File.basename(path) }
|
78
|
+
|
79
|
+
on_selected do
|
80
|
+
@selected_file = @midi_files[c.selected]
|
81
|
+
play_midi if @th&.alive?
|
82
|
+
end
|
83
|
+
}
|
84
|
+
}
|
85
|
+
}
|
86
|
+
@main_window.show
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
TinyMidiPlayer.new
|
data/glimmer-dsl-libui.gemspec
CHANGED
Binary file
|
@@ -48,6 +48,4 @@ end
|
|
48
48
|
|
49
49
|
# TODO Consider moving all controls underneath Control namespace
|
50
50
|
require 'glimmer/libui/control_proxy'
|
51
|
-
|
52
|
-
require 'glimmer/libui/horizontal_box_proxy'
|
53
|
-
require 'glimmer/libui/vertical_box_proxy'
|
51
|
+
Dir[File.expand_path('../../libui/*.rb', __dir__)].each {|f| require f}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# Copyright (c) 2021 Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
require 'glimmer/libui/control_proxy'
|
23
|
+
|
24
|
+
module Glimmer
|
25
|
+
module LibUI
|
26
|
+
# Proxy for LibUI window objects
|
27
|
+
#
|
28
|
+
# Follows the Proxy Design Pattern
|
29
|
+
class ComboboxProxy < ControlProxy
|
30
|
+
def items(values = nil)
|
31
|
+
if values.nil?
|
32
|
+
@values
|
33
|
+
else
|
34
|
+
@values = values
|
35
|
+
@values.each { |value| append value }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
alias set_items items
|
39
|
+
alias items= items
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -21,13 +21,15 @@
|
|
21
21
|
|
22
22
|
module Glimmer
|
23
23
|
module LibUI
|
24
|
-
# Proxy for LibUI
|
24
|
+
# Proxy for LibUI control objects
|
25
25
|
#
|
26
26
|
# Follows the Proxy Design Pattern
|
27
27
|
class ControlProxy
|
28
28
|
class << self
|
29
29
|
def control_exists?(keyword)
|
30
|
-
::LibUI.respond_to?("new_#{keyword}") ||
|
30
|
+
::LibUI.respond_to?("new_#{keyword}") ||
|
31
|
+
::LibUI.respond_to?(keyword) ||
|
32
|
+
Glimmer::LibUI.constants.include?("#{keyword.camelcase(:upper)}Proxy".to_sym)
|
31
33
|
end
|
32
34
|
|
33
35
|
def create(keyword, parent, args, &block)
|
@@ -115,6 +117,8 @@ module Glimmer
|
|
115
117
|
::LibUI.send("#{@keyword}_set_#{method_name.to_s.sub(/=$/, '')}", @libui, *args)
|
116
118
|
elsif ::LibUI.respond_to?("#{@keyword}_#{method_name}") && method_name.start_with?('set_') && !args.empty?
|
117
119
|
::LibUI.send("#{@keyword}_#{method_name}", @libui, *args)
|
120
|
+
elsif ::LibUI.respond_to?("#{@keyword}_#{method_name}") && !args.empty?
|
121
|
+
::LibUI.send("#{@keyword}_#{method_name}", @libui, *args)
|
118
122
|
end
|
119
123
|
end
|
120
124
|
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# Copyright (c) 2021 Andy Maleh
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
# a copy of this software and associated documentation files (the
|
5
|
+
# "Software"), to deal in the Software without restriction, including
|
6
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
# the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be
|
12
|
+
# included in all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
require 'glimmer/libui/control_proxy'
|
23
|
+
|
24
|
+
module Glimmer
|
25
|
+
module LibUI
|
26
|
+
# Proxy for LibUI menu item objects
|
27
|
+
#
|
28
|
+
# Follows the Proxy Design Pattern
|
29
|
+
class MenuItemProxy < ControlProxy
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def build_control
|
34
|
+
@libui ||= @parent_proxy.append_item('Version')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -36,6 +36,7 @@ module Glimmer
|
|
36
36
|
unless @shown_at_least_once
|
37
37
|
@shown_at_least_once = true
|
38
38
|
::LibUI.main
|
39
|
+
::LibUI.quit
|
39
40
|
end
|
40
41
|
end
|
41
42
|
|
@@ -58,7 +59,6 @@ module Glimmer
|
|
58
59
|
private
|
59
60
|
|
60
61
|
def build_control
|
61
|
-
::LibUI.init
|
62
62
|
super.tap do
|
63
63
|
handle_listener('on_closing') do
|
64
64
|
destroy
|
data/lib/glimmer-dsl-libui.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glimmer-dsl-libui
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Maleh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-09-
|
11
|
+
date: 2021-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: glimmer
|
@@ -163,6 +163,7 @@ files:
|
|
163
163
|
- examples/basic_button.rb
|
164
164
|
- examples/basic_entry.rb
|
165
165
|
- examples/basic_window.rb
|
166
|
+
- examples/midi_player.rb
|
166
167
|
- examples/simple_notepad.rb
|
167
168
|
- glimmer-dsl-libui.gemspec
|
168
169
|
- lib/glimmer-dsl-libui.rb
|
@@ -171,8 +172,10 @@ files:
|
|
171
172
|
- lib/glimmer/dsl/libui/listener_expression.rb
|
172
173
|
- lib/glimmer/dsl/libui/property_expression.rb
|
173
174
|
- lib/glimmer/libui/box.rb
|
175
|
+
- lib/glimmer/libui/combobox_proxy.rb
|
174
176
|
- lib/glimmer/libui/control_proxy.rb
|
175
177
|
- lib/glimmer/libui/horizontal_box_proxy.rb
|
178
|
+
- lib/glimmer/libui/menu_item_proxy.rb
|
176
179
|
- lib/glimmer/libui/vertical_box_proxy.rb
|
177
180
|
- lib/glimmer/libui/window_proxy.rb
|
178
181
|
homepage: http://github.com/AndyObtiva/glimmer-dsl-libui
|