Skip to content

Commit

Permalink
version bump
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Aug 25, 2021
1 parent e1d03a3 commit 577ef6b
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 49 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [0.1.10] - Unreleased
## [0.1.10] - 2021-08-25

### Added

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/actions/colorizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ async def on_load(self):
await self.bind("g", "color('green')")
await self.bind("b", "color('blue')")

async def action_color(self, color: str) -> None:
def action_color(self, color: str) -> None:
self.background = f"on {color}"


Expand Down
2 changes: 1 addition & 1 deletion examples/code_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async def on_mount(self) -> None:

# Note the directory is also in a scroll view
await self.view.dock(
ScrollView(self.directory), edge="left", size=64, name="sidebar"
ScrollView(self.directory), edge="left", size=48, name="sidebar"
)
await self.view.dock(self.body, edge="top")

Expand Down
2 changes: 1 addition & 1 deletion src/textual/binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def bind(
description,
show=show,
key_display=key_display,
allow_forward=True,
allow_forward=allow_forward,
)

def get_key(self, key: str) -> Binding:
Expand Down
1 change: 0 additions & 1 deletion src/textual/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ def y_extents(self) -> tuple[int, int]:
Returns:
tuple[int, int]: [description]
"""
return (self.x, self.x + self.width)
return (self.y, self.y + self.height)

@property
Expand Down
6 changes: 2 additions & 4 deletions src/textual/message_pump.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
import asyncio
from asyncio import CancelledError
from asyncio import Queue, QueueEmpty, Task
import inspect
from typing import TYPE_CHECKING, Awaitable, Iterable, Callable
from weakref import WeakSet

from rich.traceback import Traceback

from . import events
from . import log
from ._timer import Timer, TimerCallback
Expand Down Expand Up @@ -174,7 +171,7 @@ async def process_messages(self) -> None:
except CancelledError:
pass
finally:
self._runnning = False
self._running = False

async def _process_messages(self) -> None:
"""Process messages until the queue is closed."""
Expand All @@ -195,6 +192,7 @@ async def _process_messages(self) -> None:
pending = self.peek_message()
if pending is None or not message.can_replace(pending):
break
# self.log(message, "replaced with", pending)
try:
message = await self.get_message()
except MessagePumpClosed:
Expand Down
4 changes: 1 addition & 3 deletions src/textual/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ def can_replace(self, message: Message) -> bool:
@rich.repr.auto
class LayoutMessage(Message, verbosity=3):
def can_replace(self, message: Message) -> bool:
return isinstance(
message, LayoutMessage
) # or isinstance(message, UpdateMessage)
return isinstance(message, LayoutMessage)


@rich.repr.auto
Expand Down
7 changes: 6 additions & 1 deletion src/textual/views/_window_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@


class WindowChange(Message):
pass
def can_replace(self, message: Message) -> bool:
return isinstance(message, WindowChange)


class WindowView(View, layout=VerticalLayout):
Expand All @@ -39,6 +40,10 @@ async def update(self, widget: Widget | RenderableType) -> None:
self.refresh(layout=True)
await self.emit(WindowChange(self))

async def message_update(self, message: UpdateMessage) -> None:
message.prevent_default()
await self.emit(WindowChange(self))

async def watch_virtual_size(self, size: Size) -> None:
await self.emit(WindowChange(self))

Expand Down
11 changes: 2 additions & 9 deletions src/textual/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,10 @@ def render_lines_free(self, width: int) -> None:
self.render_cache = RenderCache(Size(width, len(lines)), lines)

def _get_lines(self) -> Lines:
"""Get render lines for given dimensions.
Args:
width (int): [description]
height (int): [description]
Returns:
Lines: [description]
"""
"""Get segment lines to render the widget."""
if self.render_cache is None:
self.render_lines()
assert self.render_cache is not None
lines = self.render_cache.lines
return lines

Expand Down
44 changes: 17 additions & 27 deletions src/textual/widgets/_tree_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(
data: NodeDataType,
) -> None:
self.parent = parent
self._node_id = node_id
self.id = node_id
self._control = control
self._tree = tree
self.label = label
Expand All @@ -46,10 +46,6 @@ def __init__(
self._tree.expanded = False
self.children: list[TreeNode] = []

@property
def id(self) -> NodeID:
return self._node_id

@property
def control(self) -> TreeControl:
return self._control
Expand Down Expand Up @@ -150,8 +146,8 @@ async def toggle(self) -> None:
await self.expand(not self._expanded)

async def add(self, label: TextType, data: NodeDataType) -> None:
await self._control.add(self._node_id, label, data=data)
self._control.refresh()
await self._control.add(self.id, label, data=data)
self._control.refresh(layout=True)
self._empty = False

def __rich__(self) -> RenderableType:
Expand All @@ -175,29 +171,29 @@ def __init__(
) -> None:
self.data = data

self._node_id = NodeID(0)
self.id = NodeID(0)
self.nodes: dict[NodeID, TreeNode[NodeDataType]] = {}
self._tree = Tree(label)
self.root: TreeNode[NodeDataType] = TreeNode(
None, self._node_id, self, self._tree, label, data
None, self.id, self, self._tree, label, data
)

self._tree.label = self.root
self.nodes[NodeID(self._node_id)] = self.root
self.nodes[NodeID(self.id)] = self.root
super().__init__(name=name)
self.padding = padding

hover_node: Reactive[NodeID | None] = Reactive(None)
cursor: Reactive[NodeID] = Reactive(NodeID(0))
cursor: Reactive[NodeID] = Reactive(NodeID(0), layout=True)
cursor_line: Reactive[int] = Reactive(0, repaint=False)
show_cursor: Reactive[bool] = Reactive(False)
show_cursor: Reactive[bool] = Reactive(False, layout=True)

def watch_show_cursor(self, value: bool) -> None:
self.emit_no_wait(CursorMoveMessage(self, self.cursor_line))

async def watch_cursor_line(self, value: int) -> None:
def watch_cursor_line(self, value: int) -> None:
if self.show_cursor:
await self.emit(CursorMoveMessage(self, value + self.gutter.top))
self.emit_no_wait(CursorMoveMessage(self, value + self.gutter.top))

async def add(
self,
Expand All @@ -206,31 +202,25 @@ async def add(
data: NodeDataType,
) -> None:
parent = self.nodes[node_id]
self._node_id = NodeID(self._node_id + 1)
self.id = NodeID(self.id + 1)
child_tree = parent._tree.add(label)
child_node: TreeNode[NodeDataType] = TreeNode(
parent, self._node_id, self, child_tree, label, data
parent, self.id, self, child_tree, label, data
)
parent.children.append(child_node)
child_tree.label = child_node
self.nodes[self._node_id] = child_node
self.nodes[self.id] = child_node

self.refresh(layout=True)

def find_cursor(self) -> int | None:
"""Find the line location for the cursor node."""

node_id = self.cursor
node = self.root
line = 0

stack: list[Iterator[TreeNode[NodeDataType]]] = []

if node.id == node_id:
return line

if node.expanded and node.children:
stack.append(iter(node.children))
stack: list[Iterator[TreeNode[NodeDataType]]]
stack = [iter([self.root])]

pop = stack.pop
push = stack.append
Expand All @@ -241,11 +231,11 @@ def find_cursor(self) -> int | None:
except StopIteration:
continue
else:
line += 1
if node.id == node_id:
return line
line += 1
push(iter_children)
if node.expanded and node.children:
if node.children and node.expanded:
push(iter(node.children))
return None

Expand Down

0 comments on commit 577ef6b

Please sign in to comment.