glimmer-dsl-tk 0.0.1 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.6
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env bash
2
+
3
+ GIRB_RUNNER="$(realpath $(dirname $0))/girb_runner.rb"
4
+
5
+ irb $@ -r $GIRB_RUNNER
6
+
7
+ if !(test -f ~/.girb_runner_exit); then
8
+ rm -rf ~/.girb_runner_exit
9
+ exec $0
10
+ fi
@@ -0,0 +1,26 @@
1
+ require 'puts_debuggerer'
2
+ require 'fileutils'
3
+ require 'etc'
4
+
5
+ require_relative '../lib/glimmer-dsl-tk'
6
+
7
+ include Glimmer
8
+
9
+ GIRB_RUNNER_EXIT_FILE = "#{Etc.getpwuid.dir}/.girb_runner_exit"
10
+ FileUtils.rm_rf GIRB_RUNNER_EXIT_FILE
11
+
12
+ @exit_method = method(:exit)
13
+
14
+ @exit_girb_block = lambda do
15
+ FileUtils.touch GIRB_RUNNER_EXIT_FILE
16
+ end
17
+
18
+ def self.exit(*args)
19
+ @exit_girb_block.call
20
+ @exit_method.call(*args)
21
+ end
22
+
23
+ def self.quit(*args)
24
+ @exit_girb_block.call
25
+ @exit_method.call(*args)
26
+ end
@@ -23,9 +23,9 @@ $LOAD_PATH.unshift(File.expand_path('..', __FILE__))
23
23
 
24
24
  # External requires
25
25
  require 'glimmer'
26
- require 'logging'
27
- # require 'puts_debuggerer'
28
- require 'super_module'
26
+ # require 'logging'
27
+ require 'puts_debuggerer' if ENV['pd'].to_s.downcase == 'true'
28
+ # require 'super_module'
29
29
  require 'tk'
30
30
 
31
31
  # Internal requires
@@ -0,0 +1,75 @@
1
+ # Copyright (c) 2020 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/data_binding/observable'
23
+ require 'glimmer/data_binding/observer'
24
+
25
+ module Glimmer
26
+ module DataBinding
27
+ module Tk
28
+ # Tk List widget selection binding
29
+ class ListSelectionBinding
30
+ include Glimmer
31
+ include Observable
32
+ include Observer
33
+
34
+ attr_reader :widget_proxy
35
+
36
+ PROPERTY_TYPE_UPDATERS = {
37
+ :string => lambda do |widget_proxy, value|
38
+ widget_proxy.selection = value.to_s
39
+ end,
40
+ :array => lambda do |widget_proxy, value|
41
+ widget_proxy.selection = (value || [])
42
+ end
43
+ }
44
+
45
+ PROPERTY_EVALUATORS = {
46
+ :string => lambda do |selection_array|
47
+ return nil if selection_array.empty?
48
+ selection_array.map(&:text)[0]
49
+ end,
50
+ :array => lambda do |selection_array|
51
+ selection_array.map(&:text)
52
+ end
53
+ }
54
+
55
+ # Initialize with list widget and property_type
56
+ # property_type :string represents default list single selection
57
+ # property_type :array represents list multi selection
58
+ def initialize(widget_proxy)
59
+ property_type = widget_proxy.selectmode == 'browse' ? :string : :array
60
+ @widget_proxy = widget_proxy
61
+ @property_type = property_type
62
+ end
63
+
64
+ def call(value)
65
+ PROPERTY_TYPE_UPDATERS[@property_type].call(@widget_proxy, value) unless evaluate_property == value
66
+ end
67
+
68
+ def evaluate_property
69
+ selection_array = @widget_proxy.tk.selection.to_a
70
+ PROPERTY_EVALUATORS[@property_type].call(selection_array)
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,28 @@
1
+ require 'glimmer/data_binding/observable'
2
+ require 'glimmer/data_binding/observer'
3
+
4
+ module Glimmer
5
+ module DataBinding
6
+ module Tk
7
+ class WidgetBinding
8
+ include Glimmer
9
+ include Observable
10
+ include Observer
11
+
12
+ attr_reader :widget, :attribute
13
+ def initialize(widget, attribute)
14
+ @widget = widget
15
+ @attribute = attribute
16
+ end
17
+
18
+ def call(value)
19
+ @widget.set_attribute(@attribute, value) unless evaluate_attribute == value
20
+ end
21
+
22
+ def evaluate_attribute
23
+ @widget.get_attribute(@attribute)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,36 @@
1
+ require 'glimmer/dsl/static_expression'
2
+ require 'glimmer/data_binding/model_binding'
3
+
4
+ module Glimmer
5
+ module DSL
6
+ module Tk
7
+ # Responsible for setting up the return value of the bind keyword (command symbol)
8
+ # as a ModelBinding. It is then used by another command handler like
9
+ # DataBindingCommandHandler for text and other attributes
10
+ class BindExpression < StaticExpression
11
+ def can_interpret?(parent, keyword, *args, &block)
12
+ (
13
+ keyword == 'bind' and
14
+ (
15
+ (
16
+ (args.size == 2) and
17
+ textual?(args[1])
18
+ ) ||
19
+ (
20
+ (args.size == 3) and
21
+ textual?(args[1]) and
22
+ (args[2].is_a?(Hash))
23
+ )
24
+ )
25
+ )
26
+ end
27
+
28
+ def interpret(parent, keyword, *args, &block)
29
+ binding_options = args[2] || {}
30
+ binding_options[:on_read] = binding_options.delete(:on_read) || binding_options.delete('on_read') || block
31
+ DataBinding::ModelBinding.new(args[0], args[1].to_s, binding_options)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,41 @@
1
+ # Copyright (c) 2020 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/dsl/expression'
23
+
24
+ module Glimmer
25
+ module DSL
26
+ module Tk
27
+ class BlockAttributeExpression < Expression
28
+ def can_interpret?(parent, keyword, *args, &block)
29
+ block_given? and
30
+ args.size == 0 and
31
+ parent.respond_to?("#{keyword}_block=")
32
+ end
33
+
34
+ def interpret(parent, keyword, *args, &block)
35
+ parent.send("#{keyword}_block=", block)
36
+ nil
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,33 @@
1
+ require 'glimmer/dsl/expression'
2
+ require 'glimmer/data_binding/model_binding'
3
+ require 'glimmer/data_binding/tk/widget_binding'
4
+
5
+ module Glimmer
6
+ module DSL
7
+ module Tk
8
+ # Responsible for wiring two-way data-binding.
9
+ # Does so by using the output of the bind(model, property) command in the form
10
+ # of a ModelBinding, which is then connected to an anonymous widget observer
11
+ #
12
+ # Depends on BindCommandHandler
13
+ class DataBindingExpression < Expression
14
+ def can_interpret?(parent, keyword, *args, &block)
15
+ args.size == 1 and
16
+ args[0].is_a?(DataBinding::ModelBinding)
17
+ end
18
+
19
+ def interpret(parent, keyword, *args, &block)
20
+ parent.class
21
+ model_binding = args[0]
22
+ widget_binding_parameters = [parent, keyword]
23
+ widget_binding = DataBinding::Tk::WidgetBinding.new(*widget_binding_parameters)
24
+ #TODO make this options observer dependent and all similar observers in widget specific data binding handlers
25
+ widget_binding.observe(model_binding)
26
+ # TODO simplify this logic and put it where it belongs
27
+ parent.add_observer(model_binding, keyword) if parent.respond_to?(:add_observer, [model_binding, keyword])
28
+ widget_binding.call(model_binding.evaluate_property)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -36,6 +36,9 @@ module Glimmer
36
36
  Engine.add_dynamic_expressions(
37
37
  Tk,
38
38
  %w[
39
+ list_selection_data_binding
40
+ data_binding
41
+ block_attribute
39
42
  attribute
40
43
  widget
41
44
  ]
@@ -0,0 +1,60 @@
1
+ # Copyright (c) 2020 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/dsl/expression'
23
+ require 'glimmer/data_binding/model_binding'
24
+ require 'glimmer/data_binding/tk/widget_binding'
25
+ require 'glimmer/data_binding/tk/list_selection_binding'
26
+
27
+ module Glimmer
28
+ module DSL
29
+ module Tk
30
+ class ListSelectionDataBindingExpression < Expression
31
+ def can_interpret?(parent, keyword, *args, &block)
32
+ keyword == 'selection' and
33
+ block.nil? and
34
+ parent.is_a?(Glimmer::Tk::ListProxy) and
35
+ args.size == 1 and
36
+ args[0].is_a?(DataBinding::ModelBinding) and
37
+ args[0].evaluate_options_property.is_a?(Array)
38
+ end
39
+
40
+ def interpret(parent, keyword, *args, &block)
41
+ model_binding = args[0]
42
+ widget_binding = DataBinding::Tk::WidgetBinding.new(parent, 'items')
43
+ widget_binding.call(model_binding.evaluate_options_property)
44
+ model = model_binding.base_model
45
+ #TODO make this options observer dependent and all similar observers in widget specific data binding interpretrs
46
+ widget_binding.observe(model, model_binding.options_property_name)
47
+
48
+ list_selection_binding = DataBinding::Tk::ListSelectionBinding.new(parent)
49
+ list_selection_binding.call(model_binding.evaluate_property)
50
+ #TODO check if nested data binding works for list widget and other widgets that need custom data binding
51
+ list_selection_binding.observe(model, model_binding.property_name_expression)
52
+
53
+ parent.tk.bind('<TreeviewSelect>') do
54
+ model_binding.call(list_selection_binding.evaluate_property)
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -33,12 +33,12 @@ module Glimmer
33
33
 
34
34
  def can_interpret?(parent, keyword, *args, &block)
35
35
  !EXCLUDED_KEYWORDS.include?(keyword) and
36
- parent.respond_to?(:tk_widget) and
36
+ parent.respond_to?(:tk) and
37
37
  Glimmer::Tk::WidgetProxy.widget_exists?(keyword)
38
38
  end
39
39
 
40
40
  def interpret(parent, keyword, *args, &block)
41
- Glimmer::Tk::WidgetProxy.new(keyword, parent, args, &block)
41
+ Glimmer::Tk::WidgetProxy.create(keyword, parent, args, &block)
42
42
  end
43
43
 
44
44
  def add_content(parent, &block)
@@ -52,3 +52,9 @@ module Glimmer
52
52
  end
53
53
 
54
54
  require 'glimmer/tk/widget_proxy'
55
+ require 'glimmer/tk/notebook_proxy'
56
+ require 'glimmer/tk/frame_proxy'
57
+ require 'glimmer/tk/button_proxy'
58
+ require 'glimmer/tk/label_proxy'
59
+ require 'glimmer/tk/list_proxy'
60
+ require 'glimmer/tk/entry_proxy'
@@ -0,0 +1,35 @@
1
+ # Copyright (c) 2020 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/tk/widget_proxy'
23
+
24
+ module Glimmer
25
+ module Tk
26
+ # Proxy for Tk::Tile::Button
27
+ #
28
+ # Follows the Proxy Design Pattern
29
+ class ButtonProxy < WidgetProxy
30
+ def command_block=(proc)
31
+ tk.command(proc)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,38 @@
1
+ # Copyright (c) 2020 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/tk/widget_proxy'
23
+
24
+ module Glimmer
25
+ module Tk
26
+ # Proxy for Tk::Tile::TEntry
27
+ #
28
+ # Follows the Proxy Design Pattern
29
+ class EntryProxy < WidgetProxy
30
+ def validatecommand_block=(proc)
31
+ tk.validatecommand(proc)
32
+ end
33
+ def invalidcommand_block=(proc)
34
+ tk.invalidcommand(proc)
35
+ end
36
+ end
37
+ end
38
+ end