diff --git a/tryton/action/main.py b/tryton/action/main.py index b0a305e1c5..a7dfa88399 100644 --- a/tryton/action/main.py +++ b/tryton/action/main.py @@ -41,12 +41,12 @@ class Action(object): return False if not res: return False - (type, data) = res + (type, data, print_p) = res (fileno, fp_name) = tempfile.mkstemp('.' + type, 'tryton_') file_d = os.fdopen(fileno, 'wb+') file_d.write(base64.decodestring(data)) file_d.close() - file_open(fp_name, type, Main.get_main().window) + file_open(fp_name, type, Main.get_main().window, print_p=print_p) return True @staticmethod diff --git a/tryton/common/common.py b/tryton/common/common.py index 74ac46da5f..0f60f337ee 100644 --- a/tryton/common/common.py +++ b/tryton/common/common.py @@ -189,10 +189,13 @@ def file_selection(title, filename='', parent=None, win.destroy() return filenames -def file_open(filename, type, parent): +def file_open(filename, type, parent, print_p=False): cmd = '' if type in CONFIG['client.actions']: - cmd = CONFIG['client.actions'][type] + if print_p: + cmd = CONFIG['client.actions'][type][1] + else: + cmd = CONFIG['client.actions'][type][0] if not cmd: #TODO add dialog box pass @@ -207,6 +210,11 @@ def file_open(filename, type, parent): file_p.close() return cmd = cmd % filename + if print_p: + prog, args = cmd.split(' ', 1) + args = [os.path.basename(prog)] + args.split(' ') + os.spawnv(os.P_WAIT, prog, args) + return pid = os.fork() if not pid: pid = os.fork() diff --git a/tryton/config.py b/tryton/config.py index d0ee58623c..c5312a2d8b 100644 --- a/tryton/config.py +++ b/tryton/config.py @@ -38,7 +38,7 @@ def get_home_dir(): else: return '.' -def find_path(progs): +def find_path(progs, args): #TODO check for win32 paths = [x for x in os.environ['PATH'].split(':') if os.path.isdir(x)] @@ -46,7 +46,7 @@ def find_path(progs): content = os.listdir(dir) for prog in progs: if prog in content: - return os.path.join(dir, prog) + ' %s' + return os.path.join(dir, prog) + ' ' + args return '' @@ -55,7 +55,7 @@ class ConfigManager(object): def __init__(self): self.options = { - 'login.login': 'demo', + 'login.login': 'admin', 'login.server': 'localhost', 'login.port': '8070', 'login.protocol': 'socket://', @@ -73,10 +73,12 @@ class ConfigManager(object): 'client.form_tab_orientation': 90, 'client.lang': 'en_US', 'client.actions': { - 'odt': find_path(['ooffice', 'ooffice2']), - 'txt': find_path(['ooffice', 'ooffice2']), - 'pdf': find_path(['evince', 'xpdf', 'gpdf', - 'kpdf', 'epdfview', 'acroread']) + 'odt': {0: find_path(['ooffice', 'ooffice2'], '%s'), + 1: find_path(['ooffice', 'ooffice2'], '-p %s')}, + 'txt': {0: find_path(['ooffice', 'ooffice2'], '%s'), + 1: find_path(['ooffice', 'ooffice2'], '-p %s')}, + 'pdf': {0: find_path(['evince', 'xpdf', 'gpdf', + 'kpdf', 'epdfview', 'acroread'], '%s'), 1: ''}, }, } parser = optparse.OptionParser(version=_("Tryton %s" % VERSION)) diff --git a/tryton/gui/window/filesactions.py b/tryton/gui/window/filesactions.py index 44880f468c..e25dda6668 100644 --- a/tryton/gui/window/filesactions.py +++ b/tryton/gui/window/filesactions.py @@ -22,20 +22,36 @@ class FilesActions(object): _('Edit files actions')), expand=False, fill=True) self.win.vbox.pack_start(gtk.HSeparator()) self.entries = {} - table = gtk.Table(len(CONFIG['client.actions']), 2) + table = gtk.Table(len(CONFIG['client.actions']) + 1, 3) table.set_col_spacings(3) table.set_row_spacings(3) table.set_border_width(1) - i = 0 - for extension in CONFIG['client.actions']: + table.attach(gtk.Label(_('File Type')), 0, 1, 0, 1, yoptions=False, + xoptions=gtk.FILL) + table.attach(gtk.Label(_('Open')), 1, 2, 0, 1, yoptions=False, + xoptions=gtk.FILL) + table.attach(gtk.Label(_('Print')), 2, 3, 0, 1, yoptions=False, + xoptions=gtk.FILL) + i = 1 + extensions = CONFIG['client.actions'].keys() + extensions.sort() + for extension in extensions: table.attach(gtk.Label(_('%s file: ') % extension.upper()), - 0, 1, i, i + 1, yoptions = False, xoptions=gtk.FILL) - self.entries[extension] = gtk.Entry() - self.entries[extension].set_property( + 0, 1, i, i + 1, yoptions=False, xoptions=gtk.FILL) + self.entries[extension] = {} + self.entries[extension][0] = gtk.Entry() + self.entries[extension][0].set_property( 'activates_default', True) - self.entries[extension].set_text( - CONFIG['client.actions'][extension]) - table.attach(self.entries[extension], 1, 2, i, i + 1, + self.entries[extension][0].set_text( + CONFIG['client.actions'][extension][0]) + table.attach(self.entries[extension][0], 1, 2, i, i + 1, + yoptions = False, xoptions=gtk.FILL) + self.entries[extension][1] = gtk.Entry() + self.entries[extension][1].set_property( + 'activates_default', True) + self.entries[extension][1].set_text( + CONFIG['client.actions'][extension][1]) + table.attach(self.entries[extension][1], 2, 3, i, i + 1, yoptions = False, xoptions=gtk.FILL) i += 1 self.win.vbox.pack_start(table, expand=True, fill=True) @@ -46,8 +62,10 @@ class FilesActions(object): res = self.win.run() if res == gtk.RESPONSE_OK: for extension in self.entries: - CONFIG['client.actions'][extension] = \ - self.entries[extension].get_text() + CONFIG['client.actions'][extension][0] = \ + self.entries[extension][0].get_text() + CONFIG['client.actions'][extension][1] = \ + self.entries[extension][1].get_text() CONFIG.save() self.parent.present() self.win.destroy()