Skip to main content

Minimalist Python library for writting cherrytree document

Project description

Cherrytree Writer

Simple library to Create, Read or Update a Cherrytree document

Usage

import os
from ctb_writer import CherryTree, CherryTreeNodeBuilder as NodeBuilder

if os.path.exists("my_notes.ctb"):
    print("The file <my_notes.ctb> already exists")
    exit(0)

ctb_document = CherryTree() # Init the cherry tree document
root_id = ctb_document.add_child("Root node") # Add a node with a name

ctb_document.add_child("child node1", parent_id=root_id) # Add a child to the root node
ctb_document.add_child("Root node 2", text="Content of this node", icon="plus") # Add another root node, with some meta_infos

# Can also use .image("path_to_image")
new_node = NodeBuilder("New node").icon("execute")\
                                  .text("Content of the node\n")\
                                  .text("Text append to the node again")\
                                  .get_node() # build the node from the previous infos

# Add node with formatting
other_node = NodeBuilder("Other node", color='#fg4895', bold=True)\
                                                    .text("Highlited text\n", style={"bold":True, "fg":"darkorange","bg": "#ffffff"})\
                                                    .get_node()

ctb_document.add_child(new_node, parent_id=root_id) # Add this node as the child of the first root node
ctb_document.add_child(other_node, parent_id=new_node)
ctb_document.save("my_notes.ctb") # Save your CherryTree in "my_notes.ctb"

It is also possible to add other type of nodes:

from ctb_writer import CherryTree, CherryTreeNodeBuilder as NodeBuilder

ctb_document = CherryTree() # Init the cherry tree document
root_id = ctb_document.add_child("Root node") # Add a node with a name

python_code = NodeBuilder("script", type="code", syntax="python", color="goldenrod")\
                         .icon("python")\
                         .text("print('I am a python code')\n")\
                         .get_node()

ctb_document.add_child(python_code, parent_id=root_id)
ctb_document.save("my_notes.ctb")

Load an existing document

from ctb_writer import CherryTree

ctb_document = CherryTree.load("my_notes.ctb")
# Change a text in a node
node = ctb_document.get_node_by_id(3)
node.replace("Content", "CONTENT", {"bold": True}) # Set a part of the text node to bold

Add other items and text beautified

from ctb_writer import CherryTree, CherryTreeNodeBuilder as NodeBuilder

ctb_document = CherryTree() # Init the cherry tree document
root_id = ctb_document.add_child("Root node") # Add a node with a name

# Tables in cherry tree contain HEADER at the END of a table
table = [["Content1", "C2"], ["Content2", "C3"], ["Col1", "Col2"]]

# Add codebox, local images or table
other_node = CherryTreeNodeBuilder("New node", bold=True, color='darkorange').icon("python")\
                                   .text("tests\n", style={"underline": True, "size":"h1"})\
                                   .codebox("import os\nprint('test')\n", syntax='python')\
                                   .image("images/ghost.png", justification="center")\
                                   .table(content=table)\
                                   .get_node()

# Add text that will be formatted
text_content = """
[(bold|underline)]Title:[/]
 - [(fg:orange)]orange[/]
 - [(bg:sun)]yellow background[/]
 - [(fg:blue|underline)]blue underlined[/]

[(bg:sun|fg:orange)]##############################################################################################[/]

"""

text_colored_node = CherryTreeNodeBuilder("Colored node").texts(text_content).get_node()

ctb_document.add_child(other_node, parent_id=root_id)
ctb_document.save("my_notes.ctb")

Installation

git clone https://github.com/Guilhem7/cherry_tree_writer.git
cd cherry_tree_writer
pip3 install .

Icons

List icons

python3 -m ctb_writer.icons 

Colors

By now colors can be applied on text and on node title. However, each colors must match the following regex:

#[0-9a-fA-F]{6}

Or be a predefined style:

python3 -m ctb_writer.styles

Other properties

Nodes can be created with the following properties:

  • Icon: The icon to use for the node (with or without the prefix ct_)
  • Text: The text inside the node (no formatting available by now)
  • Images: The images inside the node
  • Read-Only: Whether or not the node can be edited

TODO

  1. :white_check_mark: Manage codebox
  2. :white_check_mark: Manage Tables
  3. :white_check_mark: Manage text formatting
  4. :white_check_mark: Add alias for color
  5. :white_check_mark: Parse an existing Cherry tree document
  6. Allows to save with password
  7. :white_check_mark: Add an easiest way to prettify text

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cherry_tree_writer-0.3.tar.gz (30.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cherry_tree_writer-0.3-py3-none-any.whl (33.4 kB view details)

Uploaded Python 3

File details

Details for the file cherry_tree_writer-0.3.tar.gz.

File metadata

  • Download URL: cherry_tree_writer-0.3.tar.gz
  • Upload date:
  • Size: 30.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.10

File hashes

Hashes for cherry_tree_writer-0.3.tar.gz
Algorithm Hash digest
SHA256 f6f2a99ad17d016bfcb3f3972da4a89568e72d1903426f0691371281a3cc6d9e
MD5 8bc6af7d938a42bfba3428f39d40b571
BLAKE2b-256 872d6b0a8eda8b96de1fdc3e0be052b0865d0075c207711e1b6183d4dc88d8a0

See more details on using hashes here.

File details

Details for the file cherry_tree_writer-0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for cherry_tree_writer-0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a7508834daf53d76009533ef5e78a5ae79bf619eaaddcd0b1e9d58565d1a2f69
MD5 6f1b3c0ac638e425ad43408b5da6ee24
BLAKE2b-256 83abfd7bb29a9dd824ab4e294de6238eda400d8aa2b65c9a1a3a5bb00a685a37

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page