Tuesday, 31 August 2021

Using Thread in Gtk+3 Application

The script shows how to run a time consuming process in a Gtk+3 application. While the process is running in background, the process itself as well as the user are allowed to access the UI of the application. This can be achieved by starting the process in a separate thread instead of the main loop of the Gtk application.

Some skills are applied in this script:

  1. The use of thread module in running a time consuming process which is separated from the main loop of a GTK app.
  2. The use of Gtk.TextView() to keep a textual content, update and retrieval of the content through the textbuffer of the textview.
  3. Adjust the vertical position of a scroll window according the to size of the textview hold by it, allowing the scroll window to show the newly added text at the bottom part of it. See self.txtview.connect("size-allocate", self.autoscroll) below.
  4. The use of GLib.idle_add() in a time consuming process to show the progress of it through an UI of the GTK app.

Reference

PyGObject, Threads & Concurrency

Source Code



No comments:

Post a Comment