[sdk/kde-builder] kde_builder_lib: feat: Support Konsole tab and TaskBar progress reporting

Andrew Shark <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 65b3785ce43e241f433e719b3665413de8a92234 by Andrew Shark.
Committed on 26/07/2026 at 10:32.
Pushed by ashark into branch 'master'.

feat: Support Konsole tab and TaskBar progress reporting

Closes #141

M  +4    -0    kde_builder_lib/application.py
M  +1    -0    kde_builder_lib/build_system/build_system.py
M  +3    -1    kde_builder_lib/module/module.py
M  +37   -0    kde_builder_lib/status_view.py
M  +5    -4    kde_builder_lib/task_manager.py

https://invent.kde.org/sdk/kde-builder/-/commit/65b3785ce43e241f433e719b3665413de8a92234

diff --git a/kde_builder_lib/application.py b/kde_builder_lib/application.py
index 37bc9ec1..3a6c6a6d 100644
--- a/kde_builder_lib/application.py
+++ b/kde_builder_lib/application.py
@@ -648,6 +648,10 @@ class Application:
         """
         ctx = self.context
 
+        # Disabling progress bar also here, for the case when user interrupted
+        # the execution with Ctrl+C.
+        ctx.status_view.progress_bar_disable()
+
         if Debug().pretending() or self._base_pid != os.getpid():
             # Abort early if pretending or if we're not the same process
             # that was started by the user (e.g. async mode, forked pipe-opens
diff --git a/kde_builder_lib/build_system/build_system.py b/kde_builder_lib/build_system/build_system.py
index bbe8b986..a023b3f7 100644
--- a/kde_builder_lib/build_system/build_system.py
+++ b/kde_builder_lib/build_system/build_system.py
@@ -455,6 +455,7 @@ class BuildSystem:
 
         status_viewer = ctx.status_view
         status_viewer.status = Debug().colorize(f"\t{message}")
+        status_viewer.current_project_phase = self.module.current_phase
         status_viewer.update()
 
         if logger_logged_cmd.level == logging.INFO and ctx.status_view.current_project_cur_progress == -1:
diff --git a/kde_builder_lib/module/module.py b/kde_builder_lib/module/module.py
index 35b08331..ededd17d 100644
--- a/kde_builder_lib/module/module.py
+++ b/kde_builder_lib/module/module.py
@@ -95,7 +95,7 @@ class Module(OptionsBase):
         self.env: dict[str, str] = {}
 
         self.current_phase: str | None = None
-        """For disabling the line "# with environment: .../kde-builder.env" in logged commands for git commands."""
+        """For customizing behavior depending on the phase."""
 
         if self.__class__.__name__ != "BuildContext":
             # Avoid setting this for BuildContext, because it has its own option value type verification code, which needs BuildContext to be already initialized
@@ -246,7 +246,9 @@ class Module(OptionsBase):
         if self.get_option("build-system-only"):
             return True
 
+        self.current_phase = "build"
         build_results = build_system.build_internal()
+        self.current_phase = None
         if not build_results["was_successful"]:
             return False
 
diff --git a/kde_builder_lib/status_view.py b/kde_builder_lib/status_view.py
index adfb5603..687bdb82 100644
--- a/kde_builder_lib/status_view.py
+++ b/kde_builder_lib/status_view.py
@@ -19,6 +19,11 @@ class StatusView:
     """
 
     def __init__(self):
+        self.current_project_phase: str | None = None
+        """
+        We update progress bar percenatage for current project only for "build" phase, not for "install" phase.
+        """
+
         self.current_project_cur_progress = -1
         self.current_project_full_progress = -1
         """
@@ -42,6 +47,10 @@ class StatusView:
         """
         Number of modules built successfully.
         """
+        self.mod_current = -1
+        """
+        The number of module that is currently built.
+        """
 
     def set_progress(self, new_progress) -> None:
         """
@@ -53,6 +62,11 @@ class StatusView:
         if old_progress != new_progress:
             self.update()
 
+    def reset_progress(self) -> None:
+        self.current_project_cur_progress = -1
+        self.current_project_full_progress = -1
+        self.status = ""
+
     def update(self) -> None:
         """
         Send out the I/O needed to ensure the latest status is displayed.
@@ -85,6 +99,29 @@ class StatusView:
             msg = spinner[self.current_project_cur_progress % len(spinner)] + status_line
 
         StatusView._clear_line_and_update(msg)
+        # Avoid updating progress bar in "install" phase. We do this because the "install"
+        # phase is run after "build" phase, and it resets the progress back to 0.
+        # Otherwise, user will see progress bar ugly jumps back.
+        if self.current_project_phase == "build":
+             self.progress_bar_update()
+
+    def progress_bar_update(self):
+        mod_current = self.mod_current
+        mod_total = self.mod_total
+        current_project_full_progress = self.current_project_full_progress
+        current_project_cur_progress = self.current_project_cur_progress
+
+        passed_by_other_projects = int(100 * (mod_current - 1) / mod_total)
+
+        if current_project_full_progress > 0:
+            passed_by_current_project = int(100 * (current_project_cur_progress / current_project_full_progress) / mod_total)
+            percent = passed_by_other_projects + passed_by_current_project
+        else:
+            percent = passed_by_other_projects
+        print(f"\033]9;4;1;{percent}\033\\", end="")
+
+    def progress_bar_disable(self):
+        print("\033]9;4;0;0\033\\", end="")
 
     @staticmethod
     def release_tty(msg: str = "") -> None:
diff --git a/kde_builder_lib/task_manager.py b/kde_builder_lib/task_manager.py
index 9c015212..ec52cea3 100644
--- a/kde_builder_lib/task_manager.py
+++ b/kde_builder_lib/task_manager.py
@@ -111,6 +111,7 @@ class TaskManager:
             logger_taskmanager.warning(" b[<<<  Build Process  >>>]\n")
             result: int = self._handle_build(ipc, ctx) or result
 
+        ctx.status_view.progress_bar_disable()
         return result
 
     # Internal API
@@ -245,10 +246,7 @@ class TaskManager:
 
         # Clear the progress values after build process, so they do not influence on initial progress of install process.
         # This is needed because the install() is invoked after build().
-        sv = module.context.status_view
-        sv.current_project_cur_progress = -1
-        sv.current_project_full_progress = -1
-        sv.status = ""
+        module.context.status_view.reset_progress()
 
         if not module.install():
             return "install"  # phase failed at
@@ -338,6 +336,9 @@ class TaskManager:
             module_name = module.name
             block_substr = self._form_block_substring(module)
             logger_taskmanager.warning(f"Building {block_substr} ({cur_module}/{num_modules})")
+            status_viewer.mod_current = cur_module
+            status_viewer.reset_progress()  # Resetting previous project's progress
+            status_viewer.progress_bar_update()
 
             failed_phase: str = TaskManager._build_single_module(ipc, module)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.