Module: Wx
- Defined in:
- lib/wx/helpers.rb,
lib/wx/version.rb,
lib/wx/keyword_defs.rb,
lib/wx/keyword_ctors.rb,
lib/wx/classes/functions.rb
Overview
Tweaks to the global module functions
Defined Under Namespace
Modules: KeywordConstructor Classes: AcceleratorTable, Animation, App, ArtProvider, AuiNotebook, Bitmap, BusyCursor, CheckListBox, Choice, ClientDC, Clipboard, Colour, ComboBox, CommandEvent, ControlWithItems, DC, Event, EvtHandler, Font, Grid, HelpController, HelpControllerHelpProvider, HelpProvider, HtmlHelpController, HtmlWindow, Icon, IconBundle, Image, ImageList, ListBox, ListCtrl, Locale, MediaCtrl, Menu, MenuItem, Notebook, Object, PaintDC, Parameter, Point, PreviewFrame, Rect, SimpleHelpProvider, Size, Sizer, Sound, TextCtrl, TextUrlEvent, Timer, ToolBar, ToolBarTool, TreeCtrl, Window, XmlResource
Constant Summary collapse
- WXRUBY_VERSION =
'1.9.8'- Gauge95 =
Wx::Gauge
- WHITE =
Standard colours, corresponding to WxWidgets stock colours.
new(255, 255, 255)
- BLACK =
new(0, 0, 0)
- RED =
new(255, 0, 0)
- GREEN =
new(0, 255, 0)
- BLUE =
new(0, 0, 255)
- YELLOW =
new(255, 255, 0)
- MAGENTA =
new(255, 0, 255)
- CYAN =
new(0, 255, 255)
- LIGHT_GREY =
new(192, 192, 192)
Class Method Summary collapse
-
.args_as_list(param_spec, *mixed_args) ⇒ Object
Convert mixed positional / named args into a list to be passed to an underlying API method.
-
.define_keyword_ctors(klass_name, &block) ⇒ Object
accepts a string unadorned name of a WxWidgets class, and block, which defines the constructor parameters and style flags for that class.
Class Method Details
.args_as_list(param_spec, *mixed_args) ⇒ Object
Convert mixed positional / named args into a list to be passed to an underlying API method. param_spec is an Array of Parameter structs containing the keyword name and default value for each possible argument. mixed_args is an array which may optionally end with a set of named arguments
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/wx/helpers.rb', line 12 def self.args_as_list(param_spec, *mixed_args) # get keyword arguments from mixed args if supplied, else empty kwa = mixed_args.last.kind_of?(Hash) ? mixed_args.pop : {} out_args = [] param_spec.each_with_index do | param, i | if arg = mixed_args[i] # use the supplied list arg out_args << arg elsif kwa.key?(param.name) # use the keyword arg out_args << kwa[param.name] else # use the default argument out_args << param.default end end out_args rescue Kernel.raise ArgumentError, "Bad arg composition of #{mixed_args.inspect}" end |
.define_keyword_ctors(klass_name, &block) ⇒ Object
accepts a string unadorned name of a WxWidgets class, and block, which defines the constructor parameters and style flags for that class. If the named class exists in the available WxRuby, the block is run and the class may use keyword constructors. If the class is not available, the block is ignored.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/wx/keyword_defs.rb', line 27 def self.define_keyword_ctors(klass_name, &block) # check this class hasn't already been defined if @defined_kw_classes[klass_name] raise ArgumentError, "Keyword ctor for #{klass_name} already defined" else @defined_kw_classes[klass_name] = true end begin klass = Wx::const_get(klass_name) rescue NameError return nil end klass.module_eval { include Wx::KeywordConstructor } klass.instance_eval(&block) end |