widget_wrapper 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ *0.0.0*
2
+
3
+ * Put into its own gem
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2007 Lancelot Carlson
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.
data/README ADDED
@@ -0,0 +1 @@
1
+ == Widget Wrapper
@@ -0,0 +1,84 @@
1
+ require 'rake'
2
+ require 'rake/gempackagetask'
3
+ require 'rake/rdoctask'
4
+ require 'rake/testtask'
5
+ require 'spec/rake/spectask'
6
+
7
+ require 'lib/version'
8
+
9
+ NAME = "widget_wrapper"
10
+
11
+ windows = (PLATFORM =~ /win32|cygwin/)
12
+ SUDO = windows ? "" : "sudo"
13
+
14
+ dist_files = [ "lib", "spec" ]
15
+
16
+ spec = Gem::Specification.new do |s|
17
+ s.name = NAME
18
+ s.version = WidgetWrapper::VERSION
19
+ s.platform = Gem::Platform::RUBY
20
+ s.summary = "A DSL Wrapper for GUI Toolkits"
21
+ s.description = "A Ruby style DSL framework that lets you build and interact with GUI toolkits."
22
+ s.author = "Lance Carlson"
23
+ s.email = "lancecarlson@gmail.com"
24
+ s.homepage = "http://anvil.rubyforge.org"
25
+ s.has_rdoc = true
26
+
27
+ s.add_dependency('wxruby')
28
+ s.add_dependency('rake')
29
+
30
+ s.files = [ "CHANGELOG", "MIT-LICENSE", "README", "Rakefile", "spec.opts", "spec_helper.rb" ]
31
+ dist_files.each do |dir|
32
+ s.files = s.files + Dir.glob("#{dir}/**/*")
33
+ end
34
+
35
+ s.require_path = 'lib'
36
+ s.autorequire = 'widget_wrapper'
37
+ s.rubyforge_project = 'widget_wrapper'
38
+ end
39
+
40
+ Rake::GemPackageTask.new(spec) do |p|
41
+ p.gem_spec = spec
42
+ end
43
+
44
+ Rake::RDocTask.new do |rdoc|
45
+ rdoc.rdoc_dir = 'doc'
46
+ rdoc.title = 'Widget Wrapper'
47
+ rdoc.options << '--line-numbers' << '--inline-source' << '-A cattr_accessor=object'
48
+ rdoc.options << '--charset' << 'utf-8'
49
+ rdoc.rdoc_files.include('README', 'CHANGELOG', 'MIT-LICENSE')
50
+ rdoc.rdoc_files.include('lib/**/*.rb')
51
+ end
52
+
53
+ desc 'Run :package and install the resulting .gem'
54
+ task :install => :package do
55
+ sh %{#{SUDO} gem install pkg/#{NAME}-#{WidgetWrapper::VERSION} --no-rdoc --no-ri}
56
+ end
57
+
58
+ desc 'Run :clean and uninstall the .gem'
59
+ task :uninstall => [:clean] do
60
+ sh %{#{SUDO} gem uninstall #{NAME}}
61
+ end
62
+
63
+ desc "Run all specs"
64
+ Spec::Rake::SpecTask.new('spec') do |t|
65
+ t.spec_files = FileList['spec/**/*_spec.rb']
66
+ t.spec_opts = ['--options', 'spec.opts']
67
+ end
68
+
69
+ desc "Run all specs and generate an rcov report"
70
+ Spec::Rake::SpecTask.new('spec:rcov') do |t|
71
+ t.spec_files = FileList['spec/**/*_spec.rb']
72
+ t.spec_opts = ['--options', 'spec.opts']
73
+ t.rcov = true
74
+ t.rcov_dir = 'coverage'
75
+ t.rcov_opts = ['--exclude', 'gems', '--exclude', 'spec']
76
+ end
77
+
78
+ task :release => :package do
79
+ if ENV['RELEASE']
80
+ sh %{rubyforge add_release #{NAME} #{NAME} "#{ENV['RELEASE']}" pkg/#{NAME}-#{WidgetWrapper::VERSION}.gem}
81
+ else
82
+ puts 'Must specify release!'
83
+ end
84
+ end
@@ -0,0 +1,4 @@
1
+ module WidgetWrapper
2
+ class Controller
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module WidgetWrapper
2
+ VERSION = '0.0.1' unless defined?(::WidgetWrapper::VERSION)
3
+ end
@@ -0,0 +1,2 @@
1
+ require File.join(File.dirname(__FILE__), 'wx_wrapper')
2
+ require File.join(File.dirname(__FILE__), 'controller')
@@ -0,0 +1,3 @@
1
+ require 'wx'
2
+
3
+ Dir[File.dirname(__FILE__) + "/wx_wrapper/*.rb"].sort.each{|file| require(file)}
@@ -0,0 +1,14 @@
1
+ module WidgetWrapper
2
+ module Controls
3
+ def text_box(name, options={})
4
+ value = options[:value] ||= ""
5
+ position_array_to_instance(options)
6
+ size_array_to_instance(options)
7
+ style_array_to_constants(options)
8
+
9
+ Wx::TextCtrl.new(self, -1, value, options[:position], options[:size], options[:style])
10
+ end
11
+ end
12
+ end
13
+
14
+ Wx::Frame.send(:include, WidgetWrapper::Controls)
@@ -0,0 +1,8 @@
1
+ module WidgetWrapper
2
+ module Events
3
+ def self.build
4
+ yield
5
+ end
6
+
7
+ end
8
+ end
@@ -0,0 +1,49 @@
1
+
2
+ module WidgetWrapper
3
+ module FrameMethods
4
+ # Creates a new frame for the application.
5
+ # Examples:
6
+ #
7
+ # This will create a new frame with the title "test frame"
8
+ # frame "test frame", :position => [ 100, 100 ], :size => [ 640, 480 ]
9
+ #
10
+ def frame(title="", options={})
11
+ # Option Setup
12
+ options[:title] = title
13
+ position_array_to_instance(options)
14
+ size_array_to_instance(options)
15
+ full_screen = options[:full_screen]
16
+ maximize = options[:maximize]
17
+ center = case options[:center]
18
+ when :vertical : Wx::VERTICAL
19
+ when :horizontal : Wx::HORIZONTAL
20
+ when :both : Wx::BOTH
21
+ when true : Wx::BOTH
22
+ else nil
23
+ end
24
+
25
+ # Remove options that aren't supposed to be sent to wx ruby
26
+ options.delete(:maximize)
27
+ options.delete(:full_screen)
28
+ options.delete(:center)
29
+
30
+ # Create a new frame
31
+ frame = Wx::Frame.new(nil, options)
32
+
33
+ # Handle method level calls
34
+ frame.show_full_screen(true) if full_screen
35
+ frame.maximize(true) if maximize
36
+ frame.centre(center) if center
37
+
38
+ # Yield the frame instance into a block
39
+ if block_given?
40
+ yield(frame)
41
+ end
42
+
43
+ # Display the frame
44
+ frame.show
45
+ end
46
+ end
47
+ end
48
+
49
+ include WidgetWrapper::FrameMethods
@@ -0,0 +1,34 @@
1
+ # The application class is the initializer class for widgets
2
+
3
+ module WidgetWrapper
4
+ module Initializer
5
+ # Initializes the application widgets.
6
+ #
7
+ # anvil "FirstApp" do
8
+ # frame "Hello World!"
9
+ # end
10
+ def anvil(name)
11
+ Wx::App.run do
12
+ yield if block_given?
13
+ end
14
+ end
15
+
16
+ def extract_options_from_args!(args) #nodoc
17
+ args.last.is_a?(Hash) ? args.pop : {}
18
+ end
19
+
20
+ def position_array_to_instance(options) #nodoc
21
+ options[:position] = Wx::Point.new(options[:position][0], options[:position][1]) unless options[:position].nil?
22
+ end
23
+
24
+ def size_array_to_instance(options) #nodoc
25
+ options[:size] = Wx::Size.new(options[:size][0], options[:size][1]) unless options[:size].nil?
26
+ end
27
+
28
+ def style_array_to_constants(options) #nodoc
29
+ options[:style] = eval(options[:style].collect { |key| "Wx::TE_#{key.to_s.upcase}" }.join('|')) unless options[:style].nil?
30
+ end
31
+ end
32
+ end
33
+
34
+ include WidgetWrapper::Initializer
@@ -0,0 +1,157 @@
1
+ module WidgetWrapper
2
+ module Menus
3
+ module Frame
4
+ # Creates a menu bar for the frame. Example syntax:
5
+ #
6
+ # frame.menu_bar do |menu_bar|
7
+ # menu_bar.menu do |menu|
8
+ # end
9
+ # end
10
+ def menu_bar
11
+ new_menu_bar = Wx::MenuBar.new
12
+ yield(new_menu_bar) if block_given?
13
+ create_menu_events(new_menu_bar)
14
+ set_menu_bar(new_menu_bar)
15
+ end
16
+
17
+ def create_menu_events(menu_bar)
18
+ menu_bar.menus.each do |menu|
19
+ menu.items.each do |item|
20
+ evt_menu(item.get_id) { send(menu_item_label_to_method(item.get_label)) }
21
+ end
22
+ end
23
+ end
24
+
25
+ # Returns names for menu items prefixed with on_. ie on_save
26
+ def menu_item_label_to_method(label)
27
+ 'on_' + label.downcase.gsub(/[^a-zA-Z0-9 ]/, '').gsub(/[ ]/, '_')
28
+ end
29
+ end
30
+
31
+ # Menu bar syntax (This code follows after a frame block):
32
+ #
33
+ # menu_bar.menu "&File" do |item|
34
+ # item.add :new
35
+ # item.add :open
36
+ # item.separator
37
+ # item.add :save
38
+ # item.separator
39
+ # item.add :quit
40
+ # end
41
+ #
42
+ # menu_bar.menu "&Edit" do |item|
43
+ # item.add :undo
44
+ # item.add :redo
45
+ # end
46
+ #
47
+ # The & in the menu title (ie &File) is used underlined and used as a shortcut for referencing
48
+ # alt command navigation for windows. You can move the ampersand in front of a different letter
49
+ # if you would like another letter to be the shortcut for alt keys. (As of yet, I don't know how
50
+ # this works in OS X if it has any effect at all).
51
+ module MenuBar
52
+ # Gets a list of menus in the menu bar
53
+ def menus
54
+ (0..(get_menu_count-1)).collect {|menu_id| get_menu(menu_id)}
55
+ end
56
+
57
+ # Creates a menu inside of the menu bar.
58
+ #
59
+ # menu_bar.menu "&File" do |item|
60
+ # item.add :new
61
+ # end
62
+ def menu(title, options = {})
63
+ new_menu = Wx::Menu.new
64
+
65
+ if block_given?
66
+ yield(new_menu)
67
+ end
68
+
69
+ append(new_menu, title)
70
+ end
71
+ end
72
+
73
+ # Menu Syntax (Called after a menu bar block)
74
+ #
75
+ # menu "&File" do |item|
76
+ # item.add :new
77
+ # item.add :open
78
+ # item.separator
79
+ # item.add :save
80
+ # item.separator
81
+ # item.add :preview
82
+ # item.add :print
83
+ # item.separator
84
+ # item.add :close
85
+ # item.add :quit
86
+ # end
87
+ #
88
+ # Default menu items you can add are: new, open, close, exit, quit, save, print, preview, about, undo,
89
+ # redo, cut, copy, paste, delete, selectall, preferences, find, replace
90
+ #
91
+ # Default menu items have their operating system level icons loaded automatically.
92
+ module Menu
93
+ def default_items
94
+ {
95
+ :new => { :icon => get_icon(:new), :item => "&New\tCtrl-N", :help => "Create a file" },
96
+ :open => { :icon => get_icon(:open), :item => "&Open\tCtrl-O", :help => "Open a file" },
97
+ :close => { :icon => get_icon(:close), :item => "&Close\tCtrl-W", :help => "Close the file" },
98
+ :exit => { :icon => get_icon(:exit), :item => "E&xit\tAlt-F4", :help => "Exit Application" },
99
+ :quit => { :icon => get_icon(:exit), :item => "&Quit\tCtrl-Q", :help => "Quit Application" },
100
+ :save => { :icon => get_icon(:save), :item => "&Save\tCtrl-S", :help => "Save the file" },
101
+ :print => { :icon => get_icon(:print), :item => "&Print...\tCtrl-P", :help => "Print the file" },
102
+ :preview => { :icon => get_icon(:preview), :item => "Print Previe&w\tShift-Ctrl-P", :help => "Print preview the file" },
103
+ :about => { :icon => get_icon(:about), :item => "&About\tF1", :help => "About" },
104
+ :undo => { :icon => get_icon(:undo), :item => "&Undo\tCtrl+Z", :help => "Undo" },
105
+ :redo => { :icon => get_icon(:redo), :item => "&Redo\tCtrl+Shift+Z", :help => "Redo" },
106
+ :cut => { :icon => get_icon(:cut), :item => "Cu&t\tCtrl+X", :help => "Undo" },
107
+ :copy => { :icon => get_icon(:copy), :item => "&Copy\tCtrl+C", :help => "Copy" },
108
+ :paste => { :icon => get_icon(:paste), :item => "&Paste\tCtrl+V", :help => "Paste" },
109
+ :delete => { :icon => get_icon(:delete), :item => "&Delete", :help => "Delete" },
110
+ :selectall => { :icon => get_icon(:selectall), :item => "Select &All\tCtrl+A", :help => "Select All" },
111
+ :preferences => { :icon => get_icon(:preferences), :item => "Pr&eferences", :help => "Preferences" },
112
+ :find => { :icon => get_icon(:find), :item => "&Find...\tCtrl+F", :help => "Find" },
113
+ :replace => { :icon => get_icon(:replace), :item => "&Replace...\tCtrl+H", :help => "Replace" }
114
+ }
115
+ end
116
+
117
+ # Creates a menu item on the menu. Example syntax:
118
+ #
119
+ # item.add :close
120
+ def add(item, options={})
121
+ icon = options.include?(:icon) ? get_icon(options[:icon]) : default_items[item][:icon]
122
+
123
+ # 1st argument is the icon id, the next is menu item text, and then the next is the help text
124
+ args = []
125
+ args << icon
126
+ args << (options.include?(:item) ? options[:item] : default_items[item][:item])
127
+ args << (options.include?(:help) ? options[:help] : default_items[item][:help])
128
+
129
+ append(*args)
130
+ end
131
+
132
+ # Creates a new separator for the menu
133
+ def separator
134
+ append_separator
135
+ end
136
+
137
+ # Lists the menu item objects for a given menu
138
+ def items(options={})
139
+ items_list = (1..get_menu_item_count-1).collect do |position|
140
+ value = find_item_by_position(position)
141
+ value unless value.get_kind == -1 && !options.include?(:include_separators)
142
+ end
143
+ items_list.compact
144
+ end
145
+
146
+ # TODO: PUT into another module
147
+ def get_icon(icon)
148
+ Wx.const_get("ID_#{icon.to_s.upcase}")
149
+ end
150
+
151
+ end
152
+ end
153
+ end
154
+
155
+ Wx::Frame.send(:include, WidgetWrapper::Menus::Frame)
156
+ Wx::MenuBar.send(:include, WidgetWrapper::Menus::MenuBar)
157
+ Wx::Menu.send(:include, WidgetWrapper::Menus::Menu)
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ require 'wx'
4
+ require File.dirname(__FILE__) + '/../../lib/wx_wrapper/control'
5
+
6
+ describe WidgetWrapper::Controls do
7
+ before(:each) do
8
+ class MockControlParent; end
9
+ MockControlParent.send(:include, WidgetWrapper::Controls)
10
+ @parent = MockControlParent.new
11
+ @txtctrl = mock(Wx::TextCtrl)
12
+ end
13
+
14
+ it "should have a text box control" do
15
+ Wx::TextCtrl.should_receive(:new).with(@parent, -1, "", nil, nil, nil).and_return(@txtctrl)
16
+ @parent.text_box(:editor).should == @txtctrl
17
+ end
18
+ end
@@ -0,0 +1,16 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ require 'wx'
4
+ require File.dirname(__FILE__) + '/../../lib/wx_wrapper/event'
5
+
6
+ describe WidgetWrapper::Events do
7
+ before(:each) do
8
+
9
+ end
10
+
11
+ it "should have a build method that includes event class" do
12
+ WidgetWrapper::Events.build do
13
+ end
14
+ end
15
+
16
+ end
@@ -0,0 +1,99 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ require 'wx'
4
+ require File.dirname(__FILE__) + '/../../lib/wx_wrapper/initializer'
5
+ require File.dirname(__FILE__) + '/../../lib/wx_wrapper/frame'
6
+
7
+ describe WidgetWrapper::FrameMethods do
8
+ before(:each) do
9
+ @frame = mock(Wx::Frame)
10
+ @point = mock(Wx::Point)
11
+ @size = mock(Wx::Size)
12
+ end
13
+
14
+ it "should instantiate a wx ruby frame and display it" do
15
+ Wx::Frame.should_receive(:new).with(nil, :title => 'test frame').and_return(@frame)
16
+ @frame.should_receive(:show)
17
+
18
+ frame 'test frame'
19
+ end
20
+
21
+ it "should allow you to specify the position of the frame" do
22
+ Wx::Point.should_receive(:new).with(80, 100).and_return(@point)
23
+ Wx::Frame.should_receive(:new).with(nil, :title => 'test frame', :position => @point).and_return(@frame)
24
+ @frame.should_receive(:show)
25
+
26
+ frame 'test frame', :position => [ 80, 100 ]
27
+ end
28
+
29
+ it "should allow you to specify the size of the frame" do
30
+ Wx::Size.should_receive(:new).with(640, 480).and_return(@size)
31
+ Wx::Frame.should_receive(:new).with(nil, :title => 'test frame', :size => @size).and_return(@frame)
32
+ @frame.should_receive(:show)
33
+
34
+ frame 'test frame', :size => [ 640, 480 ]
35
+ end
36
+
37
+ it "should allow you to specify the style of the frame" do
38
+ pending("Need to figure out how this works")
39
+ end
40
+
41
+ it "should allow you to specify the name of the frame" do
42
+ pending("Not sure what this is for")
43
+ end
44
+
45
+ it "should allow you to stick the frame in full screen mode" do
46
+ Wx::Frame.should_receive(:new).with(nil, :title => 'Frame in full screen mode').and_return(@frame)
47
+ @frame.should_receive(:show_full_screen).with(true)
48
+ @frame.should_not_receive(:maximize)
49
+ @frame.should_receive(:show)
50
+
51
+ frame "Frame in full screen mode", :full_screen => true
52
+ end
53
+
54
+ it "should allow you to maximize the frame" do
55
+ Wx::Frame.should_receive(:new).with(nil, :title => 'Maximized Frame').and_return(@frame)
56
+ @frame.should_not_receive(:show_full_screen)
57
+ @frame.should_receive(:maximize).with(true)
58
+ @frame.should_receive(:show)
59
+
60
+ frame "Maximized Frame", :maximize => true
61
+ end
62
+
63
+ it "should allow you to center the frame horizontally" do
64
+ Wx::Frame.should_receive(:new).with(nil, :title => 'Centered Frame').and_return(@frame)
65
+ @frame.should_receive(:centre).with(Wx::HORIZONTAL)
66
+ @frame.should_receive(:show)
67
+ frame "Centered Frame", :center => :horizontal
68
+ end
69
+
70
+ it "should allow you to center the frame vertically" do
71
+ Wx::Frame.should_receive(:new).with(nil, :title => 'Centered Frame').and_return(@frame)
72
+ @frame.should_receive(:centre).with(Wx::VERTICAL)
73
+ @frame.should_receive(:show)
74
+ frame "Centered Frame", :center => :vertical
75
+ end
76
+
77
+ it "should allow you to center the frame horizontailly and vertically" do
78
+ Wx::Frame.should_receive(:new).with(nil, :title => 'Centered Frame').and_return(@frame)
79
+ @frame.should_receive(:centre).with(Wx::BOTH)
80
+ @frame.should_receive(:show)
81
+ frame "Centered Frame", :center => :both
82
+ end
83
+
84
+ it "should center the frame horizontailly and vertically when true is specified" do
85
+ Wx::Frame.should_receive(:new).with(nil, :title => 'Centered Frame').and_return(@frame)
86
+ @frame.should_receive(:centre).with(Wx::BOTH)
87
+ @frame.should_receive(:show)
88
+ frame "Centered Frame", :center => true
89
+ end
90
+
91
+ it "should yield the frame instance in a block" do
92
+ Wx::Frame.stub!(:new).and_return(@frame)
93
+ @frame.stub!(:show)
94
+
95
+ frame "Frame with block" do |frame|
96
+ frame.should == @frame
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,64 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ require 'wx'
4
+ require File.dirname(__FILE__) + '/../../lib/wx_wrapper/initializer'
5
+
6
+ describe WidgetWrapper::Initializer do
7
+ it "should run the application widgets" do
8
+ anvil "some cool app"
9
+ end
10
+
11
+ it "should have a method for extracting options from an arguments list" do
12
+ args = ["test", "test", {:test => 'test', :test2 => "test2"}]
13
+ extract_options_from_args!(args).should == {:test => 'test', :test2 => 'test2'}
14
+ end
15
+
16
+ it "should have a method that will scan options for a position array and change it to a point instance" do
17
+ @point = mock(Wx::Point)
18
+ options = {}
19
+ options[:position] = [ 100, 100 ]
20
+ Wx::Point.should_receive(:new).with(100, 100).and_return(@point)
21
+
22
+ position_array_to_instance(options).should == @point
23
+ options[:position].should == @point
24
+ end
25
+
26
+ it "should have a method that will scane options for a position array and do nothing if it can't" do
27
+ options = {}
28
+ Wx::Point.should_not_receive(:new)
29
+
30
+ position_array_to_instance(options)
31
+ end
32
+
33
+ it "should have a method that will scane options for a size array and change it to a size instance" do
34
+ @size = mock(Wx::Size)
35
+ options = {}
36
+ options[:size] = [ 100, 100 ]
37
+ Wx::Size.should_receive(:new).with(100, 100).and_return(@size)
38
+
39
+ size_array_to_instance(options).should == @size
40
+ options[:size].should == @size
41
+ end
42
+
43
+ it "should have a method that will scan options for a size array and do nothing if it can't" do
44
+ options = {}
45
+ Wx::Size.should_not_receive(:new)
46
+
47
+ size_array_to_instance(options)
48
+ end
49
+
50
+ it "should have a method that will scan options for a style array convert it to a constant" do
51
+ options = {}
52
+ options[:style] = [ :multiline, :rich ]
53
+
54
+ style_array_to_constants(options).should == Wx::TE_MULTILINE | Wx::TE_RICH
55
+ options[:style].should == Wx::TE_MULTILINE | Wx::TE_RICH
56
+ end
57
+
58
+ it "should have a method that will scan options for a style array and do nothing if it can't" do
59
+ options = {}
60
+
61
+ style_array_to_constants(options).should be_nil
62
+ options[:style].should be_nil
63
+ end
64
+ end
@@ -0,0 +1,121 @@
1
+ require File.dirname(__FILE__) + '/../../spec_helper'
2
+
3
+ require 'wx'
4
+ require File.dirname(__FILE__) + '/../../lib/wx_wrapper/menu'
5
+
6
+ describe WidgetWrapper::Menus::Frame do
7
+ before(:each) do
8
+ class MockFrame; end
9
+ MockFrame.send(:include, WidgetWrapper::Menus::Frame)
10
+ @frame = MockFrame.new
11
+ @menu_bar = mock(Wx::MenuBar)
12
+ @menu = mock(Wx::Menu)
13
+ @menu_item = mock(Wx::MenuItem)
14
+ end
15
+
16
+ it "should have a list of the menus inside of it" do
17
+ pending("Need to write test")
18
+ end
19
+
20
+ it "should have a menu_bar method for creating menu bars that yields an instance of the menu_bar" do
21
+ Wx::MenuBar.should_receive(:new).and_return(@menu_bar)
22
+ @frame.should_receive(:create_menu_events).with(@menu_bar)
23
+ @frame.should_receive(:set_menu_bar).with(@menu_bar)
24
+
25
+ @frame.menu_bar do |menu_bar|
26
+ menu_bar.should == @menu_bar
27
+ end
28
+ end
29
+
30
+ it "should have a way to generate all of the menu events" do
31
+ @menu_bar.should_receive(:menus).and_return([@menu])
32
+ @menu.should_receive(:items).and_return([@menu_item])
33
+ @menu_item.should_receive(:get_id).and_return(1)
34
+ @frame.should_receive(:evt_menu).with(1)
35
+
36
+ @frame.create_menu_events(@menu_bar)
37
+ end
38
+
39
+ it "should convert item labels to event methods" do
40
+ @frame.menu_item_label_to_method("New").should == 'on_new'
41
+ end
42
+ end
43
+
44
+ describe WidgetWrapper::Menus::MenuBar do
45
+ before(:each) do
46
+ class MockMenuBar; end
47
+ MockMenuBar.send(:include, WidgetWrapper::Menus::MenuBar)
48
+ @menu_bar = MockMenuBar.new
49
+ @menu = mock(Wx::Menu)
50
+ @menu2 = mock(Wx::Menu)
51
+ end
52
+
53
+ it "should list menus attached" do
54
+ @menu_bar.should_receive(:get_menu_count).and_return(2)
55
+ @menu_bar.should_receive(:get_menu).with(0).and_return(@menu)
56
+ @menu_bar.should_receive(:get_menu).with(1).and_return(@menu2)
57
+
58
+ @menu_bar.menus.should == [@menu, @menu2]
59
+ end
60
+
61
+ it "should return a menu if there is only one" do
62
+ @menu_bar.should_receive(:get_menu_count).and_return(1)
63
+ @menu_bar.should_receive(:get_menu).with(0).and_return(@menu)
64
+
65
+ @menu_bar.menus.should == [@menu]
66
+ end
67
+
68
+ it "should return an empty array if no menus where found" do
69
+ @menu_bar.should_receive(:get_menu_count).and_return(0)
70
+ @menu_bar.should_not_receive(:get_menu)
71
+
72
+ @menu_bar.menus.should == []
73
+ end
74
+
75
+ it "should create a menu on the menu bar" do
76
+ Wx::Menu.should_receive(:new).and_return(@menu)
77
+ @menu_bar.should_receive(:append).with(@menu, "&File")
78
+
79
+ @menu_bar.menu "&File" do |menu|
80
+ menu.should == @menu
81
+ end
82
+ end
83
+ end
84
+
85
+ describe WidgetWrapper::Menus::Menu do
86
+ before(:each) do
87
+ class MockMenu; end
88
+ MockMenu.send(:include, WidgetWrapper::Menus::Menu)
89
+ @menu = MockMenu.new
90
+ @item = mock(Wx::MenuItem)
91
+ @item2 = mock(Wx::MenuItem)
92
+ end
93
+
94
+ it "should have default menu items" do
95
+ @menu.default_items
96
+ end
97
+
98
+ it "should add a menu item to the menu" do
99
+ @menu.should_receive(:append).with(Wx::ID_NEW, "&New\tCtrl-N", "Create a file")
100
+ @menu.add :new
101
+ end
102
+
103
+ it "should add a separator to the menu" do
104
+ @menu.should_receive(:append_separator)
105
+ @menu.separator
106
+ end
107
+
108
+ it "should list the items in the menu" do
109
+ @menu.should_receive(:get_menu_item_count).and_return(3)
110
+ @menu.should_receive(:find_item_by_position).with(1).and_return(@item)
111
+ @menu.should_receive(:find_item_by_position).with(2).and_return(@item2)
112
+ @item.should_receive(:get_kind).and_return(Wx::ITEM_NORMAL)
113
+ @item2.should_receive(:get_kind).and_return(Wx::ITEM_NORMAL)
114
+ @menu.items.should == [@item, @item2]
115
+ end
116
+
117
+ it "should list the items in the menu without the separators" do
118
+ pending("NEed to write test")
119
+ end
120
+
121
+ end
@@ -0,0 +1,5 @@
1
+ require 'rubygems'
2
+
3
+ Spec::Runner.configure do |config|
4
+ end
5
+
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: widget_wrapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Lance Carlson
8
+ autorequire: widget_wrapper
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2007-12-25 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: wxruby
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: rake
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: "0"
32
+ version:
33
+ description: A Ruby style DSL framework that lets you build and interact with GUI toolkits.
34
+ email: lancecarlson@gmail.com
35
+ executables: []
36
+
37
+ extensions: []
38
+
39
+ extra_rdoc_files: []
40
+
41
+ files:
42
+ - CHANGELOG
43
+ - MIT-LICENSE
44
+ - README
45
+ - Rakefile
46
+ - spec.opts
47
+ - spec_helper.rb
48
+ - lib/controller.rb
49
+ - lib/version.rb
50
+ - lib/widget_wrapper.rb
51
+ - lib/wx_wrapper
52
+ - lib/wx_wrapper/control.rb
53
+ - lib/wx_wrapper/event.rb
54
+ - lib/wx_wrapper/frame.rb
55
+ - lib/wx_wrapper/initializer.rb
56
+ - lib/wx_wrapper/menu.rb
57
+ - lib/wx_wrapper.rb
58
+ - spec/wx_wrapper
59
+ - spec/wx_wrapper/control_spec.rb
60
+ - spec/wx_wrapper/event_spec.rb
61
+ - spec/wx_wrapper/frame_spec.rb
62
+ - spec/wx_wrapper/initializer_spec.rb
63
+ - spec/wx_wrapper/menu_spec.rb
64
+ has_rdoc: true
65
+ homepage: http://anvil.rubyforge.org
66
+ post_install_message:
67
+ rdoc_options: []
68
+
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: "0"
82
+ version:
83
+ requirements: []
84
+
85
+ rubyforge_project: widget_wrapper
86
+ rubygems_version: 1.0.0
87
+ signing_key:
88
+ specification_version: 2
89
+ summary: A DSL Wrapper for GUI Toolkits
90
+ test_files: []
91
+