Commit b8e47763 authored by David Boddie's avatar David Boddie 💬
Browse files

Use an idle callback, batch background work

parent 20bc5166
......@@ -20,9 +20,9 @@ from .package_info import Worker
class Application(Gtk.Application):
def __init__(self):
super().__init__(application_id='sm.puri.Get_Package_Info')
GLib.set_application_name('Get Package Info')
GLib.set_prgname('sm.puri.Get_Package_Info')
super().__init__(application_id='librem5_package_info_tool')
GLib.set_application_name('Librem 5 Package Information')
GLib.set_prgname('librem5_package_info_tool')
self.timeout_id = None
self.lines = []
......@@ -31,15 +31,15 @@ class Application(Gtk.Application):
def do_activate(self):
window = Gtk.ApplicationWindow(application=self)
window.set_icon_name('sm.puri.Get_Package_Info')
window.set_icon_name('librem5_package_info_tool')
header = Gtk.HeaderBar(title=_('Get Package Info'),
header = Gtk.HeaderBar(title=_('Librem 5 Package Information'),
show_close_button=True)
window.set_titlebar(header)
self.layout = Gtk.Box(orientation='vertical', margin=8, spacing=12)
if os.path.exists(self.output_dir):
if os.path.exists(os.path.join(self.output_dir, 'index.html')):
question_label = Gtk.Label()
question_label.set_markup(_('<b>Existing information is available.</b>'))
......@@ -106,7 +106,7 @@ class Application(Gtk.Application):
self.state = 'sources'
self.iter = self.worker.read_sources()
self.timeout_id = GLib.timeout_add(1, self.timeout, None)
self.timeout_id = GLib.idle_add(self.timeout, None)
def timeout(self, user_data):
......@@ -118,17 +118,18 @@ class Application(Gtk.Application):
def read_source(self):
try:
info = self.iter.__next__()
for i in range(250):
info = self.iter.__next__()
suite_name, i, total = info
if self.lines[-1] != suite_name:
self.lines.append(suite_name)
suite_name, i, total = info
self.progress.set_text('%i/%i' % (i, total))
self.progress.set_fraction(i/total)
if self.lines[-1] != suite_name:
self.lines.append(suite_name)
self.update_label()
except StopIteration:
# Start a new timer and stop the current one.
self.progress.set_fraction(1.0)
self.state = 'listing'
self.lines.append(_('Listing packages'))
self.lines.append('')
......@@ -140,8 +141,10 @@ class Application(Gtk.Application):
def list_package(self):
try:
name = self.iter.__next__()
self.lines[-1] = name
for i in range(100):
name = self.iter.__next__()
self.lines[-1] = name
self.update_label()
except StopIteration:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment