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',
}
- ATTRIBUTES =
%w[activebackground activeforeground background bitmap columnbreak compound font foreground hidemargin indicatoron menu offvalue onvalue selectcolor selectimage state underline value]
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=, #grid, #has_attribute?, #has_state?, #image_argument, #inspect, #method_missing, #on, #post_add_content, #post_initialize_child, #respond_to?, #root_parent_proxy, #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.
43
44
45
46
47
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 43
def initialize(underscored_widget_name, parent_proxy, args, &block)
@options = args.last.is_a?(Hash) ? args.last : {}
@label = @options[:label]
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.
41
42
43
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 41
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
57
58
59
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 57
def accelerator
@accelerator
end
|
#accelerator=(value) ⇒ Object
49
50
51
52
53
54
55
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 49
def accelerator=(value)
@accelerator = value
(accelerator: value)
root_parent_proxy.bind(accelerator_event) do |event|
@command_block&.call(event)
end
end
|
#accelerator_event ⇒ Object
61
62
63
64
65
66
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 61
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
176
177
178
179
180
|
# 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
if attribute_value_hash.keys.first.to_s == 'label'
@parent_proxy.tk.entryconfigure @last_label, attribute_value_hash
self.value = variable.value = attribute_value_hash.values.first if variable.value == @last_label
else
@parent_proxy.tk.entryconfigure label, attribute_value_hash
end
end
end
|
#get_attribute(attribute) ⇒ Object
196
197
198
199
200
201
202
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 196
def get_attribute(attribute)
if has_attributes_attribute?(attribute)
@parent_proxy.tk.entrycget label, attribute
else
super
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
|
#has_attributes_attribute?(attribute) ⇒ Boolean
182
183
184
185
186
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 182
def has_attributes_attribute?(attribute)
attribute = attribute.to_s
attribute = attribute.sub(/\?$/, '').sub(/=$/, '')
ATTRIBUTES.include?(attribute)
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
@label
end
|
#label=(value) ⇒ Object
68
69
70
71
72
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 68
def label=(value)
@last_label = @label
@label = value
(label: @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
self.value = variable.value = label
elsif checkbutton?
self.value = 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
|
#set_attribute(attribute, value) ⇒ Object
188
189
190
191
192
193
194
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 188
def set_attribute(attribute, value)
if has_attributes_attribute?(attribute)
(attribute => value)
else
super
end
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
|