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

#center_within_screenObject



116
117
118
119
120
121
122
123
124
125
# File 'lib/glimmer/tk/toplevel_proxy.rb', line 116

def center_within_screen
  monitor_width, monitor_height = wm_maxsize
  update :idletasks
  current_width = width
  current_height = height
  self.x = (winfo_screenwidth - width) / 2
  self.y = (winfo_screenheight - height) / 2
  self.width = width
  self.height = height
end

#handle_listener(listener_name, &listener) ⇒ Object



106
107
108
109
110
111
112
113
114
# File 'lib/glimmer/tk/toplevel_proxy.rb', line 106

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)


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

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

#heightObject



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

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

#height=(value) ⇒ Object



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

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
48
# File 'lib/glimmer/tk/toplevel_proxy.rb', line 38

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

#set_attribute(attribute, *args) ⇒ Object



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

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



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

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

#width=(value) ⇒ Object



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

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



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

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

#x=(value) ⇒ Object



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

def x=(value)
  @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



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

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

#y=(value) ⇒ Object



101
102
103
104
# File 'lib/glimmer/tk/toplevel_proxy.rb', line 101

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