Class: Teek::Widget
- Inherits:
-
Object
- Object
- Teek::Widget
- Defined in:
- lib/teek/widget.rb
Overview
Thin wrapper around a Tk widget path. Holds a reference to the App and the widget's Tcl path string.
Instances are interchangeable with plain strings anywhere a widget path is expected thanks to #to_s returning the path.
Created via App#create_widget:
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
-
#bind(event, *subs) { ... } ⇒ void
Bind an event on this widget.
-
#command(*args, **kwargs) ⇒ String
Invoke a widget subcommand.
-
#destroy ⇒ void
Destroy this widget and all its children.
-
#exist? ⇒ Boolean
Check if this widget still exists in the Tk interpreter.
-
#grid(**kwargs) ⇒ self
Grid this widget.
- #hash ⇒ Object
-
#height ⇒ Integer
Current height in pixels.
-
#initialize(app, path) ⇒ Widget
constructor
A new instance of Widget.
- #inspect ⇒ Object
-
#on_close { ... } ⇒ void
Register a handler for this window's close button (WM_DELETE_WINDOW).
-
#pack(**kwargs) ⇒ self
Pack this widget.
-
#to_s ⇒ String
The Tcl widget path.
-
#unbind(event) ⇒ void
Remove an event binding from this widget.
-
#width ⇒ Integer
Current width in pixels.
Constructor Details
#initialize(app, path) ⇒ Widget
Returns a new instance of Widget.
22 23 24 25 |
# File 'lib/teek/widget.rb', line 22 def initialize(app, path) @app = app @path = path end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
20 21 22 |
# File 'lib/teek/widget.rb', line 20 def app @app end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
20 21 22 |
# File 'lib/teek/widget.rb', line 20 def path @path end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
118 119 120 |
# File 'lib/teek/widget.rb', line 118 def ==(other) other.is_a?(Widget) ? @path == other.path : @path == other.to_s end |
#bind(event, *subs) { ... } ⇒ void
This method returns an undefined value.
Bind an event on this widget.
93 94 95 |
# File 'lib/teek/widget.rb', line 93 def bind(event, *subs, &block) @app.bind(@path, event, *subs, &block) end |
#command(*args, **kwargs) ⇒ String
Invoke a widget subcommand. Prepends the widget path as the Tcl command.
43 44 45 |
# File 'lib/teek/widget.rb', line 43 def command(*args, **kwargs) @app.command(@path, *args, **kwargs) end |
#destroy ⇒ void
This method returns an undefined value.
Destroy this widget and all its children.
49 50 51 |
# File 'lib/teek/widget.rb', line 49 def destroy @app.destroy(@path) end |
#exist? ⇒ Boolean
Check if this widget still exists in the Tk interpreter.
55 56 57 |
# File 'lib/teek/widget.rb', line 55 def exist? @app.winfo.exists?(@path) end |
#grid(**kwargs) ⇒ self
Grid this widget.
82 83 84 85 |
# File 'lib/teek/widget.rb', line 82 def grid(**kwargs) @app.command(:grid, @path, **kwargs) self end |
#hash ⇒ Object
123 124 125 |
# File 'lib/teek/widget.rb', line 123 def hash @path.hash end |
#height ⇒ Integer
Returns current height in pixels.
67 68 69 |
# File 'lib/teek/widget.rb', line 67 def height @app.winfo.height(@path) end |
#inspect ⇒ Object
114 115 116 |
# File 'lib/teek/widget.rb', line 114 def inspect "#<Teek::Widget #{@path}>" end |
#on_close { ... } ⇒ void
This method returns an undefined value.
Register a handler for this window's close button (WM_DELETE_WINDOW). Meant for toplevels; see App#on_close for the full behavior.
110 111 112 |
# File 'lib/teek/widget.rb', line 110 def on_close(&block) @app.on_close(window: @path, &block) end |
#pack(**kwargs) ⇒ self
Pack this widget.
74 75 76 77 |
# File 'lib/teek/widget.rb', line 74 def pack(**kwargs) @app.command(:pack, @path, **kwargs) self end |
#to_s ⇒ String
Returns the Tcl widget path.
28 29 30 |
# File 'lib/teek/widget.rb', line 28 def to_s @path end |
#unbind(event) ⇒ void
This method returns an undefined value.
Remove an event binding from this widget.
101 102 103 |
# File 'lib/teek/widget.rb', line 101 def unbind(event) @app.unbind(@path, event) end |
#width ⇒ Integer
Returns current width in pixels.
61 62 63 |
# File 'lib/teek/widget.rb', line 61 def width @app.winfo.width(@path) end |