Change the way we "launch" files using their default application. Instead of trying to find the application ourselves, use the OS built in functions to open a file with its default application. We no longer show the name of the application that we will open the file with because we don't know.

svn: r11781
This commit is contained in:
Brian Matherly 2009-02-01 04:21:17 +00:00
parent 6fccf8d75f
commit 3259b393da
18 changed files with 107 additions and 261 deletions

View File

@ -1356,15 +1356,15 @@ class BaseDoc:
self.paper = paper_style self.paper = paper_style
self._style_sheet = styles self._style_sheet = styles
self._creator = "" self._creator = ""
self.print_req = 0 self.open_req = 0
self.init_called = False self.init_called = False
self.type = "standard" self.type = "standard"
def init(self): def init(self):
self.init_called = True self.init_called = True
def print_requested(self): def open_requested(self):
self.print_req = 1 self.open_req = 1
def set_creator(self, name): def set_creator(self, name):
"Set the owner name" "Set the owner name"

View File

@ -55,7 +55,7 @@ import Utils
import Bookmarks import Bookmarks
import Mime import Mime
import gen.lib import gen.lib
from QuestionDialog import ErrorDialog
from Editors import EditMedia, DeleteMediaQuery from Editors import EditMedia, DeleteMediaQuery
import Errors import Errors
from Filters.SideBar import MediaSidebarFilter from Filters.SideBar import MediaSidebarFilter
@ -221,19 +221,12 @@ class MediaView(PageView.ListView):
def view_media(self, obj): def view_media(self, obj):
""" """
Launch external viewers based of mime types for the selected objects. Launch external viewers for the selected objects.
""" """
for handle in self.selected_handles(): for handle in self.selected_handles():
ref_obj = self.dbstate.db.get_object_from_handle(handle) ref_obj = self.dbstate.db.get_object_from_handle(handle)
mime_type = ref_obj.get_mime_type() mpath = Utils.media_path_full(self.dbstate.db, ref_obj.get_path())
app = Mime.get_application(mime_type) Utils.open_file_with_default_application(mpath)
if app:
Utils.launch(app[0], Utils.media_path_full(self.dbstate.db,
ref_obj.get_path()))
else:
ErrorDialog(_("Cannot view %s") % ref_obj.get_path(),
_("GRAMPS cannot find an application that can view "
"a file type of %s.") % mime_type)
def _column_editor(self, obj): def _column_editor(self, obj):
""" """

View File

@ -57,8 +57,8 @@ from DisplayTabs._ButtonTab import ButtonTab
# #
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def make_launcher(prog, path): def make_launcher(path):
return lambda x: Utils.launch(prog, path) return lambda x: Utils.open_file_with_default_application(path)
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -115,19 +115,15 @@ class GalleryTab(ButtonTab):
menu = gtk.Menu() menu = gtk.Menu()
ref_obj = self.dbstate.db.get_object_from_handle(obj.ref) ref_obj = self.dbstate.db.get_object_from_handle(obj.ref)
mime_type = ref_obj.get_mime_type() media_path = Utils.media_path_full(self.dbstate.db, ref_obj.get_path())
if mime_type: if media_path:
app = Mime.get_application(mime_type) item = gtk.MenuItem(_('View'))
if app: item.connect('activate', make_launcher(media_path))
item = gtk.MenuItem(_('Open with %s') % app[1]) item.show()
item.connect('activate', make_launcher(app[0], menu.append(item)
Utils.media_path_full(self.dbstate.db, item = gtk.SeparatorMenuItem()
ref_obj.get_path()))) item.show()
item.show() menu.append(item)
menu.append(item)
item = gtk.SeparatorMenuItem()
item.show()
menu.append(item)
for (needs_write_access, image, title, func) in itemlist: for (needs_write_access, image, title, func) in itemlist:
if image: if image:

View File

@ -206,11 +206,9 @@ class EditMedia(EditPrimary):
ref_obj = self.dbstate.db.get_object_from_handle(self.obj.handle) ref_obj = self.dbstate.db.get_object_from_handle(self.obj.handle)
if ref_obj: if ref_obj:
mime_type = ref_obj.get_mime_type() media_path = Utils.media_path_full(self.dbstate.db,
app = Mime.get_application(mime_type) ref_obj.get_path())
if app: Utils.open_file_with_default_application(media_path)
Utils.launch(app[0], Utils.media_path_full(self.dbstate.db,
ref_obj.get_path()))
def select_file(self, val): def select_file(self, val):
self.determine_mime() self.determine_mime()

View File

@ -44,7 +44,7 @@ import const
import Config import Config
import Mime import Mime
import ThumbNails import ThumbNails
from Utils import media_path_full import Utils
from gen.lib import NoteType from gen.lib import NoteType
from DisplayTabs import (SourceEmbedList, AttrEmbedList, MediaBackRefList, from DisplayTabs import (SourceEmbedList, AttrEmbedList, MediaBackRefList,
@ -102,7 +102,7 @@ class EditMediaRef(EditReference):
the path. the path.
""" """
self.mtype = self.source.get_mime_type() self.mtype = self.source.get_mime_type()
fullpath = media_path_full(self.db, self.source.get_path()) fullpath = Utils.media_path_full(self.db, self.source.get_path())
self.pix = ThumbNails.get_thumbnail_image(fullpath, self.pix = ThumbNails.get_thumbnail_image(fullpath,
self.mtype) self.mtype)
self.pixmap.set_from_pixbuf(self.pix) self.pixmap.set_from_pixbuf(self.pix)
@ -350,7 +350,7 @@ class EditMediaRef(EditReference):
self.subpixmap.hide() self.subpixmap.hide()
else: else:
try: try:
fullpath = media_path_full(self.db, path) fullpath = Utils.media_path_full(self.db, path)
pixbuf = gtk.gdk.pixbuf_new_from_file(fullpath) pixbuf = gtk.gdk.pixbuf_new_from_file(fullpath)
width = pixbuf.get_width() width = pixbuf.get_width()
height = pixbuf.get_height() height = pixbuf.get_height()
@ -389,7 +389,8 @@ class EditMediaRef(EditReference):
def button_press_event(self, obj, event): def button_press_event(self, obj, event):
if event.button==1 and event.type == gtk.gdk._2BUTTON_PRESS: if event.button==1 and event.type == gtk.gdk._2BUTTON_PRESS:
self.view_media(obj) photo_path = Utils.media_path_full(self.db, self.source.get_path())
Utils.open_file_with_default_application(photo_path)
def button_press_event_ref(self, widget, event): def button_press_event_ref(self, widget, event):
""" """
@ -489,13 +490,6 @@ class EditMediaRef(EditReference):
obj.update() obj.update()
self.draw_preview() self.draw_preview()
def view_media(self, obj):
mime_type = self.source.get_mime_type()
app = Mime.get_application(mime_type)
if app:
from Utils import launch
launch(app[0], media_path_full(self.db, self.source.get_path()))
def _connect_signals(self): def _connect_signals(self):
self.define_cancel_button(self.top.get_widget('button84')) self.define_cancel_button(self.top.get_widget('button84'))
self.define_ok_button(self.top.get_widget('button82'),self.save) self.define_ok_button(self.top.get_widget('button82'),self.save)

View File

@ -470,12 +470,8 @@ class EditPerson(EditPrimary):
menu = gtk.Menu() menu = gtk.Menu()
menu.set_title(_("Media Object")) menu.set_title(_("Media Object"))
obj = self.db.get_object_from_handle(photo.get_reference_handle()) obj = self.db.get_object_from_handle(photo.get_reference_handle())
mtype = obj.get_mime_type() if obj:
progname = Mime.get_application(mtype) Utils.add_menuitem(menu, _("View"), photo, self._popup_view_photo)
if progname and len(progname) > 1:
Utils.add_menuitem(menu, _("Open in %s") % progname[1],
photo, self._popup_view_photo)
Utils.add_menuitem(menu, _("Edit Object Properties"), photo, Utils.add_menuitem(menu, _("Edit Object Properties"), photo,
self._popup_change_description) self._popup_change_description)
menu.popup(None, None, None, event.button, event.time) menu.popup(None, None, None, event.button, event.time)
@ -488,8 +484,9 @@ class EditPerson(EditPrimary):
if media_list: if media_list:
photo = media_list[0] photo = media_list[0]
object_handle = photo.get_reference_handle() object_handle = photo.get_reference_handle()
Utils.view_photo(self.db.get_object_from_handle(object_handle), ref_obj = self.db.get_object_from_handle(object_handle)
self.db) photo_path = Utils.media_path_full(self.db, ref_obj.get_path())
Utils.open_file_with_default_application(photo_path)
def _popup_change_description(self, obj): def _popup_change_description(self, obj):
""" """

View File

@ -95,7 +95,7 @@ class DocReportDialog(ReportDialog):
self.options.set_document(self.doc) self.options.set_document(self.doc)
if self.print_report.get_active(): if self.print_report.get_active():
self.doc.print_requested() self.doc.open_requested()
def doc_type_changed(self, obj): def doc_type_changed(self, obj):
"""This routine is called when the user selects a new file """This routine is called when the user selects a new file
@ -110,7 +110,7 @@ class DocReportDialog(ReportDialog):
self.print_report.set_label (label) self.print_report.set_label (label)
self.print_report.set_sensitive (True) self.print_report.set_sensitive (True)
else: else:
self.print_report.set_label (_("Print a copy")) self.print_report.set_label (_("Open with default viewer"))
self.print_report.set_sensitive (False) self.print_report.set_sensitive (False)
# Is this to be a printed report or an electronic report # Is this to be a printed report or an electronic report

View File

@ -376,9 +376,8 @@ class GVDotDoc(GVDocBase):
dotfile.write(self._dot.getvalue()) dotfile.write(self._dot.getvalue())
dotfile.close() dotfile.close()
if self.print_req: if self.open_req:
app = Mime.get_application("text/x-graphviz") Utils.open_file_with_default_application(self._filename)
Utils.launch(app[0], self._filename)
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# #
@ -422,9 +421,8 @@ class GVPsDoc(GVDocBase):
# Delete the temporary dot file # Delete the temporary dot file
os.remove(tmp_dot) os.remove(tmp_dot)
if self.print_req: if self.open_req:
app = Mime.get_application("application/postscript") Utils.open_file_with_default_application(self._filename)
Utils.launch(app[0], self._filename)
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# #
@ -469,9 +467,8 @@ class GVSvgDoc(GVDocBase):
# Delete the temporary dot file # Delete the temporary dot file
os.remove(tmp_dot) os.remove(tmp_dot)
if self.print_req: if self.open_req:
app = Mime.get_application("image/svg") Utils.open_file_with_default_application(self._filename)
Utils.launch(app[0], self._filename)
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# #
@ -516,9 +513,8 @@ class GVSvgzDoc(GVDocBase):
# Delete the temporary dot file # Delete the temporary dot file
os.remove(tmp_dot) os.remove(tmp_dot)
if self.print_req: if self.open_req:
app = Mime.get_application("image/svgz") Utils.open_file_with_default_application(self._filename)
Utils.launch(app[0], self._filename)
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# #
@ -563,9 +559,8 @@ class GVPngDoc(GVDocBase):
# Delete the temporary dot file # Delete the temporary dot file
os.remove(tmp_dot) os.remove(tmp_dot)
if self.print_req: if self.open_req:
app = Mime.get_application("image/png") Utils.open_file_with_default_application(self._filename)
Utils.launch(app[0], self._filename)
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# #
@ -610,9 +605,8 @@ class GVJpegDoc(GVDocBase):
# Delete the temporary dot file # Delete the temporary dot file
os.remove(tmp_dot) os.remove(tmp_dot)
if self.print_req: if self.open_req:
app = Mime.get_application("image/jpeg") Utils.open_file_with_default_application(self._filename)
Utils.launch(app[0], self._filename)
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# #
@ -657,9 +651,8 @@ class GVGifDoc(GVDocBase):
# Delete the temporary dot file # Delete the temporary dot file
os.remove(tmp_dot) os.remove(tmp_dot)
if self.print_req: if self.open_req:
app = Mime.get_application("image/gif") Utils.open_file_with_default_application(self._filename)
Utils.launch(app[0], self._filename)
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# #
@ -707,9 +700,8 @@ class GVPdfGvDoc(GVDocBase):
# Delete the temporary dot file # Delete the temporary dot file
os.remove(tmp_dot) os.remove(tmp_dot)
if self.print_req: if self.open_req:
app = Mime.get_application("application/pdf") Utils.open_file_with_default_application(self._filename)
Utils.launch(app[0], self._filename)
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# #
@ -768,9 +760,8 @@ class GVPdfGsDoc(GVDocBase):
os.remove(tmp_ps) os.remove(tmp_ps)
os.remove(tmp_dot) os.remove(tmp_dot)
if self.print_req: if self.open_req:
app = Mime.get_application("application/pdf") Utils.open_file_with_default_application(self._filename)
Utils.launch(app[0], self._filename)
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# #
@ -1107,20 +1098,16 @@ class GraphvizReportDialog(ReportDialog):
ReportDialog.setup_report_options_frame(self) ReportDialog.setup_report_options_frame(self)
def doc_type_changed(self, obj): def doc_type_changed(self, obj):
"""This routine is called when the user selects a new file """
This routine is called when the user selects a new file
formats for the report. It adjust the various dialog sections formats for the report. It adjust the various dialog sections
to reflect the appropriate values for the currently selected to reflect the appropriate values for the currently selected
file format. For example, a HTML document doesn't need any file format. For example, a HTML document doesn't need any
paper size/orientation options, but it does need a template paper size/orientation options, but it does need a template
file. Those chances are made here.""" file. Those chances are made here.
"""
label = obj.get_printable() self.print_report.set_label (_("Open with default application"))
if label: self.print_report.set_sensitive(True)
self.print_report.set_label (label)
self.print_report.set_sensitive (True)
else:
self.print_report.set_label (_("Open with application"))
self.print_report.set_sensitive (False)
fname = self.target_fileentry.get_full_path(0) fname = self.target_fileentry.get_full_path(0)
(spath, ext) = os.path.splitext(fname) (spath, ext) = os.path.splitext(fname)
@ -1142,7 +1129,7 @@ class GraphvizReportDialog(ReportDialog):
self.options.set_document(self.doc) self.options.set_document(self.doc)
if self.print_report.get_active(): if self.print_report.get_active():
self.doc.print_requested() self.doc.open_requested()
def on_ok_clicked(self, obj): def on_ok_clicked(self, obj):
"""The user is satisfied with the dialog choices. Validate """The user is satisfied with the dialog choices. Validate

View File

@ -262,18 +262,6 @@ def add_menuitem(menu, msg, obj, func):
# #
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
def view_photo(photo, db):
"""
photo is a mediaobject, this utility launches a viewing application
"""
mime_type = photo.get_mime_type()
try:
data = Mime.get_application(mime_type)
prog = data[0]
except:
return
launch(prog, media_path_full(db, photo.get_path()))
def find_file( filename): def find_file( filename):
# try the filename we got # try the filename we got
try: try:
@ -1122,53 +1110,30 @@ class ProgressMeter:
Close the progress meter Close the progress meter
""" """
self.__dialog.destroy() self.__dialog.destroy()
def launch(prog_str, path):
if sys.platform == "win32":
import subprocess def open_file_with_default_application( file_path ):
if prog_str.find("%1") != -1: """
prog_str = prog_str.replace("%1", path) Launch a program to open an arbitrary file. The file will be opened using
else: whatever program is configured on the host as the default program for that
prog_str = '%s "%s"' % (prog_str, path) type of file.
# The string must be encoded using the filesystem encoding on Windows. @param file_path: The path to the file to be opened.
# Otherwise, files with non-ascii characters in their names will not Example: "c:\foo.txt"
# open. @type file_path: string
prog_str = prog_str.encode(sys.getfilesystemencoding()) @return: nothing
subprocess.Popen(prog_str) """
norm_path = os.path.normpath( file_path )
if os.sys.platform == 'win32':
norm_path = norm_path.encode(os.sys.getfilesystemencoding())
os.startfile(norm_path)
else: else:
subval = { search = os.environ['PATH'].split(':')
'%F' : path, for lpath in search:
'%f' : path, prog = os.path.join(lpath, 'xdg-open')
'%u' : path, if os.path.isfile(prog):
'%U' : path, os.spawnvpe(os.P_NOWAIT, prog, [prog, norm_path], os.environ)
'%n' : path, return
'%N' : path,
}
prog_data = prog_str.split()
prog = prog_data[0]
prog_list = []
need_path = True
if len(prog_data) > 1:
for item in prog_data:
if item in subval:
need_path = False
value = subval[item]
else:
value = item
prog_list.append(value)
else:
prog_list = [prog_data[0]]
if need_path:
prog_list.append(path)
os.spawnvpe(os.P_NOWAIT, prog, prog_list, os.environ)
def profile(func, *args): def profile(func, *args):
import hotshot.stats import hotshot.stats

View File

@ -1135,7 +1135,7 @@ class BookReportDialog(DocReportDialog):
self.doc.open(self.target_path) self.doc.open(self.target_path)
if self.print_report.get_active(): if self.print_report.get_active():
self.doc.print_requested () self.doc.open_requested ()
def make_report(self): def make_report(self):
"""The actual book report. Start it out, then go through the item list """The actual book report. Start it out, then go through the item list

View File

@ -153,10 +153,8 @@ class AsciiDoc(BaseDoc.BaseDoc,BaseDoc.TextDoc):
def close(self): def close(self):
self.f.close() self.f.close()
if self.print_req: if self.open_req:
apptype = 'text/plain' Utils.open_file_with_default_application(self.filename)
prog = Mime.get_application(apptype)
Utils.launch(prog[0],self.filename)
def get_usable_width(self): def get_usable_width(self):
return _WIDTH_IN_CHARS return _WIDTH_IN_CHARS
@ -375,16 +373,6 @@ class AsciiDoc(BaseDoc.BaseDoc,BaseDoc.TextDoc):
#------------------------------------------------------------------------ #------------------------------------------------------------------------
print_label = None print_label = None
pmgr = PluginManager.get_instance() pmgr = PluginManager.get_instance()
try: pmgr.register_text_doc(_("Plain Text"), AsciiDoc, 1, 1, ".txt",
mprog = Mime.get_application("text/plain") _("Open with default viewer"))
mtype = Mime.get_description('text/plain')
if Utils.search_for(mprog[0]):
print_label=_("Open in %s") % mprog[1]
else:
print_label=None
pmgr.register_text_doc(mtype, AsciiDoc, 1, 1, ".txt", print_label)
except:
pmgr.register_text_doc(_("Plain Text"), AsciiDoc, 1, 1, ".txt", None)

View File

@ -336,10 +336,8 @@ class HtmlDoc(BaseDoc.BaseDoc,BaseDoc.TextDoc):
self.f.close() self.f.close()
self.write_support_files() self.write_support_files()
if self.print_req: if self.open_req:
apptype = 'text/html' Utils.open_file_with_default_application(self.filename)
app = Mime.get_application(apptype)
Utils.launch(app[0],self.filename)
def write_support_files(self): def write_support_files(self):
if self.map: if self.map:
@ -482,18 +480,5 @@ class HtmlDoc(BaseDoc.BaseDoc,BaseDoc.TextDoc):
#------------------------------------------------------------------------ #------------------------------------------------------------------------
print_label = None print_label = None
pmgr = PluginManager.get_instance() pmgr = PluginManager.get_instance()
try: pmgr.register_text_doc(_('HTML'), HtmlDoc, 0, 1, ".html",
prog = Mime.get_application("text/html") _("Open with default viewer"))
mtype = Mime.get_description("text/html")
if Utils.search_for(prog[0]):
print_label=_("Open in %s") % prog[1]
else:
print_label=None
if mtype == _("unknown"):
mtype = _('HTML')
pmgr.register_text_doc(mtype, HtmlDoc, 0, 1, ".html", print_label)
except:
pmgr.register_text_doc(_('HTML'), HtmlDoc, 0, 1, ".html", None)

View File

@ -303,9 +303,8 @@ class LaTeXDoc(BaseDoc.BaseDoc,BaseDoc.TextDoc):
self.f.write('\\end{enumerate}\n') self.f.write('\\end{enumerate}\n')
self.f.write('\n\\end{document}\n') self.f.write('\n\\end{document}\n')
self.f.close() self.f.close()
if self.print_req: if self.open_req:
app = Mime.get_application(_apptype) Utils.open_file_with_default_application(self.filename)
Utils.launch(app[0], self.filename)
def end_page(self): def end_page(self):
"""Issue a new page command""" """Issue a new page command"""

View File

@ -434,9 +434,8 @@ class ODFDoc(BaseDoc.BaseDoc, BaseDoc.TextDoc, BaseDoc.DrawDoc):
self._write_meta_file() self._write_meta_file()
self._write_mimetype_file() self._write_mimetype_file()
self._write_zip() self._write_zip()
if self.print_req: if self.open_req:
app = Mime.get_application(_apptype) Utils.open_file_with_default_application(self.filename)
Utils.launch(app[0], self.filename)
def add_media_object(self, file_name, pos, x_cm, y_cm): def add_media_object(self, file_name, pos, x_cm, y_cm):
@ -1147,18 +1146,8 @@ class ODFDoc(BaseDoc.BaseDoc, BaseDoc.TextDoc, BaseDoc.DrawDoc):
# Register plugins # Register plugins
# #
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
print_label = None print_label = _("Open with default viewer")
pmgr = PluginManager.get_instance() pmgr = PluginManager.get_instance()
try:
mprog = Mime.get_application(_apptype)
if Utils.search_for(mprog[0]):
print_label = _("Open in %(program_name)s") % { 'program_name':
mprog[1]}
else:
print_label = None
except:
print_label = None
pmgr.register_text_doc(_('Open Document Text'), pmgr.register_text_doc(_('Open Document Text'),
ODFDoc, 1, 1, ".odt", print_label) ODFDoc, 1, 1, ".odt", print_label)

View File

@ -46,22 +46,6 @@ def lrgb(grp):
def coords(grp): def coords(grp):
return (gformat(grp[0]),gformat(grp[1])) return (gformat(grp[0]),gformat(grp[1]))
_apptype = 'application/postscript'
print_label = None
try:
# First try to find a viewer program
mprog = Mime.get_application(_apptype)
if Utils.search_for(mprog[0]):
print_label = _("Open in %(program_name)s") % {'program_name': mprog[1]}
except:
pass
if print_label is None:
# Second, try to print directly
if get_print_dialog_app() is not None:
print_label = _("Print a copy")
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -152,15 +136,8 @@ class PSDrawDoc(BaseDoc.BaseDoc,BaseDoc.DrawDoc):
self.f.write('%d\n' % self.page) self.f.write('%d\n' % self.page)
self.f.write('%%EOF\n') self.f.write('%%EOF\n')
self.f.close() self.f.close()
if self.print_req: if self.open_req:
if print_label == _("Print a copy"): Utils.open_file_with_default_application(self.filename)
run_print_dialog (self.filename)
elif print_label:
app = Mime.get_application(_apptype)
Utils.launch(app[0],self.filename)
else:
# This should never happen
print "Invalid print request"
def write_text(self,text,mark=None): def write_text(self,text,mark=None):
pass pass
@ -368,4 +345,5 @@ class PSDrawDoc(BaseDoc.BaseDoc,BaseDoc.DrawDoc):
self.f.write('grestore\n') self.f.write('grestore\n')
pmgr = PluginManager.get_instance() pmgr = PluginManager.get_instance()
pmgr.register_draw_doc(_("PostScript"), PSDrawDoc, 1, 1, ".ps", print_label); pmgr.register_draw_doc(_("PostScript"), PSDrawDoc, 1, 1, ".ps",
_("Open with default viewer"))

View File

@ -125,9 +125,8 @@ class PdfDoc(CairoDoc):
fontmap.set_resolution(saved_resolution) fontmap.set_resolution(saved_resolution)
# load the result into an external viewer # load the result into an external viewer
if self.print_req: if self.open_req:
app = Mime.get_application('application/pdf') Utils.open_file_with_default_application(self._filename)
Utils.launch(app[0], self._filename)
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
@ -137,17 +136,8 @@ class PdfDoc(CairoDoc):
def register_docgen(): def register_docgen():
"""Register the docgen with the GRAMPS plugin system. """Register the docgen with the GRAMPS plugin system.
""" """
try: mtype = _('PDF document')
mprog = Mime.get_application("application/pdf") print_label = _("Open with default viewer")
mtype = Mime.get_description("application/pdf")
if Utils.search_for(mprog[0]):
print_label = _("Open in %s") % mprog[1]
else:
print_label = None
except:
mtype = _('PDF document')
print_label = None
pmgr = PluginManager.get_instance() pmgr = PluginManager.get_instance()
pmgr.register_text_doc(mtype, PdfDoc, 1, 1, ".pdf", print_label) pmgr.register_text_doc(mtype, PdfDoc, 1, 1, ".pdf", print_label)

View File

@ -129,12 +129,8 @@ class RTFDoc(BaseDoc.BaseDoc,BaseDoc.TextDoc):
self.f.write('}\n') self.f.write('}\n')
self.f.close() self.f.close()
if self.print_req: if self.open_req:
try: Utils.open_file_with_default_application(self.filename)
app = Mime.get_application(mime_type)[0]
Utils.launch(app,self.filename)
except:
pass
#-------------------------------------------------------------------- #--------------------------------------------------------------------
# #
@ -443,14 +439,5 @@ class RTFDoc(BaseDoc.BaseDoc,BaseDoc.TextDoc):
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
pmgr = PluginManager.get_instance() pmgr = PluginManager.get_instance()
try: pmgr.register_text_doc(_('RTF document'), RTFDoc, 1, 1, ".rtf",
mprog = Mime.get_application(mime_type) _("Open with default viewer"))
mtype = Mime.get_description(mime_type)
if Utils.search_for(mprog[0]):
print_label=_("Open in %s") % mprog[1]
else:
print_label=None
pmgr.register_text_doc(mtype, RTFDoc, 1, 1, ".rtf", print_label)
except:
pmgr.register_text_doc(_('RTF document'), RTFDoc, 1, 1, ".rtf", None)

View File

@ -263,5 +263,5 @@ def units(val):
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
pmgr = PluginManager.get_instance() pmgr = PluginManager.get_instance()
pmgr.register_draw_doc(_("SVG (Scalable Vector Graphics)"), pmgr.register_draw_doc(_("SVG (Scalable Vector Graphics)"), SvgDrawDoc, 1, 1,
SvgDrawDoc, 1, 1, ".svg"); ".svg", _("Open with default viewer"))