wxruby3 0.9.4 → 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/INSTALL.md +315 -78
  3. data/README.md +32 -21
  4. data/ext/wxruby3/include/wxruby-ComboPopup.h +777 -0
  5. data/lib/wx/core/combo_ctrl.rb +171 -0
  6. data/lib/wx/core/ext.rb +22 -3
  7. data/lib/wx/doc/comboctrl.rb +128 -3
  8. data/lib/wx/doc/owner_drawn_combobox.rb +5 -1
  9. data/lib/wx/version.rb +1 -1
  10. data/lib/wx/wxruby/base.rb +6 -4
  11. data/lib/wx/wxruby/cmd/sampler.rb +39 -29
  12. data/lib/wx/wxruby/cmd/setup.rb +122 -0
  13. data/lib/wx/wxruby/cmd/test.rb +56 -6
  14. data/rakefile +14 -0
  15. data/rakelib/bin.rake +48 -0
  16. data/rakelib/bin.rb +62 -0
  17. data/rakelib/build.rb +11 -7
  18. data/rakelib/config.rake +3 -1
  19. data/rakelib/configure.rb +28 -8
  20. data/rakelib/doc.rake +3 -1
  21. data/rakelib/gem.rake +169 -0
  22. data/rakelib/gem.rb +82 -0
  23. data/rakelib/install.rb +2 -0
  24. data/rakelib/lib/config/linux.rb +24 -2
  25. data/rakelib/lib/config/macosx.rb +16 -0
  26. data/rakelib/lib/config/mingw.rb +133 -9
  27. data/rakelib/lib/config/pkgman/arch.rb +53 -0
  28. data/rakelib/lib/config/pkgman/base.rb +169 -0
  29. data/rakelib/lib/config/pkgman/debian.rb +66 -0
  30. data/rakelib/lib/config/pkgman/macosx.rb +183 -0
  31. data/rakelib/lib/config/pkgman/rhel.rb +54 -0
  32. data/rakelib/lib/config/pkgman/suse.rb +54 -0
  33. data/rakelib/lib/config/unixish.rb +36 -19
  34. data/rakelib/lib/config.rb +254 -61
  35. data/rakelib/lib/core/include/funcall.inc +2 -1
  36. data/rakelib/lib/core/package.rb +47 -49
  37. data/rakelib/lib/director/comboctrl.rb +104 -3
  38. data/rakelib/lib/director/defs.rb +1 -3
  39. data/rakelib/lib/director/gdicommon.rb +5 -0
  40. data/rakelib/lib/director/menu_item.rb +1 -1
  41. data/rakelib/lib/director/num_validator.rb +5 -7
  42. data/rakelib/lib/director/owner_drawn_combobox.rb +1 -0
  43. data/rakelib/lib/director/persistent_window.rb +2 -2
  44. data/rakelib/lib/director/pgeditor.rb +1 -1
  45. data/rakelib/lib/director/pgproperties.rb +3 -3
  46. data/rakelib/lib/director/pgproperty.rb +5 -1
  47. data/rakelib/lib/director/richtext_style_listbox.rb +5 -0
  48. data/rakelib/lib/director/sizer.rb +1 -1
  49. data/rakelib/lib/director/window.rb +4 -0
  50. data/rakelib/lib/extractor/module.rb +15 -0
  51. data/rakelib/lib/generate/doc/combo_ctrl.yaml +135 -0
  52. data/rakelib/lib/generate/doc/file_dialog_customize_hook.yaml +62 -0
  53. data/rakelib/lib/generate/doc/file_system.yaml +28 -0
  54. data/rakelib/lib/generate/doc.rb +29 -14
  55. data/rakelib/lib/generate/interface.rb +16 -6
  56. data/rakelib/lib/swig_runner.rb +18 -15
  57. data/rakelib/lib/typemap/combo_popup.rb +42 -0
  58. data/rakelib/prepost.rake +9 -4
  59. data/rakelib/yard/templates/default/fulldoc/html/css/wxruby3.css +14 -0
  60. data/rakelib/yard/templates/default/fulldoc/html/setup.rb +5 -5
  61. data/rakelib/yard/yard/relative_markdown_links.rb +7 -1
  62. data/tests/test_combo_ctrl.rb +196 -0
  63. metadata +28 -17
  64. data/ext/mkrf_conf_srcgem.rb +0 -67
  65. data/rakelib/run.rake +0 -52
@@ -0,0 +1,171 @@
1
+ # Copyright (c) 2023 M.J.N. Corino, The Netherlands
2
+ #
3
+ # This software is released under the MIT license.
4
+
5
+
6
+ module Wx
7
+
8
+ module ComboPopup
9
+
10
+ def self.included(mod)
11
+ unless mod == Wx::ComboPopupWx
12
+ mod.class_eval { include Wx::ComboPopup::Methods }
13
+ end
14
+ end
15
+
16
+ module Methods
17
+ # Returns pointer to the associated parent {Wx::ComboCtrl}.
18
+ # @return [Wx::ComboCtrl]
19
+ # def get_combo_ctrl; end
20
+
21
+ # The including class must implement this to initialize its internal variables.
22
+ #
23
+ # This method is called immediately after construction finishes. m_combo member variable has been initialized before the call.
24
+ # @return [void]
25
+ def init
26
+ end
27
+
28
+ # The including class may implement this to return true if it wants to delay call to {Wx::ComboPopup#create} until the popup is shown for the first time.
29
+ #
30
+ # It is more efficient, but on the other hand it is often more convenient to have the control created immediately.
31
+ #
32
+ # <div class="wxrb-remark">
33
+ # <b>Remark:</b>
34
+ # <p>Base implementation returns false.
35
+ # </p>
36
+ # </div>
37
+ # @return [Boolean]
38
+ def lazy_create
39
+ false
40
+ end
41
+
42
+ # The including class must implement this to create the popup control.
43
+ #
44
+ # true if the call succeeded, false otherwise.
45
+ # @param parent [Wx::Window]
46
+ # @return [Boolean]
47
+ def create(parent)
48
+ false
49
+ end
50
+
51
+ # You only need to implement this member function if you create your popup class in non-standard way.
52
+ #
53
+ # The default implementation can handle both multiple-inherited popup control (as seen in {Wx::ComboCtrl} samples) and one allocated separately in heap.
54
+ # If you do completely re-implement this function, make sure it calls Destroy() for the popup control and also deletes this object (usually as the last thing).
55
+ # @return [void]
56
+ def destroy_popup
57
+ end
58
+
59
+ # Implement to customize matching of value string to an item container entry.
60
+ #
61
+ # <div class="wxrb-remark">
62
+ # <b>Remark:</b>
63
+ # <p>Default implementation always return true and does not alter trueItem.
64
+ # </p>
65
+ # </div>
66
+ # @param item [String] String entered, usually by user or from SetValue() call.
67
+ # @param trueItem [Boolean] if true the true item string should be returned in case matching but different
68
+ # @return [Boolean, String] Returns true if a match is found or false if not. If trueItem == true and item matches an entry, but the entry's string representation is not exactly the same (case mismatch, for example), then the true item string should be returned as the match result.
69
+ def find_item(item, trueItem=false)
70
+ true
71
+ end
72
+
73
+ # The including class may implement this to return adjusted size for the popup control, according to the variables given.
74
+ #
75
+ # <div class="wxrb-remark">
76
+ # <b>Remark:</b>
77
+ # <p>This function is called each time popup is about to be shown.
78
+ # </p>
79
+ # </div>
80
+ # @param minWidth [Integer] Preferred minimum width.
81
+ # @param prefHeight [Integer] Preferred height. May be -1 to indicate no preference.
82
+ # @param maxHeight [Integer] Max height for window, as limited by screen size.
83
+ # @return [Wx::Size]
84
+ def get_adjusted_size(minWidth, prefHeight, maxHeight)
85
+ Wx::Size.new(minWidth, prefHeight)
86
+ end
87
+
88
+ # The including class must implement this to return pointer to the associated control created in {Wx::ComboPopup#create}.
89
+ # @return [Wx::Window]
90
+ def get_control
91
+ end
92
+
93
+ # The including class must implement this to receive string value changes from {Wx::ComboCtrl}.
94
+ # @param value [String]
95
+ # @return [void]
96
+ def set_string_value(value)
97
+ end
98
+
99
+ # The including class must implement this to return string representation of the value.
100
+ # @return [String]
101
+ def get_string_value
102
+ nil
103
+ end
104
+
105
+ # The including class may implement this to do something when the parent {Wx::ComboCtrl} gets double-clicked.
106
+ # @return [void]
107
+ def on_combo_double_click
108
+ end
109
+
110
+ # The including class may implement this to receive key down events from the parent {Wx::ComboCtrl}.
111
+ #
112
+ # Events not handled should be skipped, as usual.
113
+ # @param event [Wx::KeyEvent]
114
+ # @return [void]
115
+ def on_combo_key_event(event)
116
+ event.skip
117
+ end
118
+
119
+ # The including class may implement this to receive char events from the parent {Wx::ComboCtrl}.
120
+ #
121
+ # Events not handled should be skipped, as usual.
122
+ # @param event [Wx::KeyEvent]
123
+ # @return [void]
124
+ def on_combo_char_event(event)
125
+ event.skip
126
+ end
127
+
128
+ # The including class may implement this to do special processing when popup is hidden.
129
+ # @return [void]
130
+ def on_dismiss
131
+ end
132
+
133
+ # The including class may implement this to do special processing when popup is shown.
134
+ # @return [void]
135
+ def on_popup
136
+ end
137
+
138
+ # The including class may implement this to paint the parent {Wx::ComboCtrl}.
139
+ # This is called to custom paint in the combo control itself (ie. not the popup).
140
+ #
141
+ # Default implementation draws value as string.
142
+ # @param dc [Wx::DC]
143
+ # @param rect [Wx::Rect]
144
+ # @return [void]
145
+ def paint_combo_control(dc, rect)
146
+ combo = get_combo_ctrl
147
+ if combo.get_window_style.allbits?(Wx::CB_READONLY) # ie. no textctrl
148
+ combo.prepare_background(dc, rect,0)
149
+
150
+ dc.draw_text(combo.get_value,
151
+ rect.x + combo.get_margin_left,
152
+ (rect.height-dc.get_char_height)/2 + rect.y)
153
+ end
154
+ end
155
+
156
+ end
157
+
158
+ end
159
+
160
+ class ComboPopupWx
161
+
162
+ include ComboPopup
163
+
164
+ # this method has not been wrapped as a default popup control will always already have been
165
+ # initialized before returned from #get_combo_control
166
+ # just do nothing here (or should we raise an exception?)
167
+ def init; end
168
+
169
+ end
170
+
171
+ end
data/lib/wx/core/ext.rb CHANGED
@@ -28,18 +28,37 @@ module Wx
28
28
  end
29
29
  end
30
30
 
31
+ class Value
32
+ def initialize(code, block)
33
+ @code = code
34
+ @block = block
35
+ end
36
+
37
+ def value
38
+ @block ? @block.call : Kernel.eval(@code || 'nil')
39
+ end
40
+
41
+ def to_s
42
+ @code || ''
43
+ end
44
+ end
45
+
31
46
  def delayed_constants
32
47
  @delayed_constants ||= ::Hash.new
33
48
  end
34
49
 
35
50
  public
36
51
 
37
- def add_delayed_constant(mod, sym, &block)
38
- delayed_constants[Key.new(mod,sym)] = block
52
+ def add_delayed_constant(mod, sym, code='', &block)
53
+ delayed_constants[Key.new(mod,sym)] = Value.new(code, block)
54
+ end
55
+
56
+ def delayed_constants_for(mod)
57
+ delayed_constants.select { |k,v| k.mod == mod }
39
58
  end
40
59
 
41
60
  def load_delayed_constants
42
- delayed_constants.each_pair { |key, blk| key.mod.const_set(key.sym, blk.call) }
61
+ delayed_constants.each_pair { |key, val| key.mod.const_set(key.sym, val.value) }
43
62
  delayed_constants.clear # cleanup
44
63
  end
45
64
 
@@ -7,11 +7,136 @@
7
7
 
8
8
  module Wx
9
9
 
10
- class OwnerDrawnComboBox < ComboCtrl
10
+ # In order to use a custom popup with {Wx::ComboCtrl}, a class must include {Wx::ComboPopup}.
11
+ #
12
+ # For more information on how to use it, see {Wx::ComboCtrl Setting Custom Popup for Wx::ComboCtrl}.
13
+ module ComboPopup
11
14
 
12
- alias :get_item_data :get_client_object
15
+ # Returns pointer to the associated parent {Wx::ComboCtrl}.
16
+ # @return [Wx::ComboCtrl]
17
+ def get_combo_ctrl; end
13
18
 
14
- alias :set_item_data :set_client_object
19
+ # The including class must implement this to initialize its internal variables.
20
+ #
21
+ # This method is called immediately after construction finishes. m_combo member variable has been initialized before the call.
22
+ # @return [void]
23
+ def init; end
24
+
25
+ # The including class may implement this to return true if it wants to delay call to {Wx::ComboPopup#create} until the popup is shown for the first time.
26
+ #
27
+ # It is more efficient, but on the other hand it is often more convenient to have the control created immediately.
28
+ #
29
+ # <div class="wxrb-remark">
30
+ # <b>Remark:</b>
31
+ # <p>Base implementation returns false.
32
+ # </p>
33
+ # </div>
34
+ # @return [Boolean]
35
+ def lazy_create; end
36
+
37
+ # The including class must implement this to create the popup control.
38
+ #
39
+ # true if the call succeeded, false otherwise.
40
+ # @param parent [Wx::Window]
41
+ # @return [Boolean]
42
+ def create(parent) end
43
+
44
+ # You only need to implement this member function if you create your popup class in non-standard way.
45
+ #
46
+ # The default implementation can handle both multiple-inherited popup control (as seen in {Wx::ComboCtrl} samples) and one allocated separately in heap.
47
+ # If you do completely re-implement this function, make sure it calls Destroy() for the popup control and also deletes this object (usually as the last thing).
48
+ # @return [void]
49
+ def destroy_popup; end
50
+
51
+ # Implement to customize matching of value string to an item container entry.
52
+ #
53
+ # <div class="wxrb-remark">
54
+ # <b>Remark:</b>
55
+ # <p>Default implementation always return true and does not alter trueItem.
56
+ # </p>
57
+ # </div>
58
+ # @param item [String] String entered, usually by user or from SetValue() call.
59
+ # @param trueItem [Boolean] if true the true item string should be returned in case matching but different
60
+ # @return [Boolean, String] Returns true if a match is found or false if not. If trueItem == true and item matches an entry, but the entry's string representation is not exactly the same (case mismatch, for example), then the true item string should be returned as the match result.
61
+ def find_item(item, trueItem=false) end
62
+
63
+ # The including class may implement this to return adjusted size for the popup control, according to the variables given.
64
+ #
65
+ # <div class="wxrb-remark">
66
+ # <b>Remark:</b>
67
+ # <p>This function is called each time popup is about to be shown.
68
+ # </p>
69
+ # </div>
70
+ # @param minWidth [Integer] Preferred minimum width.
71
+ # @param prefHeight [Integer] Preferred height. May be -1 to indicate no preference.
72
+ # @param maxHeight [Integer] Max height for window, as limited by screen size.
73
+ # @return [Wx::Size]
74
+ def get_adjusted_size(minWidth, prefHeight, maxHeight) end
75
+
76
+ # The including class must implement this to return pointer to the associated control created in {Wx::ComboPopup#create}.
77
+ # @return [Wx::Window]
78
+ def get_control; end
79
+
80
+ # The including class must implement this to receive string value changes from {Wx::ComboCtrl}.
81
+ # @param value [String]
82
+ # @return [void]
83
+ def set_string_value(value) end
84
+
85
+ # The including class must implement this to return string representation of the value.
86
+ # @return [String]
87
+ def get_string_value; end
88
+
89
+ # The including class may implement this to do something when the parent {Wx::ComboCtrl} gets double-clicked.
90
+ # @return [void]
91
+ def on_combo_double_click; end
92
+
93
+ # The including class may implement this to receive key down events from the parent {Wx::ComboCtrl}.
94
+ #
95
+ # Events not handled should be skipped, as usual.
96
+ # @param event [Wx::KeyEvent]
97
+ # @return [void]
98
+ def on_combo_key_event(event) end
99
+
100
+ # The including class may implement this to receive char events from the parent {Wx::ComboCtrl}.
101
+ #
102
+ # Events not handled should be skipped, as usual.
103
+ # @param event [Wx::KeyEvent]
104
+ # @return [void]
105
+ def on_combo_char_event(event) end
106
+
107
+ # The including class may implement this to do special processing when popup is hidden.
108
+ # @return [void]
109
+ def on_dismiss; end
110
+
111
+ # The including class may implement this to do special processing when popup is shown.
112
+ # @return [void]
113
+ def on_popup; end
114
+
115
+ # The including class may implement this to paint the parent {Wx::ComboCtrl}.
116
+ # This is called to custom paint in the combo control itself (ie. not the popup).
117
+ #
118
+ # Default implementation draws value as string.
119
+ # @param dc [Wx::DC]
120
+ # @param rect [Wx::Rect]
121
+ # @return [void]
122
+ def paint_combo_control(dc, rect) end
123
+
124
+ end
125
+
126
+ # A Ruby interface class for default comboctrl popup classes used by {Wx::OwnerDrawnComboBox} and
127
+ # {Wx::RichTextStyleListBox}.
128
+ #
129
+ # If no custom popup control has been installed with {Wx::ComboCtrl#SetPopupControl} an instance of this
130
+ # class will be returned when {Wx::ComboCtrl#GetPopupControl} is called for either of the widgets mentioned
131
+ # above.
132
+ # <div class="wxrb-remark">
133
+ # <b>Remark:</b>
134
+ # <p>This is an abstract class that cannot be derived from.
135
+ # </p>
136
+ # </div>
137
+ class ComboPopupWx
138
+
139
+ include ComboPopup
15
140
 
16
141
  end
17
142
 
@@ -7,7 +7,11 @@
7
7
 
8
8
  module Wx
9
9
 
10
- class OwnerDrawnComboBox
10
+ class OwnerDrawnComboBox < ComboCtrl
11
+
12
+ alias :get_item_data :get_client_object
13
+
14
+ alias :set_item_data :set_client_object
11
15
 
12
16
  # Returns the label of the selected item or an empty string if no item is selected.
13
17
  #
data/lib/wx/version.rb CHANGED
@@ -3,5 +3,5 @@
3
3
  # This software is released under the MIT license.
4
4
 
5
5
  module Wx
6
- WXRUBY_VERSION = '0.9.4'
6
+ WXRUBY_VERSION = '0.9.7'
7
7
  end
@@ -25,12 +25,15 @@ module WxRuby
25
25
  end
26
26
  private :commands
27
27
 
28
+ def setup_done?
29
+ File.exist?(File.join(WxRuby::ROOT, 'ext', 'wxruby.setup.done'))
30
+ end
31
+
28
32
  def options
29
33
  @options ||= {
30
34
  :verbose => false
31
35
  }
32
36
  end
33
- private :options
34
37
 
35
38
  def register(cmdid, cmdhandler)
36
39
  commands[cmdid.to_s] = case
@@ -59,7 +62,7 @@ module WxRuby
59
62
  def parse_args(args)
60
63
  opts = OptionParser.new
61
64
  opts.banner = "Usage: wxruby [global options] COMMAND [arguments]\n\n" +
62
- " COMMAND\t\t\tSpecifies wxruby command to execute."
65
+ " COMMAND\t\t\t\tSpecifies wxruby command to execute."
63
66
  opts.separator ''
64
67
  opts.on('-v', '--verbose',
65
68
  'Show verbose output') { |v| ::WxRuby::Commands.options[:verbose] = true }
@@ -70,8 +73,7 @@ module WxRuby
70
73
  describe_all
71
74
  exit(0)
72
75
  end
73
- opts.raise_unknown = false
74
- opts.parse!(args)
76
+ opts.order!(args)
75
77
  end
76
78
  end
77
79
  end
@@ -10,44 +10,54 @@ require 'fileutils'
10
10
  module WxRuby
11
11
  module Commands
12
12
  class Sampler
13
- OPTIONS = {
14
- save_path: nil
15
- }
13
+
14
+ DESC = 'Run wxRuby3 Sampler application (or copy samples).'
16
15
 
17
16
  def self.description
18
- " sampler [help]|[copy DEST]\tRun wxRuby3 Sampler application (or copy samples)."
17
+ " sampler -h|[options]\t\t#{DESC}"
18
+ end
19
+
20
+ def self.options
21
+ Commands.options['sampler'] ||= { verbose: Commands.options[:verbose] }
22
+ end
23
+
24
+ def self.parse_args(args)
25
+ opts = OptionParser.new
26
+ opts.banner = "#{DESC}\n\nUsage: wxruby sampler -h|--help OR wxruby sampler [options]\n\n" +
27
+ "Runs the sampler application if no options specified.\n\n"
28
+ opts.separator ''
29
+ opts.on('--copy=DEST',
30
+ 'Copies the included wxRuby sample folders under the directory indicated by DEST (MUST exist)') {|v| Sampler.options[:copy] << v }
31
+ opts.on('-h', '--help',
32
+ 'Show this message.') do |v|
33
+ puts opts
34
+ puts
35
+ exit(0)
36
+ end
37
+ opts.parse!(args)
19
38
  end
20
39
 
21
40
  def self.run(argv)
22
- if argv == :describe
23
- description
24
- else
25
- if argv.empty?
26
- exec(RUBY, File.join(WxRuby::ROOT, 'samples', 'sampler.rb'))
27
- else
28
- arg = argv.shift
29
- if arg == 'help'
30
- puts 'Usage: wxruby [global options] sampler [help]|[copy DEST]'
31
- puts
32
- puts ' Starts the sampler application if called without arguments.'
33
- puts ' Otherwise shows this help for argument "help" or copies the included wxRuby'
34
- puts ' sample folders under the directory indicated by DEST for argument "copy DEST".'
35
- puts ' The directory indicated by DEST *must* already exist.'
36
- puts
37
- elsif arg == 'copy'
38
- unless File.directory?(dest = argv.shift)
39
- STDERR.puts "ERROR: Invalid destination folder #{dest}"
40
- exit(1)
41
- end
42
- Dir[File.join(WxRuby::ROOT, 'samples', '*')].each do |fp|
43
- FileUtils.cp_r(fp, dest, verbose: true)
44
- end
45
- end
41
+ return description if argv == :describe
42
+
43
+ parse_args(argv)
44
+
45
+ if options[:copy]
46
+ unless File.directory?(dest = options[:copy])
47
+ $stderr.puts "ERROR: Invalid destination folder #{dest}"
48
+ exit(1)
46
49
  end
50
+ Dir[File.join(WxRuby::ROOT, 'samples', '*')].each do |fp|
51
+ FileUtils.cp_r(fp, dest, verbose: true)
52
+ end
53
+ else
54
+ exec(RUBY, File.join(WxRuby::ROOT, 'samples', 'sampler.rb'))
47
55
  end
48
56
  end
49
57
  end
50
58
 
51
- self.register('sampler', Sampler)
59
+ if self.setup_done?
60
+ self.register('sampler', Sampler)
61
+ end
52
62
  end
53
63
  end
@@ -0,0 +1,122 @@
1
+ # Copyright (c) 2023 M.J.N. Corino, The Netherlands
2
+ #
3
+ # This software is released under the MIT license.
4
+
5
+ # wxruby setup command handler
6
+ #--------------------------------------------------------------------
7
+
8
+ require 'fileutils'
9
+
10
+ module WxRuby
11
+ module Commands
12
+ class Setup
13
+
14
+ DESC = 'Run wxRuby3 post-install setup.'
15
+
16
+ def self.description
17
+ " setup -h|[options]\t\t#{DESC}"
18
+ end
19
+
20
+ def self.options
21
+ Commands.options['setup'] ||= { verbose: Commands.options[:verbose] }
22
+ end
23
+
24
+ def self.parse_args(args)
25
+ opts = OptionParser.new
26
+ opts.banner = "#{DESC}\n\nUsage: wxruby setup -h|--help OR wxruby setup [options]\n\n"
27
+ opts.separator ''
28
+ opts.on('--wxwin=path',
29
+ "the installation root for the wxWidgets libraries and headers if not using the system default") {|v| Setup.options['wxwin'] = File.expand_path(v)}
30
+ opts.on('--wxxml=path',
31
+ "the path to the doxygen generated wxWidgets XML interface specs if not using bootstrap") {|v| Setup.options['wxxml'] = File.expand_path(v)}
32
+ opts.on('--with-wxwin',
33
+ "build a local copy of wxWidgets for use with wxRuby [false]") {|v| Setup.options['with-wxwin'] = true}
34
+ opts.on('--swig=path',
35
+ "the path to swig executable [swig]") {|v| Setup.options['swig'] = v}
36
+ opts.on('--doxygen=path',
37
+ "the path to doxygen executable [doxygen]") {|v| Setup.options['doxygen'] = v}
38
+ opts.on('--git=path',
39
+ "the path to git executable [git]") {|v| Setup.options['git'] = v}
40
+ opts.on('--[no-]autoinstall',
41
+ "do (not) attempt to automatically install any required packages") {|v| Setup.options['autoinstall'] = !!v }
42
+ opts.on('--log=PATH',
43
+ "write log to PATH/setup.log (PATH must exist) and do not remove when finished") {|v| Setup.options['log'] = v }
44
+ opts.on('-h', '--help',
45
+ 'Show this message.') do |v|
46
+ puts opts
47
+ puts
48
+ exit(0)
49
+ end
50
+ opts.parse!(args)
51
+ end
52
+
53
+ def self.run(argv)
54
+ return description if argv == :describe
55
+
56
+ parse_args(argv)
57
+
58
+ cfg_args = []
59
+ cfg_args << "--wxwin=#{Setup.options['wxwin']}" if Setup.options['wxwin']
60
+ cfg_args << "--wxxml=#{Setup.options['wxxml']}" if Setup.options['wxxml']
61
+ cfg_args << '--with-wxwin' if Setup.options['with-wxwin']
62
+ cfg_args << "--swig=#{Setup.options['swig']}" if Setup.options['swig']
63
+ cfg_args << "--doxygen=#{Setup.options['doxygen']}" if Setup.options['doxygen']
64
+ cfg_args << "--git=#{Setup.options['git']}" if Setup.options['git']
65
+ unless Setup.options['autoinstall'].nil?
66
+ cfg_args << (Setup.options['autoinstall'] ? '--autoinstall' : '--no-autoinstall')
67
+ end
68
+ cfg_cmd = 'rake configure'
69
+ cfg_cmd << "[#{cfg_args.join(',')}]" unless cfg_args.empty?
70
+
71
+ result = false
72
+ FileUtils.chdir(WxRuby::ROOT) do
73
+ steps = 0
74
+ actions_txt = if Setup.options['autoinstall'] != false
75
+ steps = 1
76
+ '(possibly) install required software'
77
+ else
78
+ ''
79
+ end
80
+ if Setup.options['with-wxwin'] || Setup.options['wxwin'].nil?
81
+ actions_txt << ', ' if steps>0
82
+ actions_txt << 'build the wxWidgets libraries (if needed), '
83
+ actions_txt << "\n" if steps>0
84
+ steps += 1
85
+ else
86
+ actions_txt << ',' if steps>0
87
+ end
88
+ actions_txt << 'build the native wxRuby3 extensions '
89
+ actions_txt << "\n" if steps==1
90
+ actions_txt << 'and generate the wxRuby3 reference documentation.'
91
+ $stdout.puts <<~__INFO_TXT
92
+
93
+ ---
94
+ Now running wxRuby3 post-install setup.
95
+ This will #{actions_txt}
96
+ Please be patient as this may take quite a while depending on your system.
97
+ ---
98
+
99
+ __INFO_TXT
100
+ log_file = File.join(WxRuby::ROOT, 'setup.log')
101
+ if Setup.options['log']
102
+ if File.directory?(Setup.options['log']) && File.writable?(Setup.options['log'])
103
+ log_file = File.join(Setup.options['log'], 'setup.log')
104
+ else
105
+ $stderr.puts "ERROR: cannot write log to #{Setup.options['log']}. Log path must exist and be writable."
106
+ exit(1)
107
+ end
108
+ end
109
+ run_env = {'WXRUBY_RUN_SILENT' => "#{log_file}"}
110
+ run_env['WXRUBY_VERBOSE'] = '1' if Setup.options[:verbose]
111
+ # can't rely on FileUtils#chdir returning the block result (bug in older Rubies) so assign result here
112
+ result = system(run_env, "#{cfg_cmd} && rake -m wxruby:gem:setup#{Setup.options['log'] ? '[:keep_log]' : ''} && gem rdoc wxruby3 --overwrite")
113
+ end
114
+ exit(result ? 0 : 1)
115
+ end
116
+ end
117
+
118
+ unless self.setup_done?
119
+ self.register('setup', Setup)
120
+ end
121
+ end
122
+ end