Class: Scarpe::Webview::App
- Inherits:
-
Drawable
- Object
- Shoes::Linkable
- Drawable
- Scarpe::Webview::App
- Defined in:
- lib/scarpe/wv/app.rb
Overview
Scarpe::Webview::App must only be used from the main thread, due to GTK+ limitations.
Constant Summary
Constants included from Shoes::Log
Shoes::Log::DEFAULT_COMPONENT, Shoes::Log::DEFAULT_DEBUG_LOG_CONFIG, Shoes::Log::DEFAULT_LOG_CONFIG
Instance Attribute Summary collapse
-
#control_interface ⇒ Object
readonly
App inherits from Drawable to set up linkable IDs and event methods.
-
#document_root ⇒ Object
writeonly
Sets the attribute document_root.
-
#shoes_linkable_id ⇒ Object
writeonly
Sets the attribute shoes_linkable_id.
Attributes inherited from Drawable
#children, #parent, #shoes_linkable_id
Attributes inherited from Shoes::Linkable
Instance Method Summary collapse
-
#bind(name, &block) ⇒ Object
Bind a Scarpe callback name; see handle_callback above.
- #destroy ⇒ Object
-
#handle_callback(name, *args) ⇒ Object
All JS callbacks to Scarpe drawables are dispatched via this handler.
- #init ⇒ Object
-
#initialize(properties) ⇒ App
constructor
A new instance of App.
-
#request_redraw! ⇒ void
Request a full redraw if Webview is running.
- #run ⇒ Object
Methods inherited from Drawable
#add_child, #destroy_self, display_class_for, #full_window_redraw!, #handler_js_code, #html_element, #html_id, #inspect, #needs_update!, #promise_update, #properties_changed, #remove_child, #set_parent, #shoes_styles, #to_html
Methods included from Shoes::Log
configure_logger, #log_init, logger
Methods inherited from Shoes::Linkable
#bind_shoes_event, #send_self_event, #send_shoes_event, #unsub_all_shoes_events, #unsub_shoes_event
Constructor Details
#initialize(properties) ⇒ App
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/scarpe/wv/app.rb', line 10 def initialize(properties) super # Scarpe's ControlInterface sets up event handlers # for the display service that aren't sent to # Lacci (Shoes). In general it's used for setup # and additional control or testing, outside the # Shoes app. This is how CatsCradle and Shoes-Spec # set up testing, for instance. @control_interface = ControlInterface.new # TODO: rename @view @view = Scarpe::Webview::WebWrangler.new title: @title, width: @width, height: @height, resizable: @resizable @callbacks = {} # The control interface has to exist to get callbacks like "override Scarpe app opts". # But the Scarpe App needs those options to be created. So we can't pass these to # ControlInterface.new. @control_interface.set_system_components app: self, doc_root: nil, wrangler: @view bind_shoes_event(event_name: "init") { init } bind_shoes_event(event_name: "run") { run } bind_shoes_event(event_name: "destroy") { destroy } end |
Instance Attribute Details
#control_interface ⇒ Object (readonly)
App inherits from Drawable to set up linkable IDs and event methods
6 7 8 |
# File 'lib/scarpe/wv/app.rb', line 6 def control_interface @control_interface end |
#document_root=(value) ⇒ Object (writeonly)
Sets the attribute document_root
39 40 41 |
# File 'lib/scarpe/wv/app.rb', line 39 def document_root=(value) @document_root = value end |
#shoes_linkable_id=(value) ⇒ Object (writeonly)
Sets the attribute shoes_linkable_id
8 9 10 |
# File 'lib/scarpe/wv/app.rb', line 8 def shoes_linkable_id=(value) @shoes_linkable_id = value end |
Instance Method Details
#bind(name, &block) ⇒ Object
Bind a Scarpe callback name; see handle_callback above. See Scarpe::Drawable for how the naming is set up
92 93 94 |
# File 'lib/scarpe/wv/app.rb', line 92 def bind(name, &block) @callbacks[name] = block end |
#destroy ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/scarpe/wv/app.rb', line 69 def destroy if @document_root || @view @control_interface.dispatch_event :shutdown end @document_root = nil if @view @view.destroy @view = nil end end |
#handle_callback(name, *args) ⇒ Object
All JS callbacks to Scarpe drawables are dispatched via this handler
82 83 84 85 86 87 88 |
# File 'lib/scarpe/wv/app.rb', line 82 def handle_callback(name, *args) if @callbacks.key?(name) @callbacks[name].call(*args) else raise Scarpe::UnknownEventTypeError, "No such Webview callback: #{name.inspect}!" end end |
#init ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/scarpe/wv/app.rb', line 41 def init scarpe_app = self @view.init_code("scarpeInit") do request_redraw! end @view.bind("scarpeHandler") do |*args| handle_callback(*args) end @view.bind("scarpeExit") do scarpe_app.destroy end end |
#request_redraw! ⇒ void
This method returns an undefined value.
Request a full redraw if Webview is running. Otherwise this is a no-op.
100 101 102 103 104 105 106 |
# File 'lib/scarpe/wv/app.rb', line 100 def request_redraw! wrangler = DisplayService.instance.wrangler if wrangler.is_running wrangler.replace(@document_root.to_html) end nil end |
#run ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/scarpe/wv/app.rb', line 57 def run # This is run before the Webview event loop is up and running @control_interface.dispatch_event(:init) @view.empty_page = empty_page_element # This takes control of the main thread and never returns. And it *must* be run from # the main thread. And it stops any Ruby background threads. # That's totally cool and normal, right? @view.run end |