Module: Wx

Extended by:
WxRubyStyleAccessors
Defined in:
lib/wx/helpers.rb,
lib/wx/version.rb,
lib/wx/accessors.rb,
lib/wx/keyword_defs.rb,
lib/wx/keyword_ctors.rb,
lib/wx/classes/functions.rb,
lib/wx/classes/dataformat.rb

Overview

Provide pre-cooked data formats for the standard types

Defined Under Namespace

Modules: KeywordConstructor Classes: AcceleratorTable, Animation, App, ArtProvider, AuiNotebook, Bitmap, BusyCursor, CheckListBox, Choice, ClientDC, Clipboard, Colour, ComboBox, CommandEvent, ControlWithItems, DC, DataFormat, DataObject, DataObjectSimple, Event, EvtHandler, Font, GenericDirCtrl, Grid, HBoxSizer, HelpController, HelpControllerHelpProvider, HelpProvider, HtmlHelpController, HtmlWindow, Icon, IconBundle, Image, ImageList, ListBox, ListCtrl, Locale, MediaCtrl, Menu, MenuItem, Notebook, Object, PaintDC, Parameter, Point, PreviewFrame, Rect, RichTextCtrl, SimpleHelpProvider, Size, Sizer, Sound, StandardPaths, TextCtrl, TextUrlEvent, Timer, ToolBar, ToolBarTool, TreeCtrl, VBoxSizer, Validator, Window, XmlResource

Constant Summary collapse

WXRUBY_VERSION =
'2.0.0'
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)
DF_TEXT =
DataFormat.new( DATA_FORMAT_ID_TEXT )
DF_BITMAP =
DataFormat.new( DATA_FORMAT_ID_BITMAP )
DF_METAFILE =
DataFormat.new( DATA_FORMAT_ID_METAFILE )
DF_FILENAME =
DataFormat.new( DATA_FORMAT_ID_FILENAME )
DF_UNICODETEXT =
DataFormat.new( DATA_FORMAT_ID_UNICODETEXT )

Class Method Summary collapse

Methods included from WxRubyStyleAccessors

method_missing

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



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/wx/helpers.rb', line 11

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

.find_const(sought, prefix = "") ⇒ Object

Given an integer constant int_const, returns an array Wx constant names which have this value. If a string prefix is supplied, find only constants whose names begin with this prefix. For example, passing “EVT” would return only constants with a name like Wx::EVT_XXX

This is primarily useful for debugging, when an unknown constant is returned, eg as an event type id.



38
39
40
41
42
43
44
# File 'lib/wx/helpers.rb', line 38

def self.find_const(sought, prefix = "")
  consts = constants.grep(/\A#{prefix}/)
  consts.find_all do | c | 
    c_val = const_get(c)
    c_val.instance_of?(Fixnum) and c_val == sought
  end
end