Remove "Files Actions" and instead use xdg
issue2265 review223002
This commit is contained in:
1 parent
a3e49fc54b
commit
4a7f432091
6 files changed
+38
-207
No files matched your search
@@ -581,24 +581,6 @@ Tabs Position
|
||||
* Right
|
||||
* Bottom
|
||||
|
||||
.. _Menu-Options-File_Actions:
|
||||
|
||||
File Actions...:
|
||||
Opens a dialog to set up file types for print and open actions.
|
||||
Use ``"%s"`` as a placeholder for the document name.
|
||||
|
||||
* Provided file types:
|
||||
|
||||
- ODT file: Open Office Writer Document
|
||||
- PDF file: Adobes(TM) Portable Document Format
|
||||
- PNG file: Portable Network Graphics format
|
||||
- TXT file: Pure text file
|
||||
|
||||
* Provided actions
|
||||
|
||||
- Open: Setting up program system call which opens the specific file type.
|
||||
- Print: Setting up program system call printing the specific file type.
|
||||
|
||||
.. _Menu-Options-Email:
|
||||
|
||||
Email...:
|
||||
|
||||
+38
-60
@@ -404,47 +404,7 @@ def file_selection(title, filename='',
|
||||
return filenames
|
||||
|
||||
def file_open(filename, type, print_p=False):
|
||||
if os.name == 'nt':
|
||||
operation = 'open'
|
||||
if print_p:
|
||||
operation = 'print'
|
||||
try:
|
||||
os.startfile(os.path.normpath(filename), operation)
|
||||
except WindowsError:
|
||||
save_name = file_selection(_('Save As...'),
|
||||
action=gtk.FILE_CHOOSER_ACTION_SAVE)
|
||||
if save_name:
|
||||
file_p = open(filename, 'rb')
|
||||
save_p = open(save_name, 'wb+')
|
||||
save_p.write(file_p.read())
|
||||
save_p.close()
|
||||
file_p.close()
|
||||
return
|
||||
elif sys.platform == 'darwin':
|
||||
pid = os.fork()
|
||||
if not pid:
|
||||
pid = os.fork()
|
||||
if not pid:
|
||||
try:
|
||||
os.execv('/usr/bin/open', ['/usr/bin/open', filename])
|
||||
except OSError:
|
||||
sys.exit(0)
|
||||
time.sleep(0.1)
|
||||
sys.exit(0)
|
||||
os.waitpid(pid, 0)
|
||||
return
|
||||
cmd = ''
|
||||
if isinstance(CONFIG['client.actions'], basestring):
|
||||
CONFIG['client.actions'] = safe_eval(CONFIG['client.actions'])
|
||||
if type in CONFIG['client.actions']:
|
||||
if print_p:
|
||||
cmd = CONFIG['client.actions'][type][1]
|
||||
else:
|
||||
cmd = CONFIG['client.actions'][type][0]
|
||||
if not cmd:
|
||||
#TODO add dialog box
|
||||
pass
|
||||
if not cmd:
|
||||
def save():
|
||||
save_name = file_selection(_('Save As...'),
|
||||
action=gtk.FILE_CHOOSER_ACTION_SAVE)
|
||||
if save_name:
|
||||
@@ -453,25 +413,26 @@ def file_open(filename, type, print_p=False):
|
||||
save_p.write(file_p.read())
|
||||
save_p.close()
|
||||
file_p.close()
|
||||
return
|
||||
cmd = cmd % filename
|
||||
args = shlex.split(str(cmd))
|
||||
prog = find_in_path(args[0])
|
||||
args[0] = os.path.basename(args[0])
|
||||
if print_p:
|
||||
os.spawnv(os.P_WAIT, prog, args)
|
||||
return
|
||||
pid = os.fork()
|
||||
if not pid:
|
||||
pid = os.fork()
|
||||
if not pid:
|
||||
try:
|
||||
os.execv(prog, args)
|
||||
except OSError:
|
||||
sys.exit(0)
|
||||
time.sleep(0.1)
|
||||
sys.exit(0)
|
||||
os.waitpid(pid, 0)
|
||||
|
||||
if os.name == 'nt':
|
||||
operation = 'open'
|
||||
if print_p:
|
||||
operation = 'print'
|
||||
try:
|
||||
os.startfile(os.path.normpath(filename), operation)
|
||||
except WindowsError:
|
||||
save()
|
||||
elif sys.platform == 'darwin':
|
||||
try:
|
||||
subprocess.Popen(['/usr/bin/open', filename])
|
||||
except OSError:
|
||||
save()
|
||||
else:
|
||||
try:
|
||||
subprocess.Popen(['xdg-open', filename])
|
||||
except OSError:
|
||||
save()
|
||||
|
||||
|
||||
def mailto(to=None, cc=None, subject=None, body=None, attachment=None):
|
||||
if CONFIG['client.email']:
|
||||
@@ -485,6 +446,23 @@ def mailto(to=None, cc=None, subject=None, body=None, attachment=None):
|
||||
args = shlex.split(str(cmd))
|
||||
subprocess.Popen(args)
|
||||
return
|
||||
if os.name != 'nt' and sys.platform != 'darwin':
|
||||
args = ['xdg-email', '--utf8']
|
||||
if cc:
|
||||
args.extend(['--cc', cc])
|
||||
if subject:
|
||||
args.extend(['--subject', subject])
|
||||
if body:
|
||||
args.extend(['--body', body])
|
||||
if attachment:
|
||||
args.extend(['--attach', attachment])
|
||||
if to:
|
||||
args.append(to)
|
||||
try:
|
||||
subprocess.Popen(args)
|
||||
return
|
||||
except OSError:
|
||||
pass
|
||||
#http://www.faqs.org/rfcs/rfc2368.html
|
||||
url = "mailto:"
|
||||
if to:
|
||||
|
||||
@@ -29,20 +29,6 @@ def get_config_dir():
|
||||
if not os.path.isdir(get_config_dir()):
|
||||
os.makedirs(get_config_dir(), 0700)
|
||||
|
||||
def find_path(progs, args):
|
||||
if os.name == 'nt':
|
||||
return ''
|
||||
if sys.platform == 'darwin':
|
||||
return ''
|
||||
paths = [x for x in os.environ['PATH'].split(':')
|
||||
if os.path.isdir(x)]
|
||||
for dir in paths:
|
||||
for prog in progs:
|
||||
val = os.path.join(dir, prog)
|
||||
if os.path.isfile(val) or os.path.islink(val):
|
||||
return val + ' ' + args
|
||||
return ''
|
||||
|
||||
|
||||
class ConfigManager(object):
|
||||
"Config manager"
|
||||
@@ -78,17 +64,6 @@ class ConfigManager(object):
|
||||
'client.default_path': get_home_dir(),
|
||||
'client.lang': locale.getdefaultlocale()[0],
|
||||
'client.language_direction': 'ltr',
|
||||
'client.actions': {
|
||||
'odt': {0: find_path(['ooffice', 'ooffice2', 'libreoffice'], '"%s"'),
|
||||
1: find_path(['ooffice', 'ooffice2', 'libreoffice'], '-p "%s"')},
|
||||
'txt': {0: find_path(['ooffice', 'ooffice2', 'libreoffice'], '"%s"'),
|
||||
1: find_path(['ooffice', 'ooffice2', 'libreoffice'], '-p "%s"')},
|
||||
'pdf': {0: find_path(['evince', 'xpdf', 'gpdf',
|
||||
'kpdf', 'epdfview', 'acroread'], '"%s"'), 1: ''},
|
||||
'png': {0: find_path(['feh', 'display', 'qiv', 'eye'], '"%s"'), 1: ''},
|
||||
'csv': {0: find_path(['ooffice', 'ooffice2', 'libreoffice'], '"%s"'),
|
||||
1: find_path(['ooffice', 'ooffice2', 'libreoffice'], '-p "%s"')},
|
||||
},
|
||||
'client.email': '',
|
||||
'client.can_change_accelerators': False,
|
||||
'client.limit': 1000,
|
||||
|
||||
@@ -23,7 +23,6 @@ from tryton.exceptions import TrytonServerError, TrytonError
|
||||
from tryton.gui.window import Window
|
||||
from tryton.gui.window.preference import Preference
|
||||
from tryton.gui.window import Limit
|
||||
from tryton.gui.window import FileActions
|
||||
from tryton.gui.window import Email
|
||||
from tryton.gui.window.dblogin import DBLogin
|
||||
from tryton.gui.window.dbcreate import DBCreate
|
||||
@@ -189,11 +188,6 @@ class Main(object):
|
||||
|
||||
self.sig_statusbar_show()
|
||||
|
||||
if os.name == 'nt' or sys.platform == 'darwin':
|
||||
# Disable actions, on win32 we use os.startfile
|
||||
# and on mac we use /usr/bin/open
|
||||
self.menuitem_actions.set_sensitive(False)
|
||||
|
||||
# Adding a timer the check to requests
|
||||
gobject.timeout_add(5 * 60 * 1000, self.request_set)
|
||||
_MAIN.append(self)
|
||||
@@ -631,12 +625,6 @@ class Main(object):
|
||||
menuitem_limit.set_accel_path('<tryton>/Options/Search Limit')
|
||||
menu_options.add(menuitem_limit)
|
||||
|
||||
menuitem_actions = gtk.MenuItem(_('File _Actions...'))
|
||||
self.menuitem_actions = menuitem_actions
|
||||
menuitem_actions.connect('activate', self.sig_file_actions)
|
||||
menuitem_actions.set_accel_path('<tryton>/Options/File Actions')
|
||||
menu_options.add(menuitem_actions)
|
||||
|
||||
menuitem_email = gtk.MenuItem(_('_Email...'))
|
||||
self.menuitem_email = menuitem_email
|
||||
menuitem_email.connect('activate', self.sig_email)
|
||||
@@ -817,9 +805,6 @@ class Main(object):
|
||||
def sig_limit(self, widget):
|
||||
Limit().run()
|
||||
|
||||
def sig_file_actions(self, widget):
|
||||
FileActions().run()
|
||||
|
||||
def sig_email(self, widget):
|
||||
Email().run()
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
#this repository contains the full copyright notices and license terms.
|
||||
from window import *
|
||||
from fileactions import *
|
||||
from email import *
|
||||
from limit import *
|
||||
@@ -1,88 +0,0 @@
|
||||
#This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
#this repository contains the full copyright notices and license terms.
|
||||
"File actions"
|
||||
import gtk
|
||||
import gettext
|
||||
from tryton.config import TRYTON_ICON, CONFIG
|
||||
from tryton.common import safe_eval, get_toplevel_window
|
||||
|
||||
_ = gettext.gettext
|
||||
|
||||
|
||||
class FileActions(object):
|
||||
"File actions window"
|
||||
|
||||
def __init__(self):
|
||||
self.parent= get_toplevel_window()
|
||||
self.win = gtk.Dialog(_('File Actions'), self.parent,
|
||||
gtk.DIALOG_MODAL|gtk.DIALOG_DESTROY_WITH_PARENT,
|
||||
(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
|
||||
gtk.STOCK_OK, gtk.RESPONSE_OK))
|
||||
self.win.set_default_response(gtk.RESPONSE_OK)
|
||||
self.win.set_icon(TRYTON_ICON)
|
||||
self.win.set_has_separator(True)
|
||||
self.win.vbox.pack_start(gtk.Label(
|
||||
_('Edit Files Actions')), expand=False, fill=True)
|
||||
self.win.vbox.pack_start(gtk.HSeparator())
|
||||
self.treeview = gtk.TreeView()
|
||||
|
||||
self.model = gtk.ListStore(str, str, str, str)
|
||||
self.treeview.set_model(self.model)
|
||||
|
||||
for index, text in enumerate((_('File Type'), _('Open'), _('Print'))):
|
||||
renderer = gtk.CellRendererText()
|
||||
if index != 0:
|
||||
renderer.set_property('editable', True)
|
||||
renderer.connect('edited', self._sig_edited)
|
||||
column = gtk.TreeViewColumn(text, renderer, text=index + 1)
|
||||
column.set_resizable(True)
|
||||
self.treeview.append_column(column)
|
||||
|
||||
i = 1
|
||||
if isinstance(CONFIG['client.actions'], basestring):
|
||||
CONFIG['client.actions'] = safe_eval(CONFIG['client.actions'])
|
||||
extensions = CONFIG['client.actions'].keys()
|
||||
extensions.sort()
|
||||
for extension in extensions:
|
||||
iter = self.model.append()
|
||||
self.model.set(iter, 0, extension,
|
||||
1, _('%s file') % extension.upper(),
|
||||
2, CONFIG['client.actions'][extension][0],
|
||||
3, CONFIG['client.actions'][extension][1])
|
||||
|
||||
scroll = gtk.ScrolledWindow()
|
||||
scroll.add(self.treeview)
|
||||
scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
|
||||
viewport= gtk.Viewport()
|
||||
viewport.set_shadow_type(gtk.SHADOW_ETCHED_IN)
|
||||
viewport.set_size_request(400, 200)
|
||||
viewport.add(scroll)
|
||||
self.win.vbox.pack_start(viewport, expand=True, fill=True)
|
||||
|
||||
label = gtk.Label(_('Use "%s" as a placeholder for the file name'))
|
||||
label.set_alignment(0.0, 0.5)
|
||||
label.set_padding(0, 10)
|
||||
self.win.vbox.pack_start(label, expand=False, fill=True)
|
||||
self.win.show_all()
|
||||
|
||||
def run(self):
|
||||
"Run the window"
|
||||
res = self.win.run()
|
||||
if res == gtk.RESPONSE_OK:
|
||||
config = {}
|
||||
for extension, _, cmd_open, cmd_print in self.model:
|
||||
config[extension] = {
|
||||
0: cmd_open,
|
||||
1: cmd_print,
|
||||
}
|
||||
CONFIG['client.actions'] = config
|
||||
CONFIG.save()
|
||||
self.parent.present()
|
||||
self.win.destroy()
|
||||
return res
|
||||
|
||||
def _sig_edited(self, cell, path, new_text):
|
||||
iter = self.model.get_iter_from_string(path)
|
||||
(path, column) = self.treeview.get_cursor()
|
||||
column_id = self.treeview.get_columns().index(column)
|
||||
self.model.set(iter, column_id + 1, new_text)
|
||||
Reference in new issue
Block a user