/usr/share/pyshared/tryton/gui/window/preference.py is in tryton-client 2.2.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | #This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
"Preference"
import gettext
import gtk
import tryton.rpc as rpc
import copy
from tryton.gui.window.view_form.screen import Screen
from tryton.config import TRYTON_ICON
from tryton.exceptions import TrytonServerError
import tryton.common as common
_ = gettext.gettext
class Preference(object):
"Preference window"
def __init__(self, user):
self.parent = common.get_toplevel_window()
self.win = gtk.Dialog(_('Preferences'), self.parent,
gtk.DIALOG_MODAL|gtk.DIALOG_DESTROY_WITH_PARENT)
self.win.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
self.win.set_has_separator(False)
self.win.set_icon(TRYTON_ICON)
self.accel_group = gtk.AccelGroup()
self.win.add_accel_group(self.accel_group)
self.but_cancel = self.win.add_button(gtk.STOCK_CANCEL,
gtk.RESPONSE_CANCEL)
self.but_ok = self.win.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
self.but_ok.add_accelerator('clicked', self.accel_group,
gtk.keysyms.Return, gtk.gdk.CONTROL_MASK, gtk.ACCEL_VISIBLE)
self.win.set_default_response(gtk.RESPONSE_OK)
args = ('model', 'res.user', 'get_preferences_fields_view',
rpc.CONTEXT)
try:
view = rpc.execute(*args)
except TrytonServerError, exception:
view = common.process_exception(exception, *args)
if not view:
self.win.destroy()
self.win = None
return
title = gtk.Label(_('Edit User Preferences'))
title.show()
self.win.vbox.pack_start(title, expand=False, fill=True)
self.screen = Screen('res.user', mode=[])
self.screen.new(default=False)
self.screen.add_view(view)
args = ('model', 'res.user', 'get_preferences', False, rpc.CONTEXT)
try:
preferences = rpc.execute(*args)
except TrytonServerError, exception:
preferences = common.process_exception(exception, *args)
if not preferences:
self.win.destroy()
raise
self.screen.current_record.set(preferences)
self.screen.current_record.validate(softvalidation=True)
self.screen.screen_container.set(self.screen.current_view.widget)
self.screen.display(set_cursor=True)
self.screen.widget.show()
self.win.vbox.pack_start(self.screen.widget)
self.win.set_title(_('Preference'))
width, height = self.parent.get_size()
self.win.set_default_size(int(width * 0.9), int(height * 0.9))
self.win.show()
def run(self):
"Run the window"
if not self.win:
return False
res = False
while True:
if self.win.run() == gtk.RESPONSE_OK:
if self.screen.current_record.validate():
vals = copy.copy(self.screen.get(get_modifiedonly=True))
if 'password' in vals:
password = common.ask(_('Current Password:'),
visibility=False)
if not password:
break
else:
password = False
args = ('model', 'res.user', 'set_preferences', vals,
password, rpc.CONTEXT)
try:
rpc.execute(*args)
except TrytonServerError, exception:
if not common.process_exception(exception, self.win,
*args):
continue
res = True
break
else:
break
self.parent.present()
self.win.destroy()
return res
|