Skip to content

Commit

Permalink
sisoe24/1.1.0 (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
sisoe24 committed Aug 21, 2024
1 parent 144c4bb commit 60cb950
Show file tree
Hide file tree
Showing 18 changed files with 277 additions and 142 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## [1.1.0] - 2024-08-18

### Added

* Added color to logs

### Fixed

* [[#30](https://github.com/sisoe24/nukeserversocket/issues/30)]
* [#31](https://github.com/sisoe24/nukeserversocket/issues/31)
* [#32](https://github.com/sisoe24/nukeserversocket/issues/32)
* Logs font now use proper monospace font

## [1.0.0] - 2023-11-19

Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,30 @@ For a full list of changes, see the [CHANGELOG](https://github.com/sisoe24/nukes
Client applications that use nukeserversocket:
- [Nuke Tools](https://marketplace.visualstudio.com/items?itemName=virgilsisoe.nuke-tools) - Visual Studio Code extension.
- [nuketools.nvim](https://github.com/sisoe24/nuketools.nvim) - Neovim plugin.
- [Nuke Tools ST](https://packagecontrol.io/packages/NukeToolsST) - Sublime Text package.
- [DCC WebSocket](https://marketplace.visualstudio.com/items?itemName=virgilsisoe.dcc-websocket) - Visual Studio Code Web extension (deprecated at the moment).
### 1.3.1. Create a custom client
You can create a custom client in any programming language that supports socket communication. The client sends the code to the server, which then executes it in Nuke and sends back the result. For more information, see the [wiki page](https://github.com/sisoe24/nukeserversocket/wiki/Client-Applications-for-NukeServerSocket)
```py
# ... your socket code
data = {
"text": "print([n.name() for n in nuke.allNodes()])",
"file" : "path/to/file.py",
"formatText": "0"
}
s.sendall(bytearray(json.dumps(data), 'utf-8'))
data = s.recv(1024)
s.close()
nodes = json.loads(data.decode('utf-8').replace("'", '"'))
for node in nodes:
print(node)
```
## 1.4. Installation
1. Download the repository via the [releases page](https://github.com/sisoe24/nukeserversocket/releases) or by cloning it from GitHub.
Expand Down
26 changes: 22 additions & 4 deletions nukeserversocket/console.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
from __future__ import annotations

import sys
import logging

from PySide2.QtCore import Slot
from PySide2.QtWidgets import (QCheckBox, QGroupBox, QHBoxLayout, QPushButton,
QVBoxLayout, QPlainTextEdit)

from .utils import cache
from .logger import get_logger

LOGGER = get_logger()

LOG_COLORS = {
'DEBUG': 'aqua',
'INFO': 'white',
'WARNING': 'orange',
'ERROR': 'red',
'CRITICAL': 'magenta',
}


class NssConsole(QGroupBox):
def __init__(self, parent=None):
super().__init__(parent, title='Logs')

self._console = QPlainTextEdit()
self._console.setStyleSheet('font-family: menlo;')

if sys.platform == 'darwin':
font = 'menlo'
elif sys.platform == 'win32':
font = 'consolas'
else:
font = 'monospace'

self._console.setStyleSheet(f'font-family: {font};')
self._console.setReadOnly(True)
self._console.setLineWrapMode(QPlainTextEdit.NoWrap)

Expand Down Expand Up @@ -50,8 +66,10 @@ def __init__(self, parent=None):
def _on_enable_debug(self, state: int) -> None:
LOGGER.console.setLevel(logging.DEBUG if state == 2 else logging.INFO)

def write(self, text: str) -> None:
self._console.insertPlainText(text)
def write(self, text: str, level_name: str = 'INFO') -> None:
color = LOG_COLORS.get(level_name, 'white')
text = text.replace(' ', ' ')
self._console.appendHtml(f'<font color="{color}">{text}</font>')
self._console.verticalScrollBar().setValue(
self._console.verticalScrollBar().maximum()
)
27 changes: 22 additions & 5 deletions nukeserversocket/controllers/local_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
from __future__ import annotations

import sys
import traceback

from PySide2.QtWidgets import (QLabel, QTextEdit, QPushButton, QApplication,
from PySide2.QtWidgets import (QLabel, QWidget, QTextEdit, QHBoxLayout,
QPushButton, QSizePolicy, QApplication,
QPlainTextEdit)

from ..main import NukeServerSocket
Expand All @@ -19,8 +21,12 @@ class LocalController(EditorController):
def __init__(self):
super().__init__()
self._input_editor = QPlainTextEdit()
self._input_editor.setPlaceholderText('Enter your code here...')
self._input_editor.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Maximum)

self._output_editor = QTextEdit()
self._output_editor.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Maximum)
self._output_editor.setPlaceholderText('Output will be shown here...')
self._output_editor.setReadOnly(True)

@property
Expand All @@ -33,8 +39,13 @@ def output_editor(self) -> QTextEdit:

def execute(self) -> None:
with stdoutIO() as s:
exec(self.input_editor.toPlainText())
result = s.getvalue()
try:
exec(self.input_editor.toPlainText())
except Exception:
result = traceback.format_exc()
else:
result = s.getvalue()

self.output_editor.setPlainText(result)


Expand All @@ -46,10 +57,16 @@ def __init__(self):
run_button.clicked.connect(self.editor.execute)
run_button.setShortcut('Ctrl+R')

lower_layout = QHBoxLayout()
lower_layout.addWidget(self.editor.input_editor)
lower_layout.addWidget(self.editor.output_editor)

lower_widget = QWidget()
lower_widget.setLayout(lower_layout)

main_layout = self.view.layout()
main_layout.addWidget(QLabel('<h3>Local Editor</h3>'))
main_layout.addWidget(self.editor.output_editor)
main_layout.addWidget(self.editor.input_editor)
main_layout.addWidget(lower_widget)
main_layout.addWidget(run_button)


Expand Down
2 changes: 1 addition & 1 deletion nukeserversocket/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, console: NssConsole) -> None:
self._console = console

def emit(self, record: logging.LogRecord) -> None:
self._console.write(self.format(record) + '\n')
self._console.write(self.format(record) + '\n', record.levelname)


def _file_handler() -> TimedRotatingFileHandler:
Expand Down
14 changes: 10 additions & 4 deletions nukeserversocket/received_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ def __post_init__(self):
self.data.setdefault('file', '')
self.data.setdefault('formatText', '1')
except Exception as e:
LOGGER.error(
f'Nukeserversocket: An exception occurred while decoding the data. {e}'
)
LOGGER.error(f'An exception occurred while decoding the data. {e}')
self.data = {'text': '', 'file': '', 'formatText': '1'}

LOGGER.debug('Received data: %s', self.data)
Expand All @@ -49,4 +47,12 @@ def __post_init__(self):
LOGGER.critical('Data does not contain a text field.')

self.file = self.data['file']
self.format_text = bool(int(self.data['formatText']))

try:
self.format_text = bool(int(self.data['formatText']))
except ValueError:
LOGGER.error(
'formatText must be either "0" or "1". Got "%s". Fallback to "1".',
self.data['formatText']
)
self.format_text = True
4 changes: 1 addition & 3 deletions nukeserversocket/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
from __future__ import annotations

__version__ = '1.0.0'
__version__ = '1.1.0'
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[tool.poetry]
name = "nukeserversocket"
version = "1.0.0"
version = "1.1.0"
description = "A Nuke plugin that will allow code execution from the local network via TCP/WebSocket connections and more."
authors = ["virgilsisoe <[email protected]>"]

[tool.poetry.scripts]
nukeserversocket = "nukeserversocket.controllers.local_app:main"
build = "release_manager:build"
build = "scripts.release_manager:main"

[tool.isort]
skip = ["__init__.py"]
skip = ["__init__.py" , "version.py"]
length_sort = true
add_imports = "from __future__ import annotations"

Expand Down Expand Up @@ -38,9 +38,9 @@ addopts = [

[tool.poetry.dependencies]
python = ">=3.7.7,<3.11"
pyside2 = "5.15.2.1"

[tool.poetry.group.dev.dependencies]
pyside2 = "5.15.2.1"
pytest = "^7.4.3"
tox = "4.8.0"
pytest-qt = "^4.2.0"
Expand Down
61 changes: 0 additions & 61 deletions release_manager.py

This file was deleted.

Loading

0 comments on commit 60cb950

Please sign in to comment.