Class: Glimmer::Tk::MenuItemProxy
Constant Summary
collapse
- ACCELERATOR_MODIFIER_EVENT_MAP =
{
'Command' => 'Command',
'Cmd' => 'Command',
'Meta' => 'Command',
'Option' => 'Option',
'Opt' => 'Option',
'Alt' => 'Option',
'Shift' => 'Shift',
'Ctrl' => 'Control',
'Control' => 'Control',
}
Constants inherited
from WidgetProxy
WidgetProxy::FONTS_PREDEFINED
Instance Attribute Summary collapse
Attributes inherited from WidgetProxy
#args, #bind_ids, #children, #destroyed, #keyword, #parent_proxy, #tk
#on_drag_motion_block
Instance Method Summary
collapse
Methods inherited from WidgetProxy
#add_observer, #ancestor_proxies, #apply_style, #attribute_setter, #content, create, #destroy, #font=, #get_attribute, #grid, #has_attribute?, #has_attributes_attribute?, #has_state?, #image_argument, #inspect, #method_missing, #on, #post_add_content, #post_initialize_child, #respond_to?, #root_parent_proxy, #set_attribute, #style=, tk_widget_class_for, #tk_widget_has_attribute_getter_setter?, #tk_widget_has_attribute_setter?, #toplevel_parent_proxy, #unbind_all, #widget_attribute_listener_installers, #widget_custom_attribute_mapping, widget_exists?, widget_proxy_class
#drag_source=, #drop_target=, #make_draggable, #make_droppable, #make_non_draggable, #make_non_droppable, #on_drag_start_block=, #on_drop_block=, #textvariable_defined?
Constructor Details
#initialize(underscored_widget_name, parent_proxy, args, &block) ⇒ MenuItemProxy
Returns a new instance of MenuItemProxy.
41
42
43
44
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 41
def initialize(underscored_widget_name, parent_proxy, args, &block)
@options = args.last.is_a?(Hash) ? args.last : {}
super
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Glimmer::Tk::WidgetProxy
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
39
40
41
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 39
def options
@options
end
|
Instance Method Details
#about? ⇒ Boolean
126
127
128
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 126
def about?
@args.first == :about
end
|
#accelerator ⇒ Object
54
55
56
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 54
def accelerator
@accelerator
end
|
#accelerator=(value) ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 46
def accelerator=(value)
@accelerator = value
(accelerator: value)
root_parent_proxy.bind(accelerator_event) do |event|
@command_block&.call(event)
end
end
|
#accelerator_event ⇒ Object
58
59
60
61
62
63
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 58
def accelerator_event
accelerator_parts = @accelerator.split('+')
accelerator_parts.map do |accelerator_part|
ACCELERATOR_MODIFIER_EVENT_MAP[accelerator_part.capitalize] || accelerator_part.downcase
end.join('-')
end
|
118
119
120
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 118
def checkbutton?
@args.first == :radiobutton
end
|
#command? ⇒ Boolean
110
111
112
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 110
def command?
@args.first.nil? || @args.first == :command || @args.first.is_a?(Hash)
end
|
#command_block=(proc) ⇒ Object
96
97
98
99
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 96
def command_block=(proc)
@command_block = proc
(command: @command_block)
end
|
#compound ⇒ Object
92
93
94
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 92
def compound
@compound
end
|
#compound=(value) ⇒ Object
87
88
89
90
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 87
def compound=(value)
@compound = value
(compound: @compound)
end
|
configures menu item attribute through parent menu
165
166
167
168
169
170
171
172
173
174
175
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 165
def (attribute_value_hash)
if preferences? && attribute_value_hash[:command]
::Tk.ip_eval("proc ::tk::mac::ShowPreferences {} {#{::Tk.install_cmd(attribute_value_hash[:command])}}") if OS.mac?
elsif help? && attribute_value_hash[:command]
::Tk.ip_eval("proc ::tk::mac::ShowHelp {} {#{::Tk.install_cmd(attribute_value_hash[:command])}}") if OS.mac?
elsif quit? && attribute_value_hash[:command]
::Tk.ip_eval("proc ::tk::mac::Quit {} {#{::Tk.install_cmd(attribute_value_hash[:command])}}") if OS.mac?
else
@parent_proxy.tk.entryconfigure label, attribute_value_hash
end
end
|
#handle_listener(listener_name, &listener) ⇒ Object
101
102
103
104
105
106
107
108
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 101
def handle_listener(listener_name, &listener)
case listener_name.to_s.downcase
when 'command'
self.command_block = listener
else
super
end
end
|
#help? ⇒ Boolean
134
135
136
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 134
def help?
@args.first == :help
end
|
#image ⇒ Object
83
84
85
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 83
def image
@image
end
|
#image=(*args) ⇒ Object
78
79
80
81
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 78
def image=(*args)
@image = image_argument(args)
(image: @image)
end
|
#label ⇒ Object
74
75
76
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 74
def label
@options[:label]
end
|
#preferences? ⇒ Boolean
130
131
132
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 130
def preferences?
@args.first == :preferences
end
|
#quit? ⇒ Boolean
138
139
140
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 138
def quit?
@args.first == :quit
end
|
114
115
116
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 114
def radiobutton?
@args.first == :radiobutton
end
|
#selection ⇒ Object
160
161
162
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 160
def selection
variable.value == label
end
|
#selection=(value) ⇒ Object
152
153
154
155
156
157
158
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 152
def selection=(value)
if value
variable.value = label
elsif checkbutton?
variable.value = ''
end
end
|
#separator? ⇒ Boolean
122
123
124
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 122
def separator?
@args.first == :separator
end
|
#state ⇒ Object
70
71
72
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 70
def state
@state
end
|
#state=(value) ⇒ Object
65
66
67
68
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 65
def state=(value)
@state = value
(state: value)
end
|
#variable(auto_create: true) ⇒ Object
142
143
144
145
146
147
148
149
150
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 142
def variable(auto_create: true)
if @variable.nil? && auto_create
sibling_variable = .map {|mi| mi.variable(auto_create: false)}.compact.first
@variable = sibling_variable.nil? ? ::TkVariable.new : sibling_variable
else
@variable
end
@variable
end
|