wxruby-ruby19 1.9.8-x86-linux → 1.9.10-x86-linux
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +53 -0
- data/README +297 -0
- data/lib/wx/accessors.rb +58 -0
- data/lib/wx/classes/acceleratortable.rb +28 -0
- data/lib/wx/classes/animation.rb +18 -0
- data/lib/wx/classes/app.rb +51 -0
- data/lib/wx/classes/artprovider.rb +31 -0
- data/lib/wx/classes/auinotebook.rb +9 -0
- data/lib/wx/classes/bitmap.rb +56 -0
- data/lib/wx/classes/busycursor.rb +12 -0
- data/lib/wx/classes/checklistbox.rb +45 -0
- data/lib/wx/classes/choice.rb +4 -0
- data/lib/wx/classes/clientdc.rb +13 -0
- data/lib/wx/classes/clipboard.rb +32 -0
- data/lib/wx/classes/colour.rb +49 -0
- data/lib/wx/classes/combobox.rb +4 -0
- data/lib/wx/classes/commandevent.rb +7 -0
- data/lib/wx/classes/controlwithitems.rb +10 -0
- data/lib/wx/classes/data_object.rb +14 -0
- data/lib/wx/classes/data_object_simple.rb +6 -0
- data/lib/wx/classes/dataformat.rb +23 -0
- data/lib/wx/classes/dc.rb +57 -0
- data/lib/wx/classes/event.rb +5 -0
- data/lib/wx/classes/evthandler.rb +1039 -0
- data/lib/wx/classes/font.rb +118 -0
- data/lib/wx/classes/functions.rb +44 -0
- data/lib/wx/classes/gauge.rb +12 -0
- data/lib/wx/classes/genericdirctrl.rb +36 -0
- data/lib/wx/classes/grid.rb +146 -0
- data/lib/wx/classes/hboxsizer.rb +6 -0
- data/lib/wx/classes/helpcontroller.rb +5 -0
- data/lib/wx/classes/helpcontrollerhelpprovider.rb +23 -0
- data/lib/wx/classes/helpprovider.rb +15 -0
- data/lib/wx/classes/htmlhelpcontroller.rb +5 -0
- data/lib/wx/classes/htmlwindow.rb +14 -0
- data/lib/wx/classes/icon.rb +32 -0
- data/lib/wx/classes/iconbundle.rb +3 -0
- data/lib/wx/classes/image.rb +43 -0
- data/lib/wx/classes/imagelist.rb +3 -0
- data/lib/wx/classes/listbox.rb +4 -0
- data/lib/wx/classes/listctrl.rb +33 -0
- data/lib/wx/classes/locale.rb +28 -0
- data/lib/wx/classes/mediactrl.rb +48 -0
- data/lib/wx/classes/menu.rb +62 -0
- data/lib/wx/classes/menuitem.rb +7 -0
- data/lib/wx/classes/notebook.rb +9 -0
- data/lib/wx/classes/object.rb +14 -0
- data/lib/wx/classes/paintdc.rb +12 -0
- data/lib/wx/classes/point.rb +56 -0
- data/lib/wx/classes/previewframe.rb +13 -0
- data/lib/wx/classes/rect.rb +19 -0
- data/lib/wx/classes/richtextctrl.rb +63 -0
- data/lib/wx/classes/simplehelpprovider.rb +38 -0
- data/lib/wx/classes/size.rb +58 -0
- data/lib/wx/classes/sizer.rb +37 -0
- data/lib/wx/classes/sound.rb +23 -0
- data/lib/wx/classes/standardpaths.rb +9 -0
- data/lib/wx/classes/styledtextctrl.rb +92 -0
- data/lib/wx/classes/textctrl.rb +14 -0
- data/lib/wx/classes/texturlevent.rb +18 -0
- data/lib/wx/classes/timer.rb +94 -0
- data/lib/wx/classes/toolbar.rb +27 -0
- data/lib/wx/classes/toolbartool.rb +4 -0
- data/lib/wx/classes/treectrl.rb +44 -0
- data/lib/wx/classes/vboxsizer.rb +6 -0
- data/lib/wx/classes/window.rb +89 -0
- data/lib/wx/classes/xmlresource.rb +54 -0
- data/lib/wx/helpers.rb +45 -0
- data/lib/wx/keyword_ctors.rb +204 -0
- data/lib/wx/keyword_defs.rb +558 -0
- data/lib/wx/version.rb +3 -0
- data/lib/wx.rb +53 -0
- data/lib/wxruby2.so +0 -0
- data/samples/SAMPLES-LICENSE.TXT +18 -0
- data/samples/aui/aui.rb +1356 -0
- data/samples/bigdemo/About.rbw +39 -0
- data/samples/bigdemo/ColorPanel.rbw +23 -0
- data/samples/bigdemo/GridSimple.rbw +78 -0
- data/samples/bigdemo/MDIDemo.rbw +57 -0
- data/samples/bigdemo/PopupMenu.rbw +149 -0
- data/samples/bigdemo/ShapedWindow.rbw +131 -0
- data/samples/bigdemo/Sizers.rbw +543 -0
- data/samples/bigdemo/bigdemo.rb +823 -0
- data/samples/bigdemo/demoTemplate.rbw +33 -0
- data/samples/bigdemo/helpfile.htb +0 -0
- data/samples/bigdemo/icons/Test 015.jpg +0 -0
- data/samples/bigdemo/icons/Test 015.png +0 -0
- data/samples/bigdemo/icons/choice.bmp +0 -0
- data/samples/bigdemo/icons/choice.xpm +27 -0
- data/samples/bigdemo/icons/combo.bmp +0 -0
- data/samples/bigdemo/icons/combo.xpm +27 -0
- data/samples/bigdemo/icons/copy.xpm +25 -0
- data/samples/bigdemo/icons/cut.xpm +24 -0
- data/samples/bigdemo/icons/gauge.bmp +0 -0
- data/samples/bigdemo/icons/gauge.xpm +27 -0
- data/samples/bigdemo/icons/help.xpm +25 -0
- data/samples/bigdemo/icons/list.bmp +0 -0
- data/samples/bigdemo/icons/list.xpm +27 -0
- data/samples/bigdemo/icons/mondrian.ico +0 -0
- data/samples/bigdemo/icons/mondrian.xpm +44 -0
- data/samples/bigdemo/icons/new.xpm +24 -0
- data/samples/bigdemo/icons/ogl.ico +0 -0
- data/samples/bigdemo/icons/ogl.xpm +45 -0
- data/samples/bigdemo/icons/open.xpm +26 -0
- data/samples/bigdemo/icons/paste.bmp +0 -0
- data/samples/bigdemo/icons/paste.xpm +38 -0
- data/samples/bigdemo/icons/pointy.png +0 -0
- data/samples/bigdemo/icons/preview.xpm +26 -0
- data/samples/bigdemo/icons/print.xpm +26 -0
- data/samples/bigdemo/icons/radio.bmp +0 -0
- data/samples/bigdemo/icons/radio.xpm +27 -0
- data/samples/bigdemo/icons/robert.xpm +415 -0
- data/samples/bigdemo/icons/ruby.png +0 -0
- data/samples/bigdemo/icons/sashtest.ico +0 -0
- data/samples/bigdemo/icons/save.xpm +25 -0
- data/samples/bigdemo/icons/smiles.bmp +0 -0
- data/samples/bigdemo/icons/smiles.xpm +39 -0
- data/samples/bigdemo/icons/smiley.ico +0 -0
- data/samples/bigdemo/icons/smiley.xpm +42 -0
- data/samples/bigdemo/icons/stattext.xpm +24 -0
- data/samples/bigdemo/icons/test2.bmp +0 -0
- data/samples/bigdemo/icons/test2.png +0 -0
- data/samples/bigdemo/icons/test2.xpm +79 -0
- data/samples/bigdemo/icons/text.bmp +0 -0
- data/samples/bigdemo/icons/text.xpm +27 -0
- data/samples/bigdemo/icons/tog1.bmp +0 -0
- data/samples/bigdemo/icons/tog1.xpm +38 -0
- data/samples/bigdemo/icons/tog2.bmp +0 -0
- data/samples/bigdemo/icons/tog2.xpm +38 -0
- data/samples/bigdemo/icons/wxwin.ico +0 -0
- data/samples/bigdemo/icons/wxwin16x16.png +0 -0
- data/samples/bigdemo/icons/wxwin16x16.xpm +25 -0
- data/samples/bigdemo/icons/wxwin32x32.png +0 -0
- data/samples/bigdemo/icons/wxwin48x48.png +0 -0
- data/samples/bigdemo/run.rb +90 -0
- data/samples/bigdemo/tips.txt +7 -0
- data/samples/bigdemo/utils.rb +12 -0
- data/samples/bigdemo/wxArtProvider.rbw +281 -0
- data/samples/bigdemo/wxBitmapButton.rbw +65 -0
- data/samples/bigdemo/wxButton.rbw +64 -0
- data/samples/bigdemo/wxCalendarCtrl.rbw +60 -0
- data/samples/bigdemo/wxCheckBox.rbw +50 -0
- data/samples/bigdemo/wxCheckListBox.rbw +65 -0
- data/samples/bigdemo/wxChoice.rbw +47 -0
- data/samples/bigdemo/wxChoicebook.rbw +78 -0
- data/samples/bigdemo/wxColourDialog.rbw +31 -0
- data/samples/bigdemo/wxComboBox.rbw +77 -0
- data/samples/bigdemo/wxCursor.rbw +136 -0
- data/samples/bigdemo/wxDialog.rbw +74 -0
- data/samples/bigdemo/wxDirDialog.rbw +29 -0
- data/samples/bigdemo/wxDragImage.rbw +70 -0
- data/samples/bigdemo/wxFileDialog.rbw +37 -0
- data/samples/bigdemo/wxFileDialog_Save.rbw +35 -0
- data/samples/bigdemo/wxFindReplaceDialog.rbw +82 -0
- data/samples/bigdemo/wxFontDialog.rbw +173 -0
- data/samples/bigdemo/wxFrame.rbw +53 -0
- data/samples/bigdemo/wxGauge.rbw +71 -0
- data/samples/bigdemo/wxGenericDirCtrl.rbw +74 -0
- data/samples/bigdemo/wxGrid.rbw +66 -0
- data/samples/bigdemo/wxHtmlHelpController.rbw +52 -0
- data/samples/bigdemo/wxListBox.rbw +140 -0
- data/samples/bigdemo/wxListCtrl_virtual.rbw +112 -0
- data/samples/bigdemo/wxMDIWindows.rbw +50 -0
- data/samples/bigdemo/wxMenu.rbw +236 -0
- data/samples/bigdemo/wxMessageDialog.rbw +27 -0
- data/samples/bigdemo/wxMiniFrame.rbw +70 -0
- data/samples/bigdemo/wxMultipleChoiceDialog.rbw +32 -0
- data/samples/bigdemo/wxNotebook.rbw +136 -0
- data/samples/bigdemo/wxProgressDialog.rbw +43 -0
- data/samples/bigdemo/wxRadioBox.rbw +72 -0
- data/samples/bigdemo/wxRadioButton.rbw +125 -0
- data/samples/bigdemo/wxSashWindow.rbw +141 -0
- data/samples/bigdemo/wxScrolledMessageDialog.rbw +57 -0
- data/samples/bigdemo/wxScrolledWindow.rbw +199 -0
- data/samples/bigdemo/wxSingleChoiceDialog.rbw +33 -0
- data/samples/bigdemo/wxSlider.rbw +42 -0
- data/samples/bigdemo/wxSpinButton.rbw +50 -0
- data/samples/bigdemo/wxSpinCtrl.rbw +51 -0
- data/samples/bigdemo/wxSplitterWindow.rbw +63 -0
- data/samples/bigdemo/wxStaticBitmap.rbw +51 -0
- data/samples/bigdemo/wxStaticText.rbw +55 -0
- data/samples/bigdemo/wxStatusBar.rbw +126 -0
- data/samples/bigdemo/wxTextCtrl.rbw +149 -0
- data/samples/bigdemo/wxTextEntryDialog.rbw +31 -0
- data/samples/bigdemo/wxToggleButton.rbw +49 -0
- data/samples/bigdemo/wxToolBar.rbw +131 -0
- data/samples/bigdemo/wxTreeCtrl.rbw +191 -0
- data/samples/calendar/calendar.rb +256 -0
- data/samples/caret/caret.rb +282 -0
- data/samples/caret/mondrian.xpm +44 -0
- data/samples/controls/controls.rb +1136 -0
- data/samples/controls/get_item_sample.rb +87 -0
- data/samples/controls/icons/choice.xpm +27 -0
- data/samples/controls/icons/combo.xpm +27 -0
- data/samples/controls/icons/gauge.xpm +27 -0
- data/samples/controls/icons/list.xpm +27 -0
- data/samples/controls/icons/radio.xpm +27 -0
- data/samples/controls/icons/stattext.xpm +24 -0
- data/samples/controls/icons/text.xpm +27 -0
- data/samples/controls/mondrian.ico +0 -0
- data/samples/controls/mondrian.xpm +44 -0
- data/samples/controls/test2.bmp +0 -0
- data/samples/dialogs/dialogs.rb +797 -0
- data/samples/dialogs/tips.txt +18 -0
- data/samples/dragdrop/dragdrop.rb +177 -0
- data/samples/drawing/graphics_drawing.rb +235 -0
- data/samples/drawing/images.rb +37 -0
- data/samples/drawing/paperclip.png +0 -0
- data/samples/etc/activation.rb +102 -0
- data/samples/etc/choice.rb +67 -0
- data/samples/etc/miniframe.rb +79 -0
- data/samples/etc/sash.rb +130 -0
- data/samples/etc/scrollwin.rb +110 -0
- data/samples/etc/system_settings.rb +252 -0
- data/samples/etc/threaded.rb +72 -0
- data/samples/etc/toolbar_sizer_additem.rb +55 -0
- data/samples/etc/wizard.rb +74 -0
- data/samples/event/event.rb +182 -0
- data/samples/event/update_ui_event.rb +70 -0
- data/samples/grid/grid.rb +198 -0
- data/samples/grid/gridtablebase.rb +148 -0
- data/samples/html/html.rb +262 -0
- data/samples/listbook/listbook.rb +174 -0
- data/samples/listbook/listbook.xrc +370 -0
- data/samples/mdi/mdi.rb +85 -0
- data/samples/media/mediactrl.rb +167 -0
- data/samples/minimal/minimal.rb +77 -0
- data/samples/minimal/mondrian.ico +0 -0
- data/samples/minimal/mondrian.png +0 -0
- data/samples/minimal/nothing.rb +16 -0
- data/samples/opengl/cube.rb +117 -0
- data/samples/printing/mondrian.ico +0 -0
- data/samples/printing/mondrian.xpm +44 -0
- data/samples/printing/printing.rb +487 -0
- data/samples/sockets/SocketPackets.rb +27 -0
- data/samples/sockets/res/message-new.png +0 -0
- data/samples/sockets/res/user.png +0 -0
- data/samples/sockets/wxClient.rb +395 -0
- data/samples/sockets/wxServer.rb +422 -0
- data/samples/sockets/wxSocketGUI.rb +97 -0
- data/samples/text/format-text-bold.png +0 -0
- data/samples/text/format-text-italic.png +0 -0
- data/samples/text/format-text-underline.png +0 -0
- data/samples/text/mondrian.ico +0 -0
- data/samples/text/mondrian.xpm +44 -0
- data/samples/text/rich_textctrl.rb +98 -0
- data/samples/text/scintilla.rb +169 -0
- data/samples/text/textctrl.rb +111 -0
- data/samples/text/unicode.rb +242 -0
- data/samples/text/utf8.txt +15 -0
- data/samples/treectrl/icon1.xpm +79 -0
- data/samples/treectrl/icon2.xpm +53 -0
- data/samples/treectrl/icon3.xpm +79 -0
- data/samples/treectrl/icon4.xpm +43 -0
- data/samples/treectrl/icon5.xpm +79 -0
- data/samples/treectrl/treectrl.rb +1166 -0
- data/samples/xrc/samples.xrc +46 -0
- data/samples/xrc/xrc_sample.rb +76 -0
- metadata +234 -220
@@ -0,0 +1,27 @@
|
|
1
|
+
# A set of buttons and controls attached to one edge of a Wx::Frame
|
2
|
+
class Wx::ToolBar
|
3
|
+
# Generic method to add items, supporting positional and named
|
4
|
+
# arguments
|
5
|
+
ADD_ITEM_PARAMS = [ Wx::Parameter[ :position, -1 ],
|
6
|
+
Wx::Parameter[ :id, -1 ],
|
7
|
+
Wx::Parameter[ :label, "" ],
|
8
|
+
Wx::Parameter[ :bitmap2, Wx::NULL_BITMAP ],
|
9
|
+
Wx::Parameter[ :kind, Wx::ITEM_NORMAL ],
|
10
|
+
Wx::Parameter[ :short_help, "" ],
|
11
|
+
Wx::Parameter[ :long_help, "" ],
|
12
|
+
Wx::Parameter[ :client_data, nil ] ]
|
13
|
+
|
14
|
+
def add_item(bitmap, *mixed_args)
|
15
|
+
args = Wx::args_as_list(ADD_ITEM_PARAMS, *mixed_args)
|
16
|
+
|
17
|
+
pos = args.shift
|
18
|
+
args.insert(2, bitmap)
|
19
|
+
|
20
|
+
# Call add_tool to append if default position
|
21
|
+
if pos == -1
|
22
|
+
add_tool(*args)
|
23
|
+
else
|
24
|
+
insert_tool(pos, *args)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# Hierarchical control with items
|
2
|
+
class Wx::TreeCtrl
|
3
|
+
# Make these ruby enumerables so find, find_all, map etc are available
|
4
|
+
include Enumerable
|
5
|
+
# Iterate over all items
|
6
|
+
alias :each :traverse
|
7
|
+
|
8
|
+
# Return the children of +parent+ as an array of TreeItemIDs.
|
9
|
+
def get_children(parent)
|
10
|
+
kids = [ get_first_child(parent) ]
|
11
|
+
return [] if kids[0].zero?
|
12
|
+
|
13
|
+
while kid = get_next_sibling(kids.last) and not kid.zero?
|
14
|
+
kids << kid
|
15
|
+
end
|
16
|
+
kids
|
17
|
+
end
|
18
|
+
|
19
|
+
# Returns a Wx::Rect corresponding to the edges of an individual tree
|
20
|
+
# item, including the button, identified by id. The standard wxWidgets
|
21
|
+
# API for getting the pixel location of an item is unrubyish, using an
|
22
|
+
# input/output parameter. But since the underlying get_bounding_rect
|
23
|
+
# method works, it's easier to fix the API in Ruby than adding more to
|
24
|
+
# the already-toxic swig interface TreeCtrl.i file.
|
25
|
+
def get_item_rect(tree_item_id)
|
26
|
+
rect = Wx::Rect.new
|
27
|
+
if get_bounding_rect(tree_item_id, rect, false)
|
28
|
+
return rect
|
29
|
+
else
|
30
|
+
return nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Returns a Wx::Rect corresponding to the edges of an individual tree
|
35
|
+
# item's text label. See above.
|
36
|
+
def get_label_rect(tree_item_id)
|
37
|
+
rect = Wx::Rect.new
|
38
|
+
if get_bounding_rect(tree_item_id, rect, true)
|
39
|
+
return rect
|
40
|
+
else
|
41
|
+
nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# Copyright 2004-2007 by Kevin Smith
|
2
|
+
# released under the MIT-style wxruby2 license
|
3
|
+
|
4
|
+
# The base class for all things displayed on screen
|
5
|
+
class Wx::Window
|
6
|
+
|
7
|
+
# Ruby's Object#id is deprecated and will be removed in 1.9; therefore
|
8
|
+
# for classes inheriting from Wx::Window, the id method returns the
|
9
|
+
# wxRuby Window id
|
10
|
+
alias :id :get_id
|
11
|
+
# In case a more explicit option is preferred.
|
12
|
+
alias :wx_id :get_id
|
13
|
+
|
14
|
+
# The name of Wx::Window#raise conflicts with Ruby's core Kernel#raise
|
15
|
+
# method. This can cause unexpected errors when undecorated #raise is
|
16
|
+
# used inside a Window method. For wxRuby 2.0 it's too late to remove
|
17
|
+
# Window#raise completely, but for now, offer alternatives to
|
18
|
+
# raise/lower that could replace them in future versions.
|
19
|
+
alias :bring_to_front :raise
|
20
|
+
alias :send_to_back :lower
|
21
|
+
|
22
|
+
# Recursively searches all windows below +self+ and returns the first
|
23
|
+
# window which has the id +an_id+. This corresponds to the find_window
|
24
|
+
# method method in WxWidgets when called with an integer.
|
25
|
+
def find_window_by_id(an_id)
|
26
|
+
Wx::Window.find_window_by_id(an_id, self)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Searches all windows below +self+ and returns the first window which
|
30
|
+
# has the name +a_name+ This corresponds to the find_window method method
|
31
|
+
# in WxWidgets when called with an string.
|
32
|
+
def find_window_by_name(a_name)
|
33
|
+
Wx::Window.find_window_by_name(a_name, self)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Searches all windows below +self+ and returns the first window which
|
37
|
+
# has the label +a_label+.
|
38
|
+
def find_window_by_label(a_label)
|
39
|
+
Wx:Window.find_window_by_label(a_label, self)
|
40
|
+
end
|
41
|
+
|
42
|
+
alias :__old_evt_paint :evt_paint
|
43
|
+
# This modified version of evt_paint sets a variable indicating that a
|
44
|
+
# paint event is being handled just before running the event
|
45
|
+
# handler. This ensures that any call to Window#paint within the
|
46
|
+
# handler will supply a Wx::PaintDC (see swig/Window.i).
|
47
|
+
def evt_paint(meth = nil, &block)
|
48
|
+
paint_proc = acquire_handler(meth, block)
|
49
|
+
wrapped_block = proc do | event |
|
50
|
+
instance_variable_set("@__painting__", true)
|
51
|
+
paint_proc.call(event)
|
52
|
+
remove_instance_variable("@__painting__")
|
53
|
+
end
|
54
|
+
__old_evt_paint(&wrapped_block)
|
55
|
+
end
|
56
|
+
|
57
|
+
# Provides bufferd drawing facility to reduce flicker for complex
|
58
|
+
# drawing commands. Works similar to BufferedDC and BufferedPaintDC in
|
59
|
+
# the wxWidgets API, by doing drawing on an in-memory Bitmap, then
|
60
|
+
# copying the result in bulk to the screen.
|
61
|
+
#
|
62
|
+
# The method may be passed an existing Wx::Bitmap as the +buffer+,
|
63
|
+
# otherwise one will be created.
|
64
|
+
#
|
65
|
+
# Works like wxAutoBufferedDC in that additional buffering will only
|
66
|
+
# be done on platforms that do not already natively support buffering
|
67
|
+
# for the standard PaintDC / ClientDC - Windows, in particular.
|
68
|
+
def paint_buffered(buffer = nil)
|
69
|
+
# OS X and GTK do double-buffering natively
|
70
|
+
if self.double_buffered?
|
71
|
+
paint { | dc | yield dc }
|
72
|
+
else
|
73
|
+
# client_size is the window area available for drawing upon
|
74
|
+
c_size = client_size
|
75
|
+
# Create an in-memory buffer if none supplied
|
76
|
+
buffer ||= Wx::Bitmap.new(c_size.width, c_size.height)
|
77
|
+
buffer.draw do | mem_dc |
|
78
|
+
mem_dc.background = Wx::TRANSPARENT_BRUSH
|
79
|
+
mem_dc.clear
|
80
|
+
# Yield the bitmap for the user code to draw upon
|
81
|
+
yield mem_dc
|
82
|
+
paint do | dc |
|
83
|
+
# Copy the buffer to the window
|
84
|
+
dc.blit(0, 0, c_size.width, c_size.height, mem_dc, 0, 0)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
class Wx::XmlResource
|
2
|
+
# XRC_NO_SUBCLASSING should always be in place in wxRuby - we can't
|
3
|
+
# currently link directly to wxRuby subclasses.
|
4
|
+
class << self
|
5
|
+
wx_get = self.instance_method(:get)
|
6
|
+
define_method(:get) do
|
7
|
+
res = wx_get.bind(self).call
|
8
|
+
res.flags |= Wx::XRC_NO_SUBCLASSING
|
9
|
+
res
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# WxRuby already has all XRC handlers built in so there's no way to
|
14
|
+
# control init_all_handlers to reduce binary size. So save users
|
15
|
+
# having to call it.
|
16
|
+
wx_init = self.instance_method(:initialize)
|
17
|
+
define_method(:initialize) do | *args |
|
18
|
+
result = wx_init.bind(self).call(*args)
|
19
|
+
result.flags |= Wx::XRC_NO_SUBCLASSING
|
20
|
+
result.init_all_handlers
|
21
|
+
end
|
22
|
+
|
23
|
+
# The standard .load method returns a boolean indicating success or
|
24
|
+
# failure. Failure might result from bad XML, or a non-existent
|
25
|
+
# file. In ruby, in these circumstances, it's more natural to raise an
|
26
|
+
# Exception than expect the user to test the return value.
|
27
|
+
wx_load = self.instance_method(:load)
|
28
|
+
define_method(:load) do | fname |
|
29
|
+
result = wx_load.bind(self).call(fname)
|
30
|
+
if not result
|
31
|
+
Kernel.raise( RuntimeError,
|
32
|
+
"Failed to load XRC from '#{fname}'; " +
|
33
|
+
"check the file exists and is valid XML")
|
34
|
+
end
|
35
|
+
fname
|
36
|
+
end
|
37
|
+
|
38
|
+
# Returns a Wx::Wizard object from the element named +name+ in the
|
39
|
+
# loaded XRC file. The Wizard will have the parent +parent+.
|
40
|
+
#
|
41
|
+
# This method is not available in wxWidgets, but is here for
|
42
|
+
# completeness and also to document how to use load_object (see
|
43
|
+
# below).
|
44
|
+
def load_wizard(parent, name)
|
45
|
+
wiz = Wx::Wizard.new()
|
46
|
+
load_wizard_subclass(wiz, parent, name)
|
47
|
+
wiz
|
48
|
+
end
|
49
|
+
|
50
|
+
# Completes the loading of a incomplete instance of Wx::Wizard.
|
51
|
+
def load_wizard_subclass(wizard, parent, name)
|
52
|
+
load_object(wizard, parent, name, "wxWizard")
|
53
|
+
end
|
54
|
+
end
|
data/lib/wx/helpers.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Various non-GUI helper functions
|
2
|
+
module Wx
|
3
|
+
# A named parameter in a Wx named-arg parameter list
|
4
|
+
Parameter = Struct.new( :name, :default )
|
5
|
+
|
6
|
+
# Convert mixed positional / named args into a list to be passed to
|
7
|
+
# an underlying API method. +param_spec+ is an Array of Parameter
|
8
|
+
# structs containing the keyword name and default value for each
|
9
|
+
# possible argument. +mixed_args+ is an array which may optionally end
|
10
|
+
# with a set of named arguments
|
11
|
+
def self.args_as_list(param_spec, *mixed_args)
|
12
|
+
# get keyword arguments from mixed args if supplied, else empty
|
13
|
+
kwa = mixed_args.last.kind_of?(Hash) ? mixed_args.pop : {}
|
14
|
+
out_args = []
|
15
|
+
param_spec.each_with_index do | param, i |
|
16
|
+
if arg = mixed_args[i] # use the supplied list arg
|
17
|
+
out_args << arg
|
18
|
+
elsif kwa.key?(param.name) # use the keyword arg
|
19
|
+
out_args << kwa[param.name]
|
20
|
+
else # use the default argument
|
21
|
+
out_args << param.default
|
22
|
+
end
|
23
|
+
end
|
24
|
+
out_args
|
25
|
+
rescue
|
26
|
+
Kernel.raise ArgumentError,
|
27
|
+
"Bad arg composition of #{mixed_args.inspect}"
|
28
|
+
end
|
29
|
+
|
30
|
+
# Given an integer constant +int_const+, returns an array Wx constant
|
31
|
+
# names which have this value. If a string +prefix+ is supplied, find
|
32
|
+
# only constants whose names begin with this prefix. For example,
|
33
|
+
# passing "EVT" would return only constants with a name like
|
34
|
+
# Wx::EVT_XXX
|
35
|
+
#
|
36
|
+
# This is primarily useful for debugging, when an unknown constant is
|
37
|
+
# returned, eg as an event type id.
|
38
|
+
def self.find_const(sought, prefix = "")
|
39
|
+
consts = constants.grep(/\A#{prefix}/)
|
40
|
+
consts.find_all do | c |
|
41
|
+
c_val = const_get(c)
|
42
|
+
c_val.instance_of?(Fixnum) and c_val == sought
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,204 @@
|
|
1
|
+
# = WxRuby Extensions - Keyword Constructors
|
2
|
+
#
|
3
|
+
# The *Keyword Constructors* extension allows the use of Ruby hash-style
|
4
|
+
# keyword arguments in constructors of common WxWidgets Windows, Frame,
|
5
|
+
# Dialog and Control classes.
|
6
|
+
#
|
7
|
+
# == Introduction
|
8
|
+
#
|
9
|
+
# Building a GUI in WxWidgets involves lots of calls to +new+, but
|
10
|
+
# these methods often have long parameter lists. Often the default
|
11
|
+
# values for many of these parameters are correct. For example, if
|
12
|
+
# you're using a sizer-based layout, you usually don't want to specify a
|
13
|
+
# size for widgets, but you still have to type
|
14
|
+
#
|
15
|
+
# Wx::TreeCtrl.new( parent, -1, Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE,
|
16
|
+
# Wx::NO_BUTTONS )
|
17
|
+
#
|
18
|
+
# just to create a standard TreeCtrl with the 'no buttons' style. If you
|
19
|
+
# want to specify the 'NO BUTTONS' style, you can't avoid all the typing
|
20
|
+
# of DEFAULT_POSITION etc.
|
21
|
+
#
|
22
|
+
# == Basic Keyword Constructors
|
23
|
+
#
|
24
|
+
# With keyword_constructors, you could write the above as
|
25
|
+
#
|
26
|
+
# TreeCtrl.new(parent, :style => Wx::NO_BUTTONS)
|
27
|
+
#
|
28
|
+
# And it will assume you want the default id (-1), and the default size
|
29
|
+
# and position. If you want to specify an explicit size, you can do so:
|
30
|
+
#
|
31
|
+
# TreeCtrl.new(parent, :size => Wx::Size.new(100, 300))
|
32
|
+
#
|
33
|
+
# For brevity, this module also allows you to specify positions and
|
34
|
+
# sizes using a a two-element array:
|
35
|
+
#
|
36
|
+
# TreeCtrl.new(parent, :size => [100, 300])
|
37
|
+
#
|
38
|
+
# Similarly with position:
|
39
|
+
#
|
40
|
+
# TreeCtrl.new(parent, :pos => Wx::Point.new(5, 25))
|
41
|
+
#
|
42
|
+
# TreeCtrl.new(parent, :pos => [5, 25])
|
43
|
+
#
|
44
|
+
# You can have multiple keyword arguments:
|
45
|
+
#
|
46
|
+
# TreeCtrl.new(parent, :pos => [5, 25], :size => [100, 300] )
|
47
|
+
#
|
48
|
+
# == No ID required
|
49
|
+
#
|
50
|
+
# As with position and size, you usually don't want to deal with
|
51
|
+
# assigning unique ids to every widget and frame you create - it's a C++
|
52
|
+
# hangover that often seems clunky in Ruby. The *Event Connectors*
|
53
|
+
# extension allows you to set up event handling without having to use
|
54
|
+
# ids, and if no :id argument is supplied to a constructor, the default
|
55
|
+
# (-1) will be passed.
|
56
|
+
#
|
57
|
+
# There are occasions when a specific ID does need to be used - for
|
58
|
+
# example, to tell WxWidgets that a button is a 'stock' item, so that it
|
59
|
+
# can be displayed using platform-standard text and icon. To do this,
|
60
|
+
# simply pass an :id argument to the constructor - here, the system's
|
61
|
+
# standard 'preview' button
|
62
|
+
#
|
63
|
+
# Wx::Button.new(parent, :id => Wx::ID_PREVIEW)
|
64
|
+
#
|
65
|
+
# == Class-specific arguments
|
66
|
+
#
|
67
|
+
# The arguments :size, :pos and :style are common to many WxWidgets
|
68
|
+
# window classes. The +new+ methods of these classes also have
|
69
|
+
# parameters that are specific to those classes; for example, the text
|
70
|
+
# label on a button, or the initial value of a text control.
|
71
|
+
#
|
72
|
+
# Wx::Button.new(parent, :label => 'press me')
|
73
|
+
# Wx::TextCtrl.new(parent, :value => 'type some text here')
|
74
|
+
#
|
75
|
+
# The keyword names of these arguments can be found by looking at the
|
76
|
+
# WxRuby documentation, in the relevant class's +new+ method. You can
|
77
|
+
# also get a string description of the class's +new+ method parameters
|
78
|
+
# within Ruby by doing:
|
79
|
+
#
|
80
|
+
# puts Wx::TextCtrl.describe_constructor()
|
81
|
+
#
|
82
|
+
# This will print a list of the argument names expected by the class's
|
83
|
+
# +new+ method, and the correct type for them.
|
84
|
+
#
|
85
|
+
# == Mixing positional and keyword arguments
|
86
|
+
#
|
87
|
+
# To support existing code, and to avoid forcing the use of more verbose
|
88
|
+
# keyword-style arguments where they're not desired, you can mix
|
89
|
+
# positional and keyword arguments, omitting or including +id+s as
|
90
|
+
# desired.
|
91
|
+
#
|
92
|
+
# Wx::Button.new(parent, 'press me', :style => Wx::BU_RIGHT)
|
93
|
+
|
94
|
+
module Wx
|
95
|
+
module KeywordConstructor
|
96
|
+
module ClassMethods
|
97
|
+
|
98
|
+
# Common Wx constructor argument keywords, with their default values.
|
99
|
+
STANDARD_DEFAULTS = {
|
100
|
+
:id => -1,
|
101
|
+
:size => Wx::DEFAULT_SIZE,
|
102
|
+
:pos => Wx::DEFAULT_POSITION,
|
103
|
+
:style => 0,
|
104
|
+
:title => '',
|
105
|
+
:validator => Wx::DEFAULT_VALIDATOR,
|
106
|
+
:choices => [] # for Choice, ComboBox etc
|
107
|
+
}
|
108
|
+
|
109
|
+
attr_writer :param_spec
|
110
|
+
def param_spec
|
111
|
+
@param_spec ||= []
|
112
|
+
end
|
113
|
+
|
114
|
+
# Adds a list of named parameters *params* to the parameter
|
115
|
+
# specification for this Wx class's constructor. Each parameter
|
116
|
+
# should be specified as a either a common known symbol, such as
|
117
|
+
# +:size+ or +:pos:+ or +:style:+ (corresponding to the common
|
118
|
+
# constructor arguments in WxWidgets API), or a single-key with the
|
119
|
+
# key the name of the argument, and the value a default value.
|
120
|
+
#
|
121
|
+
# Parameters should be specified in the order they occur in the Wx
|
122
|
+
# API constructor
|
123
|
+
def wx_ctor_params(*params)
|
124
|
+
self.param_spec += params.map do | param |
|
125
|
+
param.kind_of?(Hash) ?
|
126
|
+
Parameter[ param.keys.first, param.values.first ] :
|
127
|
+
Parameter[ param, STANDARD_DEFAULTS[param] ]
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def args_as_list(*mixed_args)
|
132
|
+
Wx::args_as_list(param_spec, *mixed_args)
|
133
|
+
end
|
134
|
+
|
135
|
+
def args_as_hash(*mixed_args)
|
136
|
+
kwa = mixed_args.last.kind_of?(Hash) ? mixed_args.pop : {}
|
137
|
+
param_spec.zip(mixed_args) do | param, arg |
|
138
|
+
kwa[param.name] = arg if arg
|
139
|
+
end
|
140
|
+
kwa
|
141
|
+
end
|
142
|
+
|
143
|
+
def describe_constructor()
|
144
|
+
param_spec.inject("") do | desc, param |
|
145
|
+
desc << ":#{param.name} => (#{param.default.class.name})\n"
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def self.included(klass)
|
151
|
+
klass.extend ClassMethods
|
152
|
+
klass.module_eval do
|
153
|
+
|
154
|
+
alias :pre_wx_kwctor_init :initialize
|
155
|
+
|
156
|
+
# The new definition of initialize; accepts a parent arg
|
157
|
+
# mixed_args, which may zero or more position args, optionally
|
158
|
+
# terminated with hash keyword args, and an optional block
|
159
|
+
def initialize(parent = :default_ctor, *mixed_args, &block)
|
160
|
+
# allow zero-args ctor for use with XRC
|
161
|
+
if parent == :default_ctor
|
162
|
+
pre_wx_kwctor_init()
|
163
|
+
return
|
164
|
+
end
|
165
|
+
|
166
|
+
real_args = [ parent ] + self.class.args_as_list(*mixed_args)
|
167
|
+
begin
|
168
|
+
pre_wx_kwctor_init(*real_args)
|
169
|
+
rescue => err
|
170
|
+
msg = "Error initializing #{self.inspect}\n"+
|
171
|
+
" : #{err.message} \n" +
|
172
|
+
"Correct parameters for #{self.class.name}.new are:\n" +
|
173
|
+
self.class.describe_constructor()
|
174
|
+
|
175
|
+
new_err = err.class.new(msg)
|
176
|
+
new_err.set_backtrace(caller)
|
177
|
+
Kernel.raise new_err
|
178
|
+
end
|
179
|
+
|
180
|
+
# If a block was given, pass the newly created Window instance
|
181
|
+
# into it; use block
|
182
|
+
if block
|
183
|
+
if block.arity == -1 or block.arity == 0
|
184
|
+
self.instance_eval(&block)
|
185
|
+
elsif block.arity == 1
|
186
|
+
block.call(self)
|
187
|
+
else
|
188
|
+
Kernel.raise ArgumentError,
|
189
|
+
"Block to initialize accepts zero or one arg"
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
# Any class inheriting from a class including this module must have
|
196
|
+
# its own copy of the param_spec
|
197
|
+
def klass.inherited(sub_klass)
|
198
|
+
sub_klass.instance_variable_set(:@param_spec,
|
199
|
+
instance_variable_get(:@param_spec) )
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|