glimmer-dsl-libui 0.4.6 → 0.4.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +223 -9
- data/VERSION +1 -1
- data/examples/date_time_picker.rb +19 -14
- data/examples/date_time_picker2.rb +20 -0
- data/examples/midi_player.rb +4 -5
- data/examples/midi_player2.rb +83 -0
- data/examples/midi_player3.rb +84 -0
- data/glimmer-dsl-libui.gemspec +0 -0
- data/lib/glimmer/libui/control_proxy/combobox_proxy.rb +18 -2
- data/lib/glimmer/libui/control_proxy/date_time_picker_proxy.rb +5 -0
- data/lib/glimmer/libui/control_proxy/editable_combobox_proxy.rb +5 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1256d99b9a792c92f657e9320af1264a275f26e7de5586d3f174daaf33b35f07
|
4
|
+
data.tar.gz: 5d8dcf4a6eb8870136579240d8d5337e72c6e2bac76b78fd506a3c1335ecd8a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c99de618602038c939715d95a03ac6b8296e6f46bff298808df977c161dead4859aa6e7cca1e7d72bac6216e2c4f6cbbc090e4648ab933db406aced2028cf14
|
7
|
+
data.tar.gz: ed6e9d34fe546651d72918f2e5895cfb0cfd13a6eb2ab0f5e55b78a5cf8ecbbff1bc362afb9356f0839a80852c7a5bf30e262ddd05ee76f750e98129ae980a25
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 0.4.7
|
4
|
+
|
5
|
+
- Support `date_time_picker`/`date_picker`/`time_picker` `time` bidirectional data-binding (with `<=>` sign)
|
6
|
+
- Support `combobox` `selected`/`selected_item` bidirectional data-binding (with `<=>` sign)
|
7
|
+
- Support `editable_combobox` `text` bidirectional data-binding (with `<=>` sign)
|
8
|
+
- Improve examples/date_time_picker.rb with bidirectional data-binding for `date_time_picker` `time`
|
9
|
+
- Improve examples/midi_player.rb with bidirectional data-binding for `combobox` `selected`/`selected_item`
|
10
|
+
|
3
11
|
## 0.4.6
|
4
12
|
|
5
13
|
- Support `slider` `value` bidirectional data-binding (with `<=>` sign)
|
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
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.4.
|
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.4.7
|
2
2
|
## Prerequisite-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
|
[![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)
|
5
5
|
|
6
|
-
[Glimmer](https://github.com/AndyObtiva/glimmer) DSL for [LibUI](https://github.com/kojix2/LibUI) is a prerequisite-free Ruby desktop development GUI library. No need to pre-install any prerequisites. Just install the gem and have platform-independent native GUI that just works!
|
6
|
+
[Glimmer](https://github.com/AndyObtiva/glimmer) DSL for [LibUI](https://github.com/kojix2/LibUI) is a prerequisite-free Ruby desktop development GUI (Graphical User Interface) library. No need to pre-install any prerequisites. Just install the [gem](https://rubygems.org/gems/glimmer-dsl-libui) and have platform-independent native GUI that just works!
|
7
7
|
|
8
8
|
Mac | Windows | Linux
|
9
9
|
----|---------|------
|
@@ -373,7 +373,7 @@ gem install glimmer-dsl-libui
|
|
373
373
|
Or install via Bundler `Gemfile`:
|
374
374
|
|
375
375
|
```ruby
|
376
|
-
gem 'glimmer-dsl-libui', '~> 0.4.
|
376
|
+
gem 'glimmer-dsl-libui', '~> 0.4.7'
|
377
377
|
```
|
378
378
|
|
379
379
|
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.
|
@@ -460,7 +460,7 @@ Keyword(Args) | Properties | Listeners
|
|
460
460
|
`checkbox_text_column(name as String)` | `editable` (Boolean), `editable_checkbox` (Boolean), `editable_text` (Boolean) | None
|
461
461
|
`checkbox_text_color_column(name as String)` | `editable` (Boolean), `editable_checkbox` (Boolean), `editable_text` (Boolean) | None
|
462
462
|
`check_menu_item(text as String)` | `checked` (Boolean) | `on_clicked`
|
463
|
-
`combobox` | `items` (`Array` of `String`), `selected` (`Integer`) | `on_selected`
|
463
|
+
`combobox` | `items` (`Array` of `String`), `selected` (`Integer`), `selected_item` (`String`) | `on_selected`
|
464
464
|
`color_button` | `color` (Array of `red` as `Float`, `green` as `Float`, `blue` as `Float`, `alpha` as `Float`), `red` as `Float`, `green` as `Float`, `blue` as `Float`, `alpha` as `Float` | `on_changed`
|
465
465
|
`date_picker` | `time` (`Hash` of keys: `sec` as `Integer`, `min` as `Integer`, `hour` as `Integer`, `mday` as `Integer`, `mon` as `Integer`, `year` as `Integer`, `wday` as `Integer`, `yday` as `Integer`, `dst` as Boolean) | `on_changed`
|
466
466
|
`date_time_picker` | `time` (`Hash` of keys: `sec` as `Integer`, `min` as `Integer`, `hour` as `Integer`, `mday` as `Integer`, `mon` as `Integer`, `year` as `Integer`, `wday` as `Integer`, `yday` as `Integer`, `dst` as Boolean) | `on_changed`
|
@@ -1383,6 +1383,10 @@ Data-binding supports utilizing the [MVP (Model View Presenter)](https://en.wiki
|
|
1383
1383
|
|
1384
1384
|
[Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) supports bidirectional (two-way) data-binding of the following controls/properties via the `<=>` operator (indicating data is moving in both directions between View and Model):
|
1385
1385
|
- `color_button`: `color`
|
1386
|
+
- `combobox`: `selected`, `selected_item`
|
1387
|
+
- `date_picker`: `time`
|
1388
|
+
- `date_time_picker`: `time`
|
1389
|
+
- `editable_combobox`: `text`
|
1386
1390
|
- `entry`: `text`
|
1387
1391
|
- `font_button`: `font`
|
1388
1392
|
- `multiline_entry`: `text`
|
@@ -1390,6 +1394,7 @@ Data-binding supports utilizing the [MVP (Model View Presenter)](https://en.wiki
|
|
1390
1394
|
- `search_entry`: `text`
|
1391
1395
|
- `slider`: `value`
|
1392
1396
|
- `spinbox`: `value`
|
1397
|
+
- `time_picker`: `time`
|
1393
1398
|
|
1394
1399
|
Example of bidirectional data-binding:
|
1395
1400
|
|
@@ -1439,6 +1444,11 @@ To summarize the data-binding API:
|
|
1439
1444
|
|
1440
1445
|
This is also known as the [Glimmer Shine](https://github.com/AndyObtiva/glimmer-dsl-swt/blob/master/docs/reference/GLIMMER_GUI_DSL_SYNTAX.md#shine) syntax for data-binding, a [Glimmer](https://github.com/AndyObtiva/glimmer)-only unique innovation that takes advantage of [Ruby](https://www.ruby-lang.org/en/)'s highly expressive syntax and malleable DSL support.
|
1441
1446
|
|
1447
|
+
Data-bound model attribute can be:
|
1448
|
+
- **Direct:** `Symbol` representing attribute reader/writer (e.g. `[person, :name`])
|
1449
|
+
- **Nested:** `String` representing nested attribute path (e.g. `[company, 'address.street']`). That results in "nested data-binding"
|
1450
|
+
- **Indexed:** `String` containing array attribute index (e.g. `[customer, 'addresses[0].street']`). That results in "indexed data-binding"
|
1451
|
+
|
1442
1452
|
Data-binding options include:
|
1443
1453
|
- `before_read {|value| ...}`: performs an operation before reading data from Model to update the View.
|
1444
1454
|
- `on_read {|value| ...}`: converts value read from Model to update the View.
|
@@ -1446,7 +1456,7 @@ Data-binding options include:
|
|
1446
1456
|
- `before_write {|value| ...}`: performs an operation before writing data to Model from View.
|
1447
1457
|
- `on_write {|value| ...}`: converts value read from View to update the Model.
|
1448
1458
|
- `after_write {|converted_value| ...}`: performs an operation after writing to Model from View.
|
1449
|
-
- `computed_by attribute` or `computed_by [attribute1, attribute2, ...]`: indicates model attribute is computed from specified attribute(s), thus updated when they are updated (see in [Login example version 2](/examples/login2.rb))
|
1459
|
+
- `computed_by attribute` or `computed_by [attribute1, attribute2, ...]`: indicates model attribute is computed from specified attribute(s), thus updated when they are updated (see in [Login example version 2](/examples/login2.rb)). That is known as "computed data-binding".
|
1450
1460
|
|
1451
1461
|
Note that with both `on_read` and `on_write` converters, you could pass a `Symbol` representing the name of a method on the value object to invoke.
|
1452
1462
|
|
@@ -1878,7 +1888,7 @@ Example:
|
|
1878
1888
|
|
1879
1889
|
## Examples
|
1880
1890
|
|
1881
|
-
The following examples include reimplementions of the examples in the [LibUI](https://github.com/kojix2/LibUI) project utilizing the [Glimmer GUI DSL](#glimmer-gui-dsl-concepts) (with and without data-binding) as well as brand new examples.
|
1891
|
+
The following examples include reimplementions of the examples in the [LibUI](https://github.com/kojix2/LibUI) project utilizing the [Glimmer GUI DSL](#glimmer-gui-dsl-concepts) (with and without [data-binding](#data-binding)) as well as brand new examples.
|
1882
1892
|
|
1883
1893
|
To browse all examples, simply launch the [Meta-Example](examples/meta_example.rb), which lists all examples and displays each example's code when selected. It also enables code editing to facilitate experimentation and learning.
|
1884
1894
|
|
@@ -2668,7 +2678,35 @@ UI.main
|
|
2668
2678
|
UI.quit
|
2669
2679
|
```
|
2670
2680
|
|
2671
|
-
[Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
|
2681
|
+
[Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version (with [data-binding](#data-binding)):
|
2682
|
+
|
2683
|
+
```ruby
|
2684
|
+
require 'glimmer-dsl-libui'
|
2685
|
+
|
2686
|
+
class DateTimePicker
|
2687
|
+
include Glimmer
|
2688
|
+
|
2689
|
+
attr_accessor :picked_time
|
2690
|
+
|
2691
|
+
def launch
|
2692
|
+
window('Date Time Pickers', 300, 200) {
|
2693
|
+
vertical_box {
|
2694
|
+
date_time_picker {
|
2695
|
+
time <=> [self, :picked_time, after_write: ->(time) { p time }]
|
2696
|
+
}
|
2697
|
+
}
|
2698
|
+
|
2699
|
+
on_closing do
|
2700
|
+
puts 'Bye Bye'
|
2701
|
+
end
|
2702
|
+
}.show
|
2703
|
+
end
|
2704
|
+
end
|
2705
|
+
|
2706
|
+
DateTimePicker.new.launch
|
2707
|
+
```
|
2708
|
+
|
2709
|
+
[Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version 2 (without [data-binding](#data-binding)):
|
2672
2710
|
|
2673
2711
|
```ruby
|
2674
2712
|
require 'glimmer-dsl-libui'
|
@@ -7852,7 +7890,181 @@ end
|
|
7852
7890
|
TinyMidiPlayer.new
|
7853
7891
|
```
|
7854
7892
|
|
7855
|
-
[Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version:
|
7893
|
+
[Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version (with [data-binding](#data-binding)):
|
7894
|
+
|
7895
|
+
```ruby
|
7896
|
+
# frozen_string_literal: true
|
7897
|
+
|
7898
|
+
require 'glimmer-dsl-libui'
|
7899
|
+
|
7900
|
+
class TinyMidiPlayer
|
7901
|
+
include Glimmer
|
7902
|
+
|
7903
|
+
VERSION = '0.0.1'
|
7904
|
+
|
7905
|
+
attr_accessor :selected_file
|
7906
|
+
|
7907
|
+
def initialize
|
7908
|
+
@pid = nil
|
7909
|
+
@music_directory = File.expand_path('../sounds', __dir__)
|
7910
|
+
@midi_files = Dir.glob(File.join(@music_directory, '**/*.mid'))
|
7911
|
+
.sort_by { |path| File.basename(path) }
|
7912
|
+
at_exit { stop_midi }
|
7913
|
+
create_gui
|
7914
|
+
end
|
7915
|
+
|
7916
|
+
def stop_midi
|
7917
|
+
if @pid
|
7918
|
+
Process.kill(:SIGKILL, @pid) if @th.alive?
|
7919
|
+
@pid = nil
|
7920
|
+
end
|
7921
|
+
end
|
7922
|
+
|
7923
|
+
def play_midi
|
7924
|
+
stop_midi
|
7925
|
+
if @pid.nil? && @selected_file
|
7926
|
+
begin
|
7927
|
+
@pid = spawn "timidity #{@selected_file}"
|
7928
|
+
@th = Process.detach @pid
|
7929
|
+
rescue Errno::ENOENT
|
7930
|
+
warn 'Timidty++ not found. Please install Timidity++.'
|
7931
|
+
warn 'https://sourceforge.net/projects/timidity/'
|
7932
|
+
end
|
7933
|
+
end
|
7934
|
+
end
|
7935
|
+
|
7936
|
+
def show_version
|
7937
|
+
msg_box('Tiny Midi Player',
|
7938
|
+
"Written in Ruby\n" \
|
7939
|
+
"https://github.com/kojix2/libui\n" \
|
7940
|
+
"Version #{VERSION}")
|
7941
|
+
end
|
7942
|
+
|
7943
|
+
def create_gui
|
7944
|
+
menu('Help') {
|
7945
|
+
menu_item('Version') {
|
7946
|
+
on_clicked do
|
7947
|
+
show_version
|
7948
|
+
end
|
7949
|
+
}
|
7950
|
+
}
|
7951
|
+
window('Tiny Midi Player', 200, 50) {
|
7952
|
+
horizontal_box {
|
7953
|
+
vertical_box {
|
7954
|
+
stretchy false
|
7955
|
+
|
7956
|
+
button('▶') {
|
7957
|
+
on_clicked do
|
7958
|
+
play_midi
|
7959
|
+
end
|
7960
|
+
}
|
7961
|
+
button('■') {
|
7962
|
+
on_clicked do
|
7963
|
+
stop_midi
|
7964
|
+
end
|
7965
|
+
}
|
7966
|
+
}
|
7967
|
+
|
7968
|
+
combobox { |c|
|
7969
|
+
items @midi_files.map { |path| File.basename(path) }
|
7970
|
+
# data-bind selected item (String) to self.selected_file with on-read/on-write converters and after_write operation
|
7971
|
+
selected_item <=> [self, :selected_file, on_read: ->(f) {File.basename(f.to_s)}, on_write: ->(f) {File.join(@music_directory, f)}, after_write: -> { play_midi if @th&.alive? }]
|
7972
|
+
}
|
7973
|
+
}
|
7974
|
+
}.show
|
7975
|
+
end
|
7976
|
+
end
|
7977
|
+
|
7978
|
+
TinyMidiPlayer.new
|
7979
|
+
```
|
7980
|
+
|
7981
|
+
[Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version 2 (with [data-binding](#data-binding)):
|
7982
|
+
|
7983
|
+
```ruby
|
7984
|
+
require 'glimmer-dsl-libui'
|
7985
|
+
|
7986
|
+
class TinyMidiPlayer
|
7987
|
+
include Glimmer
|
7988
|
+
|
7989
|
+
VERSION = '0.0.1'
|
7990
|
+
|
7991
|
+
attr_accessor :selected_file
|
7992
|
+
|
7993
|
+
def initialize
|
7994
|
+
@pid = nil
|
7995
|
+
@music_directory = File.expand_path('../sounds', __dir__)
|
7996
|
+
@midi_files = Dir.glob(File.join(@music_directory, '**/*.mid'))
|
7997
|
+
.sort_by { |path| File.basename(path) }
|
7998
|
+
at_exit { stop_midi }
|
7999
|
+
create_gui
|
8000
|
+
end
|
8001
|
+
|
8002
|
+
def stop_midi
|
8003
|
+
if @pid
|
8004
|
+
Process.kill(:SIGKILL, @pid) if @th.alive?
|
8005
|
+
@pid = nil
|
8006
|
+
end
|
8007
|
+
end
|
8008
|
+
|
8009
|
+
def play_midi
|
8010
|
+
stop_midi
|
8011
|
+
if @pid.nil? && @selected_file
|
8012
|
+
begin
|
8013
|
+
@pid = spawn "timidity #{@selected_file}"
|
8014
|
+
@th = Process.detach @pid
|
8015
|
+
rescue Errno::ENOENT
|
8016
|
+
warn 'Timidty++ not found. Please install Timidity++.'
|
8017
|
+
warn 'https://sourceforge.net/projects/timidity/'
|
8018
|
+
end
|
8019
|
+
end
|
8020
|
+
end
|
8021
|
+
|
8022
|
+
def show_version
|
8023
|
+
msg_box('Tiny Midi Player',
|
8024
|
+
"Written in Ruby\n" \
|
8025
|
+
"https://github.com/kojix2/libui\n" \
|
8026
|
+
"Version #{VERSION}")
|
8027
|
+
end
|
8028
|
+
|
8029
|
+
def create_gui
|
8030
|
+
menu('Help') {
|
8031
|
+
menu_item('Version') {
|
8032
|
+
on_clicked do
|
8033
|
+
show_version
|
8034
|
+
end
|
8035
|
+
}
|
8036
|
+
}
|
8037
|
+
window('Tiny Midi Player', 200, 50) {
|
8038
|
+
horizontal_box {
|
8039
|
+
vertical_box {
|
8040
|
+
stretchy false
|
8041
|
+
|
8042
|
+
button('▶') {
|
8043
|
+
on_clicked do
|
8044
|
+
play_midi
|
8045
|
+
end
|
8046
|
+
}
|
8047
|
+
button('■') {
|
8048
|
+
on_clicked do
|
8049
|
+
stop_midi
|
8050
|
+
end
|
8051
|
+
}
|
8052
|
+
}
|
8053
|
+
|
8054
|
+
combobox { |c|
|
8055
|
+
items @midi_files.map { |path| File.basename(path) }
|
8056
|
+
# data-bind selected index (Integer) to self.selected_file with on-read/on-write converters and after_write operation
|
8057
|
+
selected <=> [self, :selected_file, on_read: ->(f) {@midi_files.index(f)}, on_write: ->(i) {@midi_files[i]}, after_write: -> { play_midi if @th&.alive? }]
|
8058
|
+
}
|
8059
|
+
}
|
8060
|
+
}.show
|
8061
|
+
end
|
8062
|
+
end
|
8063
|
+
|
8064
|
+
TinyMidiPlayer.new
|
8065
|
+
```
|
8066
|
+
|
8067
|
+
[Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) Version 3 (without [data-binding](#data-binding)):
|
7856
8068
|
|
7857
8069
|
```ruby
|
7858
8070
|
require 'glimmer-dsl-libui'
|
@@ -8869,7 +9081,7 @@ https://github.com/iraamaro/i3off-gtk-ruby
|
|
8869
9081
|
|
8870
9082
|
### Issues
|
8871
9083
|
|
8872
|
-
If you encounter [issues](https://github.com/AndyObtiva/glimmer-dsl-libui/issues) that are not reported, discover missing features that are not mentioned in [TODO.md](TODO.md), or think up better ways to use [libui](https://github.com/andlabs/libui) than what is possible with [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui), you may submit an [issue](https://github.com/AndyObtiva/glimmer-dsl-libui/issues/new) or [pull request](https://github.com/AndyObtiva/glimmer-dsl-libui/compare) on [GitHub](https://github.com).
|
9084
|
+
If you encounter [issues](https://github.com/AndyObtiva/glimmer-dsl-libui/issues) that are not reported, discover missing features that are not mentioned in [TODO.md](TODO.md), or think up better ways to use [libui](https://github.com/andlabs/libui) than what is possible with [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui), you may submit an [issue](https://github.com/AndyObtiva/glimmer-dsl-libui/issues/new) or [pull request](https://github.com/AndyObtiva/glimmer-dsl-libui/compare) on [GitHub](https://github.com). In the meantime, you may try older gem versions of [Glimmer DSL for LibUI](https://rubygems.org/gems/glimmer-dsl-libui) till you find one that works until issues are resolved.
|
8873
9085
|
|
8874
9086
|
### Chat
|
8875
9087
|
|
@@ -8901,6 +9113,8 @@ These features have been planned or suggested. You might see them in a future ve
|
|
8901
9113
|
is fine, but please isolate to its own commit so I can cherry-pick
|
8902
9114
|
around it.
|
8903
9115
|
|
9116
|
+
Note that the latest development sometimes takes place in [development](https://github.com/AndyObtiva/glimmer-dsl-libui/tree/development) branch (which is deleted once merged back to [master](https://github.com/AndyObtiva/glimmer-dsl-libui)).
|
9117
|
+
|
8904
9118
|
## Contributors
|
8905
9119
|
|
8906
9120
|
* [Andy Maleh](https://github.com/AndyObtiva) (Founder)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.7
|
@@ -2,19 +2,24 @@
|
|
2
2
|
|
3
3
|
require 'glimmer-dsl-libui'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
date_time_picker { |dtp|
|
10
|
-
on_changed do
|
11
|
-
time = dtp.time
|
12
|
-
p time
|
13
|
-
end
|
14
|
-
}
|
15
|
-
}
|
5
|
+
class DateTimePicker
|
6
|
+
include Glimmer
|
7
|
+
|
8
|
+
attr_accessor :picked_time
|
16
9
|
|
17
|
-
|
18
|
-
|
10
|
+
def launch
|
11
|
+
window('Date Time Pickers', 300, 200) {
|
12
|
+
vertical_box {
|
13
|
+
date_time_picker {
|
14
|
+
time <=> [self, :picked_time, after_write: ->(time) { p time }]
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
on_closing do
|
19
|
+
puts 'Bye Bye'
|
20
|
+
end
|
21
|
+
}.show
|
19
22
|
end
|
20
|
-
|
23
|
+
end
|
24
|
+
|
25
|
+
DateTimePicker.new.launch
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'glimmer-dsl-libui'
|
4
|
+
|
5
|
+
include Glimmer
|
6
|
+
|
7
|
+
window('Date Time Pickers', 300, 200) {
|
8
|
+
vertical_box {
|
9
|
+
date_time_picker { |dtp|
|
10
|
+
on_changed do
|
11
|
+
time = dtp.time
|
12
|
+
p time
|
13
|
+
end
|
14
|
+
}
|
15
|
+
}
|
16
|
+
|
17
|
+
on_closing do
|
18
|
+
puts 'Bye Bye'
|
19
|
+
end
|
20
|
+
}.show
|
data/examples/midi_player.rb
CHANGED
@@ -6,6 +6,8 @@ class TinyMidiPlayer
|
|
6
6
|
include Glimmer
|
7
7
|
|
8
8
|
VERSION = '0.0.1'
|
9
|
+
|
10
|
+
attr_accessor :selected_file
|
9
11
|
|
10
12
|
def initialize
|
11
13
|
@pid = nil
|
@@ -70,11 +72,8 @@ class TinyMidiPlayer
|
|
70
72
|
|
71
73
|
combobox { |c|
|
72
74
|
items @midi_files.map { |path| File.basename(path) }
|
73
|
-
|
74
|
-
|
75
|
-
@selected_file = @midi_files[c.selected]
|
76
|
-
play_midi if @th&.alive?
|
77
|
-
end
|
75
|
+
# data-bind selected item (String) to self.selected_file with on-read/on-write converters and after_write operation
|
76
|
+
selected_item <=> [self, :selected_file, on_read: ->(f) {File.basename(f.to_s)}, on_write: ->(f) {File.join(@music_directory, f)}, after_write: -> { play_midi if @th&.alive? }]
|
78
77
|
}
|
79
78
|
}
|
80
79
|
}.show
|
@@ -0,0 +1,83 @@
|
|
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
|
+
attr_accessor :selected_file
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@pid = nil
|
14
|
+
@music_directory = File.expand_path('../sounds', __dir__)
|
15
|
+
@midi_files = Dir.glob(File.join(@music_directory, '**/*.mid'))
|
16
|
+
.sort_by { |path| File.basename(path) }
|
17
|
+
at_exit { stop_midi }
|
18
|
+
create_gui
|
19
|
+
end
|
20
|
+
|
21
|
+
def stop_midi
|
22
|
+
if @pid
|
23
|
+
Process.kill(:SIGKILL, @pid) if @th.alive?
|
24
|
+
@pid = nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def play_midi
|
29
|
+
stop_midi
|
30
|
+
if @pid.nil? && @selected_file
|
31
|
+
begin
|
32
|
+
@pid = spawn "timidity #{@selected_file}"
|
33
|
+
@th = Process.detach @pid
|
34
|
+
rescue Errno::ENOENT
|
35
|
+
warn 'Timidty++ not found. Please install Timidity++.'
|
36
|
+
warn 'https://sourceforge.net/projects/timidity/'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def show_version
|
42
|
+
msg_box('Tiny Midi Player',
|
43
|
+
"Written in Ruby\n" \
|
44
|
+
"https://github.com/kojix2/libui\n" \
|
45
|
+
"Version #{VERSION}")
|
46
|
+
end
|
47
|
+
|
48
|
+
def create_gui
|
49
|
+
menu('Help') {
|
50
|
+
menu_item('Version') {
|
51
|
+
on_clicked do
|
52
|
+
show_version
|
53
|
+
end
|
54
|
+
}
|
55
|
+
}
|
56
|
+
window('Tiny Midi Player', 200, 50) {
|
57
|
+
horizontal_box {
|
58
|
+
vertical_box {
|
59
|
+
stretchy false
|
60
|
+
|
61
|
+
button('▶') {
|
62
|
+
on_clicked do
|
63
|
+
play_midi
|
64
|
+
end
|
65
|
+
}
|
66
|
+
button('■') {
|
67
|
+
on_clicked do
|
68
|
+
stop_midi
|
69
|
+
end
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
combobox { |c|
|
74
|
+
items @midi_files.map { |path| File.basename(path) }
|
75
|
+
# data-bind selected index (Integer) to self.selected_file with on-read/on-write converters and after_write operation
|
76
|
+
selected <=> [self, :selected_file, on_read: ->(f) {@midi_files.index(f)}, on_write: ->(i) {@midi_files[i]}, after_write: -> { play_midi if @th&.alive? }]
|
77
|
+
}
|
78
|
+
}
|
79
|
+
}.show
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
TinyMidiPlayer.new
|
@@ -0,0 +1,84 @@
|
|
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('../sounds', __dir__)
|
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
|
+
Process.kill(:SIGKILL, @pid) if @th.alive?
|
22
|
+
@pid = nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def play_midi
|
27
|
+
stop_midi
|
28
|
+
if @pid.nil? && @selected_file
|
29
|
+
begin
|
30
|
+
@pid = spawn "timidity #{@selected_file}"
|
31
|
+
@th = Process.detach @pid
|
32
|
+
rescue Errno::ENOENT
|
33
|
+
warn 'Timidty++ not found. Please install Timidity++.'
|
34
|
+
warn 'https://sourceforge.net/projects/timidity/'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def show_version
|
40
|
+
msg_box('Tiny Midi Player',
|
41
|
+
"Written in Ruby\n" \
|
42
|
+
"https://github.com/kojix2/libui\n" \
|
43
|
+
"Version #{VERSION}")
|
44
|
+
end
|
45
|
+
|
46
|
+
def create_gui
|
47
|
+
menu('Help') {
|
48
|
+
menu_item('Version') {
|
49
|
+
on_clicked do
|
50
|
+
show_version
|
51
|
+
end
|
52
|
+
}
|
53
|
+
}
|
54
|
+
window('Tiny Midi Player', 200, 50) {
|
55
|
+
horizontal_box {
|
56
|
+
vertical_box {
|
57
|
+
stretchy false
|
58
|
+
|
59
|
+
button('▶') {
|
60
|
+
on_clicked do
|
61
|
+
play_midi
|
62
|
+
end
|
63
|
+
}
|
64
|
+
button('■') {
|
65
|
+
on_clicked do
|
66
|
+
stop_midi
|
67
|
+
end
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
combobox { |c|
|
72
|
+
items @midi_files.map { |path| File.basename(path) }
|
73
|
+
|
74
|
+
on_selected do
|
75
|
+
@selected_file = @midi_files[c.selected]
|
76
|
+
play_midi if @th&.alive?
|
77
|
+
end
|
78
|
+
}
|
79
|
+
}
|
80
|
+
}.show
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
TinyMidiPlayer.new
|
data/glimmer-dsl-libui.gemspec
CHANGED
Binary file
|
@@ -54,8 +54,24 @@ module Glimmer
|
|
54
54
|
alias set_items items
|
55
55
|
alias items= items
|
56
56
|
|
57
|
-
def selected_item
|
58
|
-
|
57
|
+
def selected_item(value = nil)
|
58
|
+
if value.nil?
|
59
|
+
items[selected]
|
60
|
+
else
|
61
|
+
self.selected = items.index(value)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
alias set_selected_item selected_item
|
65
|
+
alias selected_item= selected_item
|
66
|
+
|
67
|
+
def data_bind(property, model_binding)
|
68
|
+
super
|
69
|
+
case property
|
70
|
+
when 'selected'
|
71
|
+
handle_listener('on_selected') { model_binding.call(selected) }
|
72
|
+
when 'selected_item'
|
73
|
+
handle_listener('on_selected') { model_binding.call(selected_item) }
|
74
|
+
end
|
59
75
|
end
|
60
76
|
end
|
61
77
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glimmer-dsl-libui
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Maleh
|
@@ -253,6 +253,7 @@ files:
|
|
253
253
|
- examples/custom_draw_text.rb
|
254
254
|
- examples/custom_draw_text2.rb
|
255
255
|
- examples/date_time_picker.rb
|
256
|
+
- examples/date_time_picker2.rb
|
256
257
|
- examples/dynamic_area.rb
|
257
258
|
- examples/dynamic_area2.rb
|
258
259
|
- examples/dynamic_area3.rb
|
@@ -277,6 +278,8 @@ files:
|
|
277
278
|
- examples/method_based_custom_keyword.rb
|
278
279
|
- examples/method_based_custom_keyword2.rb
|
279
280
|
- examples/midi_player.rb
|
281
|
+
- examples/midi_player2.rb
|
282
|
+
- examples/midi_player3.rb
|
280
283
|
- examples/simple_notepad.rb
|
281
284
|
- examples/snake.rb
|
282
285
|
- examples/snake/model/apple.rb
|