From 01d8d2e5796d255580e11cdac342ab806d82b43f Mon Sep 17 00:00:00 2001 From: Valentin Iovene Date: Sat, 16 Sep 2023 18:42:56 +0200 Subject: [PATCH 1/6] [ikhal] add option to disable mouse, fixes #1289 This is done by passing the `handle_mouse` Boolean argument to urwid's main loop (currently unused). By default, the mouse remains enabled (see `khal.spec`). Mouse can be disabled either by setting `enable_mouse = False` in the `[default]` section of khal's config file, or by passing the `--no-mouse` flag to the `khal interactive` or `ikhal` click commands. --- .gitignore | 1 + khal.conf.sample | 1 + khal/cli.py | 16 ++++++++++++++-- khal/settings/khal.spec | 4 ++++ khal/ui/__init__.py | 7 ++++++- 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 1920041e7..d022b15ff 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ env/ venv/ .hypothesis/ .python-version +.dmypy.json diff --git a/khal.conf.sample b/khal.conf.sample index 243bb5547..494a2da6d 100644 --- a/khal.conf.sample +++ b/khal.conf.sample @@ -30,3 +30,4 @@ monthdisplay = firstday default_calendar = home timedelta = 2d # the default timedelta that list uses highlight_event_days = True # the default is False +enable_mouse = True # mouse is enabled by default in interactive mode diff --git a/khal/cli.py b/khal/cli.py index 8b920f572..f86292ac6 100644 --- a/khal/cli.py +++ b/khal/cli.py @@ -93,6 +93,12 @@ def multi_calendar_option(f): return d(a(f)) +def no_mouse_option(f): + o = click.option('--no-mouse', is_flag=True, + help='Disable mouse in interactive UI') + return o(f) + + def _select_one_calendar_callback(ctx, option, calendar): if isinstance(calendar, tuple): if len(calendar) > 1: @@ -480,9 +486,12 @@ def isatty(_file): @cli.command() @multi_calendar_option + @no_mouse_option @click.pass_context - def interactive(ctx, include_calendar, exclude_calendar): + def interactive(ctx, include_calendar, exclude_calendar, no_mouse): '''Interactive UI. Also launchable via `ikhal`.''' + if no_mouse: + ctx.obj['conf']['default']['enable_mouse'] = False controllers.interactive( build_collection( ctx.obj['conf'], @@ -494,10 +503,13 @@ def interactive(ctx, include_calendar, exclude_calendar): @click.command() @global_options @multi_calendar_option + @no_mouse_option @click.pass_context - def interactive_cli(ctx, config, include_calendar, exclude_calendar): + def interactive_cli(ctx, config, include_calendar, exclude_calendar, no_mouse): '''Interactive UI. Also launchable via `khal interactive`.''' prepare_context(ctx, config) + if no_mouse: + ctx.obj['conf']['default']['enable_mouse'] = False controllers.interactive( build_collection( ctx.obj['conf'], diff --git a/khal/settings/khal.spec b/khal/settings/khal.spec index 789b103a9..fb9e50f64 100644 --- a/khal/settings/khal.spec +++ b/khal/settings/khal.spec @@ -216,6 +216,10 @@ default_event_duration = timedelta(default='1d') # Define the default duration for an event ('khal new' only) default_dayevent_duration = timedelta(default='1h') +# Whether the mouse should be enabled in interactive mode ('khal interactive' and +# 'ikhal' only) +enable_mouse = boolean(default=True) + # The view section contains configuration options that effect the visual appearance # when using khal and ikhal. diff --git a/khal/ui/__init__.py b/khal/ui/__init__.py index 78892f9a0..39a722376 100644 --- a/khal/ui/__init__.py +++ b/khal/ui/__init__.py @@ -1344,7 +1344,12 @@ def emit(self, record): palette = _add_calendar_colors( getattr(colors, pane._conf['view']['theme']), pane.collection) loop = urwid.MainLoop( - frame, palette, unhandled_input=frame.on_key_press, pop_ups=True) + widget=frame, + palette=palette, + unhandled_input=frame.on_key_press, + pop_ups=True, + handle_mouse=pane._conf['default']['enable_mouse'], + ) frame.loop = loop def redraw_today(loop, pane, meta=None): From d3edf74eb860f46e7cbfe561e64d8a7911bdca72 Mon Sep 17 00:00:00 2001 From: Valentin Iovene Date: Thu, 21 Sep 2023 16:38:48 +0200 Subject: [PATCH 2/6] fix settings_test --- tests/settings_test.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/settings_test.py b/tests/settings_test.py index 22dec9704..586e69628 100644 --- a/tests/settings_test.py +++ b/tests/settings_test.py @@ -55,6 +55,7 @@ def test_simple_config(self): 'default_event_duration': dt.timedelta(days=1), 'default_dayevent_duration': dt.timedelta(hours=1), 'show_all_days': False, + 'enable_mouse': True, } } for key in comp_config: @@ -102,8 +103,8 @@ def test_small(self): 'timedelta': dt.timedelta(days=2), 'default_event_duration': dt.timedelta(days=1), 'default_dayevent_duration': dt.timedelta(hours=1), - - 'show_all_days': False + 'show_all_days': False, + 'enable_mouse': True, } } for key in comp_config: From 0ab2595890e45d034c9b63e20207ddb1430443f9 Mon Sep 17 00:00:00 2001 From: Valentin Iovene Date: Sun, 15 Oct 2023 11:04:56 +0200 Subject: [PATCH 3/6] pos/neg flag as suggested by @WhyNotHugo Co-authored-by: Hugo --- khal/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/khal/cli.py b/khal/cli.py index f86292ac6..7ffe3faf4 100644 --- a/khal/cli.py +++ b/khal/cli.py @@ -94,7 +94,7 @@ def multi_calendar_option(f): def no_mouse_option(f): - o = click.option('--no-mouse', is_flag=True, + o = click.option('--mouse/--no-mouse', is_flag=True, default=True help='Disable mouse in interactive UI') return o(f) From b61cf4add71a087111c9f4cc9c277efc922fa6ee Mon Sep 17 00:00:00 2001 From: Valentin Iovene Date: Mon, 16 Oct 2023 14:30:34 +0200 Subject: [PATCH 4/6] fixes --- khal/cli.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/khal/cli.py b/khal/cli.py index 7ffe3faf4..b723c3360 100644 --- a/khal/cli.py +++ b/khal/cli.py @@ -93,9 +93,13 @@ def multi_calendar_option(f): return d(a(f)) -def no_mouse_option(f): - o = click.option('--mouse/--no-mouse', is_flag=True, default=True - help='Disable mouse in interactive UI') +def mouse_option(f): + o = click.option( + '--mouse/--no-mouse', + is_flag=True, + default=True, + help='Disable mouse in interactive UI' + ) return o(f) @@ -486,12 +490,11 @@ def isatty(_file): @cli.command() @multi_calendar_option - @no_mouse_option + @mouse_option @click.pass_context - def interactive(ctx, include_calendar, exclude_calendar, no_mouse): + def interactive(ctx, include_calendar, exclude_calendar, mouse): '''Interactive UI. Also launchable via `ikhal`.''' - if no_mouse: - ctx.obj['conf']['default']['enable_mouse'] = False + ctx.obj['conf']['default']['enable_mouse'] = mouse controllers.interactive( build_collection( ctx.obj['conf'], @@ -503,13 +506,12 @@ def interactive(ctx, include_calendar, exclude_calendar, no_mouse): @click.command() @global_options @multi_calendar_option - @no_mouse_option + @mouse_option @click.pass_context - def interactive_cli(ctx, config, include_calendar, exclude_calendar, no_mouse): + def interactive_cli(ctx, config, include_calendar, exclude_calendar, mouse): '''Interactive UI. Also launchable via `khal interactive`.''' prepare_context(ctx, config) - if no_mouse: - ctx.obj['conf']['default']['enable_mouse'] = False + ctx.obj['conf']['default']['enable_mouse'] = mouse controllers.interactive( build_collection( ctx.obj['conf'], From e5ff223ae1e6129cf7d7f6f3861e876df70b1425 Mon Sep 17 00:00:00 2001 From: Valentin Iovene Date: Tue, 24 Oct 2023 10:43:52 +0200 Subject: [PATCH 5/6] add myself to AUTHORS --- AUTHORS.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.txt b/AUTHORS.txt index a312f47fe..1f5297dcf 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -52,3 +52,4 @@ Jason Cox - me [at] jasoncarloscox [dot] com - https://jasoncarloscox.com Michael Tretter - michael.tretter [at] posteo [dot] net Raúl Medina - raulmgcontact [at] gmail (dot] com Matthew Rademaker - matthew.rademaker [at] gmail [dot] com +Valentin Iovene - val [at] too [dot] gy From 5d7daabe7ce8c437cfcd02e76e016efc74672635 Mon Sep 17 00:00:00 2001 From: Valentin Iovene Date: Tue, 24 Oct 2023 12:47:13 +0200 Subject: [PATCH 6/6] address geier comment --- khal/cli.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/khal/cli.py b/khal/cli.py index b723c3360..538ff9d4d 100644 --- a/khal/cli.py +++ b/khal/cli.py @@ -97,7 +97,7 @@ def mouse_option(f): o = click.option( '--mouse/--no-mouse', is_flag=True, - default=True, + default=None, help='Disable mouse in interactive UI' ) return o(f) @@ -494,7 +494,8 @@ def isatty(_file): @click.pass_context def interactive(ctx, include_calendar, exclude_calendar, mouse): '''Interactive UI. Also launchable via `ikhal`.''' - ctx.obj['conf']['default']['enable_mouse'] = mouse + if mouse is not None: + ctx.obj['conf']['default']['enable_mouse'] = mouse controllers.interactive( build_collection( ctx.obj['conf'], @@ -511,7 +512,8 @@ def interactive(ctx, include_calendar, exclude_calendar, mouse): def interactive_cli(ctx, config, include_calendar, exclude_calendar, mouse): '''Interactive UI. Also launchable via `khal interactive`.''' prepare_context(ctx, config) - ctx.obj['conf']['default']['enable_mouse'] = mouse + if mouse is not None: + ctx.obj['conf']['default']['enable_mouse'] = mouse controllers.interactive( build_collection( ctx.obj['conf'],