Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions gknowledge/ui/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,18 @@ def _build_sources_pane(self):
source_actions = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=8)
source_actions.append(self.reingest_btn)
source_actions.append(self.remove_source_btn)
self.progress = Gtk.ProgressBar(show_text=True, visible=False)
self.progress = Gtk.ProgressBar(show_text=True, visible=False, hexpand=True,
valign=Gtk.Align.CENTER, ellipsize=Pango.EllipsizeMode.END)
self.cancel_ingest_btn = Gtk.Button(label="Cancel", valign=Gtk.Align.CENTER)
self.cancel_ingest_btn.connect("clicked", self._on_cancel_ingest)
progress_row = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=8)
progress_row.append(self.progress)
progress_row.append(self.cancel_ingest_btn)
self.progress.bind_property("visible", progress_row, "visible", GObject.BindingFlags.SYNC_CREATE)
bottom = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=8,
margin_top=8, margin_bottom=8, margin_start=8, margin_end=8)
bottom.append(source_actions)
bottom.append(self.progress)
bottom.append(progress_row)
bottom.append(self.ingest_btn)

side = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
Expand Down Expand Up @@ -821,17 +828,28 @@ def _remove_source(self, source_id: str):
self.refresh_all()
self.toast(f"Removed source: {source.title}")

def _on_cancel_ingest(self, *_a):
self.ingestion.cancel()
self.cancel_ingest_btn.set_sensitive(False)
self.progress.set_text("Stopping…")

def _on_ingest(self, *_a):
if not self.ingestion or self.ingestion.is_running():
return
self.progress.set_visible(True)
self.progress.set_fraction(0.0)
self.ingest_btn.set_sensitive(False)
self.cancel_ingest_btn.set_sensitive(True)
self.progress.set_text("Starting…")
ingestion = self.ingestion

def progress(event, job, message):
def update():
if self.ingestion is not ingestion:
return False
if event == "start":
self.progress.set_text(f"Ingesting: {message}")
if self.cancel_ingest_btn.get_sensitive():
self.progress.set_text(f"Ingesting: {message}")
self.progress.pulse()
elif event == "done":
self.progress.pulse()
Expand All @@ -844,6 +862,11 @@ def update():

def finished(count):
def done():
if self.ingestion is not ingestion:
return False
# The completion callback can run before the worker thread exits.
if ingestion.is_running():
return True
self.progress.set_visible(False)
self.refresh_all()
self.toast(f"Ingested {count} source(s)")
Expand Down
Loading