Stop the edition of Selection fields in editable Treeviews on focus-out
Closes #12308
This commit is contained in:
@@ -7,12 +7,12 @@ from .common import (
|
||||
RPCException, RPCExecute, RPCProgress, Tooltips, apply_label_attributes,
|
||||
ask, check_version, concurrency, data2pixbuf, date_format, ellipsize,
|
||||
error, file_open, file_selection, file_write, filter_domain,
|
||||
generateColorscheme, get_align, get_credentials, get_hostname, get_port,
|
||||
get_sensible_widget, get_toplevel_window, hex2rgb, highlight_rgb, humanize,
|
||||
idle_add, mailto, message, node_attributes, open_documentation, play_sound,
|
||||
process_exception, resize_pixbuf, selection, setup_window, slugify, sur,
|
||||
sur_3b, timezoned_date, to_xml, untimezoned_date, url_open, userwarning,
|
||||
warning)
|
||||
generateColorscheme, get_align, get_credentials, get_gdk_backend,
|
||||
get_hostname, get_port, get_sensible_widget, get_toplevel_window, hex2rgb,
|
||||
highlight_rgb, humanize, idle_add, mailto, message, node_attributes,
|
||||
open_documentation, play_sound, process_exception, resize_pixbuf,
|
||||
selection, setup_window, slugify, sur, sur_3b, timezoned_date, to_xml,
|
||||
untimezoned_date, url_open, userwarning, warning)
|
||||
from .domain_inversion import (
|
||||
concat, domain_inversion, eval_domain, extract_reference_models,
|
||||
filter_leaf, inverse_leaf, localize_domain, merge,
|
||||
@@ -55,6 +55,7 @@ __all__ = [
|
||||
generateColorscheme,
|
||||
get_align,
|
||||
get_credentials,
|
||||
get_gdk_backend,
|
||||
get_hostname,
|
||||
get_port,
|
||||
get_sensible_widget,
|
||||
|
||||
@@ -1490,3 +1490,17 @@ def play_sound(self, sound='success'):
|
||||
playsound(os.path.join(SOUNDS_DIR, f'{sound}.wav'))
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
|
||||
def get_gdk_backend():
|
||||
if sys.platform == 'darwin':
|
||||
return 'macos'
|
||||
elif sys.platform == 'win32':
|
||||
return 'win32'
|
||||
else:
|
||||
dm = Gdk.DisplayManager.get()
|
||||
default = dm.props.default_display
|
||||
dm_class_name = default.__class__.__name__.lower()
|
||||
if 'wayland' in dm_class_name:
|
||||
return 'wayland'
|
||||
return 'x11'
|
||||
|
||||
@@ -11,7 +11,8 @@ from weakref import WeakKeyDictionary
|
||||
from gi.repository import Gdk, GLib, Gtk
|
||||
|
||||
import tryton.common as common
|
||||
from tryton.common import data2pixbuf, file_open, file_selection, file_write
|
||||
from tryton.common import (
|
||||
data2pixbuf, file_open, file_selection, file_write, get_gdk_backend)
|
||||
from tryton.common.cellrendererbutton import CellRendererButton
|
||||
from tryton.common.cellrendererclickablepixbuf import (
|
||||
CellRendererClickablePixbuf)
|
||||
@@ -1131,10 +1132,12 @@ class Selection(GenericText, SelectionMixin, PopdownMixin):
|
||||
def editing_started(self, cell, editable, path):
|
||||
super(Selection, self).editing_started(cell, editable, path)
|
||||
record, field = self._get_record_field_from_path(path)
|
||||
# Combobox does not emit remove-widget when focus is changed
|
||||
self.editable.connect(
|
||||
'editing-done',
|
||||
lambda *a: self.editable.emit('remove-widget'))
|
||||
gdk_backend = get_gdk_backend()
|
||||
if gdk_backend == 'x11':
|
||||
# Combobox does not emit remove-widget when focus is changed
|
||||
self.editable.connect(
|
||||
'editing-done',
|
||||
lambda *a: self.editable.emit('remove-widget'))
|
||||
|
||||
selection_shortcuts(editable)
|
||||
|
||||
@@ -1142,6 +1145,14 @@ class Selection(GenericText, SelectionMixin, PopdownMixin):
|
||||
return self.set_value(editable, record, field)
|
||||
editable.get_child().connect('activate', set_value)
|
||||
editable.get_child().connect('focus-out-event', set_value)
|
||||
|
||||
if gdk_backend != 'x11':
|
||||
# For non X11 backend we can rely the focus-out-event to be sent
|
||||
# correctly
|
||||
def remove_entry(entry, event):
|
||||
editable.emit('editing-done')
|
||||
editable.emit('remove-widget')
|
||||
editable.get_child().connect('focus-out-event', remove_entry)
|
||||
editable.connect('changed', set_value)
|
||||
|
||||
self.update_selection(record, field)
|
||||
|
||||
Reference in New Issue
Block a user