/usr/lib/python2.7/dist-packages/tryton/gui/window/view_form/view/form_gtk/reference.py is in tryton-client 3.8.4-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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | # This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
import gtk
import gettext
from .many2one import Many2One
from tryton.common.selection import SelectionMixin, PopdownMixin, \
selection_shortcuts
from tryton.config import CONFIG
_ = gettext.gettext
class Reference(Many2One, SelectionMixin, PopdownMixin):
def __init__(self, view, attrs):
super(Reference, self).__init__(view, attrs)
self.widget_combo = gtk.ComboBoxEntry()
child = self.widget_combo.get_child()
child.connect('activate', lambda *a: self._focus_out())
child.connect('focus-out-event', lambda *a: self._focus_out())
child.get_accessible().set_name(attrs.get('string', ''))
self.widget_combo.connect('changed', self.sig_changed_combo)
selection_shortcuts(self.widget_combo)
self.widget_combo.set_focus_chain([child])
self.widget.pack_start(self.widget_combo, expand=False, fill=True)
self.widget.pack_start(gtk.Label('-'), expand=False, fill=False)
self.init_selection()
self.set_popdown(self.selection, self.widget_combo)
self.widget.set_focus_chain([self.widget_combo, self.wid_text])
def get_model(self):
active = self.widget_combo.get_active()
if active < 0:
return ''
else:
model = self.widget_combo.get_model()
return model[active][1]
def get_empty_value(self):
for name, model in self.widget_combo.get_model():
if model in (None, ''):
return model, name
return '', ''
def _set_button_sensitive(self):
super(Reference, self)._set_button_sensitive()
self.widget_combo.child.set_editable(not self._readonly)
self.widget_combo.set_button_sensitivity(
gtk.SENSITIVITY_OFF if self._readonly else gtk.SENSITIVITY_AUTO)
if self._readonly and CONFIG['client.fast_tabbing']:
self.widget.set_focus_chain([])
else:
self.widget.unset_focus_chain()
@property
def modified(self):
if self.record and self.field:
try:
model, name = self.field.get_client(self.record)
except (ValueError, TypeError):
model, name = self.get_empty_value()
return (model != self.get_model()
or name != self.wid_text.get_text())
return False
def has_target(self, value):
if value is None:
return False
model, value = value.split(',')
if not value:
value = None
else:
try:
value = int(value)
except ValueError:
value = None
result = model == self.get_model() and value >= 0
return result
def value_from_id(self, id_, str_=None):
if str_ is None:
str_ = ''
return self.get_model(), (id_, str_)
@staticmethod
def id_from_value(value):
_, value = value.split(',')
return int(value)
def sig_changed_combo(self, *args):
if not self.changed:
return
self.wid_text.set_text('')
self.wid_text.set_position(0)
model = self.get_model()
if model:
value = (model, (-1, ''))
else:
value = ('', '')
self.field.set_client(self.record, value)
def set_value(self, record, field):
if not self.get_model():
value = self.wid_text.get_text()
if not value:
field.set_client(record, None)
else:
field.set_client(record, ('', value))
return
else:
try:
model, name = field.get_client(record)
except (ValueError, TypeError):
model, name = self.get_empty_value()
if (model != self.get_model()
or name != self.wid_text.get_text()):
field.set_client(record, None)
self.wid_text.set_text('')
def set_text(self, value):
if value:
model, value = value
else:
model, value = None, None
super(Reference, self).set_text(value)
self.widget_combo.handler_block_by_func(self.sig_changed_combo)
if not self.set_popdown_value(self.widget_combo, model):
text = self.get_inactive_selection(model)
self.set_popdown(
self.selection[:] + [(model, text)], self.widget_combo)
self.set_popdown_value(self.widget_combo, value)
self.widget_combo.handler_unblock_by_func(self.sig_changed_combo)
def display(self, record, field):
self.update_selection(record, field)
self.set_popdown(self.selection, self.widget_combo)
super(Reference, self).display(record, field)
|