Author: bugman Date: Thu Aug 4 12:12:24 2011 New Revision: 14113 URL: http://svn.gna.org/viewcvs/relax?rev=14113&view=rev Log: Shifted the file opening code of the relax_manual() method to the misc.open_file() function. This code is general for opening any type of file, so has been abstracted. Modified: branches/gui_testing/gui/misc.py branches/gui_testing/gui/relax_gui.py Modified: branches/gui_testing/gui/misc.py URL: http://svn.gna.org/viewcvs/relax/branches/gui_testing/gui/misc.py?rev=14113&r1=14112&r2=14113&view=diff ============================================================================== --- branches/gui_testing/gui/misc.py (original) +++ branches/gui_testing/gui/misc.py Thu Aug 4 12:12:24 2011 @@ -26,6 +26,8 @@ # Python module imports. from math import pow +import os +import platform from string import split import wx @@ -319,6 +321,26 @@ return unicode(list) +def open_file(file): + """Open the file in the platform's native editor/viewer. + + @param file: The path of the file to open. + @type file: str + """ + + # Windows. + if platform.uname()[0] in ['Windows', 'Microsoft']: + os.startfile(file) + + # Mac OS X. + elif platform.uname()[0] == 'Darwin': + os.system('open %s' % file) + + # POSIX Systems with xdg-open. + else: + os.system('/usr/bin/xdg-open %s' % file) + + def protected_exec(fn, *args, **kargs): """Apply the given function, catching all RelaxErrors. Modified: branches/gui_testing/gui/relax_gui.py URL: http://svn.gna.org/viewcvs/relax/branches/gui_testing/gui/relax_gui.py?rev=14113&r1=14112&r2=14113&view=diff ============================================================================== --- branches/gui_testing/gui/relax_gui.py (original) +++ branches/gui_testing/gui/relax_gui.py Thu Aug 4 12:12:24 2011 @@ -341,20 +341,10 @@ # Test if it exists. if not access(file, F_OK): error_message("The relax manual '%s' cannot be found. Please compile using the scons program." % file) + return # Open the relax PDF manual using the native PDF reader. - else: - # Windows. - if platform.uname()[0] in ['Windows', 'Microsoft']: - os.startfile(file) - - # Mac OS X. - elif platform.uname()[0] == 'Darwin': - os.system('open %s' % file) - - # POSIX Systems with xdg-open. - else: - os.system('/usr/bin/xdg-open %s' % file) + open_file(file) def show_controller(self, event):