Class: Wx::Window

Inherits:
Object
  • Object
show all
Defined in:
lib/wx_sugar/wx_classes/window.rb

Overview

extensions to Wx::Window

Instance Method Summary collapse

Instance Method Details

#find_window(a_class = Wx::Window, &block) ⇒ Object

Passed a block, returns the first window within self’s window hierarchy for which the block evaluates to true. A class name may optionally be passed to restrict the search to windows of that class (or its subclasses) only - this can be useful if the search specification calls methods that are only defined for certain classes.

# Example - find a StaticText with a label matching /foo/
a_frame.find_window(Wx::StaticText) { | tx | tx.label =~ /foo/ }


20
21
22
# File 'lib/wx_sugar/wx_classes/window.rb', line 20

def find_window(a_class = Wx::Window, &block)
  get_descendants.grep(a_class).detect(&block)
end

#get_descendantsObject

Returns an array containing this window and all windows descended from it.



5
6
7
8
9
# File 'lib/wx_sugar/wx_classes/window.rb', line 5

def get_descendants
  get_children.inject([ self ]) do | desc, child |
    desc + child.get_descendants
  end
end

#get_position_xyObject

Returns the window’s current position as a two-element array.



31
32
33
34
# File 'lib/wx_sugar/wx_classes/window.rb', line 31

def get_position_xy
  pos = get_position
  return pos.x, pos.y
end

#get_size_xyObject

Returns the window’s current size as a two element array



25
26
27
28
# File 'lib/wx_sugar/wx_classes/window.rb', line 25

def get_size_xy
  size = get_size
  return size.get_width, size.get_height
end

#has_style?(style) ⇒ Boolean

Tests if the GUI object has the given window style style. Returns style if it has been applied, or nil if the window does not have that style.

combobox.has_style?(Wx::CB_READONLY)
textctrl.has_style?(Wx::TE_MULTILINE)

Note that you should at least know that the constant style is applicable to self. You may get false positives if testing a widget for a style belonging to an irrelevant class, e.g. testing a Wx::TextCtrl for the WX::CB_READONLY style.

Returns:

  • (Boolean)


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

def has_style?(style)
  ( get_window_style & style ).nonzero?
end