Class: XRC2Ruby::ObjectTypes::Window

Inherits:
Object
  • Object
show all
Extended by:
InitArgs
Defined in:
lib/wx_sugar/xrc/xrc2ruby_types/window.rb

Constant Summary collapse

BASE_NAME =
"window"

Instance Attribute Summary collapse

Attributes inherited from Object

#centered, #name, #parent, #sub_class, #win_class

Instance Method Summary collapse

Methods included from InitArgs

inherited, init_arg, init_args, translatable_string_init_arg

Methods inherited from Object

#initialize, #inspect, next_id, #var_name

Constructor Details

This class inherits a constructor from XRC2Ruby::ObjectTypes::Object

Instance Attribute Details

#bgObject

Tooltip and help text, applicable to all windows



47
48
49
# File 'lib/wx_sugar/xrc/xrc2ruby_types/window.rb', line 47

def bg
  @bg
end

#enabledObject

Tooltip and help text, applicable to all windows



47
48
49
# File 'lib/wx_sugar/xrc/xrc2ruby_types/window.rb', line 47

def enabled
  @enabled
end

#exstyleObject

Tooltip and help text, applicable to all windows



47
48
49
# File 'lib/wx_sugar/xrc/xrc2ruby_types/window.rb', line 47

def exstyle
  @exstyle
end

#fgObject

Tooltip and help text, applicable to all windows



47
48
49
# File 'lib/wx_sugar/xrc/xrc2ruby_types/window.rb', line 47

def fg
  @fg
end

#helpObject

Tooltip and help text, applicable to all windows



47
48
49
# File 'lib/wx_sugar/xrc/xrc2ruby_types/window.rb', line 47

def help
  @help
end

#hiddenObject

Tooltip and help text, applicable to all windows



47
48
49
# File 'lib/wx_sugar/xrc/xrc2ruby_types/window.rb', line 47

def hidden
  @hidden
end

#tooltipObject

Tooltip and help text, applicable to all windows



47
48
49
# File 'lib/wx_sugar/xrc/xrc2ruby_types/window.rb', line 47

def tooltip
  @tooltip
end

Instance Method Details

#argsObject

Returns the constructor arguments as a Ruby string



115
116
117
118
119
120
121
122
123
# File 'lib/wx_sugar/xrc/xrc2ruby_types/window.rb', line 115

def args
  defined_args = []
  self.class.init_args.keys.each do | arg |
    if arg_val = send(arg)
      defined_args << ":#{arg} => #{arg_val}"
    end
  end
  defined_args.join(",\n")
end

#outputObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/wx_sugar/xrc/xrc2ruby_types/window.rb', line 49

def output
  # The base constructor
  if parent
    base = "#{var_name} = #{win_class}.new(#{parent.var_name}"
    base << ( args.empty? ? ")" : ",\n#{args})" )
  else
    base = "#{var_name} = #{win_class}.new(nil" 
    base << ( args.empty? ? ")" : ",\n#{args})" )
  end
  # Re-indent the keyword arguments
  indent = base.index("(") + 1
  base.gsub!(/\n:/, "\n" + (" " * indent ) + ":") || base
  base << "\n"

  # If help text is defined
  if self.help
    base << "#{var_name}.help_text = '#{self.help}'\n"
  end

  # If a tooltip is defined
  if self.tooltip
    base << "#{var_name}.tool_tip = '#{self.tooltip}'\n"
  end

  # If foreground colour is specified, convert hex->int and set
  if self.fg
    colour = self.bg.scan(/[0-9a-fA-F]{2}/).map { | e | e.to_i(16) }
    base << "#{var_name}.background_colour = "
    base << "Wx::Colour.new(#{colour.join(', ')})\n"
  end

  # If background colour is specified, convert hex->int and set
  if self.bg
    colour = self.bg.scan(/[0-9a-fA-F]{2}/).map { | e | e.to_i(16) }
    base << "#{var_name}.foreground_colour = "
    base << "Wx::Colour.new(#{colour.join(', ')})\n"
  end

  # If extra style set
  if self.exstyle
    base << "#{var_name}.extra_style = #{exstyle.gsub(/^wx/, "Wx::")}"
  end
  
  # If explicitly disabled or enabled
  if self.enabled 
    if self.enabled.to_i.zero?
      base << "#{var_name}.disable\n"
    else
      base << "#{var_name}.enable\n"
    end
  end

  # If explicitly shown or hidden
  if self.hidden 
    if self.hidden.to_i.zero?
      base << "#{var_name}.hide\n"
    else
      base << "#{var_name}.show\n"
    end
  end

  base << setup
  base
end

#setupObject

Some classes define XRC property elements that are set in wxWidgets by method calls rather than passed as part of the constructor. This method can be overridden in subclasses to return a string with those arguments.



129
130
131
# File 'lib/wx_sugar/xrc/xrc2ruby_types/window.rb', line 129

def setup
  ''
end