Skip to content

Commit

Permalink
ver 0.1.8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
blademd committed Jun 4, 2024
1 parent fece6d8 commit 79e1860
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 45 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ Thymus supports:

## Installation

Use `pip` or `pipx` to install the package (e.g., `pip install thymus` or `pipx install thymus`). Requires Python **3.9**!
Use `pip` or `pipx` to install the package (e.g., `pip install thymus` or `pipx install thymus`).

Requires Python **3.9**!

## Operations

Expand Down
20 changes: 10 additions & 10 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[tool.poetry]
name = "thymus"
version = "0.1.8"
version = "0.1.8.1"
description = "Editor & browser for network configuration files"
authors = ["Igor Malyushkin <gmalyushkin@gmail.com>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.9"
textual = "0.61.0"
thymus-ast = "^0.1.8"
textual = "0.64.0"
thymus-ast = "^0.1.8.2"
asyncssh = "^2.14.1"
telnetlib3 = "^2.0.4"
bcrypt = "^4.1.1"
Expand Down
2 changes: 1 addition & 1 deletion thymus/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '0.1.8'
__version__ = '0.1.8.1'

LOGO = """\
▄▄▄█████▓ ██░ ██▓██ ██▓ ███▄ ▄███▓ █ ██ ██████
Expand Down
36 changes: 29 additions & 7 deletions thymus/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from textual import on
from textual.app import App, ComposeResult
from textual.binding import Binding
from textual.widgets import Footer, Label
from textual.containers import Vertical
from textual.events import Resize
Expand All @@ -19,9 +20,11 @@
class Thymus(App):
CSS_PATH = 'styles/main.css'
BINDINGS = [
('ctrl+o', 'request_open', 'Open'),
('ctrl+l', 'request_switch', 'List screens'),
('ctrl+s', 'request_settings', 'Settings'),
Binding('ctrl+o', 'request_open', 'Open'),
Binding('ctrl+l', 'request_switch', 'List screens'),
Binding('ctrl+s', 'request_settings', 'Settings'),
Binding('ctrl+c', 'request_quit', 'Quit'),
Binding('ctrl+p', 'request_screenshot', 'Screenshot', show=False),
]

def __init__(self) -> None:
Expand Down Expand Up @@ -56,19 +59,38 @@ def action_request_settings(self) -> None:

self.push_screen('settings_screen')

def action_request_quit(self) -> None:
from thymus.modals import QuitScreen

self.app.push_screen(QuitScreen('Do you really want to close Thymus?'), self.on_quit_cb)

def action_request_screenshot(self) -> None:
from pathlib import Path

try:
path = Path(self.app_settings['wrapper_folder'].value).expanduser()
path = path / Path(Path(self.app_settings['screens_folder'].value))

self.save_screenshot(path=str(path))
except Exception as error:
self.app_settings.logger.error(f'Screenshot saving error.\n{error}')

# EVENTS

def on_ready(self) -> None:
self.dark = self.app_settings['night_mode'].value

def on_resize(self, event: Resize) -> None:
# TODO: account for the left panel presence
# TODO: change with a simple text
def on_quit_cb(self, result: bool) -> None:
if result:
self.app.exit()

def on_resize(self, event: Resize) -> None:
try:
for control in self.query(Vertical):
if 'logo' in control.classes:
if event.virtual_size.width <= 120:
width = 55 if len(self.screen_stack) == 1 else 120

if event.virtual_size.width <= width:
if control.styles.display != 'none':
control.styles.display = 'none'
else:
Expand Down
20 changes: 10 additions & 10 deletions thymus/contexts/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ def heuristics(self) -> bool:
def heuristics(self, value: bool | str) -> None:
if type(value) is not bool:
if type(value) is str:
if value in ('0', 'off'):
if value.lower() in ('0', 'off', 'false'):
value = False
elif value in ('1', 'on'):
elif value.lower() in ('1', 'on', 'true'):
value = True
else:
raise ValueError(f'Incorrect value for "heuristics": {value}.')
Expand All @@ -85,9 +85,9 @@ def base_heuristics(self) -> bool:
def base_heuristics(self, value: bool | str) -> None:
if type(value) is not bool:
if type(value) is str:
if value in ('0', 'off'):
if value.lower() in ('0', 'off', 'false'):
value = False
elif value in ('1', 'on'):
elif value.lower() in ('1', 'on', 'true'):
value = True
else:
raise ValueError(f'Incorrect value for "base_heuristics": {value}.')
Expand All @@ -109,9 +109,9 @@ def crop(self) -> bool:
def crop(self, value: bool | str) -> None:
if type(value) is not bool:
if type(value) is str:
if value in ('0', 'off'):
if value.lower() in ('0', 'off', 'false'):
value = False
elif value in ('1', 'on'):
elif value.lower() in ('1', 'on', 'true'):
value = True
else:
raise ValueError(f'Incorrect value for "crop": {value}.')
Expand All @@ -136,9 +136,9 @@ def promisc(self) -> bool:
def promisc(self, value: bool | str) -> None:
if type(value) is not bool:
if type(value) is str:
if value in ('0', 'off'):
if value.lower() in ('0', 'off', 'false'):
value = False
elif value in ('1', 'on'):
elif value.lower() in ('1', 'on', 'true'):
value = True
else:
raise ValueError(f'Incorrect value for "promisc": {value}.')
Expand All @@ -160,9 +160,9 @@ def find_head(self) -> bool:
def find_head(self, value: bool | str) -> None:
if type(value) is not bool:
if type(value) is str:
if value in ('0', 'off'):
if value.lower() in ('0', 'off', 'false'):
value = False
elif value in ('1', 'on'):
elif value.lower() in ('1', 'on', 'true'):
value = True
else:
raise ValueError(f'Incorrect value for "find_head": {value}.')
Expand Down
25 changes: 18 additions & 7 deletions thymus/modals/open_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,30 @@ def __init__(self, settings: AppSettings) -> None:
self.path = path

self.platforms = settings.platforms
self.last_platform: int = settings['last_opened_platform'].value
self.last_platform: str = settings['last_opened_platform'].value

# COMPOSE

def compose_platforms(self) -> ComposeResult:
if len(self.platforms) < self.last_platform:
self.last_platform = 0

yield Static('Select platform:')

with ExtendedListView(initial_index=self.last_platform + 1, id='open-screen-switches-platform'):
for name, platform in self.platforms.items():
yield ListItem(Label(platform['short_name'].value, name=name))
with ExtendedListView(id='open-screen-switches-platform'):
if self.last_platform:
if self.last_platform in self.platforms:
platform = self.platforms[self.last_platform]
yield ListItem(Label(platform['short_name'].value, name=self.last_platform))

for name, platform in self.platforms.items():
if name == self.last_platform:
continue

yield ListItem(Label(platform['short_name'].value, name=name))
else:
for name, platform in self.platforms.items():
yield ListItem(Label(platform['short_name'].value, name=name))
else:
for name, platform in self.platforms.items():
yield ListItem(Label(platform['short_name'].value, name=name))

def compose(self) -> ComposeResult:
with Horizontal(id='open-screen-main-block'):
Expand Down
6 changes: 5 additions & 1 deletion thymus/modals/quit_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@


class QuitScreen(ModalScreen[bool]):
def __init__(self, message: str) -> None:
super().__init__()
self.message = message

def compose(self) -> ComposeResult:
with Grid(id='quit-screen-dialog'):
yield Label('Do you really want to close this context?', id='quit-screen-question')
yield Label(self.message, id='quit-screen-question')
yield Button('Cancel', variant='primary', id='quit-screen-cancel-button')
yield Button('Close', variant='error', id='quit-screen-close-button')

Expand Down
6 changes: 2 additions & 4 deletions thymus/settings/app_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@ class AppSettings:
'wrapper_folder': StrSetting('~/thymus_data', show=False, read_only=True),
'templates_folder': StrSetting('templates', show=False, read_only=True),
'system_encoding': StrSetting('UTF-8', encoding=True),
'last_opened_platform': IntSetting(2, negative=False, show=False),
'last_opened_platform': StrSetting('', show=False),
'default_folder': StrSetting('~/thymus_data/saves', description='default path for the open dialog'),
'saves_folder': StrSetting('saves'),
'screens_folder': StrSetting('screenshots'),
'logging_folder': StrSetting('log'),
'logging_level': StrSetting('DEBUG', fixed_values=('CRITICAL', 'ERROR', 'WARNING', 'INFO', 'DEBUG')),
'logging_file': StrSetting('thymus.log'),
'logging_file_max_size': IntSetting(5000000, non_zero=True, negative=False, description='in bytes'),
'logging_max_files': IntSetting(5, non_zero=True, negative=False),
'logging_buffer_capacity': IntSetting(
65535,
Expand Down Expand Up @@ -291,8 +290,7 @@ def update_last_opened_platform(self, platform: Platform) -> None:
return

try:
keys = list(self.platforms.keys())
self.settings['last_opened_platform'].value = keys.index(k)
self.settings['last_opened_platform'].value = k
self.dump()
except (KeyError, ValueError):
return
8 changes: 7 additions & 1 deletion thymus/working_screen/working_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ def on_show(self) -> None:
self.query_one(CommandLine).focus()

def on_release(self) -> None:
if self.drawing_thread:
self.drawing_thread.cancel()

if (editor := self.query_one(Editor)).drawing_thread:
editor.drawing_thread.cancel()

for context in self.contexts:
context.release()

Expand Down Expand Up @@ -260,7 +266,7 @@ def watch_mode(self) -> None:
def action_request_quit(self) -> None:
from thymus.modals import QuitScreen

self.app.push_screen(QuitScreen(), self.on_quit_cb)
self.app.push_screen(QuitScreen('Do you really want to close this context?'), self.on_quit_cb)

def action_toggle_sidebar(self) -> None:
sidebar = self.query_one('#working-screen-left-siderbar')
Expand Down

0 comments on commit 79e1860

Please sign in to comment.