diff --git a/bin/simple-apt-update b/bin/simple-apt-update index 7170658..6c1f853 100755 --- a/bin/simple-apt-update +++ b/bin/simple-apt-update @@ -72,47 +72,56 @@ class UpdateWindow(Gtk.ApplicationWindow): else: return "grey" - def prepend_mesg(self, level, text): - self.prepend(text) - self.prepend_color(level + ": ", self.level_to_color(level)) - def append_mesg(self, level, text): - self.append_color(level + ": ", self.level_to_color(level)) + self.append_color( + level + ": ", + self.level_to_color(level) + ) self.append(text) - def prepend_markup(self, markup): - self.insert_markup(markup, self.buffer.get_start_iter()) - def append_markup(self, markup): - self.insert_markup(markup, self.buffer.get_end_iter()) + self.insert_markup( + markup, + self.buffer.get_end_iter() + ) def insert_markup(self, markup, iter): self.buffer.insert_markup(iter, markup, -1) - def prepend_color(self, text, color): - self.insert_color(text, color, self.buffer.get_start_iter()) - def append_color(self, text, color): - self.insert_color(text, color, self.buffer.get_end_iter()) + self.insert_color( + text, + color, + self.buffer.get_end_iter() + ) def insert_color(self, text, color, iter): self.buffer.insert_markup( iter, - "%s" % (color, html.escape(text)), + "%s" % ( + color, + html.escape(text)), -1) - def prepend(self, text): - self.insert(text, self.buffer.get_start_iter()) - def append(self, text): - self.insert(text, self.buffer.get_end_iter()) + self.insert( + text, + self.buffer.get_end_iter() + ) self.scroll_to_bottom() def insert(self, text, iter): self.buffer.insert(iter, text + "\n") - def execute(self, args, ignore_stderr=False, output_msg=None, - empty_msg=None, env={}, clear=True): + def execute( + self, + args, + ignore_stderr=False, + output_msg=None, + empty_msg=None, + env={}, + clear=True + ): self.lock() if clear: @@ -123,15 +132,22 @@ class UpdateWindow(Gtk.ApplicationWindow): self.ignore_stderr = ignore_stderr self.stdout = '' self.stderr = '' - self.prepend_mesg( + self.append_mesg( "INFO", "Running command \"%s\" ..." % " ".join(args)) - thread = threading.Thread(target=self.run, args=(args, env,)) + + thread = threading.Thread( + target=self.run, + args=(args, env,)) + thread.start() def run(self, args, env={}): p = subprocess.Popen( - args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=False, + args, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + shell=False, env=dict(os.environ, **env)) sel = selectors.DefaultSelector() @@ -194,7 +210,7 @@ class UpdateWindow(Gtk.ApplicationWindow): ignore_stderr=True, clear=clear, output_msg="Found the following package upgrades:", - empty_msg="Currently there are no available package upgrades.") + empty_msg="No package upgrades found.") def on_list(self, *args): self.list() @@ -240,20 +256,30 @@ class UpdateWindow(Gtk.ApplicationWindow): return True def __init__(self, application): - super(UpdateWindow, self).__init__( + super( + UpdateWindow, + self + ).__init__( application=application, - title="Simple APT Update") + title="Simple APT Update" + ) + self.application = application self.stdout_queue = queue.Queue() self.stderr_queue = queue.Queue() - GLib.timeout_add(100, self.update_buffer) + self.init_ui() + GLib.timeout_add(100, self.update_buffer) + def init_ui(self): self.set_border_width(10) self.set_default_size(630, 390) - hbox = Gtk.Box(spacing=6, orientation=Gtk.Orientation.VERTICAL) + hbox = Gtk.Box( + spacing=6, + orientation=Gtk.Orientation.VERTICAL + ) self.add(hbox) grid = Gtk.Grid() @@ -272,9 +298,12 @@ class UpdateWindow(Gtk.ApplicationWindow): grid.attach(self.list_button, 1, 0, 1, 1) self.upgrade_button = Gtk.Button.new_from_icon_name( - "gtk-apply", Gtk.IconSize.BUTTON) + "gtk-apply", + Gtk.IconSize.BUTTON + ) self.upgrade_button.set_tooltip_text( - "Download and install all available upgrades") + "Download and install all available upgrades" + ) self.upgrade_button.connect("clicked", self.on_upgrade) grid.attach(self.upgrade_button, 2, 0, 1, 1) @@ -283,7 +312,9 @@ class UpdateWindow(Gtk.ApplicationWindow): grid.attach(self.spinner, 3, 0, 1, 1) self.quit_button = Gtk.Button.new_from_icon_name( - "exit", Gtk.IconSize.BUTTON) + "exit", + 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_quit) @@ -307,9 +338,16 @@ class UpdateWindow(Gtk.ApplicationWindow): class SimpleAptUpdate(Gtk.Application): def __init__(self): - super().__init__(application_id='de.linuxfoo.SimpleAptUpdate', - flags=Gio.ApplicationFlags.FLAGS_NONE) + super( + SimpleAptUpdate, + self + ).__init__( + application_id='de.linuxfoo.SimpleAptUpdate', + flags=Gio.ApplicationFlags.FLAGS_NONE + ) + self.connect('activate', self.on_activate) + signal.signal(signal.SIGINT, signal.SIG_DFL) def do_command_line(self, cmdline): @@ -321,7 +359,10 @@ class SimpleAptUpdate(Gtk.Application): action = Gio.SimpleAction.new("quit", None) action.connect("activate", self.window.on_quit) self.add_action(action) - self.set_accels_for_action('app.quit', ['q', 'w']) + self.set_accels_for_action( + 'app.quit', + ['q', 'w'] + ) action = Gio.SimpleAction.new("update", None) action.connect("activate", self.window.on_update) @@ -355,3 +396,5 @@ def main(): if __name__ == '__main__': main() + +# vim:fenc=utf-8:et:ts=4:sw=4