Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Stop the edition of Selection fields in editable Treeviews on focus-out [PREVIEW] #266

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions tryton/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -59,6 +58,7 @@
generateColorscheme,
get_align,
get_credentials,
get_gdk_backend,
get_hostname,
get_port,
get_sensible_widget,
Expand Down
16 changes: 16 additions & 0 deletions tryton/common/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
19 changes: 14 additions & 5 deletions tryton/gui/window/view_form/view/list_gtk/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -1181,17 +1182,25 @@ 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)

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)
Expand Down