WebDialog set_file
-
I think the problem is the API is not right (or explaining things the way they work.)
Sketchup.find_support_file and Sketchup.find_support_files do not return the same format.
One return a pathname with the Rubyish forward slash as file separator.
The other returns a Win32 like pathname with escaped backslashes, ie 'C:\Program Files\Google' etc.The example for WebDialog.set_file is showing:
dialog.set_file "c:\\mypage.html"
The only other thing I'd recommend is NOT using + to concat pathnames.
Use the Ruby function File.join whenever possible if forwardslash is to be the file separator. -
Excuse me for being a simpleton but why don't you just make the plugins folder the root; after all most people are used to extracting ruby things to the plugin folder.
-
@dan rathbun said:
I think the problem is the API is not right (or explaining things the way they work.)
Amen, brother.
From the console I conclude that the key is "C:".
File.dirname( ... )
does not return "C:". Absent the "C:"set_file()
can't find the file. Adding "C:" myself means there is 0% chance of working on a Mac. Therefore,find_support_file()
is a necessity to open an .HTML file in the same directory as the code. -
@chrisglasier said:
Excuse me for being a simpleton ...
I like simple. Simple is good.
I don't think
c:/Program Files/Google/Google SketchUp 7/Plugins/airshow
is simple. On my machine the airshow is/models/airshow
. I wanted your machine to have/yourchoice/airshow
.With a little Mac help, we may yet get there.
-
I'm not seeing that.
Test File: tt_file.rb
puts __FILE__.inspect puts File.dirname(__FILE__).inspect puts File.split(__FILE__).inspect
load 'tt_file.rb' "C:/Program Files (x86)/Google/Google SketchUp 7/Plugins/tt_file.rb" "C:/Program Files (x86)/Google/Google SketchUp 7/Plugins" ["C:/Program Files (x86)/Google/Google SketchUp 7/Plugins", "tt_file.rb"] true
-
I'm one who would have to disagree with your thoughts on simplicity here Martin. I can't stand things installing themselves into my c:\ root. I've come to appreciate the simplicity of knowing that all programs should be installed in the Program Files directory, instead of having to track them down in the root folder, among all the other non-program folders that already exist there.
-
But making your plugin work from wherever it's installed and anyone can install it wherever they may like.
-
That is ideal for sure!
-
@thomthom said:
I'm not seeing that.
Test File: tt_file.rb
> puts __FILE__.inspect > puts File.dirname(__FILE__).inspect > puts File.split(__FILE__).inspect >
load 'tt_file.rb' "C:/Program Files (x86)/Google/Google SketchUp 7/Plugins/tt_file.rb" "C:/Program Files (x86)/Google/Google SketchUp 7/Plugins" ["C:/Program Files (x86)/Google/Google SketchUp 7/Plugins", "tt_file.rb"] true
Now we're getting someplace! This is what I see:
(When you have to use screen shots to rule out the use of hallucinogenic drugs, you know you've got a problem.) "Tell me what's goin' on - I ain't got a clue!" J. Buffett
-
@chris fullmer said:
... I can't stand things installing themselves into my c:\ root. I've come to appreciate the simplicity of knowing that all programs should be installed in the Program Files directory, ...
I am sure of fewer and fewer things as I get older. Some because I forget, others because I question old certainties. But one thing I hold true:
Where you put stuff on your computer should always be your choice, not mine.
-
Yup, as I stated above too, that is also what I prefer. I thought it looked like you were fixing to force installation to a fixed location with this.
-
File.dirname( File.expand_path(__FILE__) )
Seems that
__FILE__
didn't return an absolute path when you skipped the in your path -
@thomthom said:
Seems that
__FILE__
didn't return an absolute path when you skipped the in your pathBingo!
A few more experiments, a Mac answer and then maybe a sensible
set_file()
. Maybe I won't have to fire myself! -
One other idea is to use the File class to get the string from the file, and then use set_html.
-
@cjthompson said:
One other idea is to use the File class to get the string from the file, and then use set_html.
Then everything the HTML file links to will be relative to a random temp folder - which can cause problems unless you use absolute URIs for everything. Or include a
<base>
tag. -
Edited solution into original post. Zero reported problems from movie viewers, so maybe it works.
-
@dan rathbun said:
Found the problem on PC.
It's a boo-boo using the File.join method. An extra SEPARATOR is getting inserted at the beginning of the URL string, so that whatever the pathname, whether you use the optional relative path (2nd argument) or not, the resulting URL passed to the browser begins with:
file:///file:///
is a valid URI. http://en.wikipedia.org/wiki/File_URI_scheme#WindowsFirefox diplay local URIs like that. IE will open such URI and convert it into what you see in Windows Explorer. So odd that it'd be problems with the webdialog then.
-
ah.
.set_file
was passed the URI. now I see. -
@thomthom said:
ah.
.set_file
was passed the URI. now I see.No I thought
.set_file
was doing this:def set_file(filename, path='') %(#F0F0F0)[__]protocol='file://' %(#F0F0F0)[__]set_url( File.join(protocol,path,filename)) end
But Ruby's File.join is actually kinda smart. Google may have used their own dumb version that adds extra /s.
But I'm not sure:
my_dialog.set_file('C:/scite/WebDialogTips.html','')
Worksmy_dialog.set_file('C:/scite/WebDialogTips.html')
Worksmy_dialog.set_file('WebDialogTips.html','C:/scite')
Error ('Cannot Load Webpage' Error Webpage, but NOT MSIE Error dialog.)my_dialog.set_file('WebDialogTips.html','C:/scite/')
WorksEDIT NOTE: For this test, I copied file 'WebDialogTips.html' into 'C:/scite/' because the sciTE folder is in my System PATH (not my Ruby $LOAD_PATH.)
my_dialog.set_file('WebDialogTips.html','')
and
my_dialog.set_file('WebDialogTips.html')
both produce the MSIE Error Dialog, that says:
"Cannot find 'file:///WebDialogTips.html'. Make sure the path or Internet address is correct."So the Win System PATH makes no difference.
_ -
@thomthom said:
file:///
is a valid URI. http://en.wikipedia.org/wiki/File_URI_scheme#WindowsFirefox diplay local URIs like that. IE will open such URI and convert it into what you see in Windows Explorer. So odd that it'd be problems with the webdialog then.
Yes 3 slashes work if I paste it into the addressbar of a normal MSIE browser.
But for WebDialog, on PC (Win32),
wherepath=Sketchup.find_support_file('')
:my_dialog.set_url('file://localhost/'+path+'/Support/webpage.html')
Worksmy_dialog.set_url('file:///localhost/'+path+'/Support/webpage.html')
Errormy_dialog.set_url('file:////localhost/'+path+'/Support/webpage.html')
Worksmy_dialog.set_url('file://///localhost/'+path+'/Support/webpage.html')
Worksmy_dialog.set_url('file://////localhost/'+path+'/Support/webpage.html')
Worksmy_dialog.set_url('file://localhost//'+path+'/Support/webpage.html')
Worksmy_dialog.set_url('file:///localhost//'+path+'/Support/webpage.html')
Errormy_dialog.set_url('file:////localhost//'+path+'/Support/webpage.html')
Worksmy_dialog.set_url('file://///localhost//'+path+'/Support/webpage.html')
Worksmy_dialog.set_url('file://////localhost//'+path+'/Support/webpage.html')
WorksAny more than 6 /'s before localhost or 2 following, does not work for WebDialog.
Advertisement