Is it possible to open a browser window in Ruby Shoes?

别等时光非礼了梦想. 提交于 2019-12-11 07:16:13

问题


I'm wanting to build a GUI for a Ruby application I maintain using Shoes, but one of the things I'd like to do is be able to display network graphs using the D3 javascript library. After some Googling, I presume it's not possible to embed javascript in a Shoes app. Does anyone know if it's possible to open a browser window from a Shoes app, or better yet embed a browser window within a window in my Shoes app?


回答1:


Sure, you didn't mension the color of shoes so i'll use my favorite, green shoes

require 'green_shoes'

Shoes.app do
  gem 'watir'
  chrome_proc = Proc.new {
    require 'watir'
    browser = Watir::Browser.new :chrome
    browser.goto("http://www.google.com")
  }
  para link("Go to google", &chrome_proc)
end

Embedding a browser window.. I wish it could but i'd be suprised.. But you could use watir (html) as your gui all the way.

Here another way based on your comment, this is on windows but i'm sure you will know how to tranpose this to a Mac.

require 'green_shoes'

Shoes.app do
  proc = Proc.new {
    system('"C:\Users\Gebruiker\AppData\Local\Google\Chrome\Application\chrome.exe" http://www.google.be')
  }
  para link("Go to google", &proc)
end



回答2:


If you are on a Mac and just wish to open safari

You can write the following:

require 'uri'

Shoes.app do

  background "#EFC"
  border("#BE8",
         strokewidth: 6)

  stack(margin: 12) do
    para "Enter your name"
    flow do
      @value = edit_box
      button "OK", width: 200, height: 200 do 
        system("open -a safari https://www.biblegateway.com/passage/?search=" + URI::encode(@value.text))
      end 
    end
  end
end



来源:https://stackoverflow.com/questions/22431325/is-it-possible-to-open-a-browser-window-in-ruby-shoes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!