Class: Scarpe::WebviewApp
- Inherits:
-
WebviewWidget
- Object
- Shoes::Linkable
- WebviewWidget
- Scarpe::WebviewApp
- Defined in:
- lib/scarpe/wv/app.rb
Overview
Scarpe::WebviewApp 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
Returns the value of attribute control_interface.
-
#document_root ⇒ Object
writeonly
Sets the attribute document_root.
-
#shoes_linkable_id ⇒ Object
writeonly
Sets the attribute shoes_linkable_id.
Attributes inherited from WebviewWidget
#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 widgets are dispatched via this handler.
- #init ⇒ Object
-
#initialize(properties) ⇒ WebviewApp
constructor
A new instance of WebviewApp.
-
#request_redraw! ⇒ void
Request a full redraw if Webview is running.
- #run ⇒ Object
Methods inherited from WebviewWidget
#add_child, #destroy_self, display_class_for, #handler_js_code, #html_element, #html_id, #inspect, #needs_update!, #promise_update, #properties_changed, #remove_child, #rgb_to_hex, #set_parent, #style, #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_shoes_event
Constructor Details
#initialize(properties) ⇒ WebviewApp
Returns a new instance of WebviewApp.
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 38 39 40 41 42 43 |
# File 'lib/scarpe/wv/app.rb', line 10 def initialize(properties) super # It's possible to provide a Ruby script by setting # SCARPE_TEST_CONTROL to its file path. This can # allow pre-setting test options or otherwise # performing additional actions not written into # the Shoes app itself. # # The control interface is what lets these files see # events, specify overrides and so on. @control_interface = ControlInterface.new if ENV["SCARPE_TEST_CONTROL"] require "scarpe/components/unit_test_helpers" @control_interface.instance_eval File.read(ENV["SCARPE_TEST_CONTROL"]) end # TODO: rename @view @view = Scarpe::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)
Returns the value of attribute control_interface.
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
45 46 47 |
# File 'lib/scarpe/wv/app.rb', line 45 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::Widget for how the naming is set up
91 92 93 |
# File 'lib/scarpe/wv/app.rb', line 91 def bind(name, &block) @callbacks[name] = block end |
#destroy ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/scarpe/wv/app.rb', line 72 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 widgets are dispatched via this handler
85 86 87 |
# File 'lib/scarpe/wv/app.rb', line 85 def handle_callback(name, *args) @callbacks[name].call(*args) end |
#init ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/scarpe/wv/app.rb', line 47 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.
99 100 101 102 103 104 105 |
# File 'lib/scarpe/wv/app.rb', line 99 def request_redraw! wrangler = WebviewDisplayService.instance.wrangler if wrangler.is_running wrangler.replace(@document_root.to_html) end nil end |
#run ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/scarpe/wv/app.rb', line 63 def run @control_interface.dispatch_event(:init) # 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 |