glimmer-dsl-tk 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 45310155a2c33c5c9ba6cbdf0b1c531a7c56b7eebe746ccaacfc28cbfb5dfa41
4
+ data.tar.gz: eb2b64327e24ff90ce3f674248b957d79fb89fab694bfe4d9795d582083552dd
5
+ SHA512:
6
+ metadata.gz: '096cb8daf02fe1cdc0aab75a143461e658fd0fd95dd9629b19d43f3cf7a274cacf9fa3daec404bbd5ec70534d28e80659579c5262b2006c02de51181b7c91398'
7
+ data.tar.gz: c20e4aef88e707f438d7fc44f5293b832430e4e8a38c46a32a53e3fac42aaccf13f80c3130ea3b080a5948432ba98315733c94c7164161d3fab7f9b6053278c5
@@ -0,0 +1,5 @@
1
+ # Change Log
2
+
3
+ ## 0.0.1
4
+
5
+ - Initial Glimmer DSL for TK implementation to support Hello, World!
@@ -0,0 +1,20 @@
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.
@@ -0,0 +1,121 @@
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 Tk 0.0.1 (Desktop GUI)
2
+ [![Gem Version](https://badge.fury.io/rb/glimmer-dsl-tk.svg)](http://badge.fury.io/rb/glimmer-dsl-tk)
3
+ [![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)
4
+
5
+ [Glimmer](https://github.com/AndyObtiva/glimmer) DSL for [Tk](https://www.tcl.tk/) enables desktop development with [Glimmer](https://github.com/AndyObtiva/glimmer).
6
+
7
+ [Tcl/Tk](https://www.tcl.tk/) has evolved into a practical desktop GUI toolkit due to gaining true native widgets on Mac, Windows, and Linux in Tk version 8.5.
8
+
9
+ Additionally, Ruby 3.0 supports truly parallel multi-threading, making both [MRI](https://github.com/ruby/ruby) and [Tk](https://www.tcl.tk/) finally viable for support in [Glimmer](https://github.com/AndyObtiva/glimmer) (Ruby Desktop Development GUI Library).
10
+
11
+ [Glimmer](https://github.com/AndyObtiva/glimmer) provides a DSL to enable more productive desktop development in Ruby with:
12
+ - Declarative DSL syntax that visually maps to the GUI widget hierarchy
13
+ - Convention over configuration via smart defaults and automation of low-level details
14
+ - Requiring the least amount of syntax possible to build GUI
15
+ - Scaffolding for new custom widgets, apps, and gems
16
+ - Native-Executable packaging on Mac, Windows, and Linux
17
+
18
+ Other [Glimmer](https://github.com/AndyObtiva/glimmer) DSL gems:
19
+ - [glimmer-dsl-swt](https://github.com/AndyObtiva/glimmer-dsl-swt): Glimmer DSL for SWT (Desktop GUI via JRuby on SWT)
20
+ - [glimmer-dsl-opal](https://github.com/AndyObtiva/glimmer-dsl-opal): Glimmer DSL for Opal (Web GUI Adapter for Desktop Apps)
21
+ - [glimmer-dsl-xml](https://github.com/AndyObtiva/glimmer-dsl-xml): Glimmer DSL for XML (& HTML)
22
+ - [glimmer-dsl-css](https://github.com/AndyObtiva/glimmer-dsl-css): Glimmer DSL for CSS (Cascading Style Sheets)
23
+
24
+ ## Pre-requisites
25
+
26
+ - [Tcl/Tk](https://www.tcl.tk/): Follow the [install instructions](https://tkdocs.com/tutorial/install.html)
27
+ - [Ruby](https://www.ruby-lang.org/en/): On Windows, obtain from the Ruby [download page](https://www.ruby-lang.org/en/downloads/). On the Mac and Linux, it is more convenient to just use [RVM](http://rvm.io) and follow the [RVM Tk instructions](https://rvm.io/integration/tk).
28
+
29
+ For example, on the Mac, you can:
30
+ - Install the ActiveTcl Mac package from [ActiveState.com](ActiveState.com)
31
+ - Install [RVM](https://rvm.io/) by running `\curl -sSL https://get.rvm.io | bash -s stable` (and run `curl -sSL https://rvm.io/pkuczynski.asc | gpg --import -` if needed for mentioned security reasons)
32
+ - Run: `rvm install 2.7.1 --enable-shared --enable-pthread --with-tk --with-tcl`
33
+
34
+ Afterwards, if you open `irb`, you should be able to run `require 'tk'` successfully.
35
+
36
+ ## Setup
37
+
38
+ ### Option 1: Install
39
+
40
+ Run this command to install directly:
41
+ ```
42
+ gem install glimmer-dsl-tk
43
+ ```
44
+
45
+ ### Option 2: Bundler
46
+
47
+ Add the following to `Gemfile`:
48
+ ```
49
+ gem 'glimmer-dsl-tk', '~> 0.0.1'
50
+ ```
51
+
52
+ And, then run:
53
+ ```
54
+ bundle
55
+ ```
56
+
57
+ ## Example
58
+
59
+ ### Hello, World!:
60
+
61
+ Glimmer code (from [samples/hello/hello_world.rb](samples/hello/hello_world.rb)):
62
+
63
+ ```ruby
64
+ root {
65
+ label {
66
+ text 'Hello, World!'
67
+ }
68
+ }.open
69
+ ```
70
+
71
+ Run:
72
+
73
+ ```
74
+ ruby samples/hello/hello_world.rb
75
+ ```
76
+
77
+ Glimmer app:
78
+
79
+ ![glimmer dsl tk screenshot sample hello world](images/glimmer-dsl-tk-screenshot-sample-hello-world.png)
80
+
81
+ ## Help
82
+
83
+ ### Issues
84
+
85
+ You may submit [issues](https://github.com/AndyObtiva/glimmer/issues) on [GitHub](https://github.com/AndyObtiva/glimmer/issues).
86
+
87
+ [Click here to submit an issue.](https://github.com/AndyObtiva/glimmer/issues)
88
+
89
+ ### Chat
90
+
91
+ If you need live help, try to [![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)
92
+
93
+ ## Feature Suggestions
94
+
95
+ These features have been suggested. You might see them in a future version of Glimmer. You are welcome to contribute more feature suggestions.
96
+
97
+ [TODO.md](TODO.md)
98
+
99
+ ## Change Log
100
+
101
+ [CHANGELOG.md](CHANGELOG.md)
102
+
103
+ ## Contributing
104
+
105
+ [CONTRIBUTING.md](CONTRIBUTING.md)
106
+
107
+ ## Contributors
108
+
109
+ * [Andy Maleh](https://github.com/AndyObtiva) (Founder)
110
+
111
+ [Click here to view contributor commits.](https://github.com/AndyObtiva/glimmer-dsl-swt/graphs/contributors)
112
+
113
+ ## License
114
+
115
+ [MIT](LICENSE.txt)
116
+
117
+ Copyright (c) 2020 - Andy Maleh.
118
+
119
+ --
120
+
121
+ [<img src="https://raw.githubusercontent.com/AndyObtiva/glimmer/master/images/glimmer-logo-hi-res.png" height=40 />](https://github.com/AndyObtiva/glimmer) Built for [Glimmer](https://github.com/AndyObtiva/glimmer) (Ruby Desktop Development GUI Library).
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,40 @@
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
+ $LOAD_PATH.unshift(File.expand_path('..', __FILE__))
23
+
24
+ # External requires
25
+ require 'glimmer'
26
+ require 'logging'
27
+ # require 'puts_debuggerer'
28
+ require 'super_module'
29
+ require 'tk'
30
+
31
+ # Internal requires
32
+ # require 'ext/glimmer/config'
33
+ # require 'ext/glimmer'
34
+ require 'glimmer/dsl/tk/dsl'
35
+ Glimmer::Config.loop_max_count = -1
36
+ Glimmer::Config.excluded_keyword_checkers << lambda do |method_symbol, *args|
37
+ method = method_symbol.to_s
38
+ result = false
39
+ result ||= method == 'load_iseq'
40
+ end
@@ -0,0 +1,43 @@
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 AttributeExpression < Expression
28
+ def can_interpret?(parent, keyword, *args, &block)
29
+ block.nil? and
30
+ args.size > 0 and
31
+ parent.respond_to?(:set_attribute) and
32
+ parent.respond_to?(:has_attribute?) and
33
+ parent.has_attribute?(keyword, *args)
34
+ end
35
+
36
+ def interpret(parent, keyword, *args, &block)
37
+ parent.set_attribute(keyword, *args)
38
+ nil
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,45 @@
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/engine'
23
+ Dir[File.expand_path('../*_expression.rb', __FILE__)].each {|f| require f}
24
+
25
+ # Glimmer DSL expression configuration module
26
+ #
27
+ # When DSL engine interprets an expression, it attempts to handle
28
+ # with expressions listed here in the order specified.
29
+
30
+ # Every expression has a corresponding Expression subclass
31
+ # in glimmer/dsl
32
+
33
+ module Glimmer
34
+ module DSL
35
+ module Tk
36
+ Engine.add_dynamic_expressions(
37
+ Tk,
38
+ %w[
39
+ attribute
40
+ widget
41
+ ]
42
+ )
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,46 @@
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/static_expression'
23
+ require 'glimmer/dsl/parent_expression'
24
+ require 'glimmer/dsl/top_level_expression'
25
+ require 'glimmer/tk/root_proxy'
26
+
27
+ module Glimmer
28
+ module DSL
29
+ module Tk
30
+ class RootExpression < StaticExpression
31
+ include TopLevelExpression
32
+ include ParentExpression
33
+
34
+ def can_interpret?(parent, keyword, *args, &block)
35
+ keyword == 'root' and
36
+ (parent.nil? or parent.is_a?(Glimmer::Tk::RootProxy))
37
+ end
38
+
39
+ def interpret(parent, keyword, *args, &block)
40
+ args = [parent] + args unless parent.nil?
41
+ Glimmer::Tk::RootProxy.new(*args)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,54 @@
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'
23
+ require 'glimmer/dsl/expression'
24
+ require 'glimmer/dsl/parent_expression'
25
+
26
+ module Glimmer
27
+ module DSL
28
+ module Tk
29
+ class WidgetExpression < Expression
30
+ include ParentExpression
31
+
32
+ EXCLUDED_KEYWORDS = %w[root]
33
+
34
+ def can_interpret?(parent, keyword, *args, &block)
35
+ !EXCLUDED_KEYWORDS.include?(keyword) and
36
+ parent.respond_to?(:tk_widget) and
37
+ Glimmer::Tk::WidgetProxy.widget_exists?(keyword)
38
+ end
39
+
40
+ def interpret(parent, keyword, *args, &block)
41
+ Glimmer::Tk::WidgetProxy.new(keyword, parent, args, &block)
42
+ end
43
+
44
+ def add_content(parent, &block)
45
+ super
46
+ parent.post_add_content
47
+ end
48
+
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ require 'glimmer/tk/widget_proxy'
@@ -0,0 +1,49 @@
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 TkRoot
27
+ #
28
+ # Follows the Proxy Design Pattern
29
+ class RootProxy < WidgetProxy
30
+
31
+ def initialize(*args)
32
+ @tk_widget = ::TkRoot.new
33
+ end
34
+
35
+ def open
36
+ start_event_loop
37
+ end
38
+
39
+ def content(&block)
40
+ Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::SWT::RootExpression.new, &block)
41
+ end
42
+
43
+ # Starts Tk mainloop
44
+ def start_event_loop
45
+ ::Tk.mainloop
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,124 @@
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
+ module Glimmer
23
+ module Tk
24
+ # Proxy for Tk Widget objects
25
+ #
26
+ # Follows the Proxy Design Pattern
27
+ class WidgetProxy
28
+ attr_reader :parent_proxy, :tk_widget, :drag_source_proxy, :drop_target_proxy, :drag_source_style, :drag_source_transfer, :drop_target_transfer
29
+
30
+ DEFAULT_INITIALIZERS = {
31
+ 'label' => lambda do |label|
32
+ label.grid
33
+ end,
34
+ }
35
+
36
+ # Initializes a new Tk Widget
37
+ #
38
+ # Styles is a comma separate list of symbols representing Tk styles in lower case
39
+ def initialize(*init_args)
40
+ underscored_widget_name, parent, extra_options = init_args
41
+ @parent_proxy = parent
42
+ tk_widget_class = self.class.tk_widget_class_for(underscored_widget_name)
43
+ @tk_widget = tk_widget_class.new(@parent_proxy.tk_widget, *extra_options)
44
+ DEFAULT_INITIALIZERS[underscored_widget_name]&.call(@tk_widget)
45
+ @parent_proxy.post_initialize_child(self)
46
+ end
47
+
48
+ # Subclasses may override to perform post initialization work on an added child
49
+ def post_initialize_child(child)
50
+ # No Op by default
51
+ end
52
+
53
+ # Subclasses may override to perform post add_content work
54
+ def post_add_content
55
+ # No Op by default
56
+ end
57
+
58
+ def self.widget_exists?(underscored_widget_name)
59
+ !!tk_widget_class_for(underscored_widget_name)
60
+ end
61
+
62
+ # This supports widgets in and out of basic Tk
63
+ def self.tk_widget_class_for(underscored_widget_name)
64
+ tk_widget_name = "::Tk::Tile::#{underscored_widget_name.camelcase(:upper)}"
65
+ tk_widget_class = eval(tk_widget_name)
66
+ tk_widget_class
67
+ rescue SyntaxError, NameError => e
68
+ puts e.full_message
69
+ nil
70
+ rescue => e
71
+ puts e.full_message
72
+ nil
73
+ end
74
+
75
+ def tk_widget_has_attribute?(attribute_name)
76
+ result = nil
77
+ begin
78
+ # TK Widget currently doesn't support respond_to? properly, so I have to resort to this trick for now
79
+ @tk_widget.send(attribute_setter(attribute_name), @tk_widget.send(attribute_name))
80
+ result = true
81
+ rescue => e
82
+ result = false
83
+ end
84
+ result
85
+ end
86
+
87
+ def has_attribute?(attribute_name, *args)
88
+ tk_widget_has_attribute?(attribute_name) || respond_to?(attribute_setter(attribute_name), args)
89
+ end
90
+
91
+ def set_attribute(attribute_name, *args)
92
+ if tk_widget_has_attribute?(attribute_name)
93
+ @tk_widget.send(attribute_setter(attribute_name), *args) unless @tk_widget.send(attribute_name) == args.first
94
+ else
95
+ send(attribute_setter(attribute_name), args)
96
+ end
97
+ end
98
+
99
+ def get_attribute(attribute_name)
100
+ @tk_widget.send(attribute_name)
101
+ end
102
+
103
+ def attribute_setter(attribute_name)
104
+ "#{attribute_name}="
105
+ end
106
+
107
+ def content(&block)
108
+ Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::Tk::WidgetExpression.new, &block)
109
+ end
110
+
111
+ def method_missing(method, *args, &block)
112
+ tk_widget.send(method, *args, &block)
113
+ rescue => e
114
+ Glimmer::Config.logger.debug {"Neither WidgetProxy nor #{tk_widget.class.name} can handle the method ##{method}"}
115
+ super
116
+ end
117
+
118
+ def respond_to?(method, *args, &block)
119
+ super ||
120
+ tk_widget.respond_to?(method, *args, &block)
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,30 @@
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-tk'
23
+
24
+ include Glimmer
25
+
26
+ root {
27
+ label {
28
+ text 'Hello, World!'
29
+ }
30
+ }.open
metadata ADDED
@@ -0,0 +1,297 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: glimmer-dsl-tk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - andy_maleh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-09-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: glimmer
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.10.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.10.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: super_module
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.4.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.4.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: puts_debuggerer
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.10.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.10.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake-tui
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 0.2.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 0.2.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: git-glimmer
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 1.7.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 1.7.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: jeweler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 2.3.9
90
+ - - "<"
91
+ - !ruby/object:Gem::Version
92
+ version: 3.0.0
93
+ type: :runtime
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: 2.3.9
100
+ - - "<"
101
+ - !ruby/object:Gem::Version
102
+ version: 3.0.0
103
+ - !ruby/object:Gem::Dependency
104
+ name: logging
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: 2.3.0
110
+ - - "<"
111
+ - !ruby/object:Gem::Version
112
+ version: 3.0.0
113
+ type: :runtime
114
+ prerelease: false
115
+ version_requirements: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: 2.3.0
120
+ - - "<"
121
+ - !ruby/object:Gem::Version
122
+ version: 3.0.0
123
+ - !ruby/object:Gem::Dependency
124
+ name: os
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: 1.0.0
130
+ - - "<"
131
+ - !ruby/object:Gem::Version
132
+ version: 2.0.0
133
+ type: :runtime
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: 1.0.0
140
+ - - "<"
141
+ - !ruby/object:Gem::Version
142
+ version: 2.0.0
143
+ - !ruby/object:Gem::Dependency
144
+ name: rake
145
+ requirement: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: 10.1.0
150
+ - - "<"
151
+ - !ruby/object:Gem::Version
152
+ version: 14.0.0
153
+ type: :runtime
154
+ prerelease: false
155
+ version_requirements: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: 10.1.0
160
+ - - "<"
161
+ - !ruby/object:Gem::Version
162
+ version: 14.0.0
163
+ - !ruby/object:Gem::Dependency
164
+ name: text-table
165
+ requirement: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: 1.2.4
170
+ - - "<"
171
+ - !ruby/object:Gem::Version
172
+ version: 2.0.0
173
+ type: :runtime
174
+ prerelease: false
175
+ version_requirements: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: 1.2.4
180
+ - - "<"
181
+ - !ruby/object:Gem::Version
182
+ version: 2.0.0
183
+ - !ruby/object:Gem::Dependency
184
+ name: tk
185
+ requirement: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - "~>"
188
+ - !ruby/object:Gem::Version
189
+ version: 0.2.0
190
+ type: :runtime
191
+ prerelease: false
192
+ version_requirements: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - "~>"
195
+ - !ruby/object:Gem::Version
196
+ version: 0.2.0
197
+ - !ruby/object:Gem::Dependency
198
+ name: rspec
199
+ requirement: !ruby/object:Gem::Requirement
200
+ requirements:
201
+ - - "~>"
202
+ - !ruby/object:Gem::Version
203
+ version: 3.5.0
204
+ type: :development
205
+ prerelease: false
206
+ version_requirements: !ruby/object:Gem::Requirement
207
+ requirements:
208
+ - - "~>"
209
+ - !ruby/object:Gem::Version
210
+ version: 3.5.0
211
+ - !ruby/object:Gem::Dependency
212
+ name: rdoc
213
+ requirement: !ruby/object:Gem::Requirement
214
+ requirements:
215
+ - - "~>"
216
+ - !ruby/object:Gem::Version
217
+ version: '3.12'
218
+ type: :development
219
+ prerelease: false
220
+ version_requirements: !ruby/object:Gem::Requirement
221
+ requirements:
222
+ - - "~>"
223
+ - !ruby/object:Gem::Version
224
+ version: '3.12'
225
+ - !ruby/object:Gem::Dependency
226
+ name: bundler
227
+ requirement: !ruby/object:Gem::Requirement
228
+ requirements:
229
+ - - ">="
230
+ - !ruby/object:Gem::Version
231
+ version: '1.0'
232
+ type: :development
233
+ prerelease: false
234
+ version_requirements: !ruby/object:Gem::Requirement
235
+ requirements:
236
+ - - ">="
237
+ - !ruby/object:Gem::Version
238
+ version: '1.0'
239
+ - !ruby/object:Gem::Dependency
240
+ name: simplecov
241
+ requirement: !ruby/object:Gem::Requirement
242
+ requirements:
243
+ - - ">="
244
+ - !ruby/object:Gem::Version
245
+ version: '0'
246
+ type: :development
247
+ prerelease: false
248
+ version_requirements: !ruby/object:Gem::Requirement
249
+ requirements:
250
+ - - ">="
251
+ - !ruby/object:Gem::Version
252
+ version: '0'
253
+ description: Glimmer DSL for TK (Ruby Desktop GUI)
254
+ email: andy.am@gmail.com
255
+ executables: []
256
+ extensions: []
257
+ extra_rdoc_files:
258
+ - CHANGELOG.md
259
+ - LICENSE.txt
260
+ - README.md
261
+ files:
262
+ - CHANGELOG.md
263
+ - LICENSE.txt
264
+ - README.md
265
+ - VERSION
266
+ - lib/glimmer-dsl-tk.rb
267
+ - lib/glimmer/dsl/tk/attribute_expression.rb
268
+ - lib/glimmer/dsl/tk/dsl.rb
269
+ - lib/glimmer/dsl/tk/root_expression.rb
270
+ - lib/glimmer/dsl/tk/widget_expression.rb
271
+ - lib/glimmer/tk/root_proxy.rb
272
+ - lib/glimmer/tk/widget_proxy.rb
273
+ - samples/hello/hello_world.rb
274
+ homepage: http://github.com/AndyObtiva/glimmer-dsl-tk
275
+ licenses:
276
+ - MIT
277
+ metadata: {}
278
+ post_install_message:
279
+ rdoc_options: []
280
+ require_paths:
281
+ - lib
282
+ required_ruby_version: !ruby/object:Gem::Requirement
283
+ requirements:
284
+ - - ">="
285
+ - !ruby/object:Gem::Version
286
+ version: '0'
287
+ required_rubygems_version: !ruby/object:Gem::Requirement
288
+ requirements:
289
+ - - ">="
290
+ - !ruby/object:Gem::Version
291
+ version: '0'
292
+ requirements: []
293
+ rubygems_version: 3.1.2
294
+ signing_key:
295
+ specification_version: 4
296
+ summary: Glimmer DSL for TK
297
+ test_files: []