wxruby-ruby19 1.9.8-x86-darwin-9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/lib/wx.rb +53 -0
  2. data/lib/wx/accessors.rb +52 -0
  3. data/lib/wx/classes/acceleratortable.rb +28 -0
  4. data/lib/wx/classes/animation.rb +18 -0
  5. data/lib/wx/classes/app.rb +45 -0
  6. data/lib/wx/classes/artprovider.rb +31 -0
  7. data/lib/wx/classes/auinotebook.rb +9 -0
  8. data/lib/wx/classes/bitmap.rb +28 -0
  9. data/lib/wx/classes/busycursor.rb +12 -0
  10. data/lib/wx/classes/checklistbox.rb +45 -0
  11. data/lib/wx/classes/choice.rb +4 -0
  12. data/lib/wx/classes/clientdc.rb +13 -0
  13. data/lib/wx/classes/clipboard.rb +16 -0
  14. data/lib/wx/classes/colour.rb +47 -0
  15. data/lib/wx/classes/combobox.rb +4 -0
  16. data/lib/wx/classes/commandevent.rb +7 -0
  17. data/lib/wx/classes/controlwithitems.rb +10 -0
  18. data/lib/wx/classes/dc.rb +57 -0
  19. data/lib/wx/classes/event.rb +5 -0
  20. data/lib/wx/classes/evthandler.rb +964 -0
  21. data/lib/wx/classes/font.rb +118 -0
  22. data/lib/wx/classes/functions.rb +44 -0
  23. data/lib/wx/classes/gauge.rb +12 -0
  24. data/lib/wx/classes/grid.rb +138 -0
  25. data/lib/wx/classes/helpcontroller.rb +5 -0
  26. data/lib/wx/classes/helpcontrollerhelpprovider.rb +23 -0
  27. data/lib/wx/classes/helpprovider.rb +15 -0
  28. data/lib/wx/classes/htmlhelpcontroller.rb +5 -0
  29. data/lib/wx/classes/htmlwindow.rb +14 -0
  30. data/lib/wx/classes/icon.rb +21 -0
  31. data/lib/wx/classes/iconbundle.rb +3 -0
  32. data/lib/wx/classes/image.rb +31 -0
  33. data/lib/wx/classes/imagelist.rb +3 -0
  34. data/lib/wx/classes/listbox.rb +4 -0
  35. data/lib/wx/classes/listctrl.rb +21 -0
  36. data/lib/wx/classes/locale.rb +28 -0
  37. data/lib/wx/classes/mediactrl.rb +48 -0
  38. data/lib/wx/classes/menu.rb +62 -0
  39. data/lib/wx/classes/menuitem.rb +7 -0
  40. data/lib/wx/classes/notebook.rb +9 -0
  41. data/lib/wx/classes/object.rb +14 -0
  42. data/lib/wx/classes/paintdc.rb +12 -0
  43. data/lib/wx/classes/point.rb +48 -0
  44. data/lib/wx/classes/previewframe.rb +13 -0
  45. data/lib/wx/classes/rect.rb +10 -0
  46. data/lib/wx/classes/simplehelpprovider.rb +38 -0
  47. data/lib/wx/classes/size.rb +49 -0
  48. data/lib/wx/classes/sizer.rb +22 -0
  49. data/lib/wx/classes/sound.rb +23 -0
  50. data/lib/wx/classes/styledtextctrl.rb +92 -0
  51. data/lib/wx/classes/textctrl.rb +14 -0
  52. data/lib/wx/classes/texturlevent.rb +6 -0
  53. data/lib/wx/classes/timer.rb +94 -0
  54. data/lib/wx/classes/toolbar.rb +29 -0
  55. data/lib/wx/classes/toolbartool.rb +4 -0
  56. data/lib/wx/classes/treectrl.rb +44 -0
  57. data/lib/wx/classes/window.rb +82 -0
  58. data/lib/wx/classes/xmlresource.rb +37 -0
  59. data/lib/wx/helpers.rb +30 -0
  60. data/lib/wx/keyword_ctors.rb +203 -0
  61. data/lib/wx/keyword_defs.rb +507 -0
  62. data/lib/wx/version.rb +3 -0
  63. data/lib/wxruby2.bundle +0 -0
  64. metadata +323 -0
data/lib/wx.rb ADDED
@@ -0,0 +1,53 @@
1
+ # Copyright 2004-2006 by Kevin Smith
2
+ # released under the MIT-style wxruby2 license
3
+
4
+ # This wrapper serves three functions:
5
+ # 1. It loads the binary library 'wxruby2.so' or 'wxruby.dll', while
6
+ # still allowing applications to just require 'wx'.
7
+ # 2. It sets up the version information
8
+ # 3. It loads in ruby extensions to the core Wx classes.
9
+
10
+
11
+ # load the binary library
12
+ require 'wxruby2'
13
+
14
+ # alias the module
15
+ Wx = Wxruby2
16
+
17
+ # Load the version information (should be bundled with all released versions)
18
+ begin
19
+ require 'wx/version'
20
+ rescue LoadError
21
+ Wx::WXRUBY_VERSION = '0.0.0'
22
+ end
23
+ # Convenience string for WxWidgets version info
24
+ Wx::WXWIDGETS_VERSION = '%i.%i.%i' % [ Wx::WXWIDGETS_MAJOR_VERSION,
25
+ Wx::WXWIDGETS_MINOR_VERSION,
26
+ Wx::WXWIDGETS_RELEASE_NUMBER ]
27
+
28
+ # Helper functions
29
+ require 'wx/helpers'
30
+
31
+ # Load in all the class extension methods written in ruby
32
+ # evthandler must be required first b/c it sets up methods modified elsewhere
33
+ require 'wx/classes/evthandler.rb'
34
+ class_files = File.join( File.dirname(__FILE__), 'wx', 'classes', '*.rb')
35
+ Dir.glob(class_files) do | class_file |
36
+ require 'wx/classes/' + class_file[/\w+\.rb$/]
37
+ end
38
+
39
+ # Load in syntax sweeteners
40
+ require 'wx/accessors'
41
+ require 'wx/keyword_ctors'
42
+ require 'wx/keyword_defs'
43
+
44
+ # If a program is ended by ruby's exit, it can bypass doing the proper
45
+ # Wx clean-up routines called by Wx::App#on_exit. This can under some
46
+ # circumstances cause crashes as the application ends.
47
+ Kernel::at_exit do
48
+ # This is set in wxRubyApp.OnExit (see swig/classes/App.i)
49
+ if not $__wx_app_ended__
50
+ Wx::THE_APP.on_exit
51
+ end
52
+ end
53
+
@@ -0,0 +1,52 @@
1
+ # = WxSugar - Accessors
2
+ #
3
+ # The default WxRuby interface has lots and lots of methods like
4
+ #
5
+ # * get_position()
6
+ # * set_size(a_size)
7
+ # * is_checked()
8
+ #
9
+ # and so on. Methods that retrieve set, or query attributes of an object
10
+ # are more normally in Ruby called simply by the attribute name:
11
+ #
12
+ # * position()
13
+ # * size = a_size
14
+ # * checked?
15
+ #
16
+ # This extension creates an alias for every WxRuby instance method that
17
+ # begins with +get_+, +set_+ or +is_+. Note that if you are calling a
18
+ # 'setter' method on self, you must explicitly send the message to self:
19
+ #
20
+ # # set's self size to be 100px by 100px
21
+ # self.size = Wx::Size.new(100, 100)
22
+ # # only sets the value of a local variable 'size'
23
+ # size = Wx::Size.new
24
+
25
+ module WxRubyStyleAccessors
26
+ def method_missing(sym, *args)
27
+ case sym.to_s
28
+ when /^(.*)\=$/
29
+ meth = "set_#{$1}"
30
+ when /^(.*)\?$/
31
+ meth = "is_#{$1}"
32
+ else
33
+ meth = "get_#{sym}"
34
+ end
35
+ if respond_to?(meth)
36
+ send(meth, *args)
37
+ else
38
+ e = NoMethodError.new("undefined method '#{sym}' for #{self.inspect}")
39
+ e.set_backtrace(caller)
40
+ Kernel.raise e
41
+ end
42
+ end
43
+ end
44
+
45
+ all_classes = Wx::constants.collect { | c | Wx::const_get(c) }.grep(Class)
46
+
47
+ all_classes.each do | klass |
48
+ klass.class_eval do
49
+ include WxRubyStyleAccessors
50
+ extend WxRubyStyleAccessors
51
+ end
52
+ end
@@ -0,0 +1,28 @@
1
+ class Wx::AcceleratorTable
2
+ # Allow new to be called as []
3
+ class << self
4
+ alias :[] :new
5
+ end
6
+
7
+ # Allow initialize to be called with a splat-like list of arguments,
8
+ # and allow entries to be specified in terser form [mod, key, id]
9
+ # rather than full AcceleratorEntry.new call.
10
+ wx_init = self.instance_method(:initialize)
11
+ define_method(:initialize) do | *args |
12
+ # Test for old-style arg passing in a single array
13
+ if args.length == 1 and args.first.kind_of?(Array) and
14
+ args.first.all? { | e | e.kind_of?(Wx::AcceleratorEntry) }
15
+ args = args[0]
16
+ end
17
+ # Convert to array of AccEntries, to pass in as single array
18
+ args = args.map do | entry |
19
+ case entry
20
+ when Wx::AcceleratorEntry then entry
21
+ when Array then Wx::AcceleratorEntry.new(*entry)
22
+ else Kernel.raise ArgumentError,
23
+ "#{entry.inspect} is not a valid AcceleratorTable entry"
24
+ end
25
+ end
26
+ wx_init.bind(self).call(args)
27
+ end
28
+ end
@@ -0,0 +1,18 @@
1
+ class Wx::Animation < Wx::GDIObject
2
+ # Redefine the initialize method so it raises an exception if a
3
+ # non-existent file is given to the constructor; otherwise, wx Widgets
4
+ # just carries on with an empty bitmap, which may cause faults later
5
+ wx_init = self.instance_method(:initialize)
6
+ define_method(:initialize) do | *args |
7
+ if args[0].kind_of? String
8
+ if not File.exist?( File.expand_path(args[0]) )
9
+ Kernel.raise( ArgumentError,
10
+ "Animation file does not exist: #{args[0]}" )
11
+ end
12
+ res = wx_init.bind(self).call()
13
+ res.load_file(args[0], args[1] || Wx::ANIMATION_TYPE_ANY)
14
+ else
15
+ wx_init.bind(self).call(*args)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,45 @@
1
+ # Copyright 2004-2006 by Kevin Smith
2
+ # released under the MIT-style wxruby2 license
3
+
4
+ # Controller class which creates and manages all windows.
5
+ class Wx::App
6
+ # Convenience class method to create simple apps. Starts an
7
+ # application main_loop, setting up initial windows etc as specified
8
+ # in the passed block.
9
+ # block
10
+ def self.run(&block)
11
+ app_klass = Class.new(self)
12
+ app_klass.class_eval do
13
+ define_method(:on_init, &block)
14
+ end
15
+ the_app = app_klass.new
16
+ the_app.main_loop
17
+ end
18
+
19
+ # This is a class method in Wx, but permit it to be an instance method
20
+ # in wxRuby
21
+ def is_main_loop_running
22
+ Wx::App.is_main_loop_running
23
+ end
24
+
25
+ # This method handles failed assertions from within the WxWidgets C++
26
+ # code. These messages are only generated by a DEBUG build of
27
+ # WxRuby. Such messages usually indicate that the API is being used
28
+ # incorrectly; the file/line reference points to the place in the
29
+ # WxWidgets source code where the assertion was made.
30
+ define_method(:on_assert_failure) do | file, line, condition, message |
31
+ warn "Wx WARNING: #{message} (#{file}:#{line})"
32
+ end
33
+
34
+ # For use in development only, of no practical use in production code.
35
+ # This method causes Ruby's garbage collection to run (roughly) at
36
+ # interval +interval+ (seconds) - the default is 1, i.e. every
37
+ # second. This should help ferret out bugs in memory management more
38
+ # quickly.
39
+ def gc_stress(interval = 1)
40
+ t = Wx::Timer.new(self, 9999)
41
+ evt_timer(9999) { Thread.pass }
42
+ Thread.new { loop { sleep interval; GC.start } }
43
+ t.start(100)
44
+ end
45
+ end
@@ -0,0 +1,31 @@
1
+ # Class which can supply icons and bitmaps
2
+ class Wx::ArtProvider
3
+ # Keep a note of supplied ArtProviders to prevent them being GC'd
4
+ @__art_provs = []
5
+
6
+ class << self
7
+ wx_insert = instance_method(:insert)
8
+ define_method(:insert) do | art_prov |
9
+ wx_insert.bind(self).call(art_prov)
10
+ @__art_provs.unshift(art_prov)
11
+ end
12
+
13
+ wx_pop = instance_method(:pop)
14
+ define_method(:pop) do
15
+ wx_pop.bind(self).call
16
+ @__art_provs.pop
17
+ end
18
+
19
+ wx_push = instance_method(:push)
20
+ define_method(:push) do | art_prov |
21
+ wx_push.bind(self).call(art_prov)
22
+ @__art_provs.push(art_prov)
23
+ end
24
+
25
+ wx_remove = instance_method(:remove)
26
+ define_method(:remove) do | art_prov |
27
+ wx_push.bind(self).call(art_prov)
28
+ @__art_provs.delete(art_prov)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,9 @@
1
+ # Advanced User Interface Notebook - draggable panes etc
2
+ class Wx::AuiNotebook
3
+ # Convenience method for iterating pages
4
+ def each_page
5
+ 0.upto(get_page_count - 1) do | i |
6
+ yield get_page(i)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,28 @@
1
+ class Wx::Bitmap
2
+ # Constructor copying data from an image
3
+ def self.from_image(img, depth = -1)
4
+ new(img, depth)
5
+ end
6
+
7
+ # Redefine the initialize method so it raises an exception if a
8
+ # non-existent file is given to the constructor; otherwise, wx Widgets
9
+ # just carries on with an empty bitmap, which may cause faults later
10
+ wx_init = self.instance_method(:initialize)
11
+ define_method(:initialize) do | *args |
12
+ if args[0].kind_of? String
13
+ if not File.exist?( File.expand_path(args[0]) )
14
+ Kernel.raise(ArgumentError, "Bitmap file does not exist: #{args[0]}")
15
+ end
16
+ end
17
+ wx_init.bind(self).call(*args)
18
+ end
19
+
20
+ # Accepts a block, which will be passed a device context which can be
21
+ # used to draw upon the Bitmap
22
+ def draw
23
+ dc = Wx::MemoryDC.new
24
+ dc.select_object(self)
25
+ yield dc
26
+ dc.select_object( Wx::NULL_BITMAP )
27
+ end
28
+ end
@@ -0,0 +1,12 @@
1
+ # Emulates the wxWidgets BusyCursor class, by providing a scope within
2
+ # which a busy cursor will be shown
3
+ class Wx::BusyCursor
4
+ # Only one class method, optionally accepting a cursor that should be
5
+ # shown, defaulting to an hour glass cursor.
6
+ def self.busy(cursor = Wx::HOURGLASS_CURSOR)
7
+ Wx::begin_busy_cursor(cursor)
8
+ yield
9
+ ensure
10
+ Wx::end_busy_cursor
11
+ end
12
+ end
@@ -0,0 +1,45 @@
1
+ # A ListBox, where each item has a checkbox next to it
2
+ class Wx::CheckListBox
3
+ # wxRuby redefinitions of core methods to add item data support (not
4
+ # available in wxWidgets). Use a private method to initialize and
5
+ # access the data, rather than in initialize(), b/c can't guarantee
6
+ # that initialize will be called (eg when loaded from XRC)
7
+ def __wx_item_data
8
+ @__wx_item_data ||= []
9
+ end
10
+ private :__wx_item_data
11
+
12
+ # Call method in ControlWithItems, then sync item data
13
+ def append(item, data = nil)
14
+ super(item)
15
+ __wx_item_data[count - 1] = data
16
+ end
17
+
18
+ # Call method in ControlWithItems, then sync item data
19
+ def clear
20
+ super
21
+ __wx_item_data.clear
22
+ end
23
+
24
+ # delete is defined in Wx::CheckListBox, so must be called in this class
25
+ wx_delete = self.instance_method(:delete)
26
+ define_method(:delete) do | n |
27
+ wx_delete.bind(self).call(n)
28
+ __wx_item_data.delete_at(n)
29
+ end
30
+
31
+ # Returns an array of indices of items that are currently checked.
32
+ def get_checked_items
33
+ find_all { | i | checked?(i) }
34
+ end
35
+
36
+ # Wholly redefined here
37
+ def get_item_data(n)
38
+ __wx_item_data[n]
39
+ end
40
+
41
+ # Wholly redefined here
42
+ def set_item_data(n, data)
43
+ __wx_item_data[n] = data
44
+ end
45
+ end
@@ -0,0 +1,4 @@
1
+ class Wx::Choice
2
+ alias :get_item_data :get_client_data
3
+ alias :set_item_data :set_client_data
4
+ end
@@ -0,0 +1,13 @@
1
+ # Device Context to paint on a window outside an on_paint handler. It is
2
+ # recommended that PaintDC is used in preference to this class.
3
+ class Wx::ClientDC
4
+ # This class should not be instantiated directly in wxRuby; it should
5
+ # always be used via Window#paint, which takes a block receiving the
6
+ # DC. This ensures that the DC is cleaned up at the correct time,
7
+ # avoiding errors and segfaults on exit.
8
+ define_method(:initialize) do | *args |
9
+ Kernel.raise RuntimeError,
10
+ "Do not instantiate ClientDC directly; use Window#paint",
11
+ caller[1..-1]
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ class Wx::Clipboard
2
+ class << self
3
+ # Class method to provide access to the clipboard within a ruby
4
+ # block. Tests that the clipboard could be accessed, and ensures
5
+ # that it is closed when the block is finished.
6
+ def open
7
+ clip = Wx::Clipboard.new
8
+ unless clip.open
9
+ Kernel.raise "Could not open clipboard"
10
+ end
11
+ yield clip
12
+ ensure
13
+ clip.close
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,47 @@
1
+ class Wx::Colour
2
+ # Redefine the initialize method so it raises an exception if an
3
+ # invalid colour value is given. This might be an unknown colour
4
+ # string (eg 'dark blue') or out-of-bounds integer values (<0 or >255)
5
+ wx_init = self.instance_method(:initialize)
6
+ define_method(:initialize) do | *args |
7
+ begin
8
+ wx_init.bind(self).call(*args)
9
+ # Invalid integer values raise SWIG 'no matching func'
10
+ rescue ArgumentError
11
+ Kernel.raise ArgumentError, "Invalid colour values #{args.inspect}"
12
+ end
13
+
14
+ if not is_ok
15
+ Kernel.raise ArgumentError, "Invalid colour values #{args.inspect}"
16
+ end
17
+ end
18
+
19
+ # Standard colours, corresponding to WxWidgets stock colours.
20
+ Wx::WHITE = new(255, 255, 255)
21
+ Wx::BLACK = new(0, 0, 0)
22
+
23
+ Wx::RED = new(255, 0, 0)
24
+ Wx::GREEN = new(0, 255, 0)
25
+ Wx::BLUE = new(0, 0, 255)
26
+
27
+ Wx::YELLOW = new(255, 255, 0)
28
+ Wx::MAGENTA = new(255, 0, 255)
29
+ Wx::CYAN = new(0, 255, 255)
30
+
31
+ Wx::LIGHT_GREY = new(192, 192, 192)
32
+
33
+ # Colours are equal to one another if they have the same red, green
34
+ # and blue intensity, and the same alpha
35
+ def ==(other)
36
+ if not other.is_a?(self.class)
37
+ raise ArgumentError, "No comparison of #{self} to #{other}"
38
+ end
39
+ [ red, green, blue, alpha ] ==
40
+ [ other.red, other.green, other.blue, other.alpha ]
41
+ end
42
+
43
+ # More informative output for inspect etc
44
+ def to_s
45
+ "#<Wx::Colour: (#{red}, #{green}, #{blue} *#{alpha})>"
46
+ end
47
+ end
@@ -0,0 +1,4 @@
1
+ class Wx::ComboBox
2
+ alias :get_item_data :get_client_data
3
+ alias :set_item_data :set_client_data
4
+ end
@@ -0,0 +1,7 @@
1
+ # Class representing interactions with controls such as ListBox
2
+ class Wx::CommandEvent
3
+ # get_int and get_selection are already synonyms, but neither name
4
+ # accurately describes what the method does as the event may be a
5
+ # (de)selection or a check in a CheckListBox
6
+ alias :get_index :get_int
7
+ end
@@ -0,0 +1,10 @@
1
+ # Superclass of a variety of controls that display lists of items (eg
2
+ # Choice, ListBox, CheckListBox)
3
+ class Wx::ControlWithItems
4
+ # Make these ruby enumerables so find, find_all, map etc are available
5
+ include Enumerable
6
+ # Passes each valid item index into the passed block
7
+ def each
8
+ 0.upto(get_count - 1) { | i | yield i }
9
+ end
10
+ end