Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experiment (for review) #3

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions lib/shoes/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,22 @@ class << self
attr_accessor :framework

def framework=(value)
@framework = value
require value
# Only SWT works this way right now
if value.to_s == 'swt'
@framework = value.to_s.downcase
require "shoes/#{@framework}"
else
@framework = value
require value
end
end
def framework_class
constant(@framework.camelcase)
# Only SWT works this way right now
if @framework == 'swt'
constant("shoes/#{@framework}".modulize)
else
constant(@framework.camelcase)
end
end
end

Expand Down
18 changes: 9 additions & 9 deletions lib/swt_shoes.rb → lib/shoes/swt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ def window(*a, &b)
Shoes.app(*a, &b)
end

require 'swt_shoes/element_methods'
require 'swt_shoes/app'
require 'swt_shoes/layout'
#require 'swt_shoes/window'
require 'swt_shoes/flow'
require 'swt_shoes/button'

module SwtShoes
module Shoes
require 'shoes/swt/element_methods'
require 'shoes/swt/app'
require 'shoes/swt/layout'
#require 'shoes/swt/window'
require 'shoes/swt/flow'
require 'shoes/swt/button'

module Shoes
module Swt


include Log4jruby::LoggerForClass
Expand Down
File renamed without changes.
16 changes: 9 additions & 7 deletions lib/swt_shoes/app.rb → lib/shoes/swt/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,32 @@

#require 'shoes/framework_adapters/swt_shoes/window'

module SwtShoes
module Shoes
module Swt

# Shoes::App.new creates a new Shoes application window!
# The default window is a [flow]
#
module App

def gui_init
self.gui_container = container = Swt::Widgets::Shell.new(Swt.display, Swt::SWT::CLOSE)
layout = Swt::Layout::RowLayout.new
self.gui_container = container = ::Swt::Widgets::Shell.new(::Swt.display, ::Swt::SWT::CLOSE)
layout = ::Swt::Layout::RowLayout.new
container.setLayout(layout)

opts = self.opts

container.setSize(self.width, self.height)
container.setText(self.title)

container.addListener(Swt::SWT::Close, main_window_on_close)
container.addListener(::Swt::SWT::Close, main_window_on_close)
end


def gui_open
self.gui_container.open

Swt.event_loop { Swt.display.isDisposed }
::Swt.event_loop { ::Swt.display.isDisposed }

Shoes.logger.debug "Swt.display disposed... exiting Shoes::App.new"
end
Expand All @@ -35,16 +36,17 @@ def gui_open
def main_window_on_close
lambda {
Shoes.logger.debug "main_window on_close block begin... disposing Swt.display"
Swt.display.dispose
::Swt.display.dispose
Shoes.logger.debug "Swt.display disposed"
}
end
end
end
end

module Shoes
class App
include SwtShoes::App
include Swt::App
end
end

8 changes: 5 additions & 3 deletions lib/swt_shoes/button.rb → lib/shoes/swt/button.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module SwtShoes
module Shoes
module Swt
module Button

def gui_button_init
# Create a button on the specified _shell_
#def initialize(container, text = 'Button', opts = {}, &blk)
self.gui_element = button = Swt::Widgets::Button.new(self.gui_container, Swt::SWT::PUSH)
self.gui_element = button = ::Swt::Widgets::Button.new(self.gui_container, ::Swt::SWT::PUSH)
button.setText(self.text)
#@native_widget.setBounds(10, 10, 150, 30)

Expand All @@ -14,9 +15,10 @@ def gui_button_init

end
end
end

module Shoes
class Button
include SwtShoes::Button
include Swt::Button
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
require 'white_shoes/element_methods'


module SwtShoes
module Shoes
module Swt
module ElementMethods

include WhiteShoes::ElementMethods
Expand Down Expand Up @@ -54,4 +55,5 @@ module ElementMethods
#end
#
end
end
end
10 changes: 6 additions & 4 deletions lib/swt_shoes/flow.rb → lib/shoes/swt/flow.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
module SwtShoes
module Shoes
module Swt
# flow takes these options
# :margin - integer - add this many pixels to all 4 sides of the layout

module Flow

def gui_flow_init
self.gui_container = container = Swt::Widgets::Composite.new(self.parent_gui_container, Swt::SWT::NONE)
self.gui_container = container = ::Swt::Widgets::Composite.new(self.parent_gui_container, ::Swt::SWT::NONE)

# RowLayout is horizontal by default, wrapping by default
layout = Swt::Layout::RowLayout.new
layout = ::Swt::Layout::RowLayout.new

# set the margins
set_margin(layout)
Expand All @@ -35,11 +36,12 @@ def set_margin(layout)
end
end
end
end


module Shoes
class Flow
include SwtShoes::Flow
include Swt::Flow
end
end

10 changes: 6 additions & 4 deletions lib/swt_shoes/layout.rb → lib/shoes/swt/layout.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
#require 'shoes/framework_adapters/swt_shoes/element_methods'

module SwtShoes
module Shoes
module Swt
class Layout

DEFAULT_WIDTH = 800
DEFAULT_HEIGHT = 600
DEFAULT_TITLE = "Shooes!"


include SwtShoes::ElementMethods
include Shoes::Swt::ElementMethods
include Log4jruby::LoggerForClass

# default initializer for calls to
# super() from descendant classes
def initialize(composite_parent, opts = {}, &blk)
@container = Swt::Widgets::Composite.new(composite_parent, Swt::SWT::NONE || Swt::SWT::BORDER)
@container = ::Swt::Widgets::Composite.new(composite_parent, ::Swt::SWT::NONE || ::Swt::SWT::BORDER)

width, height = opts['width'] || DEFAULT_WIDTH, opts['height'] || DEFAULT_HEIGHT

# RowLayout is horizontal by default, wrapping by default
@layout = Swt::Layout::RowLayout.new
@layout = ::Swt::Layout::RowLayout.new

@layout.type = opts['layout_type'] if opts['layout_type']

Expand Down Expand Up @@ -60,4 +61,5 @@ def set_layout_margins(margin_pixels)


end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def run
@frame += 1
end
def set_next_timer
Swt.display.timer_exec(@ms_per_frame, self) unless @stop
::Swt.display.timer_exec(@ms_per_frame, self) unless @stop
end
end

Expand Down
6 changes: 3 additions & 3 deletions spec/swt_shoes/app_spec.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
require "spec_helper"
require "swt_shoes/spec_helper"

describe SwtShoes::App do
describe Shoes::Swt::App do

describe "WhiteShoes requirements" do
let(:mock_shell) { mock(:swt_shell,
:setSize => true, :setText => true,
:addListener => true, :setLayout => true) }
before do
Swt::Widgets::Shell.stub(:new) { mock_shell }
::Swt::Widgets::Shell.stub(:new) { mock_shell }
end

it_behaves_like "A WhiteShoes Shoes::App"
Expand All @@ -28,4 +28,4 @@
#end


end
end
10 changes: 5 additions & 5 deletions spec/swt_shoes/button_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

#require 'support/shared_examples_for_common_elements_spec'

describe SwtShoes::Button do
describe Shoes::Swt::Button do

#it_should_behave_like "A Common Element"


class ButtonShoeLaces
include SwtShoes::Button
include Shoes::Swt::Button
attr_accessor :gui_container, :gui_element, :text, :height, :width, :margin, :click_event_lambda
end

let(:stub_gui_parent) { Swt.display }
let(:stub_gui_parent) { ::Swt.display }
let(:shoelace) {
shoelace = ButtonShoeLaces.new
debugger
Expand All @@ -27,7 +27,7 @@ class ButtonShoeLaces
:pack => true )}
before do

Swt::Widgets::Button.stub(:new).
::Swt::Widgets::Button.stub(:new).
and_return mock_element
end
it_behaves_like "A WhiteShoes Shoes::Button"
Expand Down Expand Up @@ -72,4 +72,4 @@ class ButtonShoeLaces
# end
#end

end
end
14 changes: 7 additions & 7 deletions spec/swt_shoes/flow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

require 'swt_shoes/spec_helper'

describe SwtShoes::Flow do
describe Shoes::Swt::Flow do

class FlowShoeLaces
include SwtShoes::Flow
include Shoes::Swt::Flow
attr_accessor :parent_gui_container, :gui_container, :opts, :width, :height, :margin
end

let(:parent_gui_container) { Swt.display }
let(:parent_gui_container) { ::Swt.display }
let(:mock_slot) { mock(:slot) }
let(:shoelace) {
shoelace = FlowShoeLaces.new
Expand All @@ -19,7 +19,7 @@ class FlowShoeLaces

describe "WhiteShoes requirements" do

let(:stub_gui_parent) { Swt::Widgets::Shell.new }
let(:stub_gui_parent) { ::Swt::Widgets::Shell.new }
before do
subject.parent_gui_container = stub_gui_parent
end
Expand All @@ -31,7 +31,7 @@ class FlowShoeLaces
describe "gui_flow_init" do

before do
Swt::Widgets::Composite.should_receive(:new).with(parent_gui_container, anything).and_return mock_slot
::Swt::Widgets::Composite.should_receive(:new).with(parent_gui_container, anything).and_return mock_slot
end
it "should create a composite and set accessor" do
mock_slot.stub(:setLayout)
Expand All @@ -40,7 +40,7 @@ class FlowShoeLaces
end

it "should use a RowLayout" do
mock_slot.should_receive(:setLayout).with(an_instance_of(Swt::Layout::RowLayout))
mock_slot.should_receive(:setLayout).with(an_instance_of(::Swt::Layout::RowLayout))
shoelace.gui_flow_init
end

Expand All @@ -56,7 +56,7 @@ class FlowShoeLaces
mock_slot.stub(:setLayout)
shoelace.margin = 131
mock_layout = mock(:layout)
Swt::Layout::RowLayout.should_receive(:new).and_return mock_layout
::Swt::Layout::RowLayout.should_receive(:new).and_return mock_layout
mock_layout.should_receive(:marginTop=).with 131
mock_layout.should_receive(:marginRight=).with 131
mock_layout.should_receive(:marginBottom=).with 131
Expand Down
4 changes: 2 additions & 2 deletions spec/swt_shoes/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

require "swt_shoes"
require "shoes/swt"

require 'swt'
require 'swt'
4 changes: 2 additions & 2 deletions swt-shoooes
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ $:<< "lib"

require 'shoes'
require 'shoes/configuration'
Shoes.configuration.framework = 'swt_shoes'
Shoes.configuration.framework = 'swt'

require ARGV[0]

exit 0
exit 0