-
Notifications
You must be signed in to change notification settings - Fork 0
createDom
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.
The createDom
class is responsible for the following key functionalities:
-
Root Window Creation: The class initializes a root window using the
customtkinter
module (tk.CTk()
), providing the foundation for the entire UI hierarchy. -
Rendering the User Interface: The
render
method renders all elements stored in theelements
list within the root window, effectively displaying the user interface. -
Routing and Navigation: The
createDom
class manages routing and navigation within the application by associating specific URLs with corresponding UI elements. TheaddRoute
andgetRoute
methods allow developers to define and access different routes, while thenav
method controls the navigation flow. -
Element Management: The class maintains a list of elements (
elements
) that make up the user interface. Developers can add elements to this list using theaddElement
method, making it easy to manage and update the UI components. -
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 thegetState
andsetState
methods, respectively. -
Styling and Stylesheets: The
createDom
class supports the use of stylesheets for defining styles across the UI. ThesetStylesheet
method allows developers to set the stylesheet for the entire application. -
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.
-
__init__(self)
: Constructor method that initializes thecreateDom
class. It sets up the root window, initializes lists and dictionaries for elements, routes, states, and styles, and sets default values. -
render(self)
: Renders the user interface by iterating through theelements
list and calling therender
method for each element. -
getCurrentRoute(self)
: Retrieves the current URL route within the application. -
addRoute(self, url, element)
: Associates a specific URL route with a UI element, enabling navigation to that element using the specified URL. -
getRoute(self, url)
: Retrieves the UI element associated with the given URL route. -
nav(self, url)
: Navigates to the specified URL route, showing the associated UI element while hiding the previously displayed one. -
appendChild(self, element)
: Adds a UI element to thechildren
list, making it part of the user interface. -
getState(self, attr)
: Retrieves the value of a state attribute from thestates
dictionary. -
setState(self, attr, value)
: Sets a new value for a state attribute and triggers any associated callbacks. -
useState(self, attr, value, callback)
: Registers a new state with its initial value and an associated callback. -
setStylesheet(self, sheet)
: Sets the stylesheet for the application, defining styles for various UI elements. -
setGeometry(self, val)
: Configures the window geometry (size and position) for the application.
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.