Module: Sweet
- Includes:
- Fox
- Defined in:
- lib/sweet/wx.rb,
lib/sweet/fox.rb,
lib/sweet/swt.rb,
lib/sweet/base.rb,
lib/sweet/gtk2.rb,
lib/sweet/swing.rb,
lib/sweet/swt/downloader.rb
Defined Under Namespace
Modules: Application, Component, Downloader
Classes: App, VarContainer
Constant Summary
collapse
- WIDGET_HACKS =
TODO integrate all standard widgets
{
}
- WIDGET_DEFAULTS =
{
:edit_line => default.merge(:class => JTextField),
:label => default,
:button => default.merge(:block_handler => :on_action),
:menu_bar => {:appender => :setJMenuBar}
}
- WIDGETS =
{}
- SWT_JAR =
File.join(File.dirname(__FILE__), 'swt.jar')
Class Method Summary
collapse
-
.app(*args, &block) ⇒ Object
-
.create_app(name, opts, &block) ⇒ Object
-
.create_widget(parent, name, *args, &block) ⇒ Object
-
.create_widget_class(class_name, init) ⇒ Object
-
.debug(text) ⇒ Object
-
.delegate_events(cls) ⇒ Object
-
.initialize_widget(parent, cls, opts, init) ⇒ Object
-
.set_debug(value = true) ⇒ Object
Class Method Details
.app(*args, &block) ⇒ Object
7
8
9
10
11
12
13
14
15
|
# File 'lib/sweet/base.rb', line 7
def self.app(*args, &block)
count = args.length
name = args.first.is_a?(String) ? args.shift : 'SWEET Application'
raise ArgumentError.new(count, 2) if args.size > 1
opts = args.first || {}
create_app(name, opts, &block)
end
|
.create_app(name, opts, &block) ⇒ Object
38
39
40
|
# File 'lib/sweet/wx.rb', line 38
def self.create_app(name, opts, &block)
App.new(name, opts, &block).main_loop
end
|
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/sweet/base.rb', line 17
def self.create_widget(parent, name, *args, &block)
init = WIDGET_DEFAULTS[name] || {}
unless cls = WIDGETS[name]
class_name = init[:class] || name
class_name = class_name.to_s.camelize(:upper) if class_name.is_a?(Symbol)
cls = create_widget_class(class_name, init)
unless WIDGETS.values.member? cls
delegate_events(cls)
if hacks = WIDGET_HACKS[cls]
if custom_code = hacks[:custom_code]
cls.class_eval &custom_code
end
end
end
end
opts = args.last.is_a?(Hash) ? args.pop.dup : {}
if init_args = init[:init_args]
Array(init_args).zip(args).each do |(k, v)|
opts.merge!(k => v) if v
end
end
widget = initialize_widget(parent, cls, opts, init)
widget.instance_variable_set(:@block_handler, init[:block_handler])
widget.sweeten(parent.app, opts, &block)
widget
end
|
42
43
44
|
# File 'lib/sweet/wx.rb', line 42
def self.create_widget_class(cls, init)
cls.is_a?(Class) ? cls : Wx.const_get(cls)
end
|
.debug(text) ⇒ Object
61
62
63
64
|
# File 'lib/sweet/base.rb', line 61
def self.debug(text)
puts text if @debug
end
|
.delegate_events(cls) ⇒ Object
53
54
55
|
# File 'lib/sweet/wx.rb', line 53
def self.delegate_events(cls)
end
|
46
47
48
49
50
51
|
# File 'lib/sweet/wx.rb', line 46
def self.initialize_widget(parent, cls, opts, init)
Sweet.debug "Creating #{cls}(#{parent})"
c = cls.new(parent, -1, opts.delete(:text) || '')
parent.get_sizer.add(c) if parent.get_sizer c
end
|
.set_debug(value = true) ⇒ Object
58
59
60
|
# File 'lib/sweet/base.rb', line 58
def self.set_debug(value = true)
@debug = value
end
|