Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
ankraft committed Oct 8, 2024
2 parents fff8a10 + 3074b34 commit cf6e34f
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Please see the [Changelog](CHANGELOG.md) and this [discussion](https://github.co

### What to expect in the next release

See the [announcement](https://github.com/ankraft/ACME-oneM2M-CSE/discussions/160) in the [discussions](https://github.com/ankraft/ACME-oneM2M-CSE/discussions).
See the [announcement](https://github.com/ankraft/ACME-oneM2M-CSE/discussions/166) in the [discussions](https://github.com/ankraft/ACME-oneM2M-CSE/discussions).

## Acknowledgements

Expand Down
4 changes: 2 additions & 2 deletions acme/textui/ACMEContainerRequests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"""

from __future__ import annotations
import pyperclip, json
import json

from typing import Optional, List, cast, Any
from textual import events
Expand Down Expand Up @@ -167,7 +167,7 @@ def on_click(self, event:events.Click) -> None:
t = 'Response Copied'
case _:
return
pyperclip.copy(v)
self._app.copyToClipboard(v)
self._app.showNotification(limitLines(v, 5), t, 'information')


Expand Down
4 changes: 1 addition & 3 deletions acme/textui/ACMEContainerResourceServices.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
from __future__ import annotations
from typing import cast

import pyperclip

from textual import on
from textual.app import ComposeResult
from textual.containers import Container, Horizontal, VerticalScroll, Vertical
Expand Down Expand Up @@ -197,7 +195,7 @@ def _copyInstances() -> None:
count, data = CSE.console.doExportInstances(self.resource.ri, asString = True)
self.exportInstancesLoadingIndicator.display = False
self.exportInstancesResult.display = True
pyperclip.copy(data)
self._app.copyToClipboard(data)
self.exportInstancesResult.update(n := f'Copied [{self._app.objectColor}]{count}[/] data point(s) to the clipboard')
self._app.showNotification(n, 'Data Points Copy', 'information')

Expand Down
8 changes: 4 additions & 4 deletions acme/textui/ACMEContainerTree.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from __future__ import annotations
from typing import List, Tuple, Optional, Any, cast

import pyperclip, json
import json

from textual import events
from textual.app import ComposeResult
Expand Down Expand Up @@ -326,7 +326,7 @@ def on_click(self, event:events.Click) -> None:
if event.x > len(v) + 3 and event.x < len(v) + 6 + len(ri):
v = ri
t = 'Resource Identifier Copied'
pyperclip.copy(v)
self._app.copyToClipboard(v)
self._app.showNotification(v, t, 'information')

# When clicking on the top border: Copy the resource name or type
Expand All @@ -338,12 +338,12 @@ def on_click(self, event:events.Click) -> None:
if event.x > len(v) + 3 and event.x < len(v) + 6 + len(rt):
v = rt
t = 'Resource Type Copied'
pyperclip.copy(v)
self._app.copyToClipboard(v)
self._app.showNotification(v, t, 'information')

# When clicking on the resource view
elif self.screen.get_widget_at(event.screen_x, event.screen_y)[0] is self.resourceView:
pyperclip.copy(v := json.dumps(self.currentResource.asDict(sort = True), indent = 2))
self._app.copyToClipboard(v := json.dumps(self.currentResource.asDict(sort = True), indent = 2))
self._app.showNotification(limitLines(v, 5), 'Resource Copied', 'information')


Expand Down
3 changes: 1 addition & 2 deletions acme/textui/ACMEContentDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from textual.events import Click
from textual.containers import Center, ScrollableContainer, Vertical
from rich.syntax import Syntax
import pyperclip

class ACMEContentDialog(ModalScreen):
""" A modal dialog for displaying content in the ACME text UI.
Expand Down Expand Up @@ -51,7 +50,7 @@ def compose(self) -> ComposeResult:

def on_button_pressed(self, event: Button.Pressed) -> None:
if event.button.id == 'dialog-copy':
pyperclip.copy(self.content)
self._app.copyToClipboard(self.content)
self.app.pop_screen()
self.app.notify('Copied to clipboard.')

Expand Down
15 changes: 15 additions & 0 deletions acme/textui/ACMETuiApp.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from typing_extensions import Literal, get_args
import asyncio
from enum import IntEnum, auto
import pyperclip
from textual.app import App, ComposeResult
from textual import on
from textual.widgets import Footer, TabbedContent, TabPane, Static
Expand Down Expand Up @@ -172,6 +173,20 @@ def debugConsole(self) -> Static:
return self._debugConsole


def copyToClipboard(self, text: str) -> None:
try:
pyperclip.copy(text)
except pyperclip.PyperclipException as e:
self.showNotification(f'Error copying to clipboard: {e}', 'Clipboard Error', 'error')


def pasteFromClipboard(self) -> str:
try:
return pyperclip.paste()
except pyperclip.PyperclipException as e:
self.showNotification(f'Error pasting from clipboard: {e}', 'Clipboard Error', 'error')
return ''

def on_load(self) -> None:
self.dark = Configuration.textui_theme == 'dark'
self.syntaxTheme = 'ansi_dark' if self.dark else 'ansi_light'
Expand Down
8 changes: 5 additions & 3 deletions acme/textui/ACMEViewRequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from typing import cast, Optional, Callable
from copy import deepcopy
import json
import pyperclip

from rich.syntax import Syntax
from textual import on
Expand Down Expand Up @@ -44,14 +43,17 @@ class ACMETextArea(TextArea):
Binding('ctrl+v', 'paste_from_clipboard', 'paste', key_display = 'CTRL-v'),
]


def action_copy_to_clipboard(self) -> None:
pyperclip.copy(self.selected_text)
from ..textui.ACMETuiApp import ACMETuiApp
cast(ACMETuiApp, self.app).copyToClipboard(self.selected_text)


def action_paste_from_clipboard(self) -> None:
self.begin_capture_print()
from ..textui.ACMETuiApp import ACMETuiApp
self.replace(
pyperclip.paste(),
cast(ACMETuiApp, self.app).pasteFromClipboard(),
self.selection.start,
self.selection.end,
)
Expand Down

0 comments on commit cf6e34f

Please sign in to comment.