shoes-core 4.0.0.pre8 → 4.0.0.pre9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/bin/shoes-picker +1 -0
  3. data/lib/shoes.rb +1 -0
  4. data/lib/shoes/animation.rb +1 -0
  5. data/lib/shoes/app.rb +7 -1
  6. data/lib/shoes/arc.rb +2 -3
  7. data/lib/shoes/arrow.rb +2 -3
  8. data/lib/shoes/background.rb +2 -2
  9. data/lib/shoes/border.rb +2 -2
  10. data/lib/shoes/builtin_methods.rb +2 -2
  11. data/lib/shoes/button.rb +2 -2
  12. data/lib/shoes/check_button.rb +2 -2
  13. data/lib/shoes/color.rb +1 -0
  14. data/lib/shoes/color/dsl.rb +1 -0
  15. data/lib/shoes/color/dsl_helpers.rb +1 -0
  16. data/lib/shoes/color/hex_converter.rb +1 -0
  17. data/lib/shoes/common/art_element.rb +6 -9
  18. data/lib/shoes/common/attachable.rb +1 -0
  19. data/lib/shoes/common/background_element.rb +2 -11
  20. data/lib/shoes/common/changeable.rb +1 -0
  21. data/lib/shoes/common/clickable.rb +1 -0
  22. data/lib/shoes/common/fill.rb +1 -0
  23. data/lib/shoes/common/hover.rb +2 -1
  24. data/lib/shoes/common/inspect.rb +1 -0
  25. data/lib/shoes/common/link_finder.rb +1 -0
  26. data/lib/shoes/common/positioning.rb +1 -0
  27. data/lib/shoes/common/registration.rb +1 -0
  28. data/lib/shoes/common/remove.rb +1 -0
  29. data/lib/shoes/common/rotate.rb +1 -0
  30. data/lib/shoes/common/safely_evaluate.rb +13 -0
  31. data/lib/shoes/common/state.rb +4 -10
  32. data/lib/shoes/common/stroke.rb +1 -0
  33. data/lib/shoes/common/style.rb +13 -3
  34. data/lib/shoes/common/style_normalizer.rb +1 -0
  35. data/lib/shoes/common/translate.rb +1 -0
  36. data/lib/shoes/common/ui_element.rb +67 -5
  37. data/lib/shoes/common/visibility.rb +7 -6
  38. data/lib/shoes/configuration.rb +5 -16
  39. data/lib/shoes/console.rb +91 -0
  40. data/lib/shoes/core.rb +1 -1
  41. data/lib/shoes/core/version.rb +1 -1
  42. data/lib/shoes/dialog.rb +1 -0
  43. data/lib/shoes/dimension.rb +1 -0
  44. data/lib/shoes/dimensions.rb +1 -0
  45. data/lib/shoes/download.rb +1 -0
  46. data/lib/shoes/dsl.rb +28 -588
  47. data/lib/shoes/dsl/animate.rb +51 -0
  48. data/lib/shoes/dsl/art.rb +256 -0
  49. data/lib/shoes/dsl/element.rb +56 -0
  50. data/lib/shoes/dsl/interaction.rb +76 -0
  51. data/lib/shoes/dsl/media.rb +38 -0
  52. data/lib/shoes/dsl/setup.rb +42 -0
  53. data/lib/shoes/dsl/style.rb +81 -0
  54. data/lib/shoes/dsl/text.rb +50 -0
  55. data/lib/shoes/file_not_found_error.rb +1 -0
  56. data/lib/shoes/font.rb +2 -1
  57. data/lib/shoes/gradient.rb +1 -0
  58. data/lib/shoes/image.rb +2 -2
  59. data/lib/shoes/image_pattern.rb +1 -0
  60. data/lib/shoes/input_box.rb +11 -2
  61. data/lib/shoes/internal_app.rb +16 -3
  62. data/lib/shoes/key_event.rb +1 -0
  63. data/lib/shoes/line.rb +2 -3
  64. data/lib/shoes/link.rb +2 -0
  65. data/lib/shoes/list_box.rb +3 -3
  66. data/lib/shoes/logger_collection.rb +38 -0
  67. data/lib/shoes/mock.rb +1 -0
  68. data/lib/shoes/mock/animation.rb +1 -0
  69. data/lib/shoes/mock/app.rb +1 -0
  70. data/lib/shoes/mock/arc.rb +1 -0
  71. data/lib/shoes/mock/arrow.rb +1 -0
  72. data/lib/shoes/mock/background.rb +1 -0
  73. data/lib/shoes/mock/border.rb +1 -0
  74. data/lib/shoes/mock/button.rb +1 -0
  75. data/lib/shoes/mock/check.rb +1 -0
  76. data/lib/shoes/mock/clickable.rb +1 -0
  77. data/lib/shoes/mock/common_methods.rb +1 -0
  78. data/lib/shoes/mock/dialog.rb +1 -0
  79. data/lib/shoes/mock/download.rb +1 -0
  80. data/lib/shoes/mock/font.rb +1 -0
  81. data/lib/shoes/mock/image.rb +1 -0
  82. data/lib/shoes/mock/image_pattern.rb +1 -0
  83. data/lib/shoes/mock/input_box.rb +4 -0
  84. data/lib/shoes/mock/keypress.rb +1 -0
  85. data/lib/shoes/mock/keyrelease.rb +1 -0
  86. data/lib/shoes/mock/line.rb +1 -0
  87. data/lib/shoes/mock/link.rb +1 -0
  88. data/lib/shoes/mock/list_box.rb +1 -0
  89. data/lib/shoes/mock/oval.rb +1 -0
  90. data/lib/shoes/mock/packager.rb +3 -0
  91. data/lib/shoes/mock/progress.rb +1 -0
  92. data/lib/shoes/mock/radio.rb +1 -0
  93. data/lib/shoes/mock/rect.rb +1 -0
  94. data/lib/shoes/mock/shape.rb +1 -0
  95. data/lib/shoes/mock/slot.rb +1 -0
  96. data/lib/shoes/mock/sound.rb +1 -0
  97. data/lib/shoes/mock/star.rb +1 -0
  98. data/lib/shoes/mock/text_block.rb +1 -0
  99. data/lib/shoes/mock/timer.rb +1 -0
  100. data/lib/shoes/not_implemented_error.rb +1 -0
  101. data/lib/shoes/oval.rb +2 -3
  102. data/lib/shoes/packager.rb +13 -0
  103. data/lib/shoes/point.rb +1 -0
  104. data/lib/shoes/progress.rb +2 -3
  105. data/lib/shoes/radio.rb +1 -0
  106. data/lib/shoes/rect.rb +2 -3
  107. data/lib/shoes/renamed_delegate.rb +1 -0
  108. data/lib/shoes/shape.rb +2 -4
  109. data/lib/shoes/slot.rb +3 -3
  110. data/lib/shoes/slot_contents.rb +1 -0
  111. data/lib/shoes/sound.rb +1 -0
  112. data/lib/shoes/span.rb +1 -0
  113. data/lib/shoes/standard_logger.rb +14 -0
  114. data/lib/shoes/star.rb +2 -3
  115. data/lib/shoes/text.rb +1 -0
  116. data/lib/shoes/text_block.rb +4 -4
  117. data/lib/shoes/text_block_dimensions.rb +1 -0
  118. data/lib/shoes/timer.rb +1 -0
  119. data/lib/shoes/ui/cli.rb +5 -0
  120. data/lib/shoes/ui/picker.rb +2 -1
  121. data/lib/shoes/url.rb +1 -0
  122. data/lib/shoes/version.rb +1 -1
  123. data/lib/shoes/widget.rb +1 -0
  124. data/lib/shoes/window.rb +1 -0
  125. metadata +14 -5
  126. data/lib/shoes/common/initialization.rb +0 -71
  127. data/lib/shoes/logger.rb +0 -65
  128. data/lib/shoes/logger/ruby.rb +0 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f1b7205ad873a89bbd6ed14d91f485200cf83f15
4
- data.tar.gz: eec9c9656150201d5c0fcce0b9425c6f2c842fef
3
+ metadata.gz: 4ba64133e02f0c5a97f98f1f9eff7a68b32fba38
4
+ data.tar.gz: c3ee4b52936eb0125cf87f8c21b318ada8ca949f
5
5
  SHA512:
6
- metadata.gz: f10912fc2b305ce9296d58358b0b1de4553f291ab1e9471a5cecff13a9838b595ef650ebd36bdb266f0a5f699cf2e361f30e8c3196ccdbb68ee73e4b8b747e3b
7
- data.tar.gz: e7de5b6d95f8b7ff98ade674141b42ccdf02e311b6afaa724459e9e0c69e7ca741f169757bee91f6e2155fb0e4fa312760b76e75364d9afd81b2234b3798246e
6
+ metadata.gz: 399a8a7dc9fe4057095a926b7fb9a41c442a5bfb96295a6b21122dab8f829968f34841a94e4b836be4927bd197582ef544e0c768383dc57152f46ff38f214e76
7
+ data.tar.gz: 161b478d23e6949f3c5ce41fd7178c7f75ed3ef6da3a52b1e9f57f6daddfa61d86a3dcdeb2aa9a927b5eae167ea098a7eb880a1d841d41f0019c196bb7eaa5d9
data/bin/shoes-picker CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
  lib_directory = File.expand_path('../../lib', __FILE__)
3
4
  $LOAD_PATH << lib_directory
4
5
 
data/lib/shoes.rb CHANGED
@@ -1 +1,2 @@
1
+ # frozen_string_literal: true
1
2
  require 'shoes/core'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  class Animation
3
4
  include Common::Inspect
data/lib/shoes/app.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  ICON = File.join(DIR, 'static/shoes-icon.png').freeze
3
4
 
@@ -61,6 +62,11 @@ class Shoes
61
62
  self.class.new(options, &block)
62
63
  end
63
64
 
65
+ # Remember startup block for execution later
66
+ def start(&blk)
67
+ @__app__.start_block = blk
68
+ end
69
+
64
70
  def quit
65
71
  Shoes.unregister self
66
72
  @__app__.quit
@@ -75,7 +81,7 @@ class Shoes
75
81
  delegated_to_internal_app = %w(
76
82
  width height owner started? location left top absolute_left
77
83
  absolute_top click release clear fullscreen fullscreen=
78
- contents wait_until_closed gui
84
+ contents wait_until_closed focus open? gui
79
85
  )
80
86
 
81
87
  def_delegators :@__app__, *delegated_to_internal_app
data/lib/shoes/arc.rb CHANGED
@@ -1,7 +1,6 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
- class Arc
3
- include Common::ArtElement
4
-
3
+ class Arc < Common::ArtElement
5
4
  style_with :angle1, :angle2, :art_styles, :center, :common_styles, :dimensions, :radius, :wedge
6
5
  STYLES = { wedge: false, fill: Shoes::COLORS[:black] }.freeze
7
6
 
data/lib/shoes/arrow.rb CHANGED
@@ -1,7 +1,6 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
- class Arrow
3
- include Common::ArtElement
4
-
3
+ class Arrow < Common::ArtElement
5
4
  style_with :angle, :art_styles, :curve, :common_styles, :dimensions
6
5
  STYLES = { angle: 0, fill: Shoes::COLORS[:black] }.freeze
7
6
 
@@ -1,6 +1,6 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
- class Background
3
- include Common::BackgroundElement
3
+ class Background < Common::BackgroundElement
4
4
  include Common::Fill
5
5
 
6
6
  style_with :angle, :common_styles, :curve, :dimensions, :fill
data/lib/shoes/border.rb CHANGED
@@ -1,6 +1,6 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
- class Border
3
- include Common::BackgroundElement
3
+ class Border < Common::BackgroundElement
4
4
  include Common::Stroke
5
5
 
6
6
  style_with :angle, :common_styles, :curve, :dimensions, :stroke, :strokewidth
@@ -1,9 +1,10 @@
1
+ # frozen_string_literal: true
1
2
  # The methods defined in this module/file are also available outside of the
2
3
  # Shoes.app block. So they are monkey patched onto the main object.
3
4
  # However they can also be used from the normal Shoes.app block.
4
5
  class Shoes
5
6
  def self.p(message)
6
- Shoes::LOG << ['debug', message.inspect]
7
+ Shoes.logger.debug(message.inspect)
7
8
  end
8
9
 
9
10
  module BuiltinMethods
@@ -19,7 +20,6 @@ class Shoes
19
20
 
20
21
  %w(info debug warn error).each do |log_level|
21
22
  define_method(log_level) do |message = ''|
22
- Shoes::LOG << [log_level, message]
23
23
  Shoes.logger.public_send(log_level, message)
24
24
  end
25
25
  end
data/lib/shoes/button.rb CHANGED
@@ -1,6 +1,6 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
- class Button
3
- include Common::UIElement
3
+ class Button < Common::UIElement
4
4
  include Common::Clickable
5
5
  include Common::State
6
6
 
@@ -1,6 +1,6 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
- class CheckButton
3
- include Common::UIElement
3
+ class CheckButton < Common::UIElement
4
4
  include Common::Clickable
5
5
  include Common::State
6
6
 
data/lib/shoes/color.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  class Color
3
4
  include Common::Inspect
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  # Create all of the built-in Shoes colors
3
4
  COLORS = {}
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  class Color
3
4
  module DSLHelpers
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  class Color
3
4
  class HexConverter
@@ -1,20 +1,17 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  module Common
3
- module ArtElement
4
- include Common::UIElement
4
+ class ArtElement < UIElement
5
5
  include Common::Clickable
6
6
  include Common::Fill
7
7
  include Common::Rotate
8
8
  include Common::Stroke
9
9
  include Common::Translate
10
10
 
11
- # Modules that muck with class methods need to be included like this
12
- #
13
- # We also can't rely on Common::UIElement providing these, as it gets
14
- # ArtElement, not the destination class to add things to!
15
- def self.included(base)
16
- base.include Common::Hover
17
- base.include Common::Style
11
+ def self.inherited(child)
12
+ # Hover's inclusion generates a styling class per child class.
13
+ # We need to include it at inheritance time to get that behavior.
14
+ child.include Common::Hover
18
15
  end
19
16
  end
20
17
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  module Common
3
4
  module Attachable
@@ -1,16 +1,7 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  module Common
3
- module BackgroundElement
4
- include Common::UIElement
5
-
6
- # Modules that muck with class methods need to be included like this
7
- #
8
- # We also can't rely on Common::UIElement providing these, as it gets
9
- # BackgroundElement, not the destination class to add things to!
10
- def self.included(base)
11
- base.include Common::Style
12
- end
13
-
4
+ class BackgroundElement < Common::UIElement
14
5
  def create_dimensions(*_)
15
6
  @dimensions = ParentDimensions.new @parent, @style
16
7
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  module Common
3
4
  # Changeable elements are elements that receive `change' events.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  module Common
3
4
  module Clickable
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  module Common
3
4
  module Fill
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  module Common
3
4
  module Hover
@@ -53,7 +54,7 @@ class Shoes
53
54
  end
54
55
 
55
56
  def eval_hover_block(blk)
56
- blk.call(self) if blk
57
+ safely_evaluate(self, &blk) if blk
57
58
  end
58
59
 
59
60
  def apply_style_from_hover_class
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  module Common
3
4
  module Inspect
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  module Common
3
4
  module LinkFinder
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  module Common
3
4
  module Positioning
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  module Common
3
4
  module Registration
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  module Common
3
4
  module Remove
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  module Common
3
4
  module Rotate
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+ class Shoes
3
+ module Common
4
+ module SafelyEvaluate
5
+ def safely_evaluate(*args)
6
+ yield(*args) if block_given?
7
+ rescue => e
8
+ Shoes.logger.error(e.message)
9
+ raise e if Shoes.configuration.fail_fast
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,29 +1,23 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  module Common
3
4
  module State
4
- DISABLED_STATE = "disabled".freeze
5
+ DISABLED_STATE = "disabled"
5
6
 
6
7
  def after_initialize(*_)
7
8
  super
8
- update_enabled
9
+ update_from_state
9
10
  end
10
11
 
11
12
  def state=(value)
12
13
  style(state: value)
13
- update_enabled
14
14
  end
15
15
 
16
- def state_options(opts)
17
- self.state = opts[:state]
18
- end
19
-
20
- private
21
-
22
16
  def enabled?
23
17
  !(state.to_s == DISABLED_STATE)
24
18
  end
25
19
 
26
- def update_enabled
20
+ def update_from_state
27
21
  @gui.enabled(enabled?)
28
22
  end
29
23
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  module Common
3
4
  module Stroke
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # The general Style module handles the many optional styles that may be passed
2
3
  # to shoes elements upon creates as well as the fact that they can later on be
3
4
  # altered through the #style method.
@@ -122,13 +123,15 @@ class Shoes
122
123
 
123
124
  def update_style(new_styles)
124
125
  normalized_style = StyleNormalizer.new.normalize(new_styles)
126
+ @style.merge! normalized_style
127
+
125
128
  set_dimensions(new_styles)
126
129
  set_visibility(new_styles)
127
130
  set_coloring(new_styles)
128
131
  set_hovers(new_styles)
129
132
  set_translate(new_styles)
130
- click(&new_styles[:click]) if new_styles.key?(:click)
131
- @style.merge! normalized_style
133
+ set_click(new_styles)
134
+ set_state(new_styles)
132
135
  end
133
136
 
134
137
  # if dimension is set via style, pass info on to the dimensions setter
@@ -140,7 +143,6 @@ class Shoes
140
143
 
141
144
  def set_visibility(new_styles)
142
145
  return unless new_styles.include?(:hidden)
143
- @style[:hidden] = new_styles[:hidden]
144
146
  update_visibility
145
147
  end
146
148
 
@@ -158,6 +160,14 @@ class Shoes
158
160
  clear_translate if new_styles.include?(:translate)
159
161
  end
160
162
 
163
+ def set_click(new_styles)
164
+ click(&new_styles[:click]) if new_styles.key?(:click)
165
+ end
166
+
167
+ def set_state(new_styles)
168
+ update_from_state if new_styles.include?(:state)
169
+ end
170
+
161
171
  def update_dimensions # so that @style hash matches actual values
162
172
  STYLE_GROUPS[:dimensions].each do |style|
163
173
  if respond_to?(style)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  module Common
3
4
  class StyleNormalizer
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  module Common
3
4
  module Translate
@@ -1,17 +1,79 @@
1
+ # frozen_string_literal: true
1
2
  class Shoes
2
3
  module Common
3
- module UIElement
4
+ class UIElement
4
5
  include Common::Attachable
5
- include Common::Initialization
6
6
  include Common::Inspect
7
7
  include Common::Visibility
8
8
  include Common::Positioning
9
9
  include Common::Remove
10
10
  include DimensionsDelegations
11
+ include Common::SafelyEvaluate
12
+ include Common::Style
11
13
 
12
- # Modules that muck with class methods need to be included like this
13
- def self.included(base)
14
- base.include Common::Style
14
+ attr_reader :app, :parent, :dimensions, :gui
15
+
16
+ def initialize(app, parent, *args)
17
+ blk = args.pop if args.last.is_a?(Proc) || args.last.nil?
18
+ styles = args.last.is_a?(Hash) ? args.pop : {}
19
+
20
+ before_initialize(styles, *args)
21
+
22
+ @app = app
23
+ @parent = parent
24
+
25
+ style_init(styles)
26
+ create_dimensions(*args)
27
+ update_dimensions if styles_with_dimensions?
28
+
29
+ create_backend
30
+ add_to_parent(*args)
31
+
32
+ handle_block(blk)
33
+ update_visibility
34
+
35
+ after_initialize(*args)
36
+ end
37
+
38
+ # This method will get called with the incoming styles hash and the
39
+ # other arguments passed to initialize.
40
+ #
41
+ # It is intended for performing any additions to the styles hash before
42
+ # that gets sent on to style_init.
43
+ def before_initialize(_styles, *_)
44
+ end
45
+
46
+ # Set the dimensions for the element. Defaults to using the Dimensions
47
+ # class, but is expected to be overridden in other types (art elements,
48
+ # text blocks) that require different dimensioning.
49
+ def create_dimensions(*_)
50
+ @dimensions = Dimensions.new @parent, @style
51
+ end
52
+
53
+ # Call to create the backend (aka @gui)
54
+ def create_backend
55
+ @gui = Shoes.backend_for self
56
+ end
57
+
58
+ # Calls to add child in parent, after the backend has been created.
59
+ # Can be overridden for operations that must happen after backend, but
60
+ # before addition to parent (and hence positioning)
61
+ def add_to_parent(*_)
62
+ @parent.add_child self
63
+ end
64
+
65
+ # This method handles the block passed in at creation of the DSL element.
66
+ # By default it will treat things as clickable, and assumes the
67
+ # necessary methods are there.
68
+ #
69
+ # Override if DSL element uses that block for something else (i.e. slot)
70
+ def handle_block(blk)
71
+ register_click blk if respond_to?(:register_click)
72
+ end
73
+
74
+ # Final method called in initialize. Intended for any final setup after
75
+ # the rest of the object has been set up fully.
76
+ def after_initialize(*_)
15
77
  end
16
78
 
17
79
  # Nobody rotates by default, but we need to let you check