sweet 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +9 -5
- data/bin/sweet +3 -1
- data/examples/fox/hello_world.rb +12 -0
- data/examples/gtk2/hello_world.rb +14 -0
- data/examples/swing/hello_world.rb +12 -0
- data/examples/swt/components.rb +112 -0
- data/examples/swt/components/buttons.rb +35 -0
- data/examples/{hello_world.rb → swt/hello_world.rb} +2 -2
- data/examples/{snippet108.rb → swt/snippet108.rb} +2 -2
- data/examples/{snippet128.rb → swt/snippet128.rb} +7 -8
- data/examples/{snippet169.rb → swt/snippet169.rb} +2 -2
- data/examples/{snippet82.rb → swt/snippet82.rb} +2 -2
- data/examples/wx/hello_world.rb +12 -0
- data/lib/sweet.rb +22 -1
- data/lib/sweet/base.rb +151 -177
- data/lib/sweet/fox.rb +47 -0
- data/lib/sweet/fox/application.rb +9 -0
- data/lib/sweet/fox/object.rb +19 -0
- data/lib/sweet/gtk2.rb +56 -0
- data/lib/sweet/gtk2/application.rb +11 -0
- data/lib/sweet/gtk2/widget.rb +5 -0
- data/lib/sweet/hacks.rb +0 -17
- data/lib/sweet/swing.rb +97 -0
- data/lib/sweet/swing/application.rb +9 -0
- data/lib/sweet/swing/component.rb +23 -0
- data/lib/sweet/swing/frame.rb +13 -0
- data/lib/sweet/swt.rb +193 -0
- data/lib/sweet/swt/application.rb +17 -0
- data/lib/sweet/{composite.rb → swt/composite.rb} +5 -2
- data/lib/sweet/{dialog.rb → swt/dialog.rb} +0 -0
- data/lib/sweet/{downloader.rb → swt/downloader.rb} +1 -1
- data/lib/sweet/swt/shell.rb +22 -0
- data/lib/sweet/swt/src.zip +0 -0
- data/lib/sweet/swt/swt.jar +0 -0
- data/lib/sweet/swt/widget.rb +89 -0
- data/lib/sweet/wx.rb +57 -0
- data/lib/sweet/wx/application.rb +9 -0
- data/lib/sweet/wx/object.rb +19 -0
- data/spec/api_spec.rb +15 -0
- data/spec/downloader_spec.rb +28 -26
- data/spec/fox_spec.rb +15 -0
- data/spec/gtk2_spec.rb +15 -0
- data/spec/sweet_spec.rb +15 -0
- data/spec/swing_spec.rb +15 -0
- data/spec/swt_spec.rb +15 -0
- data/spec/wx_spec.rb +15 -0
- metadata +44 -17
- data/lib/sweet/shell.rb +0 -53
- data/lib/sweet/widget.rb +0 -151
@@ -1,14 +1,17 @@
|
|
1
1
|
class Java::OrgEclipseSwtWidgets::Composite
|
2
2
|
|
3
|
-
def layout=(name,
|
3
|
+
def layout=(name, opts = {})
|
4
|
+
Sweet.debug "layout = #{name}(#{opts.inspect})"
|
5
|
+
# TODO allow instantiated layouts and layout classes
|
4
6
|
class_name = "#{name.to_s.capitalize}Layout"
|
5
7
|
l = instance_eval "org.eclipse.swt.layout.#{class_name}.new"
|
6
8
|
|
7
|
-
|
9
|
+
opts.each_pair do |k,v|
|
8
10
|
l.send("#{k}=", v)
|
9
11
|
end
|
10
12
|
|
11
13
|
setLayout l
|
14
|
+
Sweet.debug getLayout
|
12
15
|
end
|
13
16
|
|
14
17
|
end
|
File without changes
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# TODO pack into WIDGETS
|
2
|
+
class Java::OrgEclipseSwtWidgets::Shell
|
3
|
+
attr_reader :display
|
4
|
+
alias_property :title => :text
|
5
|
+
|
6
|
+
def sweeten(display, name, opts = {}, &block)
|
7
|
+
@display = display
|
8
|
+
|
9
|
+
self.text = opts.delete(:title) || name
|
10
|
+
w, h = opts.delete(:width), opts.delete(:height)
|
11
|
+
|
12
|
+
super(self, opts, &block)
|
13
|
+
|
14
|
+
pack
|
15
|
+
size = (w || width), (h || height)
|
16
|
+
end
|
17
|
+
|
18
|
+
def menubar(&block)
|
19
|
+
self.menu_bar = make_menu(:menubar, &block)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
Binary file
|
Binary file
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'forwardable' # TODO remove?
|
2
|
+
|
3
|
+
class Java::OrgEclipseSwtWidgets::Widget
|
4
|
+
include Sweet::Component
|
5
|
+
|
6
|
+
def sweet_block_handler(handler, &block)
|
7
|
+
return false unless handler.is_a? Numeric
|
8
|
+
addListener handler, &block
|
9
|
+
true
|
10
|
+
end
|
11
|
+
|
12
|
+
# TODO unify this layout mess somehow
|
13
|
+
# TODO hierarchical hash for nicer client code
|
14
|
+
def grid_data=(*options)
|
15
|
+
opts = {}
|
16
|
+
options.each do |(k, v)|
|
17
|
+
opts[k] = v
|
18
|
+
end
|
19
|
+
ax, ay = opts[:align]
|
20
|
+
gx, gy = opts[:grab]
|
21
|
+
sx, sy = opts[:span]
|
22
|
+
args = [ax || swt::BEGINNING, ay || swt::CENTER,
|
23
|
+
gx || false, gy || false, sx || 1, sy || 1]
|
24
|
+
puts args.inspect
|
25
|
+
args.map!{|v| v.is_a?(Symbol) ? v.swt_const : v}
|
26
|
+
Sweet.debug args.inspect
|
27
|
+
l = layouts::GridData.new(*args)
|
28
|
+
self.layout_data = l
|
29
|
+
end
|
30
|
+
def row_data=(x, y = nil)
|
31
|
+
self.layout_data = layouts::RowData.new(x || swt::DEFAULT, y || swt::DEFAULT)
|
32
|
+
end
|
33
|
+
|
34
|
+
def hide
|
35
|
+
self.visible = false
|
36
|
+
end
|
37
|
+
def show
|
38
|
+
self.visible = true
|
39
|
+
end
|
40
|
+
|
41
|
+
def width
|
42
|
+
size.x
|
43
|
+
end
|
44
|
+
def width=(value)
|
45
|
+
Sweet.debug "width=(#{value.inspect})"
|
46
|
+
setSize(value, height)
|
47
|
+
end
|
48
|
+
|
49
|
+
def height
|
50
|
+
size.y
|
51
|
+
end
|
52
|
+
def height=(value)
|
53
|
+
self.size = nil, value
|
54
|
+
end
|
55
|
+
|
56
|
+
def size=(*s)
|
57
|
+
Sweet.debug "size=(#{s.inspect})"
|
58
|
+
nw, nh = s.flatten
|
59
|
+
nw ||= width
|
60
|
+
nh ||= height
|
61
|
+
Sweet.debug "setSize(#{nw.inspect}, #{nh.inspect})"
|
62
|
+
setSize(nw, nh)
|
63
|
+
end
|
64
|
+
|
65
|
+
def popup(&block)
|
66
|
+
self.menu = make_menu(:popup, &block)
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
def make_menu(type, &block)
|
71
|
+
Sweet.create_widget(sweet_containers.last, type, &block)
|
72
|
+
end
|
73
|
+
|
74
|
+
# TODO replace via import?
|
75
|
+
def swt
|
76
|
+
org.eclipse.swt.SWT
|
77
|
+
end
|
78
|
+
def widgets
|
79
|
+
org.eclipse.swt.widgets
|
80
|
+
end
|
81
|
+
def layouts
|
82
|
+
org.eclipse.swt.layout
|
83
|
+
end
|
84
|
+
def custom
|
85
|
+
org.eclipse.swt.custom
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
data/lib/sweet/wx.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'sweet/base'
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'wx'
|
5
|
+
%w{object application}.each{|file| require "sweet/wx/#{file}"}
|
6
|
+
|
7
|
+
module Sweet
|
8
|
+
|
9
|
+
# TODO integrate all standard widgets
|
10
|
+
WIDGET_HACKS = {
|
11
|
+
Wx::TextCtrl => {:custom_code => proc{ alias text get_value; alias text= set_value} }
|
12
|
+
}
|
13
|
+
|
14
|
+
default = {:init_args => :text}
|
15
|
+
WIDGET_DEFAULTS = {
|
16
|
+
:label => default.merge(:class => Wx::StaticText),
|
17
|
+
:edit_line => default.merge(:class => Wx::TextCtrl),
|
18
|
+
:button => default.merge(:block_handler => :evt_button)
|
19
|
+
}
|
20
|
+
|
21
|
+
class App < Wx::App
|
22
|
+
include Sweet::Application
|
23
|
+
|
24
|
+
def initialize(name, opts, &block)
|
25
|
+
@name, @opts, @block = name, opts, block
|
26
|
+
super()
|
27
|
+
end
|
28
|
+
|
29
|
+
def on_init
|
30
|
+
title = @opts[:title] || @name
|
31
|
+
frame = Wx::Frame.new(nil, -1, title)
|
32
|
+
initialize_app(frame)
|
33
|
+
frame.sweeten(self, @opts, &@block)
|
34
|
+
frame.show
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.create_app(name, opts, &block)
|
39
|
+
App.new(name, opts, &block).main_loop
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.create_widget_class(cls, init)
|
43
|
+
cls.is_a?(Class) ? cls : Wx.const_get(cls)
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.initialize_widget(parent, cls, opts, init)
|
47
|
+
Sweet.debug "Creating #{cls}(#{parent})"
|
48
|
+
c = cls.new(parent, -1, opts.delete(:text) || '')
|
49
|
+
parent.get_sizer.add(c) if parent.get_sizer # TODO parameters
|
50
|
+
c
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.delegate_events(cls)
|
54
|
+
# nothing to do
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Wx::Object
|
2
|
+
include Sweet::Component
|
3
|
+
|
4
|
+
def handle_event(evt, &block)
|
5
|
+
send evt, get_id do |event|
|
6
|
+
block.call
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def layout=(layout)
|
11
|
+
l = case layout
|
12
|
+
when :flow
|
13
|
+
Wx::BoxSizer.new(Wx::HORIZONTAL)
|
14
|
+
when :stack
|
15
|
+
Wx::BoxSizer.new(Wx::VERTICAL)
|
16
|
+
end
|
17
|
+
set_sizer l
|
18
|
+
end
|
19
|
+
end
|
data/spec/api_spec.rb
ADDED
data/spec/downloader_spec.rb
CHANGED
@@ -1,36 +1,38 @@
|
|
1
|
-
|
1
|
+
if RUBY_PLATFORM =~ /java/
|
2
|
+
require 'sweet/swt/downloader'
|
2
3
|
|
3
|
-
describe Sweet::Downloader, '#system_qualifier' do
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
describe Sweet::Downloader, '#system_qualifier' do
|
5
|
+
before :each do
|
6
|
+
@d = Sweet::Downloader
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
it 'returns gtk-linux-x86 for Linux i686' do
|
10
|
+
@d.system_qualifier(:os => 'Linux', :arch => 'i686').should == 'gtk-linux-x86'
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
it 'returns gtk-linux-x86 for Linux x86_64' do
|
14
|
+
@d.system_qualifier(:os => 'Linux', :arch => 'x86_64').should == 'gtk-linux-x86_64'
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
it 'returns motif-linux-x86 for Linux i686 and :tk => "motif"' do
|
18
|
+
@d.system_qualifier(:os => 'Linux', :arch => 'i686', :tk => 'motif').should == 'motif-linux-x86'
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
it 'returns cocoa-macos for Mac OS X i686' do
|
22
|
+
@d.system_qualifier(:os => 'Mac OS X', :arch => 'i686').should == 'cocoa-macosx'
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
it 'returns cocoa-macos-x86_64 for Mac OS X x86_64' do
|
26
|
+
@d.system_qualifier(:os => 'Mac OS X', :arch => 'x86_64').should == 'cocoa-macosx-x86_64'
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
it 'returns win32-win32-x86 for Windows XP' do
|
30
|
+
@d.system_qualifier(:os => 'Windows XP', :arch => 'i686').should == 'win32-win32-x86'
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
it 'returns win32-win32-x86_64 for Windows Vista on x86_64' do
|
34
|
+
@d.system_qualifier(:os => 'Windows Vista', :arch => 'x86_64').should == 'win32-win32-x86_64'
|
35
|
+
end
|
35
36
|
|
37
|
+
end
|
36
38
|
end
|
data/spec/fox_spec.rb
ADDED
data/spec/gtk2_spec.rb
ADDED
data/spec/sweet_spec.rb
ADDED
data/spec/swing_spec.rb
ADDED
data/spec/swt_spec.rb
ADDED
data/spec/wx_spec.rb
ADDED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Michael Klaus
|
@@ -14,14 +14,13 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-07-27 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: zippy
|
22
22
|
prerelease: false
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
-
none: false
|
25
24
|
requirements:
|
26
25
|
- - ">="
|
27
26
|
- !ruby/object:Gem::Version
|
@@ -44,20 +43,50 @@ files:
|
|
44
43
|
- README.rdoc
|
45
44
|
- Rakefile
|
46
45
|
- bin/sweet
|
46
|
+
- spec/api_spec.rb
|
47
47
|
- spec/downloader_spec.rb
|
48
|
+
- spec/sweet_spec.rb
|
49
|
+
- spec/swing_spec.rb
|
50
|
+
- spec/wx_spec.rb
|
51
|
+
- spec/gtk2_spec.rb
|
52
|
+
- spec/fox_spec.rb
|
53
|
+
- spec/swt_spec.rb
|
48
54
|
- lib/sweet.rb
|
49
|
-
- lib/sweet/
|
50
|
-
- lib/sweet/widget.rb
|
55
|
+
- lib/sweet/gtk2.rb
|
51
56
|
- lib/sweet/hacks.rb
|
52
|
-
- lib/sweet/
|
53
|
-
- lib/sweet/
|
57
|
+
- lib/sweet/fox.rb
|
58
|
+
- lib/sweet/swt.rb
|
59
|
+
- lib/sweet/swing.rb
|
54
60
|
- lib/sweet/base.rb
|
55
|
-
- lib/sweet/
|
56
|
-
-
|
57
|
-
-
|
58
|
-
-
|
59
|
-
-
|
60
|
-
-
|
61
|
+
- lib/sweet/wx.rb
|
62
|
+
- lib/sweet/gtk2/widget.rb
|
63
|
+
- lib/sweet/gtk2/application.rb
|
64
|
+
- lib/sweet/swt/shell.rb
|
65
|
+
- lib/sweet/swt/widget.rb
|
66
|
+
- lib/sweet/swt/application.rb
|
67
|
+
- lib/sweet/swt/downloader.rb
|
68
|
+
- lib/sweet/swt/composite.rb
|
69
|
+
- lib/sweet/swt/swt.jar
|
70
|
+
- lib/sweet/swt/src.zip
|
71
|
+
- lib/sweet/swt/dialog.rb
|
72
|
+
- lib/sweet/fox/application.rb
|
73
|
+
- lib/sweet/fox/object.rb
|
74
|
+
- lib/sweet/wx/application.rb
|
75
|
+
- lib/sweet/wx/object.rb
|
76
|
+
- lib/sweet/swing/frame.rb
|
77
|
+
- lib/sweet/swing/component.rb
|
78
|
+
- lib/sweet/swing/application.rb
|
79
|
+
- examples/gtk2/hello_world.rb
|
80
|
+
- examples/swt/components.rb
|
81
|
+
- examples/swt/snippet128.rb
|
82
|
+
- examples/swt/snippet169.rb
|
83
|
+
- examples/swt/snippet108.rb
|
84
|
+
- examples/swt/snippet82.rb
|
85
|
+
- examples/swt/hello_world.rb
|
86
|
+
- examples/swt/components/buttons.rb
|
87
|
+
- examples/fox/hello_world.rb
|
88
|
+
- examples/wx/hello_world.rb
|
89
|
+
- examples/swing/hello_world.rb
|
61
90
|
has_rdoc: true
|
62
91
|
homepage: http://github.org/QaDeS/sweet
|
63
92
|
licenses: []
|
@@ -74,7 +103,6 @@ rdoc_options:
|
|
74
103
|
require_paths:
|
75
104
|
- lib
|
76
105
|
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
-
none: false
|
78
106
|
requirements:
|
79
107
|
- - ">="
|
80
108
|
- !ruby/object:Gem::Version
|
@@ -82,7 +110,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
82
110
|
- 0
|
83
111
|
version: "0"
|
84
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
-
none: false
|
86
113
|
requirements:
|
87
114
|
- - ">="
|
88
115
|
- !ruby/object:Gem::Version
|
@@ -92,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
119
|
requirements: []
|
93
120
|
|
94
121
|
rubyforge_project:
|
95
|
-
rubygems_version: 1.3.
|
122
|
+
rubygems_version: 1.3.6
|
96
123
|
signing_key:
|
97
124
|
specification_version: 3
|
98
125
|
summary: The SWT wrapper for JRuby
|