From 39dc0c7b3e0b66e1180e5b8c8c165f992c711555 Mon Sep 17 00:00:00 2001 From: Devrim Date: Mon, 2 Jan 2023 19:45:55 +0300 Subject: [PATCH] fix: jans-cli-tui refactor mouse operations (#3482) * fix: jans-cli-tui refactor mouse operations * fix: jans-cli-tui delete_uma_resource --- jans-cli-tui/cli_tui/jans_cli_tui.py | 163 +++++++----------- .../cli_tui/plugins/010_auth_server/main.py | 2 +- 2 files changed, 68 insertions(+), 97 deletions(-) diff --git a/jans-cli-tui/cli_tui/jans_cli_tui.py b/jans-cli-tui/cli_tui/jans_cli_tui.py index 5ac14ab8027..0c6a7e5d6c7 100755 --- a/jans-cli-tui/cli_tui/jans_cli_tui.py +++ b/jans-cli-tui/cli_tui/jans_cli_tui.py @@ -10,6 +10,7 @@ import asyncio import concurrent.futures +from enum import Enum from pathlib import Path from itertools import cycle from requests.models import Response @@ -392,8 +393,7 @@ def set_keybindings(self) -> None: self.bindings.add(Keys.Vt100MouseEvent)(self.mouse) - - def mouse(self,event): ### mouse: [<35;108;20M + def mouse(self, event): ### mouse: [<35;108;20M pieces = event.data.split(";") ##['LEFT', 'MOUSE_DOWN', '146', '10'] mouse_click=int(pieces[0][3:]) @@ -425,21 +425,23 @@ def mouse(self,event): ### mouse: [<35;108;20M style_tmp = '' style_tmp_red = '' + class mouse_operations(Enum): + Copy = 1 + Cut = 2 + Paste = 3 + res=[] - res.append(HTML(style_tmp.format("Copy"))) - res.append("\n") - res.append(HTML(style_tmp.format("Cut"))) - res.append("\n") - res.append(HTML(style_tmp.format("Paste"))) - res.append("\n") - - content= Window( + for mouse_op in mouse_operations: + res.append(HTML(style_tmp.format(mouse_op.name))) + res.append("\n") + + content = Window( content=FormattedTextControl( text=merge_formatted_text(res), focusable=True, ), height=D()) - floa=Float(content=content, left=x,top=y) - floa.name='mouse' + mouse_float_container = Float(content=content, left=x,top=y) + mouse_float_container.name = 'mouse' # ------------------------------------------------------------------------------------ # # ------------------------------------------------------------------------------------ # @@ -447,112 +449,81 @@ def mouse(self,event): ### mouse: [<35;108;20M if mouse_click == "RIGHT" and mouse_event == MouseEventType.MOUSE_DOWN : if self.mouse_float == True : - self.root_layout.floats.append(floa) + self.root_layout.floats.append(mouse_float_container) self.mouse_cord=(x,y) self.mouse_float = False else: try: - if get_app().layout.container.floats: - if get_app().layout.container.floats[-1].name =='mouse': - get_app().layout.container.floats.remove(get_app().layout.container.floats[-1]) - self.root_layout.floats.append(floa) + if self.layout.container.floats: + if self.layout.container.floats[-1].name =='mouse': + self.layout.container.floats.remove(self.layout.container.floats[-1]) + self.root_layout.floats.append(mouse_float_container) self.mouse_cord=(x,y) self.mouse_float = False else: - self.root_layout.floats.append(floa) + self.root_layout.floats.append(mouse_float_container) self.mouse_cord=(x,y) self.mouse_float = False else: - self.root_layout.floats.append(floa) + self.root_layout.floats.append(mouse_float_container) self.mouse_cord=(x,y) self.mouse_float = False except Exception: pass - + elif mouse_click == "LEFT" and mouse_event == MouseEventType.MOUSE_DOWN and self.mouse_float == False: try: - if get_app().layout.container.floats: - if get_app().layout.container.floats[-1].name =='mouse': - - if self.mouse_select =='Copy': - data = get_app().current_buffer.copy_selection(False) - get_app().clipboard.set_data(data) - get_app().layout.container.floats.remove(get_app().layout.container.floats[-1]) - self.mouse_float = True - - elif self.mouse_select =='Paste': - data = get_app().clipboard.get_data() - get_app().current_buffer.paste_clipboard_data(data) - get_app().layout.container.floats.remove(get_app().layout.container.floats[-1]) - self.mouse_float = True - - elif self.mouse_select =='Cut': - data = get_app().current_buffer.copy_selection(True) - get_app().clipboard.set_data(data) - get_app().layout.container.floats.remove(get_app().layout.container.floats[-1]) - self.mouse_float = True - - else: - get_app().layout.container.floats.remove(get_app().layout.container.floats[-1]) - self.mouse_float = True - + if self.layout.container.floats: + if self.layout.container.floats[-1].name == 'mouse': + self.layout.container.floats.remove(self.layout.container.floats[-1]) + self.mouse_float = True + if self.mouse_select == mouse_operations.Copy.name: + data = self.current_buffer.copy_selection(False) + self.clipboard.set_data(data) + elif self.mouse_select == mouse_operations.Paste.name: + data = self.clipboard.get_data() + self.current_buffer.paste_clipboard_data(data) + elif self.mouse_select == mouse_operations.Cut.name: + data = self.current_buffer.copy_selection(True) + self.clipboard.set_data(data) except Exception: pass - - - if get_app().layout.container.floats: + + if self.layout.container.floats: try : - get_float_name = get_app().layout.container.floats[-1].name + get_float_name = self.layout.container.floats[-1].name except Exception: get_float_name = '' - if get_float_name =='mouse': + if get_float_name == 'mouse': + if self.mouse_cord[0] <= x and self.mouse_cord[0] >= x-5: - if self.mouse_cord[1] == y-1: - res = [] - res.append(HTML(style_tmp_red.format("Copy "))) - res.append("\n") - res.append(HTML(style_tmp.format("Cut"))) - res.append("\n") - res.append(HTML(style_tmp.format("Paste"))) - res.append("\n") - get_app().layout.container.floats[-1].content.content.text=merge_formatted_text(res) - self.mouse_select = 'Copy' - elif self.mouse_cord[1] == y-2: - res = [] - res.append(HTML(style_tmp.format("Copy"))) - res.append("\n") - res.append(HTML(style_tmp_red.format("Cut "))) - res.append("\n") - res.append(HTML(style_tmp.format("Paste"))) - res.append("\n") - get_app().layout.container.floats[-1].content.content.text=merge_formatted_text(res) - self.mouse_select = 'Cut' - elif self.mouse_cord[1] == y-3: - res = [] - res.append(HTML(style_tmp.format("Copy"))) - res.append("\n") - res.append(HTML(style_tmp.format("Cut"))) - res.append("\n") - res.append(HTML(style_tmp_red.format("Paste"))) - res.append("\n") - get_app().layout.container.floats[-1].content.content.text=merge_formatted_text(res) - self.mouse_select = 'Paste' + res = [] + if self.mouse_cord[1] in [y - mouse_op.value for mouse_op in mouse_operations]: + for mouse_op in mouse_operations: + tmp_ = style_tmp + if self.mouse_cord[1] == y - mouse_op.value: + self.mouse_select = mouse_op.name + tmp_ = style_tmp_red + res.append(HTML(tmp_.format(mouse_op.name.ljust(5)))) + res.append("\n") else: - self.mouse_select = 'None' + self.mouse_select = None + + if res: + self.layout.container.floats[-1].content.content.text=merge_formatted_text(res) + else: - res = [] - res.append(HTML(style_tmp.format("Copy"))) + res = [] + for mouse_op in mouse_operations: + res.append(HTML(style_tmp.format(mouse_op.name))) res.append("\n") - res.append(HTML(style_tmp.format("Cut"))) - res.append("\n") - res.append(HTML(style_tmp.format("Paste"))) - res.append("\n") - get_app().layout.container.floats[-1].content.content.text=merge_formatted_text(res) - self.mouse_select = 'None' + self.layout.container.floats[-1].content.content.text=merge_formatted_text(res) + self.mouse_select = None + def up(self, ev: KeyPressEvent) -> None: - get_app().layout.focus(Frame(self.nav_bar.nav_window)) + self.layout.focus(Frame(self.nav_bar.nav_window)) def focus_next(self, ev: KeyPressEvent) -> None: focus_next(ev) @@ -567,13 +538,13 @@ def help(self,ev: KeyPressEvent) -> None: def escape(self,ev: KeyPressEvent) -> None: try: - if get_app().layout.container.floats: - if len(get_app().layout.container.floats) >=2 : - get_app().layout.container.floats.remove(get_app().layout.container.floats[-1]) - get_app().layout.focus(get_app().layout.container.floats[-1].content) + if self.layout.container.floats: + if len(self.layout.container.floats) >=2 : + self.layout.container.floats.remove(self.layout.container.floats[-1]) + self.layout.focus(self.layout.container.floats[-1].content) else: - get_app().layout.container.floats.remove(get_app().layout.container.floats[0]) - get_app().layout.focus(self.center_frame) + self.layout.container.floats.remove(self.layout.container.floats[0]) + self.layout.focus(self.center_frame) except Exception as e: pass diff --git a/jans-cli-tui/cli_tui/plugins/010_auth_server/main.py b/jans-cli-tui/cli_tui/plugins/010_auth_server/main.py index 6990ff5a6a3..f5fba51eba2 100755 --- a/jans-cli-tui/cli_tui/plugins/010_auth_server/main.py +++ b/jans-cli-tui/cli_tui/plugins/010_auth_server/main.py @@ -730,7 +730,7 @@ async def coroutine(): asyncio.ensure_future(coroutine()) - def delete_UMAresource(self, **kwargs: Any): + def delete_uma_resource(self, **kwargs: Any): """This method for the deletion of the UMAresource Returns: