From 1ef810cb2b926bbcba9442890e68873bc43376f1 Mon Sep 17 00:00:00 2001 From: Stephen Watson Date: Fri, 2 Jan 2004 14:39:10 +0000 Subject: [PATCH] Put icons in the list, add to SendTo for type (uses CanRun) git-svn-id: https://rox.svn.sourceforge.net/svnroot/rox/trunk/ROX-Lib2@3281 66de3db3-b00d-0410-b41b-f4738ad19bea --- python/rox/mime_handler.py | 124 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 97 insertions(+), 27 deletions(-) diff --git a/python/rox/mime_handler.py b/python/rox/mime_handler.py index 4f549a3..f53e7c0 100644 --- a/python/rox/mime_handler.py +++ b/python/rox/mime_handler.py @@ -1,6 +1,6 @@ """This module allows applications to set themselves as the default handler for -a particular MIME type. This is generally not a good thing to do, because it annoys users -if programs fight over the defaults.""" +a particular MIME type. This is generally not a good thing to do, because it +annoys users if programs fight over the defaults.""" import os @@ -12,15 +12,18 @@ _TNAME = 0 _COMMENT = 1 _CURRENT = 2 _INSTALL = 3 +_ICON = 4 class InstallList(rox.Dialog): """Dialog to select installation of MIME type handlers""" - def __init__(self, application, itype, dir, types): + def __init__(self, application, itype, dir, types, info=None, check=True): """Create the install list dialog. application - path to application to install itype - string describing the type of action to install dir - directory in Choices to store links in - types - list of MIME types""" + types - list of MIME types + info - optional message to display below list + check - if true (the default), check for existing entries""" rox.Dialog.__init__(self, title='Install %s' % itype, buttons=(rox.g.STOCK_CANCEL, rox.g.RESPONSE_CLOSE, rox.g.STOCK_OK, rox.g.RESPONSE_ACCEPT)) @@ -30,6 +33,7 @@ class InstallList(rox.Dialog): self.types=types self.app=application self.aname=os.path.basename(application) + self.check=check vbox=self.vbox @@ -40,12 +44,16 @@ class InstallList(rox.Dialog): swin.set_shadow_type(rox.g.SHADOW_IN) vbox.pack_start(swin, True, True, 0) - self.model = rox.g.ListStore(str, str, str, int) + self.model = rox.g.ListStore(str, str, str, int, rox.g.gdk.Pixbuf) view = rox.g.TreeView(self.model) self.view = view swin.add(view) view.set_search_column(1) + cell = rox.g.CellRendererPixbuf() + column = rox.g.TreeViewColumn('', cell, pixbuf = _ICON) + view.append_column(column) + cell = rox.g.CellRendererText() column = rox.g.TreeViewColumn('Type', cell, text = _TNAME) view.append_column(column) @@ -56,10 +64,11 @@ class InstallList(rox.Dialog): view.append_column(column) column.set_sort_column_id(_COMMENT) - cell = rox.g.CellRendererText() - column = rox.g.TreeViewColumn('Current', cell, text = _CURRENT) - view.append_column(column) - column.set_sort_column_id(_CURRENT) + if check: + cell = rox.g.CellRendererText() + column = rox.g.TreeViewColumn('Current', cell, text = _CURRENT) + view.append_column(column) + column.set_sort_column_id(_CURRENT) cell = rox.g.CellRendererToggle() cell.set_property('activatable', True) @@ -70,6 +79,18 @@ class InstallList(rox.Dialog): view.get_selection().set_mode(rox.g.SELECTION_NONE) + if info: + hbox=rox.g.HBox(spacing=4) + img=rox.g.image_new_from_stock(rox.g.STOCK_DIALOG_INFO, + rox.g.ICON_SIZE_DIALOG) + hbox.pack_start(img) + + lbl=rox.g.Label(info) + lbl.set_line_wrap(True) + hbox.pack_start(lbl) + + vbox.pack_start(hbox) + vbox.show_all() self.load_types() @@ -88,25 +109,36 @@ class InstallList(rox.Dialog): self.model.clear() for tname in self.types: - type = mime.lookup(tname) - old=rox.choices.load(self.dir, '%s_%s' % - (type.media, type.subtype)) - if old and os.path.islink(old): - old=os.readlink(old) - oname=os.path.basename(old) - elif old: - oname='script' - else: - oname='' - #print oname, old, self.app - if old==self.app: - dinstall=False + type=rox.mime.lookup(tname) + if self.check: + old=rox.choices.load(self.dir, '%s_%s' % + (type.media, type.subtype)) + if old and os.path.islink(old): + old=os.readlink(old) + oname=os.path.basename(old) + elif old: + oname='script' + else: + oname='' + + if old==self.app: + dinstall=False + else: + dinstall=True else: dinstall=True + oname='' + + icon=type.get_icon(rox.mime.ICON_SIZE_SMALL) iter=self.model.append() self.model.set(iter, _TNAME, tname, _COMMENT, type.get_comment(), - _CURRENT, oname, _INSTALL, dinstall) + _INSTALL, dinstall) + if self.check: + self.model.set(iter, _CURRENT, oname) + if icon: + self.model.set(iter, _ICON, icon) + def get_active(self): """Return list of selected types""" @@ -119,7 +151,8 @@ class InstallList(rox.Dialog): return active -def _install_type_handler(types, dir, desc, application=None, overwrite=True): +def _install_type_handler(types, dir, desc, application=None, overwrite=True, + info=None): if len(types)<1: return @@ -128,7 +161,7 @@ def _install_type_handler(types, dir, desc, application=None, overwrite=True): if application[0]!='/': application=os.path.abspath(application) - win=InstallList(application, desc, dir, types) + win=InstallList(application, desc, dir, types, info) if win.run()!=rox.g.RESPONSE_ACCEPT: win.destroy() @@ -146,6 +179,7 @@ def _install_type_handler(types, dir, desc, application=None, overwrite=True): win.destroy() +run_action_msg=_("""Run actions can be changed by selecting a file of the appropriate type in the Filer and selecting the menu option 'Set Run Action...'""") def install_run_action(types, application=None, overwrite=True): """Install application as the run action for 1 or more types. application should be the full path to the AppDir. @@ -154,7 +188,7 @@ def install_run_action(types, application=None, overwrite=True): not be changed. The user is asked to confirm the setting for each type.""" _install_type_handler(types, "MIME-types", _("run action"), - application, overwrite) + application, overwrite, run_action_msg) def install_thumbnailer(types, application=None, overwrite=True): """Install application as the thumbnail handler for 1 or more types. @@ -164,8 +198,43 @@ def install_thumbnailer(types, application=None, overwrite=True): not be changed. The user is asked to confirm the setting for each type.""" _install_type_handler(types, "MIME-thumb", _("thumbnail handler"), - application, overwrite) + application, overwrite, _("""Thumbnail handlers provide support for creating thumbnail images of types of file. The filer can generate thumbnails for most types of image (JPEG, PNG, etc.) but relies on helper applications for the others.""")) +def install_send_to_types(types, application=None): + """Install application in the SendTo menu for 1 or more types. + application should be the full path to the AppDir. + If application is None then it is the running program which will + be installed. The user is asked to confirm the setting for each + type.""" + if len(types)<1: + return + + if not application: + application=rox.app_dir + if application[0]!='/': + application=os.path.abspath(application) + + win=InstallList(application, _('type handler'), 'SendTo', types, + _("""The application can handle files of these types. Click on OK to add it to the SendTo menu for the type of file, and also the customized File menu."""), + check=False) + + if win.run()!=rox.g.RESPONSE_ACCEPT: + win.destroy() + return + + types=win.get_active() + + for tname in types: + type=lookup(tname) + + sname=rox.choices.save('SendTo/.%s_%s' % (type.media, + type.subtype), + win.aname) + os.symlink(application, sname+'.tmp') + os.rename(sname+'.tmp', sname) + + win.destroy() + def install_from_appinfo(appdir = rox.app_dir): """Read the AppInfo file from the AppDir and perform the installations indicated. The elements to use are and , each containing @@ -182,6 +251,7 @@ def install_from_appinfo(appdir = rox.app_dir): if can_run or can_thumbnail: install_run_action(can_run, appdir) install_thumbnailer(can_thumbnail, appdir) + install_send_to_types(ainfo.getCanRun(), appdir) else: raise Exception('Internal error: No actions found in %s. ' 'Check your namespaces!' % app_info_path) -- 2.11.4.GIT