From 72342e8d3e692d055f2b52a8436d0fdfd639ad61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20=C3=89vrard?= Date: Thu, 29 Jun 2023 09:57:37 +0200 Subject: [PATCH] Stop the edition of Selection fields in editable Treeviews on focus-out [PREVIEW] (#266) PCLAS-215 --- tryton/common/__init__.py | 14 +++++++------- tryton/common/common.py | 16 ++++++++++++++++ .../window/view_form/view/list_gtk/widget.py | 19 ++++++++++++++----- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/tryton/common/__init__.py b/tryton/common/__init__.py index d3c85f8268..cb1f130dac 100644 --- a/tryton/common/__init__.py +++ b/tryton/common/__init__.py @@ -2,18 +2,17 @@ # this repository contains the full copyright notices and license terms. from . import timedelta from .common import ( - COLORS, - COLOR_RGB, COLOR_SCHEMES, FORMAT_ERROR, MODELACCESS, MODELHISTORY, + COLOR_RGB, COLOR_SCHEMES, COLORS, FORMAT_ERROR, MODELACCESS, MODELHISTORY, MODELNAME, MODELNOTIFICATION, TRYTON_ICON, VIEW_SEARCH, IconFactory, Logout, RPCContextReload, 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, process_exception, - resize_pixbuf, selection, setup_window, slugify, sur, sur_3b, - timezoned_date, to_xml, untimezoned_date, url_open, userwarning, warning) + get_gdk_backend, get_hostname, get_port, get_sensible_widget, + get_toplevel_window, hex2rgb, highlight_rgb, humanize, idle_add, mailto, + message, node_attributes, 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, @@ -59,6 +58,7 @@ generateColorscheme, get_align, get_credentials, + get_gdk_backend, get_hostname, get_port, get_sensible_widget, diff --git a/tryton/common/common.py b/tryton/common/common.py index 07ba1395e6..b8d473448f 100644 --- a/tryton/common/common.py +++ b/tryton/common/common.py @@ -1485,3 +1485,19 @@ def wrapper(*args, **kwargs): def setup_window(window): if sys.platform == 'darwin': window.set_mnemonic_modifier(Gdk.ModifierType.CONTROL_MASK) + + +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__ + if 'X11' in dm_class_name: + return 'x11' + elif 'Wayland' in dm_class_name: + return 'wayland' + return 'x11' diff --git a/tryton/gui/window/view_form/view/list_gtk/widget.py b/tryton/gui/window/view_form/view/list_gtk/widget.py index 75cbd8fb8e..883f50a525 100644 --- a/tryton/gui/window/view_form/view/list_gtk/widget.py +++ b/tryton/gui/window/view_form/view/list_gtk/widget.py @@ -10,7 +10,8 @@ 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) @@ -1181,10 +1182,12 @@ def set_editable(self): 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) @@ -1192,6 +1195,12 @@ def set_value(*a): 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': + 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)