[Update] クリップボード機能を統合し、コピーとペーストを一度の呼び出しで実行できるように変更
This commit is contained in:
@@ -424,8 +424,7 @@ class Controller:
|
|||||||
|
|
||||||
if config.ENABLE_CLIPBOARD is True:
|
if config.ENABLE_CLIPBOARD is True:
|
||||||
clipboard_message = self.messageFormatter("SEND", translation, message)
|
clipboard_message = self.messageFormatter("SEND", translation, message)
|
||||||
model.setCopyToClipboard(clipboard_message)
|
model.setCopyToClipboardAndPasteFromClipboard(clipboard_message)
|
||||||
model.setPasteFromClipboard()
|
|
||||||
|
|
||||||
if model.checkWebSocketServerAlive() is True:
|
if model.checkWebSocketServerAlive() is True:
|
||||||
model.websocketSendMessage(
|
model.websocketSendMessage(
|
||||||
@@ -779,11 +778,6 @@ class Controller:
|
|||||||
)
|
)
|
||||||
model.updateOverlayLargeLog(overlay_image)
|
model.updateOverlayLargeLog(overlay_image)
|
||||||
|
|
||||||
if config.ENABLE_CLIPBOARD is True:
|
|
||||||
clipboard_message = self.messageFormatter("SEND", translation, message)
|
|
||||||
model.setCopyToClipboard(clipboard_message)
|
|
||||||
model.setPasteFromClipboard()
|
|
||||||
|
|
||||||
if model.checkWebSocketServerAlive() is True:
|
if model.checkWebSocketServerAlive() is True:
|
||||||
model.websocketSendMessage(
|
model.websocketSendMessage(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1299,11 +1299,11 @@ class Model:
|
|||||||
errorLogging()
|
errorLogging()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def setCopyToClipboard(self, text:str) -> bool:
|
def setCopyToClipboardAndPasteFromClipboard(self, text:str) -> bool:
|
||||||
self.ensure_initialized()
|
self.ensure_initialized()
|
||||||
try:
|
try:
|
||||||
if isinstance(self.clipboard, Clipboard):
|
if isinstance(self.clipboard, Clipboard):
|
||||||
self.clipboard.copy(text)
|
self.clipboard.copy_and_paste(text)
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
@@ -1311,17 +1311,6 @@ class Model:
|
|||||||
errorLogging()
|
errorLogging()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def setPasteFromClipboard(self) -> bool:
|
|
||||||
self.ensure_initialized()
|
|
||||||
try:
|
|
||||||
if isinstance(self.clipboard, Clipboard):
|
|
||||||
return self.clipboard.paste()
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
except Exception:
|
|
||||||
errorLogging()
|
|
||||||
return False
|
|
||||||
|
|
||||||
def telemetryInit(self, enabled: bool, app_version: str):
|
def telemetryInit(self, enabled: bool, app_version: str):
|
||||||
"""Model 内で Telemetry を初期化"""
|
"""Model 内で Telemetry を初期化"""
|
||||||
self.telemetry.init(enabled=enabled, app_version=app_version)
|
self.telemetry.init(enabled=enabled, app_version=app_version)
|
||||||
|
|||||||
@@ -139,7 +139,6 @@ def paste_via_pyautogui(countdown: int = 0) -> bool:
|
|||||||
|
|
||||||
class Clipboard:
|
class Clipboard:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.is_enabled = True
|
|
||||||
self._vr_monitor_thread = None
|
self._vr_monitor_thread = None
|
||||||
self._stop_monitoring = False
|
self._stop_monitoring = False
|
||||||
self.app_name = None
|
self.app_name = None
|
||||||
@@ -192,47 +191,7 @@ class Clipboard:
|
|||||||
printLog(f"Clipboard: Error setting up VR app name: {e}")
|
printLog(f"Clipboard: Error setting up VR app name: {e}")
|
||||||
self.app_name = None
|
self.app_name = None
|
||||||
|
|
||||||
def enable(self):
|
def copy_and_paste(self, message: str, window_name: str|None = None, countdown: int = 0) -> bool:
|
||||||
"""Enable clipboard functionality. Reinitialize the class."""
|
|
||||||
printLog("Clipboard: Enabling clipboard functionality.")
|
|
||||||
self.is_enabled = True
|
|
||||||
self._initialize()
|
|
||||||
|
|
||||||
def disable(self):
|
|
||||||
"""Disable clipboard functionality. Stop VR monitoring."""
|
|
||||||
printLog("Clipboard: Disabling clipboard functionality.")
|
|
||||||
self.is_enabled = False
|
|
||||||
self._stop_monitoring = True
|
|
||||||
if self._vr_monitor_thread is not None and self._vr_monitor_thread.is_alive():
|
|
||||||
self._vr_monitor_thread.join(timeout=1)
|
|
||||||
self._vr_monitor_thread = None
|
|
||||||
|
|
||||||
def copy(self, message: str) -> bool:
|
|
||||||
"""Copy `message` to clipboard.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
message: Text to copy.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
True if copy succeeded, False otherwise.
|
|
||||||
"""
|
|
||||||
if not self.is_enabled:
|
|
||||||
return False
|
|
||||||
return copy_to_clipboard(message)
|
|
||||||
|
|
||||||
def paste(self, window_name: str|None = None, countdown: int = 0) -> bool:
|
|
||||||
"""Focus a window identified by `window_name`, then paste via Ctrl+V.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
window_name: Window title substring or process name to find and focus (Windows only). Required.
|
|
||||||
countdown: Seconds to wait before sending paste key.
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
True if paste command was sent, False otherwise.
|
|
||||||
"""
|
|
||||||
if not self.is_enabled:
|
|
||||||
return False
|
|
||||||
|
|
||||||
window_name = window_name if window_name is not None else self.app_name
|
window_name = window_name if window_name is not None else self.app_name
|
||||||
|
|
||||||
# If window_name is provided, attempt to focus it (Windows only).
|
# If window_name is provided, attempt to focus it (Windows only).
|
||||||
@@ -265,11 +224,17 @@ class Clipboard:
|
|||||||
# small delay to allow focus to settle
|
# small delay to allow focus to settle
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
|
|
||||||
|
# copy
|
||||||
|
copied = copy_to_clipboard(message)
|
||||||
|
if not copied:
|
||||||
|
printLog("copy_and_paste: failed to copy to clipboard")
|
||||||
|
return False
|
||||||
# paste
|
# paste
|
||||||
pasted = paste_via_pyautogui(countdown)
|
pasted = paste_via_pyautogui(countdown)
|
||||||
return bool(pasted)
|
return bool(pasted)
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
clipboard = Clipboard()
|
clipboard = Clipboard()
|
||||||
clipboard.copy("Sample text to copy to clipboard.")
|
clipboard.copy_and_paste("Sample text to copy to clipboard.", window_name=None, countdown=3)
|
||||||
clipboard.paste(window_name=None, countdown=3)
|
|
||||||
Reference in New Issue
Block a user