/usr/share/pyshared/tryton/gui/window/view_form/view/form_gtk/char.py is in tryton-client 3.0.2-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 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | #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 gettext
import gobject
import gtk
from interface import WidgetInterface, TranslateMixin
from tryton.common import Tooltips
_ = gettext.gettext
class Char(WidgetInterface, TranslateMixin):
"Char"
def __init__(self, field_name, model_name, attrs=None):
super(Char, self).__init__(field_name, model_name, attrs=attrs)
self.widget = gtk.HBox()
self.autocomplete = bool(attrs.get('autocomplete'))
if self.autocomplete:
self.entry = gtk.ComboBoxEntry()
self.entry_store = gtk.ListStore(gobject.TYPE_STRING)
self.entry.set_model(self.entry_store)
self.entry.set_text_column(0)
completion = gtk.EntryCompletion()
completion.set_model(self.entry_store)
completion.set_text_column(0)
self.entry.get_child().set_completion(completion)
focus_entry = self.entry.get_child()
else:
self.entry = gtk.Entry()
focus_entry = self.entry
focus_entry.set_property('activates_default', True)
focus_entry.connect('activate', self.sig_activate)
focus_entry.connect('focus-out-event', lambda x, y: self._focus_out())
focus_entry.connect('key-press-event', self.send_modified)
expand, fill = True, True
if attrs.get('size'):
expand, fill = False, False
self.widget.pack_start(self.entry, expand=expand, fill=fill)
self.button = None
if attrs.get('translate'):
self.button = self.translate_button()
self.widget.pack_start(self.button, False, False)
def translate_widget(self):
entry = gtk.Entry()
entry.set_property('activates_default', True)
entry.set_width_chars(int(self.attrs.get('size', -1)))
entry.set_max_length(int(self.attrs.get('size', 0)))
return entry
@staticmethod
def translate_widget_set(widget, value):
widget.set_text(value or '')
@staticmethod
def translate_widget_get(widget):
return widget.get_text()
@staticmethod
def translate_widget_set_readonly(widget, value):
widget.set_editable(not value)
widget.props.sensitive = not value
def _color_widget(self):
if self.autocomplete:
return self.entry.get_child()
return self.entry
def grab_focus(self):
return self.entry.grab_focus()
@property
def modified(self):
if self.record and self.field:
entry = self.entry.get_child() if self.autocomplete else self.entry
value = entry.get_text() or ''
return self.field.get_client(self.record) != value
return False
def set_value(self, record, field):
entry = self.entry.get_child() if self.autocomplete else self.entry
value = entry.get_text() or ''
return field.set_client(record, value)
def get_value(self):
return self.entry.get_text()
def display(self, record, field):
super(Char, self).display(record, field)
if record and self.autocomplete:
autocompletion = record.autocompletion.get(self.field_name, [])
current = [elem[0] for elem in self.entry_store]
if autocompletion != current:
self.entry_store.clear()
for row in autocompletion:
self.entry_store.append((row,))
elif self.autocomplete:
self.entry_store.clear()
# Set size
if self.autocomplete:
size_entry = self.entry.get_child()
else:
size_entry = self.entry
if record:
field_size = record.expr_eval(self.attrs.get('size'))
size_entry.set_width_chars(field_size or -1)
size_entry.set_max_length(field_size or 0)
else:
size_entry.set_width_chars(-1)
size_entry.set_max_length(0)
if not field:
value = ''
else:
value = field.get_client(record)
if not self.autocomplete:
self.entry.set_text(value)
else:
for idx, row in enumerate(self.entry_store):
if row[0] == value:
self.entry.set_active(idx)
return
else:
self.entry.get_child().set_text(value)
def _readonly_set(self, value):
sensitivity = {True: gtk.SENSITIVITY_OFF, False: gtk.SENSITIVITY_AUTO}
super(Char, self)._readonly_set(value)
if self.autocomplete:
self.entry.get_child().set_editable(not value)
self.entry.set_button_sensitivity(sensitivity[value])
else:
self.entry.set_editable(not value)
if self.button:
self.button.set_sensitive(not value)
if value:
self.widget.set_focus_chain([])
else:
self.widget.set_focus_chain([self.entry])
class Sha(Char):
def __init__(self, field_name, model_name, attrs=None):
super(Sha, self).__init__(field_name, model_name, attrs=attrs)
self.entry.props.visibility = False
self.visibility_checkbox = gtk.CheckButton()
self.visibility_checkbox.connect('toggled', self.toggle_visibility)
Tooltips().set_tip(self.visibility_checkbox, _('Show plain text'))
self.widget.pack_start(self.visibility_checkbox, expand=False)
def _readonly_set(self, value):
super(Char, self)._readonly_set(value)
self.entry.set_editable(not value)
self.visibility_checkbox.props.visible = not value
if value:
self.widget.set_focus_chain([])
else:
self.widget.set_focus_chain([self.entry, self.visibility_checkbox])
def toggle_visibility(self, button):
self.entry.props.visibility = not self.entry.props.visibility
|