Class: SKUI::Window

Inherits:
Base
  • Object
show all
Includes:
ControlManager
Defined in:
src/SKUI/window.rb

Overview

Basic window class. Use this as the foundation for custom window types.

Since:

  • 1.0.0

Constant Summary collapse

THEME_DEFAULT =

Since:

  • 1.0.0

nil
THEME_GRAPHITE =

Since:

  • 1.0.0

File.join( PATH_CSS, 'theme_graphite.css' ).freeze

Instance Attribute Summary

Attributes included from ControlManager

#controls

Attributes inherited from Base

#properties, #window

Instance Method Summary collapse

Methods included from ControlManager

#add_control, #find_control_by_name, #find_control_by_ui_id, #remove_control

Methods inherited from Base

#background_color, #font, #foreground_color, #inspect, #parent, #to_js, #typename, #ui_id

Methods included from Events

#add_event_handler, included, #release_events, #trigger_event

Constructor Details

#initialize(options = {}) ⇒ Window

Returns a new instance of Window.

Parameters:

  • options (Hash) (defaults to: {})

Since:

  • 1.0.0



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'src/SKUI/window.rb', line 53

def initialize( options = {} )
  super()

  defaults = {
    :title            => 'Untitled',

    :left             => 400,
    :top              => 250,
    :width            => 300,
    :height           => 200,

    :width_limit      => nil,
    :height_limit     => nil,

    :resizable        => false,
    :minimize         => false,
    :maximize         => false,

    :modal            => false,

    :preferences_key  => nil,

    :theme            => THEME_DEFAULT
  }
  active_options = defaults.merge( options )

  @options = active_options

  @properties[:theme] = @options[:theme]

  @scripts = []

  # Create a dummy WebDialog here in order for the Bridge to respond in a
  # more sensible manner other than being `nil`. The WebDialog is recreated
  # right before the window is displayed due to a SketchUp bug.
  # @see #show
  @webdialog = UI::WebDialog.new
  @bridge = Bridge.new( self, @webdialog )
end

Instance Method Details

#add_script(script_file) ⇒ Nil

Adds the given JavaScript. This allow custom solutions outside of SKUI’s Ruby class wrappers.

Returns:

  • (Nil)

Since:

  • 1.0.0



98
99
100
101
102
103
104
# File 'src/SKUI/window.rb', line 98

def add_script(script_file)
  unless File.exist?(script_file)
    raise ArgumentError, "File not found: #{script_file}"
  end
  @scripts << script_file
  nil
end

#bring_to_frontNil

Returns:

  • (Nil)

Since:

  • 1.0.0



141
142
143
# File 'src/SKUI/window.rb', line 141

def bring_to_front
  @webdialog.bring_to_front
end

#cancel_buttonString

Returns:

  • (String)

Since:

  • 1.0.0



18
# File 'src/SKUI/window.rb', line 18

prop( :cancel_button, &TypeCheck::BUTTON )

#client_sizeArray(Integer,Integer)

Returns an array with the width and height of the client area.

Returns:

  • (Array(Integer,Integer))

Since:

  • 1.0.0



110
111
112
# File 'src/SKUI/window.rb', line 110

def client_size
  @bridge.call( 'WebDialog.get_client_size' )
end

#client_size=(value) ⇒ Boolean

Adjusts the window so the client area fits the given width and height.

Parameters:

  • value (Array(Integer,Integer))

Returns:

  • (Boolean)

    Returns false if the size can’t be set.

Since:

  • 2.5.0



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'src/SKUI/window.rb', line 120

def client_size=( value )
  width, height = value
  unless @webdialog.visible?
    # (?) Queue up size for when dialog opens.
    return false
  end
  # (!) Cache size difference.
  @webdialog.set_size( width, height )
  client_width, client_height = client_size()
  adjust_width  = width  - client_width
  adjust_height = height - client_height
  unless adjust_width == 0 && adjust_height == 0
    new_width  = width  + adjust_width
    new_height = height + adjust_height
    @webdialog.set_size( new_width, new_height )
  end
  true
end

#closeNil

Returns:

  • (Nil)

Since:

  • 1.0.0



147
148
149
# File 'src/SKUI/window.rb', line 147

def close
  @webdialog.close
end

#default_buttonString

Returns:

  • (String)

Since:

  • 1.0.0



22
# File 'src/SKUI/window.rb', line 22

prop( :default_button, &TypeCheck::BUTTON )

#releaseNil

Returns:

  • (Nil)

See Also:

Since:

  • 1.0.0



154
155
156
157
158
159
160
161
162
163
# File 'src/SKUI/window.rb', line 154

def release
  @webdialog.close if @webdialog.visible?
  super
  @bridge.release
  @bridge = nil
  @options.clear
  @options = nil
  @webdialog = nil
  nil
end

#set_position(left, top) ⇒ Nil

Parameters:

  • left (Numeric)
  • top (Numeric)

Returns:

  • (Nil)

Since:

  • 1.0.0



171
172
173
# File 'src/SKUI/window.rb', line 171

def set_position( *args )
  @webdialog.set_position( *args )
end

#set_size(width, height) ⇒ Nil

Parameters:

  • width (Numeric)
  • height (Numeric)

Returns:

  • (Nil)

Since:

  • 1.0.0



181
182
183
# File 'src/SKUI/window.rb', line 181

def set_size( *args )
  @webdialog.set_size( *args )
end

#showObject

Since:

  • 1.0.0



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'src/SKUI/window.rb', line 186

def show
  if @webdialog.visible?
    @webdialog.bring_to_front
  else
    # Recreate WebDialog instance in order for last position and size to be
    # used. Otherwise old preferences would be used.
    @webdialog = init_webdialog( @options )
    @bridge.webdialog = @webdialog
    # OSX doesn't have modal WebDialogs. Instead a 'modal' WebDialog means
    # it'll stay on top of the SketchUp window - where as otherwist it'd
    # fall behind.
    if PLATFORM_IS_OSX
      # (!) Implement alternative for OSX modal windows.
      @webdialog.show_modal
    else
      if @options[:modal]
        @webdialog.show_modal
      else
        @webdialog.show
      end
    end
  end
end

#themeString

Returns:

  • (String)

Since:

  • 1.0.0



26
# File 'src/SKUI/window.rb', line 26

prop( :theme, &TypeCheck::STRING )

#titleString

Returns:

  • (String)

Since:

  • 1.0.0



212
213
214
# File 'src/SKUI/window.rb', line 212

def title
  @options[:title].dup
end

#toggleNil

Returns:

  • (Nil)

Since:

  • 1.0.0



218
219
220
221
222
223
224
# File 'src/SKUI/window.rb', line 218

def toggle
  if visible?
    close()
  else
    show()
  end
end

#visible?Boolean

Returns:

  • (Boolean)

Since:

  • 1.0.0



228
229
230
# File 'src/SKUI/window.rb', line 228

def visible?
  @webdialog.visible?
end

#write_image(image_path, top_left_x, top_left_y) ⇒ Nil

@param [String] image_path

@param [Numeric] top_left_x
@param [Numeric] top_left_y
@param [Numeric] bottom_right_x
@param [Numeric] bottom_right_y

bottom_right_x, bottom_right_y )

Returns:

  • (Nil)

Since:

  • 1.0.0



242
243
244
# File 'src/SKUI/window.rb', line 242

def write_image( *args )
  @webdialog.write_image( *args )
end