From d20848878aacc584aec6d7b7305c44f43b67281d Mon Sep 17 00:00:00 2001 From: Tilman Kranz Date: Tue, 18 Jul 2023 23:12:56 +0200 Subject: [PATCH] modified button layout; monospace font textview; spinner (WIP) --- bin/simple-apt-update | 86 ++++++++++++++++++++++++++++++------------- 1 file changed, 61 insertions(+), 25 deletions(-) diff --git a/bin/simple-apt-update b/bin/simple-apt-update index 432649b..8064de1 100755 --- a/bin/simple-apt-update +++ b/bin/simple-apt-update @@ -78,6 +78,12 @@ class UpdateWindow(Gtk.ApplicationWindow): def run(self, args, ignore_stderr=False, output_msg=None, empty_msg=None, env={}): + self.clear() + self.lock() + self.spinner.start() + self.prepend_mesg( + "INFO", + "Running command \"%s\" ..." % " ".join(args)) p = subprocess.Popen( args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False, env=dict(os.environ, **env)) @@ -113,6 +119,9 @@ class UpdateWindow(Gtk.ApplicationWindow): done = True break + self.spinner.stop() + self.unlock() + if error: return False else: @@ -134,28 +143,36 @@ class UpdateWindow(Gtk.ApplicationWindow): self.upgrade_button.set_sensitive(True) self.list_button.set_sensitive(True) - def on_upgrade(self, *args): - self.clear() + def upgrade(self): + args = ['/usr/bin/apt-get', '-yqq', 'full-upgrade'] + env = {'DEBIAN_FRONTEND': 'noninteractive'} self.run( - ['/usr/bin/apt-get', '-y', 'full-upgrade'], - env={'DEBIAN_FRONTEND': 'noninteractive'}) - self.append_mesg("INFO", "Upgrade done.") + args, + env=env, + empty_msg="No package upgrades were performed.") + + def on_upgrade(self, *args): + self.upgrade() + + def update(self): + args = ['/usr/bin/apt-get', '-y', 'update'] + env = {'DEBIAN_FRONTEND': 'noninteractive'} + self.run(args, env=env) def on_update(self, *args): - self.clear() - self.run( - ['/usr/bin/apt-get', '-y', 'update'], - env={'DEBIAN_FRONTEND': 'noninteractive'}) - self.append_mesg("INFO", "The package cache was updated.") + self.update() - def on_list(self, *args): - self.clear() + def list(self): + args = ['/usr/bin/apt', '-qq', 'list', '--upgradable'] self.run( - ['/usr/bin/apt', '-qq', 'list', '--upgradable'], + args, ignore_stderr=True, output_msg="Found the following package upgrades:", empty_msg="Currently there are no available package upgrades.") + def on_list(self, *args): + self.list() + def on_ctrl_w(self, *args): self.app.quit() @@ -180,20 +197,38 @@ class UpdateWindow(Gtk.ApplicationWindow): hbox = Gtk.Box(spacing=6, orientation=Gtk.Orientation.VERTICAL) self.add(hbox) - self.update_button = Gtk.Button.new_with_label( - "Update the Package Cache") - self.update_button.connect("clicked", self.on_update) - hbox.pack_start(self.update_button, True, True, 0) + grid = Gtk.Grid() + grid.set_row_spacing(5) + grid.set_column_spacing(5) + hbox.add(grid) - self.upgrade_button = Gtk.Button.new_with_label( - "Apply all Package Upgrades") - self.upgrade_button.connect("clicked", self.on_upgrade) - hbox.pack_start(self.upgrade_button, True, True, 0) + self.update_button = Gtk.Button.new_with_label( + "Update Cache") + self.update_button.connect("clicked", self.on_update) + grid.attach(self.update_button, 0, 0, 1, 1) self.list_button = Gtk.Button.new_with_label( - "List available Package Updates") + "List Upgrades") self.list_button.connect("clicked", self.on_list) - hbox.pack_start(self.list_button, True, True, 0) + grid.attach(self.list_button, 1, 0, 1, 1) + + self.upgrade_button = Gtk.Button.new_from_icon_name( + "gtk-apply", Gtk.IconSize.BUTTON) + self.upgrade_button.set_tooltip_text( + "Download and install all available upgrades") + self.upgrade_button.connect("clicked", self.on_upgrade) + grid.attach(self.upgrade_button, 2, 0, 1, 1) + + self.spinner = Gtk.Spinner() + self.spinner.set_hexpand(True) + grid.attach(self.spinner, 4, 0, 1, 1) + + self.quit_button = Gtk.Button.new_from_icon_name( + "gtk-cancel", Gtk.IconSize.BUTTON) + self.quit_button.set_tooltip_text("Exit the program") + self.quit_button.set_halign(Gtk.Align.END) + self.quit_button.connect("clicked", self.on_ctrl_w) + grid.attach(self.quit_button, 4, 0, 1, 1) self.scrolledwindow = Gtk.ScrolledWindow() self.scrolledwindow.set_hexpand(True) @@ -204,6 +239,7 @@ class UpdateWindow(Gtk.ApplicationWindow): text_view = Gtk.TextView(buffer=self.buffer) text_view.set_editable(False) + text_view.set_monospace(True) text_view.set_cursor_visible(False) self.scrolledwindow.add(text_view) @@ -214,8 +250,8 @@ def on_activate(app): win = UpdateWindow(app) win.present() win.show_all() - win.on_update() - win.on_list() + win.update() + win.list() app = Gtk.Application(application_id='org.linuxfoo.SimpleAptUpdate')