Class: Glimmer::Tk::RootProxy

Inherits:
ToplevelProxy show all
Defined in:
lib/glimmer/tk/root_proxy.rb

Overview

Proxy for TkRoot

Follows the Proxy Design Pattern

Constant Summary

Constants inherited from ToplevelProxy

ToplevelProxy::DEFAULT_HEIGHT, ToplevelProxy::DEFAULT_WIDTH, ToplevelProxy::REGEX_GEOMETRY

Constants inherited from WidgetProxy

WidgetProxy::FONTS_PREDEFINED, WidgetProxy::HEXADECIMAL_CHARACTERS

Instance Attribute Summary

Attributes inherited from ToplevelProxy

#centered, #escapable, #modal, #tk

Attributes inherited from WidgetProxy

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

Attributes included from DraggableAndDroppable

#on_drag_motion_block

Instance Method Summary collapse

Methods inherited from ToplevelProxy

#center_within_root, #center_within_screen, #closest_window, #get_attribute, #has_attribute?, #height, #height=, #icon_photo, #set_attribute, #width, #width=, #window?, #x, #x=, #y, #y=

Methods inherited from WidgetProxy

#add_observer, #ancestor_proxies, #apply_style, #attribute_argument_normalizers, #attribute_setter, #clear_children, create, #destroy, #disabled, #disabled=, #enabled, #enabled=, #event_generate, #font=, #get_attribute, #grid, #has_attribute?, #has_attributes_attribute?, #has_state?, #hidden, #hidden=, #image_argument, #inspect, #method_missing, #normalize_attribute_arguments, #on, #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, #visible, #visible=, #widget_attribute_listener_installers, #widget_custom_attribute_mapping, widget_exists?, widget_proxy_class, #window?

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

#initialize(*args, &block) ⇒ RootProxy

Returns a new instance of RootProxy.



30
31
32
33
34
35
# File 'lib/glimmer/tk/root_proxy.rb', line 30

def initialize(*args, &block)
  @tk = ::TkRoot.new.tap {|tk| tk.singleton_class.include(Glimmer::Tk::Widget); tk.proxy = self}
  @tk.minsize = DEFAULT_WIDTH, DEFAULT_HEIGHT
  initialize_defaults
  post_add_content if block.nil?
end

Dynamic Method Handling

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

Instance Method Details

#content(&block) ⇒ Object



46
47
48
# File 'lib/glimmer/tk/root_proxy.rb', line 46

def content(&block)
  Glimmer::DSL::Engine.add_content(self, Glimmer::DSL::Tk::RootExpression.new, keyword, *args, &block)
end

#handle_listener(listener_name, &listener) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/glimmer/tk/root_proxy.rb', line 50

def handle_listener(listener_name, &listener)
  case listener_name.to_s.upcase
  when 'WM_OPEN_WINDOW', 'OPEN_WINDOW'
    @on_open_window_procs ||= []
    @on_open_window_procs << listener
  else
    super
  end
end

#openObject



42
43
44
# File 'lib/glimmer/tk/root_proxy.rb', line 42

def open
  start_event_loop
end

#post_add_contentObject



37
38
39
40
# File 'lib/glimmer/tk/root_proxy.rb', line 37

def post_add_content
  set_attribute('iconphoto', File.expand_path('../../../icons/glimmer.png', __dir__)) if @tk.iconphoto.nil?
  super
end

#start_event_loopObject

Starts Tk mainloop



61
62
63
64
65
66
67
68
69
70
# File 'lib/glimmer/tk/root_proxy.rb', line 61

def start_event_loop
  if @on_open_window_procs.to_a.any?
    ::Tk.after(100) do # ensure root window showed up first
      @on_open_window_procs.to_a.each do |on_open_window|
        ::Tk.after(0, on_open_window)
      end
    end
  end
  ::Tk.mainloop
end