Skip to content
This repository was archived by the owner on Jun 30, 2023. It is now read-only.

Commit 843c4c2

Browse files
authored
make working again with the new ui events "contract" (#35)
i e ignore new parameters and events also fix button press issue
1 parent 64a5f39 commit 843c4c2

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

neovim_gui/cli.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
from .ui_bridge import UIBridge
77
from neovim import attach
8-
from neovim.compat import IS_PYTHON3
98

109

1110
@click.command(context_settings=dict(allow_extra_args=True))

neovim_gui/gtk_ui.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def __init__(self, font):
9595

9696
def start(self, bridge):
9797
"""Start the UI event loop."""
98-
bridge.attach(80, 24, True)
98+
bridge.attach(80, 24, rgb=True)
9999
drawing_area = Gtk.DrawingArea()
100100
drawing_area.connect('draw', self._gtk_draw)
101101
window = Gtk.Window()
@@ -378,6 +378,7 @@ def _gtk_button_press(self, widget, event, *args):
378378
input_str += '<{0},{1}>'.format(col, row)
379379
self._bridge.input(input_str)
380380
self._pressed = button
381+
return True
381382

382383
def _gtk_button_release(self, widget, event, *args):
383384
self._pressed = None

neovim_gui/ui_bridge.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
"""Bridge for connecting a UI instance to nvim."""
22
import sys
3+
import os
34
from threading import Semaphore, Thread
45
from traceback import format_exc
6+
from inspect import signature
57

68

79
class UIBridge(object):
@@ -20,6 +22,7 @@ def connect(self, nvim, ui, profile=None, notify=False):
2022
self._ui = ui
2123
self._profile = profile
2224
self._sem = Semaphore(0)
25+
self.debug_events = len(os.environ.get("NVIM_PYTHON_UI_DEBUG", "")) > 0
2326
t = Thread(target=self._nvim_event_loop)
2427
t.daemon = True
2528
t.start()
@@ -42,9 +45,9 @@ def resize(self, columns, rows):
4245
"""Send a resize request to nvim."""
4346
self._call(self._nvim.ui_try_resize, columns, rows)
4447

45-
def attach(self, columns, rows, rgb):
48+
def attach(self, columns, rows, **options):
4649
"""Attach the UI to nvim."""
47-
self._call(self._nvim.ui_attach, columns, rows, rgb)
50+
self._call(self._nvim.api.ui_attach, columns, rows, options)
4851

4952
def detach(self):
5053
"""Detach the UI from nvim."""
@@ -90,12 +93,17 @@ def apply_updates():
9093
# print >> sys.stderr, update[0], ' '.join(l)
9194
try:
9295
handler = getattr(self._ui, '_nvim_' + update[0])
96+
nparam = len(signature(handler).parameters)
97+
9398
except AttributeError:
94-
pass
99+
if self.debug_events:
100+
print(repr(update), file=sys.stderr)
95101
else:
102+
if self.debug_events and len(update[1]) > nparam:
103+
print(repr(update), file=sys.stderr)
96104
for args in update[1:]:
97-
handler(*args)
98-
except:
105+
handler(*args[:nparam])
106+
except Exception:
99107
self._error = format_exc()
100108
self._call(self._nvim.quit)
101109
if method == 'redraw':

0 commit comments

Comments
 (0)