wx_sugar 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/LICENCE ADDED
@@ -0,0 +1,20 @@
1
+ WxSugar
2
+ Copyright (c) 2006 Alex Fenton
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in
12
+ all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
data/lib/wx_sugar/all.rb CHANGED
@@ -50,7 +50,14 @@
50
50
  # [menu.rb]
51
51
  # Create and update menus without a mess of system ids
52
52
 
53
+
53
54
  %w[ accessors delayed_constructors event_connector itemdata
54
55
  keyword_constructors layout menu wx_classes ].each do | ext_feature |
55
56
  require 'wx_sugar/' + ext_feature
56
57
  end
58
+
59
+ begin
60
+ require 'wx_sugar/version'
61
+ rescue LoadError
62
+ WxSugar::VERSION = ''
63
+ end
@@ -12,7 +12,7 @@
12
12
  # pass the argument +:click+
13
13
  #
14
14
  # The parameter +source+ is the widget whose events should be listened
15
- # for. This might be a particular button. If no +source+ is specified,
15
+ # for. This might be a particular button. If +source+ is set to *nil*,
16
16
  # and lots of widgets might generate this kind of event (for example, if
17
17
  # you have multiple buttons), it assumes that *ANY* button's clicking
18
18
  # should be handled.
@@ -42,9 +42,9 @@
42
42
  # ...
43
43
  # panel = Wx::Panel.new(parent, -1) # create the container
44
44
  # panel.arrange_horizontally(:padding => 4) # specify layout strategy
45
- # panel.add( Wx::Checkbox.new(panel, -1, 'item A') ) # add item,
46
- # panel.add( Wx::Checkbox.new(panel, -1, 'item B') ) # another,
47
- # panel.add( Wx::Checkbox.new(panel, -1, 'item C') ) # and another
45
+ # panel.add( Wx::CheckBox.new(panel, -1, 'item A') ) # add item,
46
+ # panel.add( Wx::CheckBox.new(panel, -1, 'item B') ) # another,
47
+ # panel.add( Wx::CheckBox.new(panel, -1, 'item C') ) # and another
48
48
 
49
49
  require 'wx_sugar/class_definitions'
50
50
 
@@ -96,9 +96,10 @@ module Arranger
96
96
  yield(self)
97
97
  @current_sizer = superior_sizer
98
98
  proportion = layout[:proportion] || 0
99
+ this_padding = padding || 0
99
100
  superior_sizer.add( a_sizer, proportion,
100
101
  Wx::EXPAND|Wx::ALL|Wx::ADJUST_MINSIZE,
101
- padding)
102
+ this_padding)
102
103
 
103
104
  if layout[:padding]
104
105
  @padding = old_padding
@@ -0,0 +1,3 @@
1
+ module WxSugar
2
+ VERSION = '0.1.2'
3
+ end
@@ -0,0 +1,45 @@
1
+ # extensions to Wx::Colour
2
+ class Wx::Colour
3
+
4
+ # Create a new Colour from the hex-string +hex_str+, which should be a six-
5
+ # character colour RGB specification. The hash character '#' may optionally
6
+ # be prepended to the string, and will be ignored.
7
+ def self.from_hex(hex_str)
8
+ unless hex_str =~ /\A#?[0-9A-F]{6}\z/i
9
+ raise ArgumentError,
10
+ "Invalid colour string #{hex_str} received, " +
11
+ "should be six-char hexadecimal RGB"
12
+ end
13
+ components = hex_str.scan(/[0-9A-F]{2}/i).map { | x | Integer("0x#{x}") }
14
+ new(*components)
15
+ end
16
+
17
+ # Returns the colour as a six character hexadecimal string (as used in
18
+ # HTML/CSS for example).
19
+ def to_hex
20
+ [ :red, :green, :blue ].inject('') do | hex_str, component |
21
+ hex_str << sprintf('%02X', send(component) )
22
+ end
23
+ end
24
+
25
+ # Create a new colour by mixing +self_parts+ of +self+ with
26
+ # +other_parts+ of other. The new colour is produced by applying the
27
+ # following averaging formula to the red, green and blue components
28
+ # of each colour
29
+ #
30
+ # ( colour_1 * conc_1 ) + ( colour_2 * conc_2 )
31
+ # --------------------------
32
+ # conc_1 + conc_2
33
+ #
34
+ def mix(other, self_parts = 1, other_parts = 1)
35
+ return self if self_parts.zero? && other_parts.zero?
36
+ rgb = [ :red, :green, :blue ].map do | component |
37
+ mix = self.send(component) * self_parts
38
+ mix += other.send(component) * other_parts
39
+ mix = mix.to_f
40
+ mix /= self_parts + other_parts
41
+ mix.to_i
42
+ end
43
+ Wx::Colour.new(*rgb)
44
+ end
45
+ end
@@ -0,0 +1,14 @@
1
+ # extensions to Wx::Window
2
+ class Wx::Window
3
+ # Returns the window's current size as a two element array
4
+ def get_size_xy
5
+ size = get_size
6
+ return size.get_width, size.get_height
7
+ end
8
+
9
+ # Returns the window's current position as a two-element array.
10
+ def get_position_xy
11
+ pos = get_position
12
+ return pos.x, pos.y
13
+ end
14
+ end
@@ -0,0 +1,76 @@
1
+ require 'wx'
2
+ require 'wx_sugar/all'
3
+
4
+ class MyButton < Wx::Button
5
+ def on_button()
6
+ p "clicked my button"
7
+ end
8
+ end
9
+
10
+ class SugaryFrame < Wx::Frame
11
+ def initialize(*args)
12
+ super
13
+ # binds evt_close automatically to self#on_close
14
+ listen(:close)
15
+
16
+ arrange_vertically(:padding => 5)
17
+ # This panel and contents should expand to fit
18
+ add( Wx::Panel, :proportion => 1 ) do | panel |
19
+ # a text control
20
+ panel.background_colour = Wx::Colour.new(200, 150, 100)
21
+ panel.add( Wx::TextCtrl[ :value => 'initial value',
22
+ :style => Wx::TE_MULTILINE,
23
+ :size => [200, 300] ] )
24
+ end
25
+
26
+ # use a nested grid sizer to arrange bottom area
27
+ arrange_grid( :cols => 2, :rows => 2, :proportion => 0,
28
+ :vgap => 2, :minsize => true, :padding => 1 ) do
29
+ # a custom button subclass
30
+ add( MyButton[ :label => 'baz' ], :proportion => 1 ) do | button |
31
+ listen(:button, button, :on_baz_button)
32
+ end
33
+
34
+ # a drop down
35
+ choices = %w[ nasty nice ]
36
+ add( Wx::Choice[ :choices => choices ], :padding => 4)
37
+
38
+ # another button
39
+ add( Wx::Button[ :label => 'foo' ] ) do | button |
40
+ # handle using a method
41
+ listen(:button, button, :on_foo_button)
42
+ # handle using a block
43
+ listen(:button, button) { | e | p "clicked in a block"; e.skip }
44
+ end
45
+ add( Wx::TextCtrl[ :value => 'foo' ], :align => 'right' )
46
+ end
47
+ end
48
+
49
+ def on_close(event)
50
+ puts "CLOSING"
51
+ event.skip()
52
+ end
53
+
54
+ def on_button(event)
55
+ p event
56
+ end
57
+
58
+ def on_foo_button(e)
59
+ p "FOO"
60
+ e.skip()
61
+ end
62
+
63
+ # you aren't required to receive the event
64
+ def on_baz_button()
65
+ p "baZ"
66
+ end
67
+ end
68
+
69
+ class SugaryApp < Wx::App
70
+ def on_init
71
+ frame = SugaryFrame.new( nil, :title => "Arranger Application" )
72
+ frame.show()
73
+ end
74
+ end
75
+
76
+ SugaryApp.new.main_loop()
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.10
3
3
  specification_version: 1
4
4
  name: wx_sugar
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.1
7
- date: 2006-09-15
6
+ version: 0.1.2
7
+ date: 2006-10-19
8
8
  summary: Syntax extensions for WxRuby.
9
9
  require_paths:
10
10
  - lib
@@ -27,6 +27,7 @@ platform: ruby
27
27
  authors:
28
28
  - Alex Fenton
29
29
  files:
30
+ - lib/wx_sugar
30
31
  - lib/wx_sugar/accessors.rb
31
32
  - lib/wx_sugar/all.rb
32
33
  - lib/wx_sugar/class_definitions.rb
@@ -37,7 +38,13 @@ files:
37
38
  - lib/wx_sugar/keyword_constructors.rb
38
39
  - lib/wx_sugar/layout.rb
39
40
  - lib/wx_sugar/menu.rb
41
+ - lib/wx_sugar/version.rb
42
+ - lib/wx_sugar/wx_classes
40
43
  - lib/wx_sugar/wx_classes.rb
44
+ - lib/wx_sugar/wx_classes/colour.rb
45
+ - lib/wx_sugar/wx_classes/window.rb
46
+ - samples/sugar-sample.rb
47
+ - LICENCE
41
48
  test_files: []
42
49
  rdoc_options: []
43
50
  extra_rdoc_files: []