Class: XRCClass

Inherits:
Object
  • Object
show all
Defined in:
lib/wx_sugar/xrc/xml_class.rb

Overview

Representation of a single GUI class defined in XRC. wxRuby permits subclasses of Frames, Dialog and Panels to be loaded from XRC.

Defined Under Namespace

Classes: Control

Constant Summary collapse

VALID_CLASSES =

Only these classes may be subclassed in Ruby

%|wxFrame wxDialog wxPanel wxWizard|

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml_elem, xrc_file) ⇒ XRCClass

Create a new class from xml_elem



37
38
39
40
41
42
43
44
45
46
# File 'lib/wx_sugar/xrc/xml_class.rb', line 37

def initialize(xml_elem, xrc_file)
  @xml_src   = xml_elem
  @file_name = xrc_file

  @base_id   = xml_elem.attributes['name']
  @wx_class  = xml_elem.attributes['class']
  @sub_class = xml_elem.attributes['subclass']
  @controls  = []
  read_controls
end

Instance Attribute Details

#base_idObject (readonly)

base_id : the Wx identifier of the main window wx_class : the Wx class which this window inherits from sub_class : the ruby class name of this window class controls : an array of identified controls within this window file_name : the XRC file from which this class can be loaded



15
16
17
# File 'lib/wx_sugar/xrc/xml_class.rb', line 15

def base_id
  @base_id
end

#controlsObject (readonly)

base_id : the Wx identifier of the main window wx_class : the Wx class which this window inherits from sub_class : the ruby class name of this window class controls : an array of identified controls within this window file_name : the XRC file from which this class can be loaded



15
16
17
# File 'lib/wx_sugar/xrc/xml_class.rb', line 15

def controls
  @controls
end

#file_nameObject (readonly)

base_id : the Wx identifier of the main window wx_class : the Wx class which this window inherits from sub_class : the ruby class name of this window class controls : an array of identified controls within this window file_name : the XRC file from which this class can be loaded



15
16
17
# File 'lib/wx_sugar/xrc/xml_class.rb', line 15

def file_name
  @file_name
end

#sub_classObject (readonly)

base_id : the Wx identifier of the main window wx_class : the Wx class which this window inherits from sub_class : the ruby class name of this window class controls : an array of identified controls within this window file_name : the XRC file from which this class can be loaded



15
16
17
# File 'lib/wx_sugar/xrc/xml_class.rb', line 15

def sub_class
  @sub_class
end

#wx_classObject (readonly)

base_id : the Wx identifier of the main window wx_class : the Wx class which this window inherits from sub_class : the ruby class name of this window class controls : an array of identified controls within this window file_name : the XRC file from which this class can be loaded



15
16
17
# File 'lib/wx_sugar/xrc/xml_class.rb', line 15

def wx_class
  @wx_class
end

Class Method Details

.extract(xml_elem, xrc_file) ⇒ Object

Checks to see if a valid class can be created from xml_elem, and returns one if it can, or nil if it can’t. To be a valid class, the window must inherit from Frame, Dialog or Window, and must define a subclass name.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/wx_sugar/xrc/xml_class.rb', line 21

def self.extract(xml_elem, xrc_file)
  p_class = xml_elem.attributes['class']
  if not VALID_CLASSES.include?(p_class)
    warn "Cannot create wrapper for subclass of #{p_class}"
    return 
  end

  if not xml_elem.attributes['subclass']
    warn "Cannot create wrapper for class without 'subclass'
    attribute"
    return
  end
  new(xml_elem, xrc_file)
end

Instance Method Details

#load_funcObject



52
53
54
55
# File 'lib/wx_sugar/xrc/xml_class.rb', line 52

def load_func
  unadorned = wx_class.sub(/^wx/, '').downcase
  "load_#{unadorned}_subclass"
end

#superclassObject



48
49
50
# File 'lib/wx_sugar/xrc/xml_class.rb', line 48

def superclass
  wx_class.sub(/^wx/, "Wx::")
end