Class: Glimmer::Tk::ToplevelProxy

Inherits:
WidgetProxy show all
Defined in:
lib/glimmer/tk/toplevel_proxy.rb

Overview

Proxy for TkToplevel

Follows the Proxy Design Pattern

Direct Known Subclasses

RootProxy

Constant Summary collapse

REGEX_GEOMETRY =
/[x+-]/
DEFAULT_WIDTH =
190
DEFAULT_HEIGHT =
95

Constants inherited from WidgetProxy

WidgetProxy::FONTS_PREDEFINED

Instance Attribute Summary collapse

Attributes inherited from WidgetProxy

#args, #bind_ids, #children, #destroyed, #keyword, #parent_proxy

Attributes included from DraggableAndDroppable

#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_attributes_attribute?, #has_state?, #image_argument, #initialize, #inspect, #method_missing, #on, #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

Methods included from DraggableAndDroppable

#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

This class inherits a constructor from Glimmer::Tk::WidgetProxy

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Glimmer::Tk::WidgetProxy

Instance Attribute Details

#escapableObject Also known as: escapable?

Returns the value of attribute escapable.



35
36
37
# File 'lib/glimmer/tk/toplevel_proxy.rb', line 35

def escapable
  @escapable
end

#tkObject (readonly)

Returns the value of attribute tk.



34
35
36
# File 'lib/glimmer/tk/toplevel_proxy.rb', line 34

def tk
  @tk
end

Instance Method Details

#handle_listener(listener_name, &listener) ⇒ Object



103
104
105
106
107
108
109
110
111
# File 'lib/glimmer/tk/toplevel_proxy.rb', line 103

def handle_listener(listener_name, &listener)
  case listener_name.to_s.upcase
  when 'WM_DELETE_WINDOW', 'DELETE_WINDOW'
    listener_name = 'WM_DELETE_WINDOW'
    @tk.protocol(listener_name, &listener)
  else
    super
  end
end

#has_attribute?(attribute, *args) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/glimmer/tk/toplevel_proxy.rb', line 49

def has_attribute?(attribute, *args)
  %w[width height x y].include?(attribute.to_s) || super
end

#heightObject



73
74
75
# File 'lib/glimmer/tk/toplevel_proxy.rb', line 73

def height
  geometry.split(REGEX_GEOMETRY)[1].to_i
end

#height=(value) ⇒ Object



90
91
92
93
# File 'lib/glimmer/tk/toplevel_proxy.rb', line 90

def height=(value)
  @height = value.to_i
  self.geometry = "#{@width || DEFAULT_WIDTH}x#{value.to_i}#{x_sign}#{abs_x}#{y_sign}#{abs_y}"
end

#post_add_contentObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/glimmer/tk/toplevel_proxy.rb', line 38

def post_add_content
  if escapable?
     on('KeyPress') do |event|
      if event.keysym == 'Escape'
        grab_release
        destroy
      end
    end
  end
end

#set_attribute(attribute, *args) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/glimmer/tk/toplevel_proxy.rb', line 53

def set_attribute(attribute, *args)
  case attribute.to_s
  when 'iconphoto'
    args[0..-1] = [image_argument(args)]
    super
  when 'resizable'
    if args.size == 1 && !args.first.is_a?(Array)
      self.resizable = [args.first]*2
    else
      super
    end
  else
    super
  end
end

#widthObject



69
70
71
# File 'lib/glimmer/tk/toplevel_proxy.rb', line 69

def width
  geometry.split(REGEX_GEOMETRY)[0].to_i
end

#width=(value) ⇒ Object



85
86
87
88
# File 'lib/glimmer/tk/toplevel_proxy.rb', line 85

def width=(value)
  @width = value.to_i
  self.geometry = "#{value.to_i}x#{@height || DEFAULT_HEIGHT}#{x_sign}#{abs_x}#{y_sign}#{abs_y}"
end

#xObject



77
78
79
# File 'lib/glimmer/tk/toplevel_proxy.rb', line 77

def x
  sign_number(x_sign, geometry.split(REGEX_GEOMETRY)[2].to_i)
end

#x=(value) ⇒ Object



95
96
97
# File 'lib/glimmer/tk/toplevel_proxy.rb', line 95

def x=(value)
  self.geometry = "#{@width || DEFAULT_WIDTH}x#{@height || DEFAULT_HEIGHT}#{value.to_i > 0 ? '+' : '-'}#{value.to_i.abs}#{y_sign}#{abs_y}"
end

#yObject



81
82
83
# File 'lib/glimmer/tk/toplevel_proxy.rb', line 81

def y
  sign_number(y_sign, geometry.split(REGEX_GEOMETRY)[3].to_i)
end

#y=(value) ⇒ Object



99
100
101
# File 'lib/glimmer/tk/toplevel_proxy.rb', line 99

def y=(value)
  self.geometry = "#{@width || DEFAULT_WIDTH}x#{@height || DEFAULT_HEIGHT}#{x_sign}#{abs_x}#{value.to_i > 0 ? '+' : '-'}#{value.to_i.abs}"
end