Sunday, September 22, 2024

Custom Script Editor Project: Adding More Features (4th Enhancement)

 In this post, we continue with the fourth enhancement to the Custom Script Editor Project, adding exciting new features that bring more interactivity and dynamic capabilities to our script interpreter. These recent updates focus on enhancing the way data is fetched and displayed, and enabling the execution of program functions directly from within the script.

And as usual, if have not read the previous posts, here are the link: Custom Script Editor Project.

Here is the screenshot with the working enhancements:



1. Fetching Table Contents from the Server

As discussed in the previous post, we integrated a Flask Application to serve as our backend. This allows the script editor to fetch data dynamically from a server. The tables available on the server can now be accessed by the script editor, giving us real-time data capabilities. 

2. New Script Commands: Displaying Table Data and Structure

The newly introduced script command Table(showdata | showstructure) allows users to fetch and display both table data and table structure. This command can be written in the custom script, and depending on the argument (showdata or showstructure), the interpreter will fetch:

  • Table Data: Displays the actual records in the table fetched from the server.
  • Table Structure: Shows the structure or schema of the table (i.e., column names and types).

Once fetched, the table data or structure is presented in a QTableWidget in the right pane, making it easier to visualize and interact with the dataset.

Example Script

Here’s an example of how the Table() command can be used in the custom script:

1
2
Table(Employees, showdata)
Table(Departments, showstructure)

In the above script:

  • The first line fetches and displays the data for the Employees table.
  • The second line fetches and displays the structure of the Departments table.

Both will appear on the right pane of the script editor as dynamic, scrollable tables, providing a clear and interactive view of the information.

3. Function Block Command: Executing Methods Inside the Program

The new Function block feature introduces the ability to call functions (methods) within the program directly from the script. This is a powerful addition, allowing for dynamic interaction between the script and the underlying PyQt6 application. Functions can now be written as part of the program, and by calling them in the script, users can trigger custom logic like displaying data, performing calculations, or updating the UI.

Example Usage:

1
2
3
Function:
     Show_Current_Date(Label4)
End Function

In this example, the Show_Current_Date function is executed when the script is run. It updates Label1 with the current date and time, making it an ideal way to showcase dynamic updates within the user interface.

This function execution capability adds flexibility to the script and enables custom behaviors to be attached to script commands. As a developer, you can define any method and trigger it from within the script block.

4. Upcoming Features: CRUD Operations and Custom Function Creation

In the next phase of the project, we aim to extend this functionality even further. The next enhancement will focus on enabling CRUD (Create, Read, Update, Delete) operations directly from the script. Users will be able to write commands in the script editor that allow them to:

  • Insert new records into the database.
  • Update existing records.
  • Delete records.
  • Perform custom queries.

Additionally, we will introduce a function creation feature, allowing users to define their own functions within the script. This will make the editor even more powerful, giving users control over the logic of their application directly through scripting.

Conclusion

With these new features, the Custom Script Editor is evolving into a more versatile and dynamic tool. By enabling table data and structure display, along with the ability to execute functions, we've significantly enhanced the editor’s interactivity and functionality. In the next phase, we’ll take another big leap by adding database CRUD operations and empowering users to create custom functions, pushing the boundaries of what the script editor can do.

You may download the project on my github page: Custom Script Editor

Stay tuned for the next update!

No comments:

Post a Comment