### Complete Dooit Configuration Example with Custom Theme and Widgets Source: https://context7.com/dooit-org/dooit/llms.txt This comprehensive example showcases a full `config.py` setup for Dooit. It includes defining a custom theme ('TokyoNight'), creating dynamic status bar widgets that display the current mode and time, and implementing custom formatters for todo status and due dates. It also demonstrates setting keybindings, defining workspace and todo layouts, and configuring the status bar and dashboard. ```python from datetime import datetime from dooit.api import Todo from dooit.api.theme import DooitThemeBase from dooit.ui.api import DooitAPI, subscribe, timer from dooit.ui.api.widgets import TodoWidget, WorkspaceWidget from dooit.ui.api.events import Startup, ModeChanged, TodoStatusChanged from dooit.ui.widgets.bars import StatusBarWidget from rich.text import Text from rich.style import Style # Custom theme class TokyoNight(DooitThemeBase): _name = "tokyo-night" background1 = "#1a1b26" background2 = "#24283b" background3 = "#414868" foreground1 = "#a9b1d6" foreground2 = "#c0caf5" foreground3 = "#cfc9c2" red = "#f7768e" orange = "#ff9e64" yellow = "#e0af68" green = "#9ece6a" blue = "#7aa2f7" purple = "#bb9af7" magenta = "#bb9af7" cyan = "#7dcfff" primary = cyan secondary = blue # Bar widgets @subscribe(ModeChanged) def mode_display(api: DooitAPI, event: ModeChanged): theme = api.vars.theme return Text(f" {event.mode} ", style=Style(color=theme.background1, bgcolor=theme.primary)) @timer(1) def clock_display(api: DooitAPI): theme = api.vars.theme return Text(f" {datetime.now().strftime('%H:%M')} ", style=Style(color=theme.background1, bgcolor=theme.secondary)) # Formatters def format_status(status: str, _: Todo, api: DooitAPI): theme = api.vars.theme icons = {"completed": "✓", "pending": "○", "overdue": "!"} colors = {"completed": theme.green, "pending": theme.yellow, "overdue": theme.red} return Text(icons[status], style=colors[status]) def format_due(due, _): return due.strftime("%b %d") if due else "" # Main setup @subscribe(Startup) def setup(api: DooitAPI, _): # Apply theme api.css.set_theme(TokyoNight) # Configure vars api.vars.show_confirm = True # Set keybindings api.keys.set("j", api.move_down) api.keys.set("k", api.move_up) api.keys.set("i", api.edit_description) api.keys.set("a", api.add_sibling) api.keys.set("A", api.add_child_node) api.keys.set("xx", api.remove_node) api.keys.set("c", api.toggle_complete) api.keys.set("/", api.start_search) api.keys.set("?", api.show_help) api.keys.set("", api.quit) # Set layouts api.layouts.workspace_layout = [WorkspaceWidget.description] api.layouts.todo_layout = [ TodoWidget.status, TodoWidget.description, TodoWidget.due, TodoWidget.urgency, ] # Set formatters api.formatter.todos.status.add(format_status) api.formatter.todos.due.add(format_due) # Set bar api.bar.set([ StatusBarWidget(mode_display), StatusBarWidget(lambda: "", width=0), StatusBarWidget(clock_display), ]) # Set dashboard api.dashboard.set([ Text("DOOIT", style=api.vars.theme.primary), "", "Press ? for help", ]) # Event handler @subscribe(TodoStatusChanged) def celebrate_completion(api: DooitAPI, event: TodoStatusChanged): if event.new == "completed": api.notify(f"Done: {event.todo.description}") ``` -------------------------------- ### Install Dooit Globally with Pixi Source: https://github.com/dooit-org/dooit/blob/main/site/docs/getting_started/installation.md Installs Dooit globally using Pixi, a dependency manager for Rust and Python projects. The `pixi global install` command makes Dooit accessible from any directory. ```bash pixi global install dooit ``` -------------------------------- ### Install Dooit with Yay on Arch Linux Source: https://github.com/dooit-org/dooit/blob/main/site/docs/getting_started/installation.md Installs Dooit and its extras on Arch Linux using the `yay` AUR helper. This command leverages the Arch User Repository for package management. ```bash yay -S dooit dooit-extras ``` -------------------------------- ### NixOS Installation using Flakes and Home Manager Source: https://github.com/dooit-org/dooit/blob/main/site/docs/getting_started/installation.md Sets up Dooit and Dooit Extras for Home Manager within a NixOS flake configuration. It imports Dooit's Home Manager module and applies an overlay for Dooit Extras. ```nix # flake.nix { inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; dooit.url = "github:dooit-org/dooit"; dooit-extras.url = "github:dooit-org/dooit-extras"; }; # ... outputs = inputs @ { nixpkgs, ... }; let pkgs = import nixpkgs {}; system = "x86_64-linux"; # change to whatever your system should be in { homeConfigurations."${username}" = nixpkgs.lib.nixosSystem { pkgs = pkgs; extraSpecialArgs = { inherit system inputs; }; modules = [ ./home-manager/dooit.nix ]; }; }; } ``` ```nix # home-manager/dooit.nix { inputs, pkgs, ... }: { imports = [ # home manager module for dooit inputs.dooit.homeManagerModules.default ]; # adds dooit-extras to pkgs nixpkgs.overlays = [inputs.dooit-extras.overlay]; programs.dooit = { enable = true; extraPackages = [pkgs.dooit-extras]; }; } ``` -------------------------------- ### Install Dooit with Pip Source: https://github.com/dooit-org/dooit/blob/main/site/docs/getting_started/installation.md Installs the Dooit package and its extras using pip, the standard Python package installer. This is a common method for Python projects. ```bash pip install dooit dooit-extras ``` -------------------------------- ### NixOS Installation using Flakes and Nix Module Source: https://github.com/dooit-org/dooit/blob/main/site/docs/getting_started/installation.md Configures NixOS to use Dooit and Dooit Extras via flakes. This involves defining inputs in `flake.nix` and setting up an overlay and system package in a separate Nix module. ```nix # flake.nix { inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; dooit.url = "github:dooit-org/dooit"; dooit-extras.url = "github:dooit-org/dooit-extras"; }; # ... outputs = inputs @ { nixpkgs, ... }; let pkgs = import nixpkgs {}; system = "x86_64-linux"; # change to whatever your system should be in { nixosConfigurations."${host}" = nixpkgs.lib.nixosSystem { specialArgs = { inherit system inputs pkgs; }; modules = [ ./dooit.nix ]; }; }; } ``` ```nix # dooit.nix { inputs, pkgs, ... }: let mydooit = pkgs.dooit.override { extraPackages = [ pkgs.dooit-extras ]; }; in { # this overlay allows you to use dooit from pkgs.dooit nixpkgs.overlays = [inputs.dooit.overlay inputs.dooit-extras.overlay]; environment.systemPackages = [ mydooit ]; } ``` -------------------------------- ### Python: Setup Dooit API Configuration Source: https://github.com/dooit-org/dooit/blob/main/site/docs/configuration/dooit_api.md This snippet demonstrates how to subscribe to the Startup event and access the DooitAPI object for configuration within a Python environment. It serves as an entry point for customizing Dooit's behavior. ```python from dooit.api.core import DooitAPI from dooit.api.events import Startup @subscribe(Startup) def setup(api: DooitAPI, _): api. ``` -------------------------------- ### Set Up Welcome Dashboard Screen (Python) Source: https://context7.com/dooit-org/dooit/llms.txt Configures the initial welcome screen (dashboard) that appears when no workspace is selected in Dooit. It displays ASCII art, a welcome message, and a help prompt, styled using theme colors. This setup is triggered by the `Startup` event. ```python from dooit.ui.api import DooitAPI, subscribe from dooit.ui.api.events import Startup from rich.text import Text @subscribe(Startup) def dashboard_setup(api: DooitAPI, _): theme = api.vars.theme ascii_art = """ ██████╗ ██████╗ ██████╗ ██╗████████╗ ██╔══██╗██╔═══██╗██╔═══██╗██║╚══██╔══╝ ██║ ██║██║ ██║██║ ██║██║ ██║ ██║ ██║██║ ██║██║ ██║██║ ██║ ██████╔╝╚██████╔╝╚██████╔╝██║ ██║ ╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝ """ api.dashboard.set([ Text(ascii_art, style=theme.primary), "", Text("Welcome to Dooit!", style=theme.secondary, justify="center"), "", Text("Press '?' for help", style=theme.foreground2, justify="center"), ]) ``` -------------------------------- ### Multiple Key Binding in Python Source: https://github.com/dooit-org/dooit/blob/main/site/docs/configuration/keys.md Shows how to associate multiple keys with the same callback function. This is useful for accommodating different keyboard layouts or user preferences, allowing for flexibility in shortcut definition. For example, both '+' and '=' can be used to increase urgency. ```python from dooit.ui.api import DooitAPI, subscribe from dooit.ui.api.events import Startup @subscribe(Startup) def setup(api: DooitAPI, _): api.keys.set(["=","+"], api.increase_urgency) api.keys.set(["-","_"], api.decrease_urgency) ``` -------------------------------- ### Python: Start Search Source: https://github.com/dooit-org/dooit/blob/main/site/docs/configuration/dooit_api.md Initiates the search functionality within the Dooit list. Allows users to find specific items. ```python api.start_search() ``` -------------------------------- ### Python: Start Sorting Source: https://github.com/dooit-org/dooit/blob/main/site/docs/configuration/dooit_api.md Begins the sorting process for the siblings of the currently highlighted item. Enables users to organize lists. ```python api.start_sort() ``` -------------------------------- ### Get All Todos (classmethod) Source: https://github.com/dooit-org/dooit/blob/main/site/docs/backend/todo.md Fetches a list of all Todo objects stored in the database. This method provides a comprehensive view of all available todos. ```python all() -> List[Todo]: # Returns all the todos from the database ``` -------------------------------- ### New Keybindings Setup with Dooit API (Python) Source: https://github.com/dooit-org/dooit/blob/main/site/docs/extra/moving_from_v2.md This Python code demonstrates the new approach to setting up keybindings in Dooit using the `DooitAPI`. It utilizes the `subscribe` decorator and the `api.keys.set` method to bind specific keys or key combinations to various API functions. ```python @subscribe(Startup) def key_setup(api: DooitAPI, _): api.keys.set("j", api.move_down) api.keys.set("k", api.move_up) api.keys.set("i", api.edit_description) api.keys.set("d", api.edit_due) api.keys.set("r", api.edit_recurrence) api.keys.set("a", api.add_sibling) api.keys.set("z", api.toggle_expand) api.keys.set("Z", api.toggle_expand_parent) api.keys.set("gg", api.go_to_top) api.keys.set("G", api.go_to_bottom) api.keys.set("A", api.add_child_node) api.keys.set("J", api.shift_down) api.keys.set("K", api.shift_up) api.keys.set("xx", api.remove_node) api.keys.set("c", api.toggle_complete) api.keys.set("=,+", api.increase_urgency) api.keys.set("-,_", api.decrease_urgency) api.keys.set("/", api.start_search) api.keys.set("", api.start_sort) ``` -------------------------------- ### Install Dooit with Conda/Mamba Source: https://github.com/dooit-org/dooit/blob/main/site/docs/getting_started/installation.md Installs Dooit and Dooit Extras using Conda or Mamba package managers. These are commonly used for managing Python environments and packages, especially in scientific computing. ```bash conda install dooit dooit-extras ``` ```bash mamba install dooit dooit-extras ``` -------------------------------- ### Creating a Custom Theme in Python Source: https://github.com/dooit-org/dooit/blob/main/site/docs/configuration/theme.md Provides an example of creating a custom color theme in Python by inheriting from `DooitThemeBase`. It defines various color properties like background, foreground, accent, and other specific colors, assigning hexadecimal color codes to each. ```python from dooit.api.theme import DooitThemeBase class Nord(DooitThemeBase): _name = "dooit-nord" background1: str = "#2E3440" # Darkest background2: str = "#3B4252" # Lighter background3: str = "#434C5E" # Lightest # foreground colors foreground1: str = "#D8DEE9" # Darkest foreground2: str = "#E5E9F0" # Lighter foreground3: str = "#ECEFF4" # Lightest # other colors red: str = "#BF616A" orange: str = "#D08770" yellow: str = "#EBCB8B" green: str = "#A3BE8C" blue: str = "#81a1c1" purple: str = "#B48EAD" magenta: str = "#B48EAD" cyan: str = "#8fbcbb" # accent colors primary: str = cyan secondary: str = blue ``` -------------------------------- ### Migrate Data using CLI Source: https://github.com/dooit-org/dooit/blob/main/site/docs/extra/moving_from_v2.md This command initiates the data migration process from Dooit V2 to V3. It is a crucial first step for users upgrading their Dooit installation. The command is executed directly in the terminal. ```bash dooit migrate ``` -------------------------------- ### Highlight Words Starting with '!' in Description (Python) Source: https://github.com/dooit-org/dooit/blob/main/site/docs/configuration/formatter.md A Python function that highlights words in a description string that start with an exclamation mark ('!'). It uses regular expressions and the `rich.text.Text` object for styling, leveraging the Dooit API's theme for the highlight color. This formatter takes a description string, a `Todo` object, and a `DooitAPI` object as input, returning a styled `Text` object. ```python from dooit.api import Todo from dooit.ui.api import DooitAPI from rich.text import Text def redify_important(description: str, model: Todo, api: DooitAPI) -> Text: regex = r"!([\w]+)" text = Text(description) text.highlight_regex(regex, style = api.vars.theme.red) return text ``` -------------------------------- ### Todo Tags Property Source: https://github.com/dooit-org/dooit/blob/main/site/docs/backend/todo.md Extracts and returns a list of all tags present in a Todo item. Tags are identified as words starting with the '@' symbol. ```python tags -> List[str]: # Returns all the tags in the todo (words starting with @) ``` -------------------------------- ### Set Default Dashboard Content (Python) Source: https://github.com/dooit-org/dooit/blob/main/site/docs/configuration/dashboard.md Configures the initial dashboard display with plain text messages. This function subscribes to the `Startup` event to ensure the dashboard is set when the application starts. It takes a list of strings as input. ```python from dooit.ui.api import DooitAPI, subscribe from dooit.ui.api.events import Startup @subscribe(Startup) def dashboard_setup(api: DooitAPI, _): api.dashboard.set( [ "Welcome to Dooit!", "", "If you're stuck, press '?' for help.", ] ) ``` -------------------------------- ### Creating Custom Formatters for Dooit Source: https://context7.com/dooit-org/dooit/llms.txt Provides an example of creating a custom formatter for Dooit to display due dates in a more readable format. The `custom_due_formatter` function takes a datetime object and a Todo model, returning a formatted string based on whether the year is the current year. ```python from datetime import datetime from dooit.api import Todo from dooit.ui.api import DooitAPI, subscribe, extra_formatter from dooit.ui.api.events import Startup from rich.text import Text from rich.style import Style # Format due date in a readable way def custom_due_formatter(due: datetime, model: Todo) -> str: if due is None: return "" if due.year != datetime.today().year: return due.strftime("%b %d, %Y") return due.strftime("%b %d") ``` -------------------------------- ### Get Todo by ID (classmethod) Source: https://github.com/dooit-org/dooit/blob/main/site/docs/backend/todo.md Retrieves a specific Todo object using its unique identifier. It handles potential ValueErrors for invalid IDs. ```python from_id(id: str | int) -> Todo: # Returns the todo object with the given id # Raises ValueError if an invalid ID is passed ``` -------------------------------- ### Highlight Important Words in Description (Python) Source: https://context7.com/dooit-org/dooit/llms.txt Highlights words in a todo item's description that start with an exclamation mark ('!'). It uses regular expressions to find these words and applies a red style from the theme. This formatter is managed via IDs and can be enabled/disabled. ```python from dooit.ui.api import DooitAPI from dooit.ui.widgets.default import Todo from rich.text import Text def highlight_important(description: str, model: Todo, api: DooitAPI) -> Text: text = Text(description) text.highlight_regex(r"!([\w]+)", style=api.vars.theme.red) return text ``` -------------------------------- ### Get Todo Status (Python) Source: https://github.com/dooit-org/dooit/blob/main/site/docs/backend/todo.md Retrieves the current status of a todo item. The status can be one of 'completed', 'pending', or 'overdue'. This property returns a string representing the todo's state. ```python status -> str Returns the status of the todo (one of `completed`/`pending`/`overdue`) ``` -------------------------------- ### Set Dooit Bar Widgets with Python Source: https://github.com/dooit-org/dooit/blob/main/site/docs/configuration/bar.md This Python code snippet demonstrates how to set the widgets for the Dooit bar using the `api.bar.set()` method. It imports necessary classes from `dooit_extras.bar_widgets` and `dooit.ui.api.events`, and uses the `subscribe` decorator to run the setup function on startup. The function configures widgets like Mode, Spacer, Clock, and Date, customizing their appearance and format. ```python from dooit_extras.bar_widgets import Mode, Spacer, Clock, Date from dooit.ui.api.events import Startup from dooit.ui.api import DooitAPI, subscribe @subscribe(Startup) def setup(api: DooitAPI, _): theme = api.vars.theme api.bar.set( [ Mode(api), Spacer(api, width = 0), Clock(api, fmt=" 󰥔 {} ", bg=theme.yellow), Spacer(api, width = 1), Date(api, fmt = " {} ") ] ) ``` -------------------------------- ### Get Siblings of a Todo (Python) Source: https://github.com/dooit-org/dooit/blob/main/site/docs/backend/todo.md Retrieves a list of all sibling todos, including the current todo itself. This method is useful for understanding the context of a todo within a group. ```python siblings() -> List[Todo] Returns the siblings for the todo (including self) ``` -------------------------------- ### Basic Key Binding in Python Source: https://github.com/dooit-org/dooit/blob/main/site/docs/configuration/keys.md Demonstrates how to bind a single key to a specific callback function using `api.keys.set`. This method is useful for creating custom shortcuts for actions like moving up or down. The `description` and `group` parameters are optional. ```python from dooit.ui.api import DooitAPI, subscribe from dooit.ui.api.events import Startup @subscribe(Startup) def setup(api: DooitAPI, _): api.keys.set("j", api.move_down, "my custom vim keys") api.keys.set("k", api.move_up, "my custom vim keys") ``` -------------------------------- ### Basic Configuration with DooitAPI Source: https://context7.com/dooit-org/dooit/llms.txt Demonstrates basic configuration of Dooit using the DooitAPI and the `@subscribe` decorator to hook into the `Startup` event. It shows how to access theme colors, current workspace/todo, mode, and send notifications. ```python from dooit.ui.api import DooitAPI, subscribe from dooit.ui.api.events import Startup @subscribe(Startup) def setup(api: DooitAPI, _): # Access theme colors theme = api.vars.theme # Access current workspace and todo current_workspace = api.vars.current_workspace current_todo = api.vars.current_todo # Get current mode (NORMAL, INSERT, SEARCH, etc.) mode = api.vars.mode # Send a notification api.notify("Dooit is ready!", level="info") ``` -------------------------------- ### Initialize Theme API in Dooit V3 (Python) Source: https://github.com/dooit-org/dooit/blob/main/site/docs/extra/moving_from_v2.md This Python code demonstrates the new approach to handling colors in Dooit V3 using a dedicated theme API. It shows how to subscribe to the Startup event and access the theme object via DooitAPI. ```python from dooit.ui.api import DooitAPI, subscribe from dooit.ui.api.events import Startup @subscribe(Startup) def foo(api: DooitAPI, _): theme = api.vars.theme ``` -------------------------------- ### Configure Status Bar Widgets on Startup (Python) Source: https://context7.com/dooit-org/dooit/llms.txt Sets up the main status bar layout upon application startup. It defines a list of `StatusBarWidget` instances, including dynamic widgets for mode and clock, a static user widget, and spacers. This function subscribes to the `Startup` event. ```python from dooit.ui.api import DooitAPI, subscribe, timer from dooit.ui.api.events import Startup, ModeChanged from dooit.ui.widgets.bars import StatusBarWidget from rich.text import Text from rich.style import Style # (Assume mode_widget, clock_widget, user_widget are defined above) @subscribe(Startup) def bar_setup(api: DooitAPI, _): api.bar.set([ StatusBarWidget(mode_widget), StatusBarWidget(lambda: "", width=0), # Flexible spacer StatusBarWidget(clock_widget), StatusBarWidget(lambda: " ", width=1), # Fixed spacer StatusBarWidget(user_widget), ]) ``` -------------------------------- ### Get Current Workspace in Dooit Source: https://github.com/dooit-org/dooit/blob/main/site/docs/configuration/vars.md Returns the currently selected workspace object. If no workspace is currently active or highlighted, it returns None. ```python def current_workspace(self) -> Optional[Workspace]: ``` ```python from dooit.ui.api.events import DooitEvent from dooit.ui.api import DooitAPI, subscribe @subscribe(DooitEvent) def foo(api: DooitAPI, event: DooitEvent): current_workspace = api.vars.current_workspace ``` -------------------------------- ### Setting Up Vim-like Keybindings with DooitAPI Source: https://context7.com/dooit-org/dooit/llms.txt Configures vim-like keybindings for Dooit using the `keys` API. It covers basic navigation, editing, node operations, clipboard actions, toggling, search, sorting, pane switching, help, and quitting. It also shows how to bind multiple keys to an action and remove default keybinds. ```python from dooit.ui.api import DooitAPI, subscribe from dooit.ui.api.events import Startup @subscribe(Startup) def key_setup(api: DooitAPI, _): # Basic navigation api.keys.set("j", api.move_down, "Move down") api.keys.set("k", api.move_up, "Move up") api.keys.set("gg", api.go_to_top, "Go to top") api.keys.set("G", api.go_to_bottom, "Go to bottom") # Editing api.keys.set("i", api.edit_description, "Edit description") api.keys.set("d", api.edit_due, "Edit due date") api.keys.set("r", api.edit_recurrence, "Edit recurrence") api.keys.set("e", api.edit_effort, "Edit effort") # Node operations api.keys.set("a", api.add_sibling, "Add sibling") api.keys.set("A", api.add_child_node, "Add child") api.keys.set("xx", api.remove_node, "Remove node") api.keys.set("z", api.toggle_expand, "Toggle expand") # Multiple keys for same action api.keys.set(["=", "+"], api.increase_urgency, "Increase urgency") api.keys.set(["-", "_"], api.decrease_urgency, "Decrease urgency") # Clipboard operations api.keys.set("y", api.copy_description_to_clipboard, "Copy description") api.keys.set("Y", api.copy_model, "Copy whole item") api.keys.set("p", api.paste_model_below, "Paste below") # Toggle and search api.keys.set("c", api.toggle_complete, "Toggle complete") api.keys.set("/", api.start_search, "Start search") api.keys.set("", api.start_sort, "Start sort") api.keys.set("", api.switch_focus, "Switch pane") api.keys.set("?", api.show_help, "Show help") api.keys.set("", api.quit, "Quit") # Remove a default keybind api.keys.set("x", api.no_op) ``` -------------------------------- ### Configure Dashboard with API in Dooit V3 (Python) Source: https://github.com/dooit-org/dooit/blob/main/site/docs/extra/moving_from_v2.md This Python code shows the Dooit V3 method for setting up the dashboard using the `DooitAPI`. It utilizes the `rich.text.Text` object for styling and accesses theme colors. ```python from dooit.ui.api import DooitAPI, subscribe from dooit.ui.api.events import Startup from rich.text import Text @subscribe(Startup) def dashboard_setup(api: DooitAPI, _): def colored(text, color): return Text(text, style = color).markup theme = api.vars.theme ART = "some ascii art" NL = " \n" SEP = Text("─" * 60, "d " + theme.background3) help_message = f"Press {colored('?', magenta)} to spawn help menu" DASHBOARD = [ART, NL, SEP, NL, NL, NL, help_message] api.dashboard.set(DASHBOARD) ``` -------------------------------- ### Python: Edit Todo Due Date Source: https://github.com/dooit-org/dooit/blob/main/site/docs/configuration/dooit_api.md Starts the editing process for the due date of the currently selected todo item. Essential for managing deadlines. ```python api.edit_due() ``` -------------------------------- ### Configure Dooit Widget Layouts with Python Source: https://github.com/dooit-org/dooit/blob/main/site/docs/configuration/layout.md This snippet demonstrates how to import and use TodoWidget and WorkspaceWidget to define the column order and visibility in Dooit. It subscribes to the Startup event to set the initial layouts for workspace and todo items, specifying which columns should be displayed. ```python from dooit.ui.api.widgets import TodoWidget, WorkspaceWidget from dooit.ui.api import DooitAPI, subscribe from dooit.ui.api.events import Startup @subscribe(Startup) def layout_setup(api: DooitAPI, _): api.layouts.workspace_layout = [WorkspaceWidget.description] api.layouts.todo_layout = [ TodoWidget.status, TodoWidget.description, TodoWidget.recurrence, TodoWidget.due, TodoWidget.urgency, ] ``` -------------------------------- ### Get Current Todo Item in Dooit Source: https://github.com/dooit-org/dooit/blob/main/site/docs/configuration/vars.md Returns the currently highlighted todo item object. If no todo item is selected or available, it returns None. ```python def current_todo(self) -> Optional[Todo]: ``` ```python from dooit.ui.api.events import DooitEvent from dooit.ui.api import DooitAPI, subscribe @subscribe(DooitEvent) def foo(api: DooitAPI, event: DooitEvent): current_todo = api.vars.current_todo ``` -------------------------------- ### Register Formatters on Startup (Python) Source: https://context7.com/dooit-org/dooit/llms.txt Sets up various formatters for todo items upon application startup. It registers formatters for status, due dates, urgency, and description highlighting using the `api.formatter` object. Formatters can be added with optional IDs for management and can be enabled, disabled, or removed. ```python from dooit.ui.api import DooitAPI, subscribe, extra_formatter from dooit.ui.api.events import Startup from dooit.ui.widgets.default import Todo from rich.text import Text from rich.style import Style # (Assume status_formatter, urgency_formatter, highlight_important, add_due_icon are defined above) def custom_due_formatter(due: str, model: Todo) -> str: # Placeholder for a custom due formatter if needed return due @subscribe(Startup) def formatter_setup(api: DooitAPI, _): fmt = api.formatter # Add formatters with optional IDs for later management fmt.todos.status.add(status_formatter, id="status_fmt") fmt.todos.due.add(custom_due_formatter, id="due_fmt") fmt.todos.due.add(add_due_icon) # Chain formatters fmt.todos.urgency.add(urgency_formatter) fmt.todos.description.add(highlight_important, id="highlight") # Manage formatters fmt.todos.description.disable("highlight") # Temporarily disable fmt.todos.description.enable("highlight") # Re-enable # fmt.todos.description.remove("highlight") # Permanently remove ``` -------------------------------- ### Get Todos Tree for Current Workspace in Dooit Source: https://github.com/dooit-org/dooit/blob/main/site/docs/configuration/vars.md Returns the todos tree associated with the current workspace. If no workspace is active or it has no todos, it returns None. ```python def todos_tree(self) -> Optional[TodosTree]: ``` ```python from dooit.ui.api.events import DooitEvent from dooit.ui.api import DooitAPI, subscribe @subscribe(DooitEvent) def foo(api: DooitAPI, event: DooitEvent): todos_tree = api.vars.todos_tree ``` -------------------------------- ### Dooit Todo SQLAlchemy Model Definition Source: https://github.com/dooit-org/dooit/blob/main/site/docs/backend/introduction.md Defines the Todo model for Dooit, specifying its relationships with workspaces and other todos. This model is part of the SQLAlchemy ORM setup. ```python class Todo(DooitModel): parent_workspace_id: Mapped[Optional[int]] = mapped_column( ForeignKey("workspace.id") ) parent_workspace: Mapped[Optional["Workspace"]] = relationship( "Workspace", back_populates="todos", ) parent_todo_id: Mapped[Optional[int]] = mapped_column(ForeignKey("todo.id")) parent_todo: Mapped[Optional["Todo"]] = relationship( "Todo", back_populates="todos", remote_side=[id], ) todos: Mapped[List["Todo"]] = relationship( "Todo", back_populates="parent_todo", cascade="all, delete-orphan", order_by=order_index, ) ``` -------------------------------- ### Old Workspace and Todo Formatting Configuration (Python) Source: https://github.com/dooit-org/dooit/blob/main/site/docs/extra/moving_from_v2.md This Python code snippet shows the old configuration for workspace and todo formatting. It defines settings for visual elements like pointers, hints, colors, and icons used in the Dooit interface. ```python ################################# # WORKSPACE # ################################# WORKSPACE = { "editing": cyan, "pointer": ">", "children_hint": "+", # "[{count}]", # vars: count "start_expanded": False, } COLUMN_ORDER = ["description", "due", "urgency"] # order of columns TODO = { "color_todos": False, "editing": cyan, "pointer": ">", "children_hint": colored( " ({done}/{total})", green ), # vars: remaining, done, total # "children_hint": "[b magenta]({remaining}!)[/b magenta]", "due_icon": "? ", "effort_icon": "+", "effort_color": yellow, "recurrence_icon": "!", "recurrence_color": blue, "tags_color": red, "completed_icon": "x", "pending_icon": "o", "overdue_icon": "!", "urgency1_icon": "A", "urgency2_icon": "B", "urgency3_icon": "C", "urgency4_icon": "D", "start_expanded": False, "initial_urgency": 1, "urgency1_color": "green", "urgency2_color": "yellow", "urgency3_color": "orange", "urgency4_color": "red", } ``` -------------------------------- ### Get Current App Mode in Dooit Source: https://github.com/dooit-org/dooit/blob/main/site/docs/configuration/vars.md Returns a string representing the current operational mode of the Dooit application. Possible modes include NORMAL, INSERT, SORT, CONFIRM, DATE, and SEARCH. ```python def mode(self) -> str: ``` ```python from dooit.ui.api.events import DooitEvent from dooit.ui.api import DooitAPI, subscribe @subscribe(DooitEvent) def foo(api: DooitAPI, event: DooitEvent): mode = api.vars.mode ``` -------------------------------- ### Removing Key Binding in Python Source: https://github.com/dooit-org/dooit/blob/main/site/docs/configuration/keys.md Explains how to remove default key bindings by setting their callback to `api.no_op`. This effectively disables the key and also hides it from the help menu. This is helpful for users with custom keyboard layouts or those who prefer not to use certain default shortcuts. ```python from dooit.ui.api import DooitAPI, subscribe from dooit.ui.api.events import Startup @subscribe(Startup) def setup(api: DooitAPI, _): api.keys.set("=", api.no_op) api.keys.set("_", api.no_op) ``` -------------------------------- ### Python: Show Help Screen Source: https://github.com/dooit-org/dooit/blob/main/site/docs/configuration/dooit_api.md Displays the help screen within the Dooit application. Provides users with information on how to use the application. ```python api.show_help() ``` -------------------------------- ### Setting a Theme in Python Source: https://github.com/dooit-org/dooit/blob/main/site/docs/configuration/theme.md Illustrates how to change the active theme in Dooit using Python. It shows importing a theme (e.g., `Gruvbox` from `dooit_extras.themes`) and applying it via `api.css.set_theme()`. ```python from dooit.ui.api import DooitAPI, subscribe from dooit.ui.api.events import Startup from dooit_extras.themes import Gruvbox @subscribe(Startup) def layout_setup(api: DooitAPI, _): api.css.set_theme(Gruvbox) ``` -------------------------------- ### Old Keybindings Configuration (Python) Source: https://github.com/dooit-org/dooit/blob/main/site/docs/extra/moving_from_v2.md This Python code snippet illustrates the old method of defining keybindings in Dooit. It uses a dictionary to map action names to key sequences. ```python keybindings = { "switch pane": "", "sort menu toggle": "", "start search": ["/", "S"], "remove item": "xx", "edit effort": "e", "edit recurrence": "r", } ``` -------------------------------- ### Define Column Order in Dooit V2 (Python) Source: https://github.com/dooit-org/dooit/blob/main/site/docs/extra/moving_from_v2.md This Python snippet shows the simple list-based configuration for column order in Dooit V2. ```python COLUMN_ORDER = ["description", "due", "urgency"] # order of columns ``` -------------------------------- ### Configuring Todo and Workspace Layouts with DooitAPI Source: https://context7.com/dooit-org/dooit/llms.txt Defines the columns displayed in Dooit's todo and workspace views using the `layouts` API. It shows how to set the workspace layout to only display the description and the todo layout with multiple columns like status, description, recurrence, due date, and urgency. ```python from dooit.ui.api import DooitAPI, subscribe from dooit.ui.api.widgets import TodoWidget, WorkspaceWidget from dooit.ui.api.events import Startup @subscribe(Startup) def layout_setup(api: DooitAPI, _): # Workspace only has description api.layouts.workspace_layout = [WorkspaceWidget.description] # Todo layout with multiple columns # Available: status, description, due, effort, recurrence, urgency api.layouts.todo_layout = [ TodoWidget.status, TodoWidget.description, TodoWidget.recurrence, TodoWidget.due, TodoWidget.urgency, ] ``` -------------------------------- ### Create Custom Themes in Python Source: https://context7.com/dooit-org/dooit/llms.txt Define a custom color scheme for Dooit by extending the DooitThemeBase class. This involves setting various background, foreground, and standard color attributes. The custom theme can then be applied using the `api.css.set_theme()` method. ```python from dooit.api.theme import DooitThemeBase from dooit.ui.api import DooitAPI, subscribe from dooit.ui.api.events import Startup class MyCustomTheme(DooitThemeBase): _name = "my-custom-theme" # Background colors (dark to light) background1: str = "#1a1b26" background2: str = "#24283b" background3: str = "#414868" # Foreground colors (dark to light) foreground1: str = "#a9b1d6" foreground2: str = "#c0caf5" foreground3: str = "#cfc9c2" # Standard colors red: str = "#f7768e" orange: str = "#ff9e64" yellow: str = "#e0af68" green: str = "#9ece6a" blue: str = "#7aa2f7" purple: str = "#bb9af7" magenta: str = "#bb9af7" cyan: str = "#7dcfff" # Accent colors primary: str = cyan secondary: str = blue @subscribe(Startup) def apply_theme(api: DooitAPI, _): api.css.set_theme(MyCustomTheme) # Or use a theme from dooit-extras # from dooit_extras.themes import Gruvbox, Nord, Catppuccin # api.css.set_theme(Gruvbox) ``` -------------------------------- ### Configure Runtime Variables with DooitAPI Source: https://context7.com/dooit-org/dooit/llms.txt This snippet demonstrates how to access and modify runtime configuration variables using the DooitAPI. It shows how to disable confirmation prompts, auto-expand workspaces and todos, and access read-only variables like theme and mode. It also illustrates how to retrieve tree structures and currently highlighted items. ```python from dooit.ui.api import DooitAPI, subscribe from dooit.ui.api.events import Startup @subscribe(Startup) def configure_vars(api: DooitAPI, _): # Editable vars api.vars.show_confirm = False # Disable delete confirmation api.vars.always_expand_workspaces = True # Auto-expand workspaces api.vars.always_expand_todos = True # Auto-expand todos # Readonly vars theme = api.vars.theme # Current theme mode = api.vars.mode # Current mode (NORMAL, INSERT, etc.) # Access trees and current items workspaces_tree = api.vars.workspaces_tree todos_tree = api.vars.todos_tree current_workspace = api.vars.current_workspace # Currently highlighted current_todo = api.vars.current_todo # Currently highlighted ``` -------------------------------- ### Workspace Siblings and Sorting Methods (Python) Source: https://github.com/dooit-org/dooit/blob/main/site/docs/backend/workspace.md Includes methods to retrieve sibling workspaces (including the workspace itself) and to sort these siblings based on their description. These methods aid in managing and navigating related workspaces. ```python siblings() -> List[Workspace]: """ Returns the siblings for the workspace (including self) """ # Implementation details for returning siblings ``` ```python sort_siblings(): """ Sorts all the siblings ***(by description)*** """ # Implementation details for sorting siblings ``` -------------------------------- ### Accessing Theme Colors in Python Source: https://github.com/dooit-org/dooit/blob/main/site/docs/configuration/theme.md Demonstrates how to access the current theme's colors within a Python script using the `DooitAPI`. It shows how to retrieve the `theme` object and access individual color properties like `red` and `cyan`. ```python from dooit.ui.api import DooitAPI, subscribe from dooit.ui.api.events import Startup @subscribe(Startup) def setup(api: DooitAPI, _): theme = api.vars.theme # red = theme.red # cyan = theme.cyan # so on ...... ``` -------------------------------- ### Toggle Todo Completion Status (Python) Source: https://github.com/dooit-org/dooit/blob/main/site/docs/backend/todo.md Switches the completion status of a todo item. If the todo is pending, it becomes completed, and vice versa. ```python toggle_complete() Toggles the pending status of a todo ``` -------------------------------- ### Workspace Management Source: https://github.com/dooit-org/dooit/blob/main/site/docs/backend/workspace.md Endpoints for managing workspace objects, including adding new workspaces and reordering existing ones. ```APIDOC ## POST /workspaces/add ### Description Adds a child workspace to the current workspace object. ### Method POST ### Endpoint /workspaces/add ### Parameters #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **workspace** (Workspace) - The newly added Workspace object. #### Response Example ```json { "workspace": { "id": "workspace_123", "name": "New Workspace" } } ``` ``` ```APIDOC ## PUT /workspaces/shift_down ### Description Shifts the current workspace down by one index in its parent. This operation has no effect if the workspace is already the first one. ### Method PUT ### Endpoint /workspaces/shift_down ### Parameters #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **message** (string) - Indicates the operation was successful. #### Response Example ```json { "message": "Workspace shifted down successfully." } ``` ``` ```APIDOC ## PUT /workspaces/shift_up ### Description Shifts the current workspace up by one index in its parent. This operation has no effect if the workspace is already the last one. ### Method PUT ### Endpoint /workspaces/shift_up ### Parameters #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **message** (string) - Indicates the operation was successful. #### Response Example ```json { "message": "Workspace shifted up successfully." } ``` ``` ```APIDOC ## POST /workspaces/save ### Description Saves any modifications made to the attributes of the current workspace object to the database. ### Method POST ### Endpoint /workspaces/save ### Parameters #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **message** (string) - Indicates the save operation was successful. #### Response Example ```json { "message": "Workspace saved successfully." } ``` ``` -------------------------------- ### Define Dashboard in Dooit V2 (Python) Source: https://github.com/dooit-org/dooit/blob/main/site/docs/extra/moving_from_v2.md This Python snippet illustrates how the dashboard was configured in Dooit V2, including ASCII art, separators, and help messages. It uses a `colored` function for styling. ```python ART = "some ascii art" NL = " \n" SEP = colored("─" * 60, "d " + grey) # some function to color help_message = f"Press {colored('?', magenta)} to spawn help menu" DASHBOARD = [ART, NL, SEP, NL, NL, NL, help_message] ``` -------------------------------- ### Format Todo Status with Colored Icons (Python) Source: https://context7.com/dooit-org/dooit/llms.txt Formats the status of a todo item (completed, pending, overdue) with corresponding colored icons and bold text. It uses a dictionary lookup for icons and colors based on the status string and theme settings from the DooitAPI. ```python from dooit.ui.api import DooitAPI from dooit.ui.widgets.default import Todo from rich.text import Text from rich.style import Style def status_formatter(status: str, model: Todo, api: DooitAPI) -> Text: theme = api.vars.theme icons = {"completed": "✓", "pending": "○", "overdue": "!"} colors = {"completed": theme.green, "pending": theme.yellow, "overdue": theme.red} return Text(icons.get(status, "○"), style=Style(color=colors.get(status), bold=True)) ``` -------------------------------- ### Manage Workspaces with Dooit Backend API in Python Source: https://context7.com/dooit-org/dooit/llms.txt Interact with Dooit's workspace data using the SQLAlchemy-backed API. This includes connecting to the database, retrieving all workspaces or specific ones by ID, accessing workspace properties and relationships, and performing operations like adding todos/workspaces, shifting order, and sorting siblings. ```python from dooit.api import Workspace, Todo, manager # Connect to database (required before operations) manager.connect() # Get all workspaces all_workspaces = Workspace.all() # Get workspace by ID workspace = Workspace.from_id(1) # Workspace properties print(workspace.description) print(workspace.nest_level) print(workspace.parent) # Parent workspace or None # Workspace relationships child_workspaces = workspace.workspaces # List of child workspaces todos = workspace.todos # List of todos in workspace # Add items to workspace new_todo = workspace.add_todo() new_todo.description = "My new task" new_todo.save() new_child_workspace = workspace.add_workspace() new_child_workspace.description = "Sub-project" new_child_workspace.save() # Workspace operations workspace.shift_up() # Move up in order workspace.shift_down() # Move down in order siblings = workspace.siblings() # Get sibling workspaces workspace.sort_siblings() # Sort siblings by description ``` -------------------------------- ### Python: Copy Node Description to Clipboard Source: https://github.com/dooit-org/dooit/blob/main/site/docs/configuration/dooit_api.md Copies the description of the currently selected node to the system clipboard. This facilitates easy sharing or referencing of node details. ```python api.copy_description_to_clipboard() ```