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, WidgetProxy::HEXADECIMAL_CHARACTERS
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_argument_normalizers, #attribute_setter, #clear_children, #content, create, #destroy, #disabled, #disabled=, #enabled, #enabled=, #event_generate, #font=, #grid, #has_attribute?, #has_state?, #hidden, #hidden=, #image_argument, #inspect, #method_missing, #normalize_attribute_arguments, #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, #visible, #visible=, #widget_attribute_listener_installers, #widget_custom_attribute_mapping, widget_exists?, widget_proxy_class, #window?
#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
48
|
# 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]
@label ||= 'About' if args.first == :about
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
134
135
136
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 134
def about?
@args.first == :about
end
|
#accelerator ⇒ Object
58
59
60
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 58
def accelerator
@accelerator
end
|
#accelerator=(value) ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 50
def accelerator=(value)
@accelerator = value
(accelerator: value)
root_parent_proxy.bind(accelerator_event) do |event|
@command_block&.call(event)
end
end
|
#accelerator_event ⇒ Object
62
63
64
65
66
67
68
69
70
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 62
def accelerator_event
accelerator_parts = @accelerator.split('+')
accelerator_parts.map do |accelerator_part|
ACCELERATOR_MODIFIER_EVENT_MAP[accelerator_part.capitalize] ||
(accelerator_part.size == 1 && accelerator_part.downcase) ||
(function_key?(accelerator_part) && accelerator_part.upcase) ||
accelerator_part
end.join('-')
end
|
126
127
128
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 126
def checkbutton?
@args.first == :radiobutton
end
|
#command? ⇒ Boolean
118
119
120
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 118
def command?
@args.first.nil? || @args.first == :command || @args.first.is_a?(Hash)
end
|
#command_block=(proc) ⇒ Object
104
105
106
107
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 104
def command_block=(proc)
@command_block = proc
(command: @command_block)
end
|
#compound ⇒ Object
100
101
102
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 100
def compound
@compound
end
|
#compound=(value) ⇒ Object
95
96
97
98
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 95
def compound=(value)
@compound = value
(compound: @compound)
end
|
configures menu item attribute through parent menu
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 173
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
|
#function_key?(string) ⇒ Boolean
72
73
74
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 72
def function_key?(string)
string.downcase.match(/^f\d+$/)
end
|
#get_attribute(attribute) ⇒ Object
204
205
206
207
208
209
210
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 204
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
109
110
111
112
113
114
115
116
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 109
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
190
191
192
193
194
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 190
def has_attributes_attribute?(attribute)
attribute = attribute.to_s
attribute = attribute.sub(/\?$/, '').sub(/=$/, '')
ATTRIBUTES.include?(attribute)
end
|
#help? ⇒ Boolean
142
143
144
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 142
def help?
@args.first == :help
end
|
#image ⇒ Object
91
92
93
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 91
def image
@image
end
|
#image=(*args) ⇒ Object
86
87
88
89
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 86
def image=(*args)
@image = image_argument(args)
(image: @image)
end
|
#label ⇒ Object
82
83
84
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 82
def label
@label
end
|
#label=(value) ⇒ Object
76
77
78
79
80
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 76
def label=(value)
@last_label = @label
@label = value
(label: @label)
end
|
#preferences? ⇒ Boolean
138
139
140
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 138
def preferences?
@args.first == :preferences
end
|
#quit? ⇒ Boolean
146
147
148
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 146
def quit?
@args.first == :quit
end
|
122
123
124
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 122
def radiobutton?
@args.first == :radiobutton
end
|
#selection ⇒ Object
168
169
170
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 168
def selection
variable.value == label
end
|
#selection=(value) ⇒ Object
160
161
162
163
164
165
166
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 160
def selection=(value)
if value
self.value = variable.value = label
elsif checkbutton?
self.value = variable.value = ''
end
end
|
#separator? ⇒ Boolean
130
131
132
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 130
def separator?
@args.first == :separator
end
|
#set_attribute(attribute, value) ⇒ Object
196
197
198
199
200
201
202
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 196
def set_attribute(attribute, value)
if has_attributes_attribute?(attribute)
(attribute => value)
else
super
end
end
|
#variable(auto_create: true) ⇒ Object
150
151
152
153
154
155
156
157
158
|
# File 'lib/glimmer/tk/menu_item_proxy.rb', line 150
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
|