Skip to content

createDom

Zacharie edited this page Jul 19, 2023 · 2 revisions

createDom Class

Introduction

The createDom class is a core component of the PynamicUI library, designed to facilitate the dynamic creation and management of user interfaces for desktop applications. This class serves as a bridge between the PynamicUI framework and the CustomTkinter library, enabling seamless integration and efficient UI rendering.

Class Overview

The createDom class is responsible for the following key functionalities:

  1. Root Window Creation: The class initializes a root window using the customtkinter module (tk.CTk()), providing the foundation for the entire UI hierarchy.

  2. Rendering the User Interface: The render method renders all elements stored in the elements list within the root window, effectively displaying the user interface.

  3. Routing and Navigation: The createDom class manages routing and navigation within the application by associating specific URLs with corresponding UI elements. The addRoute and getRoute methods allow developers to define and access different routes, while the nav method controls the navigation flow.

  4. Element Management: The class maintains a list of elements (elements) that make up the user interface. Developers can add elements to this list using the addElement method, making it easy to manage and update the UI components.

  5. State Management: The class implements a state management system using the states dictionary. Developers can register states, access their values, and set new values using the getState and setState methods, respectively.

  6. Styling and Stylesheets: The createDom class supports the use of stylesheets for defining styles across the UI. The setStylesheet method allows developers to set the stylesheet for the entire application.

  7. Geometry Configuration: The class provides the setGeometry method to configure the window geometry, allowing developers to set the size and position of the application window.

Methods and Functionality

  1. __init__(self): Constructor method that initializes the createDom class. It sets up the root window, initializes lists and dictionaries for elements, routes, states, and styles, and sets default values.

  2. render(self): Renders the user interface by iterating through the elements list and calling the render method for each element.

  3. getCurrentRoute(self): Retrieves the current URL route within the application.

  4. addRoute(self, url, element): Associates a specific URL route with a UI element, enabling navigation to that element using the specified URL.

  5. getRoute(self, url): Retrieves the UI element associated with the given URL route.

  6. nav(self, url): Navigates to the specified URL route, showing the associated UI element while hiding the previously displayed one.

  7. appendChild(self, element): Adds a UI element to the children list, making it part of the user interface.

  8. getState(self, attr): Retrieves the value of a state attribute from the states dictionary.

  9. setState(self, attr, value): Sets a new value for a state attribute and triggers any associated callbacks.

  10. useState(self, attr, value, callback): Registers a new state with its initial value and an associated callback.

  11. setStylesheet(self, sheet): Sets the stylesheet for the application, defining styles for various UI elements.

  12. setGeometry(self, val): Configures the window geometry (size and position) for the application.

Conclusion

The createDom class plays a central role in the PynamicUI library, offering powerful capabilities for managing dynamic user interfaces in Python desktop applications. By providing essential methods for UI rendering, routing, navigation, state management, and styling, createDom simplifies the process of creating interactive and responsive user interfaces. Developers can leverage its functionality to build elegant and efficient GUI applications with ease.