Tiny project to open quickstart.pdf from the help menu (feel free to help)

It would be nice if one could open the quickstart.pdf by using the Help menu as was mentioned on http://blenderartists.org/forum/showthread.php?t=91143 thread. I looked into this issue a bit. It seems that the simple solution, os.startfile, works only Windows as no one has written implementations for other systems.

As a workaround we could use os.system. I heard that os.system(“open filenamehere”) works on OSX. I have not been able to figure out how to do this on Linux yet. You can help in this regard. I got a hint that http://freedesktop.org/wiki/ might be helpful in that problem.

Python’s os module can be found at http://docs.python.org/lib/module-os.html in case you are interested on the mentioned functions. It would be possible to use webbrowser module to open the pdf file via the default web browser but that would be somewhat hackish.

So the problems to be solved are:
-Figure out how to check which OS the user has. It may be that there’s a ready solution for this. (We have to remember there are OSes beyond Windows, Linux and OSX too.)
-Figure out how to open pdf files on each OS. (Windows and OSX are ok so far.)
-Test the script well.
-Post it to the patch tracker.

FYI, on Win XP all of these work :


import os,webbrowser

 os.system("BlenderQuickStart.pdf")

os.startfile("BlenderQuickStart.pdf")

webbrowser.open(“file://f:/blender/BlenderQuickStart.pdf”)

But ;

import os

 os.system("open BlenderQuickStart.pdf")


generates an error “open is not recognized as an internal or external command”

The working commands above, actually launch whatever PDF program has been installed and associated with PDF files. So IMO webbrowser is no more “hacky” than the other two commands.

All of the commands depend on a pdf reader to be installed … (which most people probably have I guess).

But how is the python code going to be hooked to the help menu? Is a script going to have to be present in the text window? Or are the python functions going to be used within the program ?

Another suggestion :

Instead of trying to develop code to figure out what O.S. … how to launch the pdf reader …etc etc why not :

Have the startup (.b.blend) file have the quickstart info :

  1. Simplest solution … just have a .jpg capture of the PDF, and set it as the background image.

With the new image tools, if the user wants to load another background image, they can easily toggle back to the quickstart image using the “double arrows” in the background image dialog

Another neat idea would be to have something either in the G.E. or an animation (.blend file).

But the b.g. image in .b.blend seems to me to be the simplest idea.

Are there any python hooks to the background image functionality? … This could be an easy way to have “embedded” help or possibly context-sensitve help available… i.e. “giant” tooltips :slight_smile:

Mike

But how is the python code going to be hooked to the help menu? Is a script going to have to be present in the text window? Or are the python functions going to be used within the program ?

#!BPY
"""
Name: 'Manual'
Blender: 243
Group: 'Help'
Tooltip: 'Blender quickstart'
"""

__author__ = ""
__url__ = ("blender", "blenderartists")
__version__ = "1.0"
__bpydoc__ = """\
This script opens the quickstart file.
"""

# --------------------------------------------------------------------------
# Manual Help Menu Item
# --------------------------------------------------------------------------
# ***** BEGIN GPL LICENSE BLOCK *****
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#
# ***** END GPL LICENCE BLOCK *****
# --------------------------------------------------------------------------

#do stuff here

We can use that snippet as our basis. That’s the way it’s done in the other scripts. It automagically appears on the help menu due to the group setting.

The image idea is interesting. What if we provided a webpage that has the image in it instead? The we could use the webbrowser module. I looked into opening an image in Blender. It seems you can open an image to a datablock but I am not sure if you can feed it somehow to an image window. What do you think about opening the quickstart image to the webbrowser?

Ok I tried this on my Xp box with 2.43. :

The “os.system” call for some reason has a ~30-45 second delay before Adobe Acrobat actually gets launched, while the webbrowser and os.startfile calls both work pretty much instantly, so (on my system anyway), “os.system” doesn’t seem to be useable.

When I run the system method from a command line though using the python interpreter there is no delay. Weird. :eek:

#!BPY
"""
Name: 'QuickStart PDF (web/system/startfile)'
Blender: 243
Group: 'Help'
Tooltip: 'Blender quickstart'
"""

__author__ = ""
__url__ = ("blender", "blenderartists")
__version__ = "1.0"
__bpydoc__ = """\
This script opens the quickstart file.
"""

#### the 'stuff'  ###########

import Blender,os,webbrowser
from os import *
from webbrowser import *

##
##  this 'pdfDir' thing works with windows  "X:\Blender\  .....  probably won't with other OS's
##
###

homedir = Blender.Get('homedir')
pdfDir = homedir[:11]

pdf = pdfDir + "BlenderQuickStart.pdf"

###
###################3

#
#  only 1 of  the next 3 calls is neccesary.  All 3 are here for testing purposes, comment out the one you don't want.
#



##########  launch with system call ##################
#print 'BlenderQuickStart (system) PDF launch : attempting to launch Quickstart pdf from "'+pdf+'"'

#####     the launch command #####
# os.system(pdf)
###########

##########################################

##### launch with 'webbrowser' call ###############
print 'BlenderQuickStart (webbrowser) PDF launch : attempting to launch Quickstart pdf from "'+pdf+'"'



#####     the launch command #####
pdf = "file://" + pdfDir + "BlenderQuickStart.pdf"
webbrowser.open(pdf)
#####

##########################################

##### launch with 'startfile'  call ###############
#print 'BlenderQuickStart (openfile) PDF launch : attempting to launch Quickstart pdf from "'+pdf+'"'

#####     the launch command #####
# os.startfile(pdf)
####


Cool… is that group behavior actually documented anywhere ? :smiley:

I might start adding my own “non-help” often used scripts to the Help menu :slight_smile:

Actually it should be pretty easy (???) to just add a “User” Menu beside the help menu that utilizes the same “group hook” shouldn’t it?

While I was thinking of that, I had another “brilliant” brainstorm and just split my User Preferences vertically and put the Scripts window on the far left corner and shrunk the window down (moved the split over) so just the “Scripts” label/button is visible. It does cutoff the La:0 and Mem fields (what does La:0 mean ??? anyway). I think that would make a good default layout :slight_smile:

EDIT* Not so briliant for scripts that use a Gui :slight_smile: … The window needs to be maximized in order to see the gui

As I mentioned above, the webbrowser does open the pdf file (by launching the “system PDF” app (Abobe acrobat) on my (XP) system.

I also tried a test to launch a web page, that works too. I guess if that JPG were embedded in a web page, then it would be one less application (on Windows at least) being launched.

If you do a “chmod + x BlenderQuickStart.pdf” on Linux, and then trying to “launch” the pdf by just typing it’s name, does that work? If so, then after chmod’ing it, maybe the os.startfile(<filename>) or webbrowser.open(<filename>) variations will then work on the file.

I wonder if that’s even necessary on current Linux systems. I haven’t run Linux for a couple of years, so I don’t know how / if it uses “file associations”.

Mike

Cool… is that group behavior actually documented anywhere ?
I am not sure about this. You can learn a lot by just looking at existing scripts.

Actually it should be pretty easy (???) to just add a “User” Menu beside the help menu that utilizes the same “group hook” shouldn’t it?
That’s a nice idea. We have to poke Python guys about this. They might have even nicer plans.

what does La:0 mean ??? anyway
The amount of lamps on active layers. This reminds me that it might be nice if Blender would warn the user in case he tries to render without active lamps.

I tried executing pdf file as you told (chmod, ./file.pdf) but it does not seem to work on Linux.

What if the menu entry would just open the quickstart page (http://wiki.blender.org/index.php/QuickStart) on the wiki? This would be the simplest solution in my opinion. Though it would be nasty in case the user doesn’t have an internet connection.

Overall it would be better just to make a beginner friendly .b.blend with instructions to Quickstart and things like that. This might be a nice subject to talk about at the funboard. I recall that when I started blending a nice welcome to the program would have been nice.