Class: Bowline::Desktop::WindowManager

Inherits:
Object
  • Object
show all
Extended by:
Bridge::ClassMethods, Watcher::Base
Defined in:
lib/bowline/desktop/window_manager.rb

Overview

This class provides a useful abstraction on the Window class. It’s the usual way of interfacing with your application’s windows, and all of Bowline’s windows normally inherit from it.

You’ll need to call the setup! method, before calling using this class. If the window is deallocated (i.e. closed), you’ll need to call it again. It’s worth not calling the setup method before you need it, since it’ll increase the amount of CPU your application uses.

By default, windows are hidden. You’ll need to show your custom windows explicitly before any user interaction using the show method. You can still load HTML/JavaScript while the window is hidden.

If you don’t want to show the window until it’s properly loaded, you can use this pattern:

MyWindow.on_load { MyWindow.show }
MyWindow.file = :test

Any undefined methods are delegated to the Window class. See that class for the full windowing API.

Class Method Summary collapse

Methods included from Bridge::ClassMethods

js_expose

Methods included from Watcher::Base

extended, included, watcher

Class Method Details

.allocated?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/bowline/desktop/window_manager.rb', line 51

def allocated?
  !deallocated?
end

.allocated_windowsObject

An array of all the application’s allocated windows



41
42
43
# File 'lib/bowline/desktop/window_manager.rb', line 41

def allocated_windows
  windows.select(&:allocated?)
end

.bowlineObject



97
98
99
# File 'lib/bowline/desktop/window_manager.rb', line 97

def bowline
  page.Bowline
end

.deallocated?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/bowline/desktop/window_manager.rb', line 55

def deallocated?
  !@window || @window.deallocated?
end

.eval(*args, &block) ⇒ Object

Evaluate JavaScript in this window. Pass a block to capture the result. Example:

eval("Bowline.msgs") {|res| puts res }


83
84
85
# File 'lib/bowline/desktop/window_manager.rb', line 83

def eval(*args, &block)
  JS.eval(window, *args, &block)
end

.loaded!Object

:singleton-method: on_load(method = nil, &block) A Watcher event method that gets called when this window loads. Example:

on_load { puts "Window loaded!" }


114
115
116
117
118
# File 'lib/bowline/desktop/window_manager.rb', line 114

def loaded! # :nodoc:
  @loaded = true
  watcher.call(:on_load)
  true
end

.loaded?Boolean

Returns true if the both the HTML and JavaScript in this window have loaded. Use the on_load event to know when this window has loaded.

Returns:

  • (Boolean)


104
105
106
# File 'lib/bowline/desktop/window_manager.rb', line 104

def loaded?
  @loaded
end

.method_missing(sym, *args) ⇒ Object

Delegate most methods to Window



121
122
123
124
125
126
127
# File 'lib/bowline/desktop/window_manager.rb', line 121

def method_missing(sym, *args) #:nodoc:
  if window && window.respond_to?(sym)
    return window.send(sym, *args)
  end
  # Window won't be around if Bowline::Desktop isn't enabled
  Bowline::Desktop.enabled? ? super : nil
end

.pageObject

Window Proxy instance. Use this to evaluate JavaScript in this window, but in an object orientated way. Example:

page.yourFunc.call

See Bowline::Desktop::Proxy for full usage.



93
94
95
# File 'lib/bowline/desktop/window_manager.rb', line 93

def page
  Proxy.new(self)
end

.setup!Object

Call this method to allocate a new window. You’ll need to do this before using it, or after it has been closed.



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/bowline/desktop/window_manager.rb', line 62

def setup!
  return unless Desktop.enabled?
  return if allocated?
  if self.name == "MainWindow"
    @window = MainWindow.get
  else
    @window = Window.new
  end
  # Has to be an instance variable since
  # it is getting GCed (even if I mark it).
  @script_callback = Proc.new {|str|
    Bowline::Desktop::Bridge.call(self, str)
  }
  @window.script_callback = @script_callback
  true
end

.shown_windowsObject

An array of all the application’s windows that are currently shown



36
37
38
# File 'lib/bowline/desktop/window_manager.rb', line 36

def shown_windows
  windows.select(&:shown?)
end

.windowObject

Methods for subclasses:



47
48
49
# File 'lib/bowline/desktop/window_manager.rb', line 47

def window #:nodoc:
  @window
end

.windowsObject

An array of all the application’s windows



31
32
33
# File 'lib/bowline/desktop/window_manager.rb', line 31

def windows
  Bowline::Desktop::WindowManager.subclasses.map(&:constantize)
end